From fcd9f69f807f8254d49e05245537fedefe6e4421 Mon Sep 17 00:00:00 2001 From: Davide Oddone Date: Sun, 10 Dec 2023 20:08:55 +0100 Subject: [PATCH] New structure for kak config folder --- autoload/default | 1 + autoload/snippets/golang.kak | 34 ++++++++++++++++++++++++++++++++++ kakrc | 18 ++++++++++++++++++ 3 files changed, 53 insertions(+) create mode 120000 autoload/default create mode 100644 autoload/snippets/golang.kak diff --git a/autoload/default b/autoload/default new file mode 120000 index 0000000..b45d656 --- /dev/null +++ b/autoload/default @@ -0,0 +1 @@ +/usr/share/kak/autoload \ No newline at end of file diff --git a/autoload/snippets/golang.kak b/autoload/snippets/golang.kak new file mode 100644 index 0000000..048cfcb --- /dev/null +++ b/autoload/snippets/golang.kak @@ -0,0 +1,34 @@ +hook global BufSetOption filetype=go %{ + set buffer snippets %opt{snippets} # keep global snippets (if any) + # Main structure of a go file + set -add buffer snippets 'init-structure' 'inist' \ + %{ phantom-selection-clear ; snippets-insert %{package main + +import(${}) + +func main() {${}} + }; phantom-selection-add-selection ; phantom-selection-iterate-next } + + # Basic read file and populate array + set -add buffer snippets 'read-populate' 'rbufpop' \ + %{ phantom-selection-clear ; snippets-insert %{file, err := os.Open("${}") +check(err) +defer file.Close() + +${} := make([]string, 0) + +scanner := bufio.NewScanner(file) +for scanner.Scan() { + lines = append(${}, scanner.Text()) +} + }; phantom-selection-add-selection ; phantom-selection-iterate-next } +} + +# With phantom +#set -add buffer snippets 'name' 'short' \ +# %{ phantom-selection-clear ; snippets-insert %{snippet-here +#}; phantom-selection-add-selection ; phantom-selection-iterate-next } +# +# Without phantom +#set -add buffer snippets 'name' 'short' %{ snippets-insert %snippet-here{ +#}} diff --git a/kakrc b/kakrc index 773d641..1342717 100644 --- a/kakrc +++ b/kakrc @@ -1,6 +1,24 @@ # Load plug.kak source "%val{config}/plugins/plug.kak/rc/plug.kak" plug "andreyorst/plug.kak" noload +# plug kakoune-snippets +plug "occivink/kakoune-snippets" +plug "occivink/kakoune-phantom-selection" config %{ + map global user f ": phantom-selection-add-selection" + map global user F ": phantom-selection-select-all; phantom-selection-clear" + map global user ": phantom-selection-iterate-next" + map global user ": phantom-selection-iterate-prev" + + # this would be nice, but currrently doesn't work + # see https://github.com/mawww/kakoune/issues/1916 + #map global insert ": phantom-selection-iterate-next" + #map global insert ": phantom-selection-iterate-prev" + # so instead, have an approximate version that uses 'i' + map global insert ": phantom-selection-iterate-nexti" + map global insert ": phantom-selection-iterate-previ" +} +# plug collection of snippets +plug "andreyorst/kakoune-snippet-collection" # plug auto-pairs plug "alexherbo2/auto-pairs.kak" # plug kak-lsp