From c0dccdd90dd615cf663d95fd94fbdbdf2a88b165 Mon Sep 17 00:00:00 2001 From: Alex Leferry 2 Date: Mon, 18 Mar 2019 19:56:34 +0100 Subject: Add categories in rc/ Closes #2783 --- rc/base/autowrap.kak | 48 --- rc/base/clojure.kak | 208 ---------- rc/base/css.kak | 76 ---- rc/base/ctags.kak | 123 ------ rc/base/d.kak | 132 ------- rc/base/etc.kak | 79 ---- rc/base/file.kak | 17 - rc/base/fish.kak | 84 ---- rc/base/gas.kak | 91 ----- rc/base/git.kak | 40 -- rc/base/go.kak | 97 ----- rc/base/haskell.kak | 105 ----- rc/base/html.kak | 75 ---- rc/base/ini.kak | 15 - rc/base/java.kak | 65 --- rc/base/javascript.kak | 117 ------ rc/base/json.kak | 60 --- rc/base/julia.kak | 30 -- rc/base/lint.kak | 176 --------- rc/base/lisp.kak | 74 ---- rc/base/lua.kak | 103 ----- rc/base/mail.kak | 13 - rc/base/markdown.kak | 85 ---- rc/base/mercurial.kak | 18 - rc/base/new-client.kak | 12 - rc/base/ocaml.kak | 38 -- rc/base/perl.kak | 114 ------ rc/base/restructuredtext.kak | 74 ---- rc/base/ruby.kak | 168 -------- rc/base/rust.kak | 88 ----- rc/base/scala.kak | 75 ---- rc/base/screen.kak | 69 ---- rc/base/spell.kak | 121 ------ rc/base/sql.kak | 107 ----- rc/base/swift.kak | 28 -- rc/base/tmux.kak | 61 --- rc/base/x11.kak | 73 ---- rc/base/yaml.kak | 58 --- rc/core/asciidoc.kak | 43 -- rc/core/c-family.kak | 437 --------------------- rc/core/comment.kak | 180 --------- rc/core/diff.kak | 13 - rc/core/doc.kak | 165 -------- rc/core/formatter.kak | 31 -- rc/core/grep.kak | 73 ---- rc/core/kakrc.kak | 110 ------ rc/core/make.kak | 84 ---- rc/core/makefile.kak | 60 --- rc/core/man.kak | 68 ---- rc/core/python.kak | 148 ------- rc/core/sh.kak | 43 -- rc/detection/editorconfig.kak | 57 +++ rc/detection/file.kak | 17 + rc/detection/modeline.kak | 102 +++++ rc/extra/arch-linux.kak | 4 - rc/extra/autorestore.kak | 71 ---- rc/extra/cabal.kak | 74 ---- rc/extra/clang.kak | 180 --------- rc/extra/cmake.kak | 27 -- rc/extra/coffee.kak | 79 ---- rc/extra/cucumber.kak | 89 ----- rc/extra/dart.kak | 106 ----- rc/extra/dockerfile.kak | 48 --- rc/extra/editorconfig.kak | 57 --- rc/extra/elixir.kak | 77 ---- rc/extra/elm.kak | 67 ---- rc/extra/exherbo.kak | 121 ------ rc/extra/git-tools.kak | 214 ---------- rc/extra/go-tools.kak | 182 --------- rc/extra/haml.kak | 62 --- rc/extra/hbs.kak | 97 ----- rc/extra/i3.kak | 81 ---- rc/extra/iterm.kak | 131 ------ rc/extra/jedi.kak | 47 --- rc/extra/just.kak | 48 --- rc/extra/kickstart.kak | 30 -- rc/extra/kitty.kak | 65 --- rc/extra/latex.kak | 35 -- rc/extra/modeline.kak | 102 ----- rc/extra/moon.kak | 107 ----- rc/extra/nim.kak | 112 ------ rc/extra/php.kak | 90 ----- rc/extra/pony.kak | 92 ----- rc/extra/protobuf.kak | 85 ---- rc/extra/pug.kak | 74 ---- rc/extra/racer.kak | 153 -------- rc/extra/ragel.kak | 70 ---- rc/extra/ranger.kak | 59 --- rc/extra/sass.kak | 62 --- rc/extra/scheme.kak | 133 ------- rc/extra/scss.kak | 45 --- rc/extra/systemd.kak | 14 - rc/extra/taskpaper.kak | 47 --- rc/extra/tmux-repl.kak | 67 ---- rc/extra/toml.kak | 63 --- rc/extra/troff.kak | 30 -- rc/extra/tupfile.kak | 33 -- rc/extra/void-linux.kak | 4 - rc/extra/x11-repl.kak | 26 -- rc/filetype/arch-linux.kak | 4 + rc/filetype/asciidoc.kak | 43 ++ rc/filetype/c-family.kak | 437 +++++++++++++++++++++ rc/filetype/cabal.kak | 74 ++++ rc/filetype/clojure.kak | 208 ++++++++++ rc/filetype/cmake.kak | 27 ++ rc/filetype/coffee.kak | 79 ++++ rc/filetype/css.kak | 76 ++++ rc/filetype/cucumber.kak | 89 +++++ rc/filetype/d.kak | 132 +++++++ rc/filetype/dart.kak | 106 +++++ rc/filetype/diff.kak | 13 + rc/filetype/dockerfile.kak | 48 +++ rc/filetype/elixir.kak | 77 ++++ rc/filetype/elm.kak | 67 ++++ rc/filetype/etc.kak | 79 ++++ rc/filetype/exherbo.kak | 121 ++++++ rc/filetype/fish.kak | 84 ++++ rc/filetype/gas.kak | 91 +++++ rc/filetype/git.kak | 40 ++ rc/filetype/go.kak | 97 +++++ rc/filetype/haml.kak | 62 +++ rc/filetype/haskell.kak | 105 +++++ rc/filetype/hbs.kak | 97 +++++ rc/filetype/html.kak | 75 ++++ rc/filetype/i3.kak | 81 ++++ rc/filetype/ini.kak | 15 + rc/filetype/java.kak | 65 +++ rc/filetype/javascript.kak | 117 ++++++ rc/filetype/json.kak | 60 +++ rc/filetype/julia.kak | 30 ++ rc/filetype/just.kak | 48 +++ rc/filetype/kakrc.kak | 110 ++++++ rc/filetype/kickstart.kak | 30 ++ rc/filetype/latex.kak | 35 ++ rc/filetype/lisp.kak | 74 ++++ rc/filetype/lua.kak | 103 +++++ rc/filetype/mail.kak | 13 + rc/filetype/makefile.kak | 60 +++ rc/filetype/markdown.kak | 85 ++++ rc/filetype/mercurial.kak | 18 + rc/filetype/moon.kak | 107 +++++ rc/filetype/nim.kak | 112 ++++++ rc/filetype/ocaml.kak | 38 ++ rc/filetype/perl.kak | 114 ++++++ rc/filetype/php.kak | 90 +++++ rc/filetype/pony.kak | 92 +++++ rc/filetype/protobuf.kak | 85 ++++ rc/filetype/pug.kak | 74 ++++ rc/filetype/python.kak | 148 +++++++ rc/filetype/ragel.kak | 70 ++++ rc/filetype/restructuredtext.kak | 74 ++++ rc/filetype/ruby.kak | 168 ++++++++ rc/filetype/rust.kak | 88 +++++ rc/filetype/sass.kak | 62 +++ rc/filetype/scala.kak | 75 ++++ rc/filetype/scheme.kak | 133 +++++++ rc/filetype/scss.kak | 45 +++ rc/filetype/sh.kak | 43 ++ rc/filetype/sql.kak | 107 +++++ rc/filetype/swift.kak | 28 ++ rc/filetype/systemd.kak | 14 + rc/filetype/taskpaper.kak | 47 +++ rc/filetype/toml.kak | 63 +++ rc/filetype/troff.kak | 30 ++ rc/filetype/tupfile.kak | 33 ++ rc/filetype/void-linux.kak | 4 + rc/filetype/yaml.kak | 58 +++ rc/tools/autorestore.kak | 71 ++++ rc/tools/autowrap.kak | 48 +++ rc/tools/clang.kak | 180 +++++++++ rc/tools/comment.kak | 180 +++++++++ rc/tools/ctags.kak | 123 ++++++ rc/tools/doc.kak | 165 ++++++++ rc/tools/formatter.kak | 31 ++ rc/tools/git.kak | 214 ++++++++++ rc/tools/go/go-tools.kak | 182 +++++++++ rc/tools/grep.kak | 73 ++++ rc/tools/lint.kak | 176 +++++++++ rc/tools/make.kak | 84 ++++ rc/tools/man.kak | 68 ++++ rc/tools/python/jedi.kak | 47 +++ rc/tools/ranger.kak | 59 +++ rc/tools/rust/racer.kak | 153 ++++++++ rc/tools/spell.kak | 121 ++++++ rc/windowing/iterm.kak | 131 ++++++ rc/windowing/kitty.kak | 65 +++ rc/windowing/new-client.kak | 12 + rc/windowing/screen.kak | 69 ++++ rc/windowing/tmux.kak | 61 +++ rc/windowing/tmux/repl.kak | 67 ++++ rc/windowing/x11.kak | 73 ++++ rc/windowing/x11/repl.kak | 26 ++ test/indent/c-family/align-while-expr/rc | 2 +- test/indent/c-family/close-namespace/rc | 2 +- test/indent/c-family/close-struct/rc | 2 +- test/indent/c-family/comment-line-continuation/rc | 2 +- test/indent/c-family/construct-align/rc | 2 +- test/indent/c-family/deindent-if-body/rc | 2 +- test/indent/c-family/indent-after-parenthesis/rc | 2 +- test/indent/c-family/indent-if-body/rc | 2 +- test/indent/c-family/indent-if-brace/rc | 2 +- test/indent/c-family/move-brace/rc | 2 +- test/indent/c-family/multiline-nested-align/rc | 2 +- test/indent/c-family/nested-align/rc | 2 +- test/indent/c-family/open-function/rc | 2 +- .../comment/comment-multiple-lines-indented/rc | 4 +- .../comment/comment-multiple-lines-unindented/rc | 4 +- .../rc | 4 +- .../comment/uncomment-multiple-indented-lines/rc | 4 +- test/indent/haskell/before-comment/rc | 2 +- test/indent/haskell/indented-comment/rc | 2 +- test/indent/haskell/inside-comment/rc | 2 +- test/indent/html/indent-closing-tag/rc | 2 +- test/indent/lua/insert-end-only-when-needed/rc | 2 +- test/indent/markdown/inside-complex-blockquote/rc | 2 +- test/indent/markdown/inside-list-item/rc | 2 +- test/indent/markdown/inside-nested-list-item/rc | 2 +- test/indent/markdown/inside-simple-blockquote/rc | 2 +- test/indent/markdown/inside-strong-emphasis/rc | 2 +- test/indent/markdown/list-item/rc | 2 +- .../indent/markdown/open-after-setext-heading-1/rc | 2 +- .../indent/markdown/open-after-setext-heading-2/rc | 2 +- .../following-blocks-should-not-prevent-end/rc | 2 +- test/indent/ruby/indent-after-class/rc | 2 +- .../ruby/method-definition-shouldnt-duplicate/rc | 2 +- .../1074-comment-leader-autoinsert-error/rc | 2 +- .../rc | 2 +- test/regression/1118-misaligned-comment-start/rc | 2 +- .../rc | 2 +- test/regression/1525-lua-indent-error/rc | 2 +- .../1920-crash-on-python-in-docstring/rc | 2 +- test/regression/2499-html-regions-assert/rc | 2 +- test/regression/860-python-incorrect-commenting/rc | 2 +- .../regression/872-indentation-misbeahviour-c++/rc | 2 +- test/regression/918-wrong-asterisk-inserted/rc | 2 +- 235 files changed, 7979 insertions(+), 7979 deletions(-) delete mode 100644 rc/base/autowrap.kak delete mode 100644 rc/base/clojure.kak delete mode 100644 rc/base/css.kak delete mode 100644 rc/base/ctags.kak delete mode 100644 rc/base/d.kak delete mode 100644 rc/base/etc.kak delete mode 100644 rc/base/file.kak delete mode 100644 rc/base/fish.kak delete mode 100644 rc/base/gas.kak delete mode 100644 rc/base/git.kak delete mode 100644 rc/base/go.kak delete mode 100644 rc/base/haskell.kak delete mode 100644 rc/base/html.kak delete mode 100644 rc/base/ini.kak delete mode 100644 rc/base/java.kak delete mode 100644 rc/base/javascript.kak delete mode 100644 rc/base/json.kak delete mode 100644 rc/base/julia.kak delete mode 100644 rc/base/lint.kak delete mode 100644 rc/base/lisp.kak delete mode 100644 rc/base/lua.kak delete mode 100644 rc/base/mail.kak delete mode 100644 rc/base/markdown.kak delete mode 100644 rc/base/mercurial.kak delete mode 100644 rc/base/new-client.kak delete mode 100644 rc/base/ocaml.kak delete mode 100644 rc/base/perl.kak delete mode 100644 rc/base/restructuredtext.kak delete mode 100644 rc/base/ruby.kak delete mode 100644 rc/base/rust.kak delete mode 100644 rc/base/scala.kak delete mode 100644 rc/base/screen.kak delete mode 100644 rc/base/spell.kak delete mode 100644 rc/base/sql.kak delete mode 100644 rc/base/swift.kak delete mode 100644 rc/base/tmux.kak delete mode 100644 rc/base/x11.kak delete mode 100644 rc/base/yaml.kak delete mode 100644 rc/core/asciidoc.kak delete mode 100644 rc/core/c-family.kak delete mode 100644 rc/core/comment.kak delete mode 100644 rc/core/diff.kak delete mode 100644 rc/core/doc.kak delete mode 100644 rc/core/formatter.kak delete mode 100644 rc/core/grep.kak delete mode 100644 rc/core/kakrc.kak delete mode 100644 rc/core/make.kak delete mode 100644 rc/core/makefile.kak delete mode 100644 rc/core/man.kak delete mode 100644 rc/core/python.kak delete mode 100644 rc/core/sh.kak create mode 100644 rc/detection/editorconfig.kak create mode 100644 rc/detection/file.kak create mode 100644 rc/detection/modeline.kak delete mode 100644 rc/extra/arch-linux.kak delete mode 100644 rc/extra/autorestore.kak delete mode 100644 rc/extra/cabal.kak delete mode 100644 rc/extra/clang.kak delete mode 100644 rc/extra/cmake.kak delete mode 100644 rc/extra/coffee.kak delete mode 100644 rc/extra/cucumber.kak delete mode 100644 rc/extra/dart.kak delete mode 100644 rc/extra/dockerfile.kak delete mode 100644 rc/extra/editorconfig.kak delete mode 100644 rc/extra/elixir.kak delete mode 100644 rc/extra/elm.kak delete mode 100644 rc/extra/exherbo.kak delete mode 100644 rc/extra/git-tools.kak delete mode 100644 rc/extra/go-tools.kak delete mode 100644 rc/extra/haml.kak delete mode 100644 rc/extra/hbs.kak delete mode 100644 rc/extra/i3.kak delete mode 100644 rc/extra/iterm.kak delete mode 100644 rc/extra/jedi.kak delete mode 100644 rc/extra/just.kak delete mode 100644 rc/extra/kickstart.kak delete mode 100644 rc/extra/kitty.kak delete mode 100644 rc/extra/latex.kak delete mode 100644 rc/extra/modeline.kak delete mode 100644 rc/extra/moon.kak delete mode 100644 rc/extra/nim.kak delete mode 100644 rc/extra/php.kak delete mode 100644 rc/extra/pony.kak delete mode 100644 rc/extra/protobuf.kak delete mode 100644 rc/extra/pug.kak delete mode 100644 rc/extra/racer.kak delete mode 100644 rc/extra/ragel.kak delete mode 100644 rc/extra/ranger.kak delete mode 100644 rc/extra/sass.kak delete mode 100644 rc/extra/scheme.kak delete mode 100644 rc/extra/scss.kak delete mode 100644 rc/extra/systemd.kak delete mode 100644 rc/extra/taskpaper.kak delete mode 100644 rc/extra/tmux-repl.kak delete mode 100644 rc/extra/toml.kak delete mode 100644 rc/extra/troff.kak delete mode 100644 rc/extra/tupfile.kak delete mode 100644 rc/extra/void-linux.kak delete mode 100644 rc/extra/x11-repl.kak create mode 100644 rc/filetype/arch-linux.kak create mode 100644 rc/filetype/asciidoc.kak create mode 100644 rc/filetype/c-family.kak create mode 100644 rc/filetype/cabal.kak create mode 100644 rc/filetype/clojure.kak create mode 100644 rc/filetype/cmake.kak create mode 100644 rc/filetype/coffee.kak create mode 100644 rc/filetype/css.kak create mode 100644 rc/filetype/cucumber.kak create mode 100644 rc/filetype/d.kak create mode 100644 rc/filetype/dart.kak create mode 100644 rc/filetype/diff.kak create mode 100644 rc/filetype/dockerfile.kak create mode 100644 rc/filetype/elixir.kak create mode 100644 rc/filetype/elm.kak create mode 100644 rc/filetype/etc.kak create mode 100644 rc/filetype/exherbo.kak create mode 100644 rc/filetype/fish.kak create mode 100644 rc/filetype/gas.kak create mode 100644 rc/filetype/git.kak create mode 100644 rc/filetype/go.kak create mode 100644 rc/filetype/haml.kak create mode 100644 rc/filetype/haskell.kak create mode 100644 rc/filetype/hbs.kak create mode 100644 rc/filetype/html.kak create mode 100644 rc/filetype/i3.kak create mode 100644 rc/filetype/ini.kak create mode 100644 rc/filetype/java.kak create mode 100644 rc/filetype/javascript.kak create mode 100644 rc/filetype/json.kak create mode 100644 rc/filetype/julia.kak create mode 100644 rc/filetype/just.kak create mode 100644 rc/filetype/kakrc.kak create mode 100644 rc/filetype/kickstart.kak create mode 100644 rc/filetype/latex.kak create mode 100644 rc/filetype/lisp.kak create mode 100644 rc/filetype/lua.kak create mode 100644 rc/filetype/mail.kak create mode 100644 rc/filetype/makefile.kak create mode 100644 rc/filetype/markdown.kak create mode 100644 rc/filetype/mercurial.kak create mode 100644 rc/filetype/moon.kak create mode 100644 rc/filetype/nim.kak create mode 100644 rc/filetype/ocaml.kak create mode 100644 rc/filetype/perl.kak create mode 100644 rc/filetype/php.kak create mode 100644 rc/filetype/pony.kak create mode 100644 rc/filetype/protobuf.kak create mode 100644 rc/filetype/pug.kak create mode 100644 rc/filetype/python.kak create mode 100644 rc/filetype/ragel.kak create mode 100644 rc/filetype/restructuredtext.kak create mode 100644 rc/filetype/ruby.kak create mode 100644 rc/filetype/rust.kak create mode 100644 rc/filetype/sass.kak create mode 100644 rc/filetype/scala.kak create mode 100644 rc/filetype/scheme.kak create mode 100644 rc/filetype/scss.kak create mode 100644 rc/filetype/sh.kak create mode 100644 rc/filetype/sql.kak create mode 100644 rc/filetype/swift.kak create mode 100644 rc/filetype/systemd.kak create mode 100644 rc/filetype/taskpaper.kak create mode 100644 rc/filetype/toml.kak create mode 100644 rc/filetype/troff.kak create mode 100644 rc/filetype/tupfile.kak create mode 100644 rc/filetype/void-linux.kak create mode 100644 rc/filetype/yaml.kak create mode 100644 rc/tools/autorestore.kak create mode 100644 rc/tools/autowrap.kak create mode 100644 rc/tools/clang.kak create mode 100644 rc/tools/comment.kak create mode 100644 rc/tools/ctags.kak create mode 100644 rc/tools/doc.kak create mode 100644 rc/tools/formatter.kak create mode 100644 rc/tools/git.kak create mode 100644 rc/tools/go/go-tools.kak create mode 100644 rc/tools/grep.kak create mode 100644 rc/tools/lint.kak create mode 100644 rc/tools/make.kak create mode 100644 rc/tools/man.kak create mode 100644 rc/tools/python/jedi.kak create mode 100644 rc/tools/ranger.kak create mode 100644 rc/tools/rust/racer.kak create mode 100644 rc/tools/spell.kak create mode 100644 rc/windowing/iterm.kak create mode 100644 rc/windowing/kitty.kak create mode 100644 rc/windowing/new-client.kak create mode 100644 rc/windowing/screen.kak create mode 100644 rc/windowing/tmux.kak create mode 100644 rc/windowing/tmux/repl.kak create mode 100644 rc/windowing/x11.kak create mode 100644 rc/windowing/x11/repl.kak diff --git a/rc/base/autowrap.kak b/rc/base/autowrap.kak deleted file mode 100644 index 0fb12123..00000000 --- a/rc/base/autowrap.kak +++ /dev/null @@ -1,48 +0,0 @@ -declare-option -docstring "maximum amount of characters per line, after which a newline character will be inserted" \ - int autowrap_column 80 - -declare-option -docstring %{when enabled, paragraph formatting will reformat the whole paragraph in which characters are being inserted -This can potentially break formatting of documents containing markup (e.g. markdown)} \ - bool autowrap_format_paragraph no -declare-option -docstring %{command to which the paragraphs to wrap will be passed -all occurences of '%c' are replaced with `autowrap_column`} \ - str autowrap_fmtcmd 'fold -s -w %c' - -define-command -hidden autowrap-cursor %{ evaluate-commands -save-regs '/"|^@m' %{ - try %{ - ## if the line isn't too long, do nothing - execute-keys -draft "^[^\n]{%opt{autowrap_column},}[^\n]" - - try %{ - reg m "%val{selections_desc}" - - ## if we're adding characters past the limit, just wrap them around - execute-keys -draft ".{%opt{autowrap_column}}\h*[^\s]*1s(\h+)[^\h]*\zc" - } catch %{ - ## if we're adding characters in the middle of a sentence, use - ## the `fmtcmd` command to wrap the entire paragraph - evaluate-commands %sh{ - if [ "${kak_opt_autowrap_format_paragraph}" = true ] \ - && [ -n "${kak_opt_autowrap_fmtcmd}" ]; then - format_cmd=$(printf %s "${kak_opt_autowrap_fmtcmd}" \ - | sed "s/%c/${kak_opt_autowrap_column}/g") - printf %s " - evaluate-commands -draft %{ - execute-keys 'p|${format_cmd}' - try %{ execute-keys s\h+$ d } - } - select '${kak_main_reg_m}' - " - fi - } - } - } -} } - -define-command autowrap-enable -docstring "Automatically wrap the lines in which characters are inserted" %{ - hook -group autowrap window InsertChar [^\n] autowrap-cursor -} - -define-command autowrap-disable -docstring "Disable automatic line wrapping" %{ - remove-hooks window autowrap -} diff --git a/rc/base/clojure.kak b/rc/base/clojure.kak deleted file mode 100644 index da6134a6..00000000 --- a/rc/base/clojure.kak +++ /dev/null @@ -1,208 +0,0 @@ -# http://clojure.org -# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ - -# require lisp.kak - -# Detection -# ‾‾‾‾‾‾‾‾‾ - -hook global BufCreate .*[.](clj|cljc|cljs|cljx|edn) %{ - set-option buffer filetype clojure -} - -# Highlighters -# ‾‾‾‾‾‾‾‾‾‾‾‾ - -add-highlighter shared/clojure regions -add-highlighter shared/clojure/code default-region group -add-highlighter shared/clojure/comment region '(? ! : "'" -} - -evaluate-commands %sh{ - exec awk -f - <<'EOF' - BEGIN{ - symbol_char="[^\\s()\\[\\]{}\"\\;@^`~\\\\%/]"; - in_core="(clojure\\.core/|(? cond->> def definline definterface defmacro defmethod "\ - "defmulti defn defn- defonce defprotocol defrecord defstruct deftype fn if "\ - "if-let if-not if-some let letfn new ns when when-first when-let when-not "\ - "when-some . ..", keywords); - - split( \ - "* *' + +' - -' -> ->> ->ArrayChunk ->Eduction ->Vec ->VecNode ->VecSeq / < "\ - "<= = == > >= StackTraceElement->vec Throwable->map accessor aclone "\ - "add-classpath add-watch agent agent-error agent-errors aget alength alias "\ - "all-ns alter alter-meta! alter-var-root amap ancestors and any? apply "\ - "areduce array-map as-> aset aset-boolean aset-byte aset-char aset-double "\ - "aset-float aset-int aset-long aset-short assert assoc assoc! assoc-in "\ - "associative? atom await await-for bases bean bigdec bigint biginteger "\ - "binding bit-and bit-and-not bit-clear bit-flip bit-not bit-or bit-set "\ - "bit-shift-left bit-shift-right bit-test bit-xor boolean boolean-array "\ - "boolean? booleans bound-fn bound-fn* bound? bounded-count butlast byte "\ - "byte-array bytes bytes? cast cat catch char char-array char-escape-string "\ - "char-name-string char? chars class class? clear-agent-errors "\ - "clojure-version coll? comment commute comp comparator compare "\ - "compare-and-set! compile complement completing concat conj conj! cons "\ - "constantly construct-proxy contains? count counted? create-ns "\ - "create-struct cycle dec dec' decimal? declare dedupe default-data-readers "\ - "delay delay? deliver denominator deref derive descendants disj disj! "\ - "dissoc dissoc! distinct distinct? do doall dorun doseq dosync dotimes doto "\ - "double double-array double? doubles drop drop-last drop-while eduction "\ - "empty empty? ensure ensure-reduced enumeration-seq error-handler "\ - "error-mode eval even? every-pred every? ex-data ex-info extend "\ - "extend-protocol extend-type extenders extends? false? ffirst file-seq "\ - "filter filterv finally find find-keyword find-ns find-var first flatten "\ - "float float-array float? floats flush fn? fnext fnil for force format "\ - "frequencies future future-call future-cancel future-cancelled? "\ - "future-done? future? gen-class gen-interface gensym get get-in get-method "\ - "get-proxy-class get-thread-bindings get-validator group-by halt-when hash "\ - "hash-map hash-ordered-coll hash-set hash-unordered-coll ident? identical? "\ - "identity ifn? import in-ns inc inc' indexed? init-proxy inst-ms inst? "\ - "instance? int int-array int? integer? interleave intern interpose into "\ - "into-array ints io! isa? iterate iterator-seq juxt keep keep-indexed key "\ - "keys keyword keyword? last lazy-cat lazy-seq line-seq list list* list? "\ - "load load-file load-reader load-string loaded-libs locking long long-array "\ - "longs loop macroexpand macroexpand-1 make-array make-hierarchy map "\ - "map-entry? map-indexed map? mapcat mapv max max-key memfn memoize merge "\ - "merge-with meta methods min min-key mix-collection-hash mod monitor-enter "\ - "monitor-exit name namespace namespace-munge nat-int? neg-int? neg? newline "\ - "next nfirst nil? nnext not not-any? not-empty not-every? not= ns-aliases "\ - "ns-imports ns-interns ns-map ns-name ns-publics ns-refers ns-resolve "\ - "ns-unalias ns-unmap nth nthnext nthrest num number? numerator object-array "\ - "odd? or parents partial partition partition-all partition-by pcalls peek "\ - "persistent! pmap pop pop! pop-thread-bindings pos-int? pos? pr pr-str "\ - "prefer-method prefers print print-str printf println println-str prn "\ - "prn-str promise proxy proxy-mappings proxy-super push-thread-bindings "\ - "pvalues qualified-ident? qualified-keyword? qualified-symbol? quot quote "\ - "rand rand-int rand-nth random-sample range ratio? rational? rationalize "\ - "re-find re-groups re-matcher re-matches re-pattern re-seq read read-line "\ - "read-string reader-conditional reader-conditional? realized? record? recur "\ - "reduce reduce-kv reduced reduced? reductions ref ref-history-count "\ - "ref-max-history ref-min-history ref-set refer refer-clojure reify "\ - "release-pending-sends rem remove remove-all-methods remove-method "\ - "remove-ns remove-watch repeat repeatedly replace replicate require reset! "\ - "reset-meta! reset-vals! resolve rest restart-agent resultset-seq reverse "\ - "reversible? rseq rsubseq run! satisfies? second select-keys send send-off "\ - "send-via seq seq? seqable? seque sequence sequential? set set! "\ - "set-agent-send-executor! set-agent-send-off-executor! set-error-handler! "\ - "set-error-mode! set-validator! set? short short-array shorts shuffle "\ - "shutdown-agents simple-ident? simple-keyword? simple-symbol? slurp some "\ - "some-> some->> some-fn some? sort sort-by sorted-map sorted-map-by "\ - "sorted-set sorted-set-by sorted? special-symbol? spit split-at split-with "\ - "str string? struct struct-map subs subseq subvec supers swap! swap-vals! "\ - "symbol symbol? sync tagged-literal tagged-literal? take take-last take-nth "\ - "take-while test the-ns thread-bound? throw time to-array to-array-2d "\ - "trampoline transduce transient tree-seq true? try type unchecked-add "\ - "unchecked-add-int unchecked-byte unchecked-char unchecked-dec "\ - "unchecked-dec-int unchecked-divide-int unchecked-double unchecked-float "\ - "unchecked-inc unchecked-inc-int unchecked-int unchecked-long "\ - "unchecked-multiply unchecked-multiply-int unchecked-negate "\ - "unchecked-negate-int unchecked-remainder-int unchecked-short "\ - "unchecked-subtract unchecked-subtract-int underive unreduced "\ - "unsigned-bit-shift-right update update-in update-proxy uri? use uuid? val "\ - "vals var var-get var-set var? vary-meta vec vector vector-of vector? "\ - "volatile! volatile? vreset! vswap! while with-bindings with-bindings* "\ - "with-in-str with-local-vars with-meta with-open with-out-str "\ - "with-precision with-redefs with-redefs-fn xml-seq zero? zipmap", core_fns); - - split( \ - "*1 *2 *3 *agent* *clojure-version* *command-line-args* *compile-files* "\ - "*compile-path* *compiler-options* *data-readers* *default-data-reader-fn* "\ - "*e *err* *file* *flush-on-newline* *in* *ns* *out* *print-dup* "\ - "*print-length* *print-level* *print-meta* *print-namespace-maps* "\ - "*print-readably* *read-eval* *unchecked-math* *warn-on-reflection*", core_vars); - } - function print_word_highlighter(words, face, first) { - printf("add-highlighter shared/clojure/code/ regex (?"wZ' - - try %{ - # If a special form, indent another (indentwidth - 1) spaces - execute-keys -draft '"wze\A' %opt{clojure_special_indent_forms} '\z' - execute-keys -draft '"wzes.{' %sh{printf $(( kak_opt_indentwidth - 1 ))} '}\K.*;"i' - } catch %{ - # If not special and parameter appears on line 1, indent to parameter - execute-keys -draft '"wzes\h\K[^\s].*;"i' - } - } - try %{ execute-keys -draft '[rl"i' } - try %{ execute-keys -draft '[Bl"i' } - execute-keys -draft ';"ia&' - } -} - -# Initialization -# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ -hook -group clojure-highlight global WinSetOption filetype=clojure %{ - add-highlighter window/clojure ref clojure - hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/clojure } -} - -hook global WinSetOption filetype=clojure %[ - hook window ModeChange insert:.* -group clojure-trim-indent clojure-trim-indent - hook window InsertChar \n -group clojure-indent clojure-indent-on-new-line - - hook -once -always window WinSetOption filetype=.* %{ remove-hooks window clojure-.+ } -] diff --git a/rc/base/css.kak b/rc/base/css.kak deleted file mode 100644 index ecc456ed..00000000 --- a/rc/base/css.kak +++ /dev/null @@ -1,76 +0,0 @@ -# http://w3.org/Style/CSS -# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ - -# Detection -# ‾‾‾‾‾‾‾‾‾ - -hook global BufCreate .*[.](css) %{ - set-option buffer filetype css -} - -# Highlighters -# ‾‾‾‾‾‾‾‾‾‾‾‾ - -add-highlighter shared/css regions -add-highlighter shared/css/selector default-region group -add-highlighter shared/css/declaration region [{] [}] regions -add-highlighter shared/css/comment region /[*] [*]/ fill comment - -add-highlighter shared/css/declaration/base default-region group -add-highlighter shared/css/declaration/double_string region '"' (? s \h+$ d } -} - -define-command -hidden css-indent-on-new-line %[ - evaluate-commands -draft -itersel %[ - # preserve previous line indent - try %[ execute-keys -draft \; K ] - # filter previous line - try %[ execute-keys -draft k : css-trim-indent ] - # indent after lines ending with with { - try %[ execute-keys -draft k \{$ j ] - ] -] - -define-command -hidden css-indent-on-closing-curly-brace %[ - evaluate-commands -draft -itersel %[ - # align to opening curly brace when alone on a line - try %[ execute-keys -draft ^\h+\}$ m s \A|.\z 1 ] - ] -] - -# Initialization -# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ - -hook -group css-highlight global WinSetOption filetype=css %{ - add-highlighter window/css ref css - hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/css } -} - -hook global WinSetOption filetype=css %[ - hook window ModeChange insert:.* -group css-trim-indent css-trim-indent - hook window InsertChar \n -group css-indent css-indent-on-new-line - hook window InsertChar \} -group css-indent css-indent-on-closing-curly-brace - set-option buffer extra_word_chars '_' '-' - - hook -once -always window WinSetOption filetype=.* %{ remove-hooks window css-.+ } -] diff --git a/rc/base/ctags.kak b/rc/base/ctags.kak deleted file mode 100644 index 20eabac0..00000000 --- a/rc/base/ctags.kak +++ /dev/null @@ -1,123 +0,0 @@ -# Kakoune Exuberant CTags support script -# -# This script requires the readtags command available in ctags source but -# not installed by default - -declare-option -docstring "list of paths to tag files to parse when looking up a symbol" \ - str-list ctagsfiles 'tags' - -define-command -params ..1 \ - -shell-script-candidates %{ - realpath() { ( cd "$(dirname "$1")"; printf "%s/%s\n" "$(pwd -P)" "$(basename "$1")" ) } - eval "set -- $kak_opt_ctagsfiles" - for candidate in "$@"; do - [ -f "$candidate" ] && realpath "$candidate" - done | awk '!x[$0]++' | # remove duplicates - while read -r tags; do - namecache="${tags%/*}/.kak.${tags##*/}.namecache" - if [ -z "$(find "$namecache" -prune -newer "$tags")" ]; then - cut -f 1 "$tags" | grep -v '^!' | uniq > "$namecache" - fi - cat "$namecache" - done} \ - -docstring %{ctags-search []: jump to a symbol's definition -If no symbol is passed then the current selection is used as symbol name} \ - ctags-search \ - %{ evaluate-commands %sh{ - realpath() { ( cd "$(dirname "$1")"; printf "%s/%s\n" "$(pwd -P)" "$(basename "$1")" ) } - export tagname=${1:-${kak_selection}} - eval "set -- $kak_opt_ctagsfiles" - for candidate in "$@"; do - [ -f "$candidate" ] && realpath "$candidate" - done | awk '!x[$0]++' | # remove duplicates - while read -r tags; do - printf '!TAGROOT\t%s\n' "$(realpath "${tags%/*}")/" - readtags -t "$tags" $tagname - done | awk -F '\t|\n' ' - /^!TAGROOT\t/ { tagroot=$2 } - /[^\t]+\t[^\t]+\t\/\^.*\$?\// { - re=$0; - sub(".*\t/\\^", "", re); sub("\\$?/$", "", re); gsub("(\\{|\\}|\\\\E).*$", "", re); - keys=re; gsub(/", keys); gsub(/\t/, "", keys); - out = out " %{" $2 " {MenuInfo}" re "} %{evaluate-commands %{ try %{ edit %{" path($2) "}; execute-keys %{/\\Q" keys "vc} } catch %{ echo %{unable to find tag} } } }" - } - /[^\t]+\t[^\t]+\t[0-9]+/ { out = out " %{" $2 ":" $3 "} %{evaluate-commands %{ edit %{" path($2) "} %{" $3 "}}}" } - END { print ( length(out) == 0 ? "echo -markup %{{Error}no such tag " ENVIRON["tagname"] "}" : "menu -markup -auto-single " out ) } - - # Ensure x is an absolute file path, by prepending with tagroot - function path(x) { return x ~/^\// ? x : tagroot x }' - }} - -define-command ctags-complete -docstring "Insert completion candidates for the current selection into the buffer's local variables" %{ evaluate-commands -draft %{ - execute-keys hb^\w+$ - nop %sh{ { - compl=$(readtags -p "$kak_selection" | cut -f 1 | sort | uniq | sed -e 's/:/\\:/g' | sed -e 's/\n/:/g' ) - compl="${kak_cursor_line}.${kak_cursor_column}+${#kak_selection}@${kak_timestamp}:${compl}" - printf %s\\n "set-option buffer=$kak_bufname ctags_completions '${compl}'" | kak -p ${kak_session} - } > /dev/null 2>&1 < /dev/null & } -}} - -define-command ctags-funcinfo -docstring "Display ctags information about a selected function" %{ - evaluate-commands -draft %{ - try %{ - execute-keys '[(;B[a-zA-Z_]+\(' - evaluate-commands %sh{ - f=${kak_selection%?} - sig='\tsignature:(.*)' - csn='\t(class|struct|namespace):(\S+)' - sigs=$(readtags -e -Q '(eq? $kind "f")' "${f}" | sed -re "s/^.*${csn}.*${sig}$/\3 [\2::${f}]/ ;t ;s/^.*${sig}$/\1 [${f}]/") - if [ -n "$sigs" ]; then - printf %s\\n "evaluate-commands -client ${kak_client} %{info -anchor $kak_cursor_line.$kak_cursor_column -placement above '$sigs'}" - fi - } - } - } -} - -define-command ctags-enable-autoinfo -docstring "Automatically display ctags information about function" %{ - hook window -group ctags-autoinfo NormalIdle .* ctags-funcinfo - hook window -group ctags-autoinfo InsertIdle .* ctags-funcinfo -} - -define-command ctags-disable-autoinfo -docstring "Disable automatic ctags information displaying" %{ remove-hooks window ctags-autoinfo } - -declare-option -docstring "shell command to run" \ - str ctagscmd "ctags -R --fields=+S" -declare-option -docstring "path to the directory in which the tags file will be generated" str ctagspaths "." - -define-command ctags-generate -docstring 'Generate tag file asynchronously' %{ - echo -markup "{Information}launching tag generation in the background" - nop %sh{ ( - while ! mkdir .tags.kaklock 2>/dev/null; do sleep 1; done - trap 'rmdir .tags.kaklock' EXIT - - if ${kak_opt_ctagscmd} -f .tags.kaktmp ${kak_opt_ctagspaths}; then - mv .tags.kaktmp tags - msg="tags generation complete" - else - msg="tags generation failed" - fi - - printf %s\\n "evaluate-commands -client $kak_client echo -markup '{Information}${msg}'" | kak -p ${kak_session} - ) > /dev/null 2>&1 < /dev/null & } -} - -define-command ctags-update-tags -docstring 'Update tags for the given file' %{ - nop %sh{ ( - while ! mkdir .tags.kaklock 2>/dev/null; do sleep 1; done - trap 'rmdir .tags.kaklock' EXIT - - if ${kak_opt_ctagscmd} -f .file_tags.kaktmp $kak_bufname; then - export LC_COLLATE=C LC_ALL=C # ensure ASCII sorting order - # merge the updated tags tags with the general tags (filtering out out of date tags from it) into the target file - grep -Fv "$(printf '\t%s\t' "$kak_bufname")" tags | grep -v '^!' | sort --merge - .file_tags.kaktmp >> .tags.kaktmp - rm .file_tags.kaktmp - mv .tags.kaktmp tags - msg="tags updated for $kak_bufname" - else - msg="tags update failed for $kak_bufname" - fi - - printf %s\\n "evaluate-commands -client $kak_client echo -markup '{Information}${msg}'" | kak -p ${kak_session} - ) > /dev/null 2>&1 < /dev/null & } -} diff --git a/rc/base/d.kak b/rc/base/d.kak deleted file mode 100644 index f0f08248..00000000 --- a/rc/base/d.kak +++ /dev/null @@ -1,132 +0,0 @@ -# http://dlang.org/ -# - -# Detection -# ‾‾‾‾‾‾‾‾‾ - -hook global BufCreate .*\.di? %{ - set-option buffer filetype d -} - -# Highlighters -# ‾‾‾‾‾‾‾‾‾‾‾‾ - -add-highlighter shared/d regions -add-highlighter shared/d/code default-region group -add-highlighter shared/d/string region %{(? } - # indent after lines ending with { or ( - try %[ execute-keys -draft k [{(]\h*$ j ] - # cleanup trailing white spaces on the previous line - try %{ execute-keys -draft k s \h+$ d } - # align to opening paren of previous line - try %{ execute-keys -draft [( \A\([^\n]+\n[^\n]*\n?\z s \A\(\h*.|.\z '' & } - # copy // comments prefix - try %{ execute-keys -draft \;k s ^\h*\K/{2,} yP } - # indent after a switch's case/default statements - try %[ execute-keys -draft k ^\h*(case|default).*:$ j ] - # indent after if|else|while|for - try %[ execute-keys -draft \;)MB \A(if|else|while|for)\h*\(.*\)\h*\n\h*\n?\z s \A|.\z 11 ] - = -~ - -define-command -hidden d-indent-on-opening-curly-brace %[ - # align indent with opening paren when { is entered on a new line after the closing paren - try %[ execute-keys -draft -itersel h)M \A\(.*\)\h*\n\h*\{\z s \A|.\z 1 ] -] - -define-command -hidden d-indent-on-closing-curly-brace %[ - # align to opening curly brace when alone on a line - try %[ execute-keys -itersel -draft ^\h+\}$hms\A|.\z1 ] -] - -# Initialization -# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ - -hook -group d-highlight global WinSetOption filetype=d %{ - add-highlighter window/d ref d - hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/d } -} - -hook global WinSetOption filetype=d %{ - # cleanup trailing whitespaces when exiting insert mode - hook window ModeChange insert:.* -group d-trim-indent %{ try %{ execute-keys -draft s^\h+$d } } - hook window InsertChar \n -group d-indent d-indent-on-new-line - hook window InsertChar \{ -group d-indent d-indent-on-opening-curly-brace - hook window InsertChar \} -group d-indent d-indent-on-closing-curly-brace - - hook -once -always window WinSetOption filetype=.* %{ remove-hooks window d-.+ } -} diff --git a/rc/base/etc.kak b/rc/base/etc.kak deleted file mode 100644 index 1e2067fe..00000000 --- a/rc/base/etc.kak +++ /dev/null @@ -1,79 +0,0 @@ -# Highlighting for common files in /etc -hook global BufCreate .*/etc/(hosts|networks|services) %{ set-option buffer filetype etc-hosts } -hook global BufCreate .*/etc/resolv.conf %{ set-option buffer filetype etc-resolv-conf } -hook global BufCreate .*/etc/shadow %{ set-option buffer filetype etc-shadow } -hook global BufCreate .*/etc/passwd %{ set-option buffer filetype etc-passwd } -hook global BufCreate .*/etc/gshadow %{ set-option buffer filetype etc-gshadow } -hook global BufCreate .*/etc/group %{ set-option buffer filetype etc-group } -hook global BufCreate .*/etc/(fs|m)tab %{ set-option buffer filetype etc-fstab } -hook global BufCreate .*/etc/environment %{ set-option buffer filetype sh } -hook global BufCreate .*/etc/env.d/.* %{ set-option buffer filetype sh } -hook global BufCreate .*/etc/profile(\.(csh|env))? %{ set-option buffer filetype sh } -hook global BufCreate .*/etc/profile\.d/.* %{ set-option buffer filetype sh } - -# Highlighters -## /etc/resolv.conf -add-highlighter shared/etc-resolv-conf group -add-highlighter shared/etc-resolv-conf/ regex ^#.*?$ 0:comment -add-highlighter shared/etc-resolv-conf/ regex ^(nameserver|server|domain|sortlist|options)[\s\t]+(.*?)$ 1:type 2:attribute - -hook -group etc-resolv-conf-highlight global WinSetOption filetype=etc-resolv-conf %{ - add-highlighter window/etc-resolv-conf ref etc-resolv-conf - hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/etc-resolv-conf } -} - -## /etc/hosts -add-highlighter shared/etc-hosts group -add-highlighter shared/etc-hosts/ regex ^(.+?)[\s\t]+?(.*?)$ 1:type 2:attribute -add-highlighter shared/etc-hosts/ regex '#.*?$' 0:comment - -hook -group etc-hosts-highlight global WinSetOption filetype=etc-hosts %{ - add-highlighter window/etc-hosts ref etc-hosts - hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/etc-hosts } -} - -## /etc/fstab -add-highlighter shared/etc-fstab group -add-highlighter shared/etc-fstab/ regex ^(\S{1,})\s+?(\S{1,})\s+?(\S{1,})\s+?(\S{1,})\s+?(\S{1,})\s+?(\S{1,})(?:\s+)?$ 1:keyword 2:value 3:type 4:string 5:attribute 6:attribute -add-highlighter shared/etc-fstab/ regex '#.*?$' 0:comment - -hook -group etc-fstab-highlight global WinSetOption filetype=etc-fstab %{ - add-highlighter window/etc-fstab ref etc-fstab - hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/etc-fstab } -} - -## /etc/group -add-highlighter shared/etc-group group -add-highlighter shared/etc-group/ regex ^(\S+?):(\S+?)?:(\S+?)?:(\S+?)?$ 1:keyword 2:type 3:value 4:string - -hook -group etc-group-highlight global WinSetOption filetype=etc-group %{ - add-highlighter window/etc-group ref etc-group - hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/etc-group } -} - -## /etc/gshadow -add-highlighter shared/etc-gshadow group -add-highlighter shared/etc-gshadow/ regex ^(\S+?):(\S+?)?:(\S+?)?:(\S+?)?$ 1:keyword 2:type 3:value 4:string - -hook -group etc-gshadow-highlight global WinSetOption filetype=etc-gshadow %{ - add-highlighter window/etc-gshadow ref etc-gshadow - hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/etc-gshadow } -} - -## /etc/shadow -add-highlighter shared/etc-shadow group -add-highlighter shared/etc-shadow/ regex ^(\S+?):(\S+?):([0-9]+?):([0-9]+?)?:([0-9]+?)?:([0-9]+?)?:([0-9]+?)?:([0-9]+?)?:(.*?)?$ 1:keyword 2:type 3:value 4:value 5:value 6:value 7:value 8:value - -hook -group etc-shadow-highlight global WinSetOption filetype=etc-shadow %{ - add-highlighter window/etc-shadow ref etc-shadow - hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/etc-shadow } -} - -## /etc/passwd -add-highlighter shared/etc-passwd group -add-highlighter shared/etc-passwd/ regex ^(\S+?):(\S+?):([0-9]+?):([0-9]+?):(.*?)?:(.+?):(.+?)$ 1:keyword 2:type 3:value 4:value 5:string 6:attribute 7:attribute - -hook -group etc-passwd-highlight global WinSetOption filetype=etc-passwd %{ - add-highlighter window/etc-passwd ref etc-passwd - hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/etc-passwd } -} diff --git a/rc/base/file.kak b/rc/base/file.kak deleted file mode 100644 index 073e9ce0..00000000 --- a/rc/base/file.kak +++ /dev/null @@ -1,17 +0,0 @@ -hook global BufOpenFile .* %{ evaluate-commands %sh{ - if [ -z "${kak_opt_filetype}" ]; then - mime=$(file -b --mime-type "${kak_buffile}") - case "${mime}" in - application/*+xml) filetype="xml" ;; - image/*+xml) filetype="xml" ;; #SVG - message/rfc822) filetype="mail" ;; - text/x-shellscript) filetype="sh" ;; - text/x-*) filetype="${mime#text/x-}" ;; - text/*) filetype="${mime#text/}" ;; - application/*) filetype="${mime#application/}" ;; - esac - if [ -n "${filetype}" ]; then - printf "set-option buffer filetype '%s'\n" "${filetype}" - fi - fi -} } diff --git a/rc/base/fish.kak b/rc/base/fish.kak deleted file mode 100644 index 8e23ede4..00000000 --- a/rc/base/fish.kak +++ /dev/null @@ -1,84 +0,0 @@ -# http://fishshell.com -# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ - -# Detection -# ‾‾‾‾‾‾‾‾‾ - -hook global BufCreate .*[.](fish) %{ - set-option buffer filetype fish -} - -# Highlighters -# ‾‾‾‾‾‾‾‾‾‾‾‾ - -add-highlighter shared/fish regions -add-highlighter shared/fish/code default-region group -add-highlighter shared/fish/double_string region '"' (?s\h+$d } - } -} - -define-command -hidden fish-indent-on-char %{ - evaluate-commands -no-hooks -draft -itersel %{ - # align middle and end structures to start and indent when necessary - try %{ execute-keys -draft ^\h*(else)$^\h*(if)s\A|\z) } - try %{ execute-keys -draft ^\h*(end)$^\h*(begin|for|function|if|switch|while)s\A|\z) } - try %{ execute-keys -draft ^\h*(case)$^\h*(switch)s\A|\z)) } - } -} - -define-command -hidden fish-indent-on-new-line %{ - evaluate-commands -no-hooks -draft -itersel %{ - # preserve previous line indent - try %{ execute-keys -draft K } - # filter previous line - try %{ execute-keys -draft k:fish-trim-indent } - # indent after start structure - try %{ execute-keys -draft k^\h*(begin|case|else|for|function|if|switch|while)\bj } - } -} - -define-command -hidden fish-insert-on-new-line %{ - evaluate-commands -no-hooks -draft -itersel %{ - # copy _#_ comment prefix and following white spaces - try %{ execute-keys -draft ks^\h*\K#\h*yjp } - # wisely add end structure - evaluate-commands -save-regs x %{ - try %{ execute-keys -draft ks^\h+"xy } catch %{ reg x '' } - try %{ execute-keys -draft k^x(begin|for|function|if|switch|while)jiXK^x(begin|for|function|if|switch|while).*\nxend$jxypjaend } - } - } -} - -# Initialization -# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ - -hook -group fish-highlight global WinSetOption filetype=fish %{ - add-highlighter window/fish ref fish - hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/fish } -} - -hook global WinSetOption filetype=fish %{ - hook window InsertChar .* -group fish-indent fish-indent-on-char - hook window InsertChar \n -group fish-insert fish-insert-on-new-line - hook window InsertChar \n -group fish-indent fish-indent-on-new-line - - hook -once -always window WinSetOption filetype=.* %{ remove-hooks window fish-.+ } -} diff --git a/rc/base/gas.kak b/rc/base/gas.kak deleted file mode 100644 index 0c1f79f8..00000000 --- a/rc/base/gas.kak +++ /dev/null @@ -1,91 +0,0 @@ -# Detection -# --------- -hook global BufCreate .*\.(s|S|asm)$ %{ - set-option buffer filetype gas -} - -add-highlighter shared/gas regions -add-highlighter shared/gas/code default-region group -add-highlighter shared/gas/string region '"' (? - # remove trailing white spaces - try %{ execute-keys -draft s \h+$ d } - } -} - -define-command -hidden gas-indent-on-new-line %~ - evaluate-commands -draft -itersel %< - # preserve previous line indent - try %{ execute-keys -draft \; K } - # filter previous line - try %{ execute-keys -draft k : gas-trim-indent } - # indent after label - try %[ execute-keys -draft k :$ j ] - > -~ - -hook -group gas-highlight global WinSetOption filetype=gas %{ - add-highlighter window/gas ref gas - hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/gas } -} - -hook global WinSetOption filetype=gas %{ - hook window InsertChar \n -group gas-indent gas-indent-on-new-line - hook -once -always window WinSetOption filetype=.* %{ remove-hooks window gas-.+ } -} diff --git a/rc/base/git.kak b/rc/base/git.kak deleted file mode 100644 index 13d58f0a..00000000 --- a/rc/base/git.kak +++ /dev/null @@ -1,40 +0,0 @@ -hook global BufCreate .*(COMMIT_EDITMSG|MERGE_MSG) %{ - set-option buffer filetype git-commit -} - -hook global BufCreate .*/NOTES_EDITMSG %{ - set-option buffer filetype git-notes -} - -hook global BufCreate .*(\.gitconfig|git/config) %{ - set-option buffer filetype ini -} - -hook -group git-commit-highlight global WinSetOption filetype=git-commit %{ - add-highlighter window/git-commit-highlight regions - add-highlighter window/git-commit-highlight/diff region '^diff --git' '^(?=diff --git)' ref diff # highlight potential diffs from the -v option - add-highlighter window/git-commit-highlight/comments region '^\h*#' '$' group - add-highlighter window/git-commit-highlight/comments/ fill comment - add-highlighter window/git-commit-highlight/comments/ regex "\b(?:(modified)|(deleted)|(new file)|(renamed|copied)):([^\n]*)$" 1:yellow 2:red 3:green 4:blue 5:magenta - - hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/git-commit-highlight } -} - -hook -group git-commit-highlight global WinSetOption filetype=git-notes %{ - add-highlighter window/git-notes-highlight regex '^\h*#[^\n]*$' 0:comment - - hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/git-notes-highlight } -} - - -hook global BufCreate .*git-rebase-todo %{ - set-option buffer filetype git-rebase -} - -hook -group git-rebase-highlight global WinSetOption filetype=git-rebase %{ - add-highlighter window/git-rebase-highlight group - add-highlighter window/git-rebase-highlight/ regex "#[^\n]*\n" 0:comment - add-highlighter window/git-rebase-highlight/ regex "^(pick|edit|reword|squash|fixup|exec|break|drop|label|reset|merge|[persfxbdltm]) (\w+)" 1:keyword 2:meta - - hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/git-rebase-highlight } -} diff --git a/rc/base/go.kak b/rc/base/go.kak deleted file mode 100644 index 8aebe657..00000000 --- a/rc/base/go.kak +++ /dev/null @@ -1,97 +0,0 @@ -# https://golang.org/ -# - -# Detection -# ‾‾‾‾‾‾‾‾‾ - -hook global BufCreate .*\.go %{ - set-option buffer filetype go -} - -# Highlighters -# ‾‾‾‾‾‾‾‾‾‾‾‾ - -add-highlighter shared/go regions -add-highlighter shared/go/code default-region group -add-highlighter shared/go/back_string region '`' '`' fill string -add-highlighter shared/go/double_string region '"' (? } - # indent after lines ending with { or ( - try %[ execute-keys -draft k [{(]\h*$ j ] - # cleanup trailing white spaces on the previous line - try %{ execute-keys -draft k s \h+$ d } - # align to opening paren of previous line - try %{ execute-keys -draft [( \A\([^\n]+\n[^\n]*\n?\z s \A\(\h*.|.\z '' & } - # copy // comments prefix - try %{ execute-keys -draft \;k s ^\h*\K/{2,} yP } - # indent after a switch's case/default statements - try %[ execute-keys -draft k ^\h*(case|default).*:$ j ] - # indent after if|else|while|for - try %[ execute-keys -draft \;)MB \A(if|else|while|for)\h*\(.*\)\h*\n\h*\n?\z s \A|.\z 11 ] - = -~ - -define-command -hidden go-indent-on-opening-curly-brace %[ - # align indent with opening paren when { is entered on a new line after the closing paren - try %[ execute-keys -draft -itersel h)M \A\(.*\)\h*\n\h*\{\z s \A|.\z 1 ] -] - -define-command -hidden go-indent-on-closing-curly-brace %[ - # align to opening curly brace when alone on a line - try %[ execute-keys -itersel -draft ^\h+\}$hms\A|.\z1 ] -] - -# Initialization -# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ - -hook -group go-highlight global WinSetOption filetype=go %{ - add-highlighter window/go ref go - hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/go } -} - -hook global WinSetOption filetype=go %{ - # cleanup trailing whitespaces when exiting insert mode - hook window ModeChange insert:.* -group go-trim-indent %{ try %{ execute-keys -draft s^\h+$d } } - hook window InsertChar \n -group go-indent go-indent-on-new-line - hook window InsertChar \{ -group go-indent go-indent-on-opening-curly-brace - hook window InsertChar \} -group go-indent go-indent-on-closing-curly-brace - - hook -once -always window WinSetOption filetype=.* %{ remove-hooks window go-.+ } -} diff --git a/rc/base/haskell.kak b/rc/base/haskell.kak deleted file mode 100644 index c51bcaf4..00000000 --- a/rc/base/haskell.kak +++ /dev/null @@ -1,105 +0,0 @@ -# http://haskell.org -# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ - -# Detection -# ‾‾‾‾‾‾‾‾‾ - -hook global BufCreate .*[.](hs) %{ - set-option buffer filetype haskell -} - -# Highlighters -# ‾‾‾‾‾‾‾‾‾‾‾‾ - -add-highlighter shared/haskell regions -add-highlighter shared/haskell/code default-region group -add-highlighter shared/haskell/string region (??@\\\^|~=]|$) $ fill comment - -add-highlighter shared/haskell/code/ regex (?" -# Quantifier separator in "forall a . [a] -> [a]" -# Enum comprehensions like "[1..]" and "[a..b]" (making ".." and "Module..." illegal) - -# matches uppercase identifiers: Monad Control.Monad -# not non-space separated dot: Just.const -add-highlighter shared/haskell/code/ regex \b([A-Z]['\w]*\.)*[A-Z]['\w]*(?!['\w])(?![.a-z]) 0:variable - -# matches infix identifier: `mod` `Apa._T'M` -add-highlighter shared/haskell/code/ regex `\b([A-Z]['\w]*\.)*[\w]['\w]*` 0:operator -# matches imported operators: M.! M.. Control.Monad.>> -# not operator keywords: M... M.-> -add-highlighter shared/haskell/code/ regex \b[A-Z]['\w]*\.[~<=>|:!?/.@$*&#%+\^\-\\]+ 0:operator -# matches dot: . -# not possibly incomplete import: a. -# not other operators: !. .! -add-highlighter shared/haskell/code/ regex (?|:!?/.@$*&#%+\^\-\\])\.(?![~<=>|:!?/.@$*&#%+\^\-\\]) 0:operator -# matches other operators: ... > < <= ^ <*> <$> etc -# not dot: . -# not operator keywords: @ .. -> :: ~ -add-highlighter shared/haskell/code/ regex (?|:!?/.@$*&#%+\^\-\\])[~<=>|:!?/.@$*&#%+\^\-\\]+ 0:operator - -# matches operator keywords: @ -> -add-highlighter shared/haskell/code/ regex (?|:!?/.@$*&#%+\^\-\\])(@|~|<-|->|=>|::|=|:|[|])(?![~<=>|:!?/.@$*&#%+\^\-\\]) 1:keyword -# matches: forall [..variables..] . -# not the variables -add-highlighter shared/haskell/code/ regex \b(forall)\b[^.\n]*?(\.) 1:keyword 2:keyword - -# matches 'x' '\\' '\'' '\n' '\0' -# not incomplete literals: '\' -# not valid identifiers: w' _' -add-highlighter shared/haskell/code/ regex \B'([^\\]|[\\]['"\w\d\\])' 0:string -# this has to come after operators so '-' etc is correct - -# Commands -# ‾‾‾‾‾‾‾‾ - -# http://en.wikibooks.org/wiki/Haskell/Indentation - -define-command -hidden haskell-trim-indent %{ - # remove trailing white spaces - try %{ execute-keys -draft -itersel s \h+$ d } -} - -define-command -hidden haskell-indent-on-new-line %{ - evaluate-commands -draft -itersel %{ - # copy -- comments prefix and following white spaces - try %{ execute-keys -draft k s ^\h*\K--\h* y gh j P } - # preserve previous line indent - try %{ execute-keys -draft \; K } - # align to first clause - try %{ execute-keys -draft \; k x X s ^\h*(if|then|else)?\h*(([\w']+\h+)+=)?\h*(case\h+[\w']+\h+of|do|let|where)\h+\K.* s \A|.\z & } - # filter previous line - try %{ execute-keys -draft k : haskell-trim-indent } - # indent after lines beginning with condition or ending with expression or =( - try %{ execute-keys -draft \; k x ^\h*(if)|(case\h+[\w']+\h+of|do|let|where|[=(])$ j } - } -} - -# Initialization -# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ - -hook -group haskell-highlight global WinSetOption filetype=haskell %{ - add-highlighter window/haskell ref haskell - hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/haskell } -} - -hook global WinSetOption filetype=haskell %{ - set-option window extra_word_chars '_' "'" - hook window ModeChange insert:.* -group haskell-trim-indent haskell-trim-indent - hook window InsertChar \n -group haskell-indent haskell-indent-on-new-line - - hook -once -always window WinSetOption filetype=.* %{ remove-hooks window haskell-.+ } -} diff --git a/rc/base/html.kak b/rc/base/html.kak deleted file mode 100644 index 5f76721d..00000000 --- a/rc/base/html.kak +++ /dev/null @@ -1,75 +0,0 @@ -# http://w3.org/html -# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ - -# Detection -# ‾‾‾‾‾‾‾‾‾ - -hook global BufCreate .*\.html %{ - set-option buffer filetype html -} - -hook global BufCreate .*\.xml %{ - set-option buffer filetype xml -} - -# Highlighters -# ‾‾‾‾‾‾‾‾‾‾‾‾ - -add-highlighter shared/html regions -add-highlighter shared/html/comment region fill comment -add-highlighter shared/html/tag region < > regions -add-highlighter shared/html/style region \K (?=) ref css -add-highlighter shared/html/script region \K (?=) ref javascript - -add-highlighter shared/html/tag/base default-region group -add-highlighter shared/html/tag/ region '"' (? s \h+$ d } -} - -define-command -hidden html-indent-on-greater-than %[ - evaluate-commands -draft -itersel %[ - # align closing tag to opening when alone on a line - try %[ execute-keys -draft s ^\h+/(\w+)$ {c1,/1 s \A|.\z 1 ] - ] -] - -define-command -hidden html-indent-on-new-line %{ - evaluate-commands -draft -itersel %{ - # preserve previous line indent - try %{ execute-keys -draft \; K } - # filter previous line - try %{ execute-keys -draft k : html-trim-indent } - # indent after lines ending with opening tag - try %{ execute-keys -draft k (?!area)(?!base)(?!br)(?!col)(?!command)(?!embed)(?!hr)(?!img)(?!input)(?!keygen)(?!link)(?!menuitem)(?!meta)(?!param)(?!source)(?!track)(?!wbr)(?!/)(?!>)[a-zA-Z0-9_-]+[^>]*?>$ j } } -} - -# Initialization -# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ - -hook -group html-highlight global WinSetOption filetype=(html|xml) %{ - add-highlighter "window/%val{hook_param_capture_1}" ref html - hook -once -always window WinSetOption "filetype=.*" " - remove-highlighter ""window/%val{hook_param_capture_1}"" - " -} - -hook global WinSetOption filetype=(html|xml) %{ - hook window ModeChange insert:.* -group "%val{hook_param_capture_1}-trim-indent" html-trim-indent - hook window InsertChar '>' -group "%val{hook_param_capture_1}-indent" html-indent-on-greater-than - hook window InsertChar \n -group "%val{hook_param_capture_1}-indent" html-indent-on-new-line - - hook -once -always window WinSetOption "filetype=.*" " - remove-hooks window ""%val{hook_param_capture_1}-.+"" - " -} diff --git a/rc/base/ini.kak b/rc/base/ini.kak deleted file mode 100644 index c03cae4e..00000000 --- a/rc/base/ini.kak +++ /dev/null @@ -1,15 +0,0 @@ -hook global BufCreate .+\.(repo|ini|cfg|properties) %{ - set-option buffer filetype ini -} - -add-highlighter shared/ini regions -add-highlighter shared/ini/code default-region group -add-highlighter shared/ini/comment region '(^|\h)\K[#;]' $ fill comment - -add-highlighter shared/ini/code/ regex "^\h*\[[^\]]*\]" 0:title -add-highlighter shared/ini/code/ regex "^\h*([^\[][^=\n]*)=([^\n]*)" 1:variable 2:value - -hook -group ini-highlight global WinSetOption filetype=ini %{ - add-highlighter window/ini ref ini - hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/ini } -} diff --git a/rc/base/java.kak b/rc/base/java.kak deleted file mode 100644 index 7caa5aee..00000000 --- a/rc/base/java.kak +++ /dev/null @@ -1,65 +0,0 @@ -hook global BufCreate .*\.java %{ - set-option buffer filetype java -} - -add-highlighter shared/java regions -add-highlighter shared/java/code default-region group -add-highlighter shared/java/string region %{(? } - # indent after lines ending with { or ( - try %[ execute-keys -draft k [{(]\h*$ j ] - # cleanup trailing white spaces on the previous line - try %{ execute-keys -draft k s \h+$ d } - # align to opening paren of previous line - try %{ execute-keys -draft [( \A\([^\n]+\n[^\n]*\n?\z s \A\(\h*.|.\z '' & } - # copy // comments prefix - try %{ execute-keys -draft \;k s ^\h*\K/{2,} yP } - # indent after a switch's case/default statements - try %[ execute-keys -draft k ^\h*(case|default).*:$ j ] - # indent after keywords - try %[ execute-keys -draft \;)MB \A(if|else|while|for|try|catch)\h*\(.*\)\h*\n\h*\n?\z s \A|.\z 11 ] - = -~ - -define-command -hidden java-indent-on-opening-curly-brace %[ - # align indent with opening paren when { is entered on a new line after the closing paren - try %[ execute-keys -draft -itersel h)M \A\(.*\)\h*\n\h*\{\z s \A|.\z 1 ] -] - -define-command -hidden java-indent-on-closing-curly-brace %[ - # align to opening curly brace when alone on a line - try %[ execute-keys -itersel -draft ^\h+\}$hms\A|.\z1 ] -] - -# Initialization -# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ - -hook -group java-highlight global WinSetOption filetype=java %{ - add-highlighter window/java ref java - hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/java } -} - -hook global WinSetOption filetype=java %{ - # cleanup trailing whitespaces when exiting insert mode - hook window ModeChange insert:.* -group java-trim-indent %{ try %{ execute-keys -draft s^\h+$d } } - hook window InsertChar \n -group java-indent java-indent-on-new-line - hook window InsertChar \{ -group java-indent java-indent-on-opening-curly-brace - hook window InsertChar \} -group java-indent java-indent-on-closing-curly-brace - - hook -once -always window WinSetOption filetype=.* %{ remove-hooks window java-.+ } -} diff --git a/rc/base/javascript.kak b/rc/base/javascript.kak deleted file mode 100644 index 4d16ee68..00000000 --- a/rc/base/javascript.kak +++ /dev/null @@ -1,117 +0,0 @@ -# Detection -# ‾‾‾‾‾‾‾‾‾ - -hook global BufCreate .*[.](js)x? %{ - set-option buffer filetype javascript -} - -hook global BufCreate .*[.](ts)x? %{ - set-option buffer filetype typescript -} - -# Commands -# ‾‾‾‾‾‾‾‾ - -define-command -hidden javascript-trim-indent %{ - # remove trailing white spaces - try %{ execute-keys -draft -itersel s \h+$ d } -} - -define-command -hidden javascript-indent-on-char %< - evaluate-commands -draft -itersel %< - # align closer token to its opener when alone on a line - try %/ execute-keys -draft ^\h+[\]}]$ m s \A|.\z 1 / - > -> - -define-command -hidden javascript-indent-on-new-line %< - evaluate-commands -draft -itersel %< - # copy // comments prefix and following white spaces - try %{ execute-keys -draft k s ^\h*\K#\h* y gh j P } - # preserve previous line indent - try %{ execute-keys -draft \; K } - # filter previous line - try %{ execute-keys -draft k : javascript-trim-indent } - # indent after lines beginning / ending with opener token - try %_ execute-keys -draft k ^\h*[[{]|[[{]$ j _ - > -> - -# Highlighting and hooks bulder for JavaScript and TypeScript -# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ -define-command -hidden init-javascript-filetype -params 1 %~ - # Highlighters - # ‾‾‾‾‾‾‾‾‾‾‾‾ - - add-highlighter "shared/%arg{1}" regions - add-highlighter "shared/%arg{1}/code" default-region group - add-highlighter "shared/%arg{1}/double_string" region '"' (?])(?!>\()) (|/>) regions - add-highlighter "shared/%arg{1}/division" region '[\w\)\]]\K(/|(\h+/\h+))' '(?=\w)' group # Help Kakoune to better detect /…/ literals - - # Regular expression flags are: g → global match, i → ignore case, m → multi-lines, u → unicode, y → sticky - # https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp - - add-highlighter "shared/%arg{1}/literal/" fill string - add-highlighter "shared/%arg{1}/literal/" regex \$\{.*?\} 0:value - - add-highlighter "shared/%arg{1}/code/" regex [^$_]\b(document|false|null|parent|self|this|true|undefined|window)\b 1:value - add-highlighter "shared/%arg{1}/code/" regex "-?\b[0-9]*\.?[0-9]+" 0:value - add-highlighter "shared/%arg{1}/code/" regex \b(Array|Boolean|Date|Function|Number|Object|RegExp|String|Symbol)\b 0:type - - # jsx: In well-formed xml the number of opening and closing tags match up regardless of tag name. - # - # We inline a small XML highlighter here since it anyway need to recurse back up to the starting highlighter. - # To make things simple we assume that jsx is always enabled. - - add-highlighter "shared/%arg{1}/jsx/tag" region -recurse < <(?=[/a-zA-Z]) (? regions - add-highlighter "shared/%arg{1}/jsx/expr" region -recurse \{ \{ \} ref %arg{1} - - add-highlighter "shared/%arg{1}/jsx/tag/base" default-region group - add-highlighter "shared/%arg{1}/jsx/tag/double_string" region =\K" (?) 0:meta - - add-highlighter "shared/%arg{1}/jsx/tag/expr/" ref %arg{1} - - # Keywords are collected at - # https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#Keywords - add-highlighter "shared/%arg{1}/code/" regex \b(async|await|break|case|catch|class|const|continue|debugger|default|delete|do|else|export|extends|finally|for|function|if|import|in|instanceof|let|new|of|return|static|super|switch|throw|try|typeof|var|void|while|with|yield)\b 0:keyword - - # Initialization - # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ - - hook -group "%arg{1}-highlight" global WinSetOption "filetype=%arg{1}" " - add-highlighter window/%arg{1} ref %arg{1} - - hook -once -always window WinSetOption filetype=.* %%{ remove-highlighter window/%arg{1} } - " - - hook global WinSetOption "filetype=%arg{1}" " - hook window ModeChange insert:.* -group %arg{1}-trim-indent javascript-trim-indent - hook window InsertChar .* -group %arg{1}-indent javascript-indent-on-char - hook window InsertChar \n -group %arg{1}-indent javascript-indent-on-new-line - - hook -once -always window WinSetOption filetype=.* %%{ remove-hooks window %arg{1}-.+ } - " -~ - -init-javascript-filetype javascript -init-javascript-filetype typescript - -# Highlighting specific to TypeScript -# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ -add-highlighter shared/typescript/code/ regex \b(array|boolean|date|number|object|regexp|string|symbol)\b 0:type - -# Keywords grabbed from https://github.com/Microsoft/TypeScript/issues/2536 -add-highlighter shared/typescript/code/ regex \b(as|constructor|declare|enum|from|implements|interface|module|namespace|package|private|protected|public|readonly|static|type)\b 0:keyword diff --git a/rc/base/json.kak b/rc/base/json.kak deleted file mode 100644 index ae04c55a..00000000 --- a/rc/base/json.kak +++ /dev/null @@ -1,60 +0,0 @@ -# http://json.org -# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ - -# Detection -# ‾‾‾‾‾‾‾‾‾ - -hook global BufCreate .*[.](json) %{ - set-option buffer filetype json -} - -# Highlighters -# ‾‾‾‾‾‾‾‾‾‾‾‾ - -add-highlighter shared/json regions -add-highlighter shared/json/code default-region group -add-highlighter shared/json/string region '"' (? s \h+$ d } -} - -define-command -hidden json-indent-on-char %< - evaluate-commands -draft -itersel %< - # align closer token to its opener when alone on a line - try %< execute-keys -draft ^\h+[]}]$ m s \A|.\z 1 > - > -> - -define-command -hidden json-indent-on-new-line %< - evaluate-commands -draft -itersel %< - # preserve previous line indent - try %{ execute-keys -draft \; K } - # filter previous line - try %{ execute-keys -draft k : json-trim-indent } - # indent after lines beginning with opener token - try %< execute-keys -draft k ^\h*[[{] j > - > -> - -# Initialization -# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ - -hook -group json-highlight global WinSetOption filetype=json %{ - add-highlighter window/json ref json - hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/json } -} - -hook global WinSetOption filetype=json %{ - hook window ModeChange insert:.* -group json-trim-indent json-trim-indent - hook window InsertChar .* -group json-indent json-indent-on-char - hook window InsertChar \n -group json-indent json-indent-on-new-line - - hook -once -always window WinSetOption filetype=.* %{ remove-hooks window json-.+ } -} diff --git a/rc/base/julia.kak b/rc/base/julia.kak deleted file mode 100644 index abdf547a..00000000 --- a/rc/base/julia.kak +++ /dev/null @@ -1,30 +0,0 @@ -# http://julialang.org -# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ - -# Detection -# ‾‾‾‾‾‾‾‾‾ - -hook global BufCreate .*\.(jl) %{ - set-option buffer filetype julia -} - -# Highlighters -# ‾‾‾‾‾‾‾‾‾‾‾‾ - -add-highlighter shared/julia regions -add-highlighter shared/julia/code default-region group -add-highlighter shared/julia/string region '"' (? "$dir"/stderr - - # Flags for the gutter: - # stamp l3|{red}█ l11|{yellow}█ - # Contextual error messages: - # stamp 'l1.c1,l1.c1|kind:message' 'l2.c2,l2.c2|kind:message' - awk -F: -v file="$kak_buffile" -v stamp="$kak_timestamp" -v client="$kak_client" ' - BEGIN { - error_count = 0 - warning_count = 0 - } - /:[1-9][0-9]*:[1-9][0-9]*: ([Ff]atal )?[Ee]rror/ { - flags = flags " " $2 "|{red}█" - error_count++ - } - /:[1-9][0-9]*:[1-9][0-9]*:/ { - if ($4 !~ /[Ee]rror/) { - flags = flags " " $2 "|{yellow}█" - warning_count++ - } - } - /:[1-9][0-9]*:[1-9][0-9]*:/ { - kind = substr($4, 2) - error = $2 "." $3 "," $2 "." $3 "|" kind - msg = "" - # fix case where $5 is not the last field because of extra colons in the message - for (i=5; i<=NF; i++) msg = msg ":" $i - gsub(/\|/, "\\|", msg) - gsub("'\''", "'"''"'", msg) - error = error msg " (col " $3 ")" - errors = errors " '\''" error "'\''" - } - END { - print "set-option \"buffer=" file "\" lint_flags " stamp flags - gsub("~", "\\~", errors) - print "set-option \"buffer=" file "\" lint_errors " stamp errors - print "set-option \"buffer=" file "\" lint_error_count " error_count - print "set-option \"buffer=" file "\" lint_warning_count " warning_count - print "evaluate-commands -client " client " lint-show-counters" - } - ' "$dir"/stderr | kak -p "$kak_session" - - cut -d: -f2- "$dir"/stderr | awk -v bufname="${kak_bufname}" ' - /^[1-9][0-9]*:[1-9][0-9]*:/ { - print bufname ":" $0 - } - ' > "$dir"/fifo - - } >/dev/null 2>&1 |<=|=|>=) 0:operator -add-highlighter shared/lisp/code/ regex \b(def[a-z]+|if|do|let|lambda|catch|and|assert|while|def|do|fn|finally|let|loop|new|quote|recur|set!|throw|try|var|case|if-let|if-not|when|when-first|when-let|when-not|(cond(->|->>)?))\b 0:keyword -add-highlighter shared/lisp/code/ regex (#?(['`:]|,@?))?\b[a-zA-Z][\w!$%&*+./:<=>?@^_~-]* 0:variable -add-highlighter shared/lisp/code/ regex \*[a-zA-Z][\w!$%&*+./:<=>?@^_~-]*\* 0:variable -add-highlighter shared/lisp/code/ regex (\b\d+)?\.\d+([eEsSfFdDlL]\d+)?\b 0:value - -# Commands -# ‾‾‾‾‾‾‾‾ - -define-command -hidden lisp-trim-indent %{ - # remove trailing white spaces - try %{ execute-keys -draft -itersel s \h+$ d } -} - -declare-option \ - -docstring 'regex matching the head of forms which have options *and* indented bodies' \ - regex lisp_special_indent_forms \ - '(?:def.*|if(-.*|)|let.*|lambda|with-.*|when(-.*|))' - -define-command -hidden lisp-indent-on-new-line %{ - # registers: i = best align point so far; w = start of first word of form - evaluate-commands -draft -save-regs '/"|^@iw' -itersel %{ - execute-keys -draft 'gk"iZ' - try %{ - execute-keys -draft '[bl"i"wZ' - - try %{ - # If a special form, indent another (indentwidth - 1) spaces - execute-keys -draft '"wze\A' %opt{lisp_special_indent_forms} '\z' - execute-keys -draft '"wzes.{' %sh{printf $(( kak_opt_indentwidth - 1 ))} '}\K.*;"i' - } catch %{ - # If not "special" form and parameter appears on line 1, indent to parameter - execute-keys -draft '"wzes\h\K[^\s].*;"i' - } - } - try %{ execute-keys -draft '[rl"i' } - try %{ execute-keys -draft '[Bl"i' } - execute-keys -draft ';"ia&' - } -} - -# Initialization -# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ - -hook -group lisp-highlight global WinSetOption filetype=lisp %{ - add-highlighter window/lisp ref lisp - hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/lisp } -} - -hook global WinSetOption filetype=lisp %{ - hook window ModeChange insert:.* -group lisp-trim-indent lisp-trim-indent - hook window InsertChar \n -group lisp-indent lisp-indent-on-new-line - - hook -once -always window WinSetOption filetype=.* %{ remove-hooks window lisp-.+ } -} diff --git a/rc/base/lua.kak b/rc/base/lua.kak deleted file mode 100644 index 605148e0..00000000 --- a/rc/base/lua.kak +++ /dev/null @@ -1,103 +0,0 @@ -# http://lua.org -# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ - -# Detection -# ‾‾‾‾‾‾‾‾‾ - -hook global BufCreate .*[.](lua) %{ - set-option buffer filetype lua -} - -# Highlighters -# ‾‾‾‾‾‾‾‾‾‾‾‾ - -add-highlighter shared/lua regions -add-highlighter shared/lua/code default-region group -add-highlighter shared/lua/raw_string region -match-capture '\[(=*)\[' '\](=*)\]' fill string -add-highlighter shared/lua/raw_comment region -match-capture '--\[(=*)\[' '\](=*)\]' fill comment -add-highlighter shared/lua/double_string region '"' (?^\h*(else)$^\h*(if)s\A|\z) } - try %{ execute-keys -draft ^\h*(end)$^\h*(for|function|if|while)s\A|\z) } - } -} - -define-command -hidden lua-indent-on-new-line %{ - evaluate-commands -no-hooks -draft -itersel %{ - # preserve previous line indent - try %{ execute-keys -draft K } - # remove trailing white spaces from previous line - try %{ execute-keys -draft ks\h+$d } - # indent after start structure - try %{ execute-keys -draft k^\h*(else|elseif|for|function|if|while)\bj } - } -} - -define-command -hidden lua-insert-on-new-line %[ - evaluate-commands -no-hooks -draft -itersel %[ - # copy -- comment prefix and following white spaces - try %{ execute-keys -draft ks^\h*\K--\h*yghjP } - # wisely add end structure - evaluate-commands -save-regs x %[ - try %{ execute-keys -draft ks^\h+"xy } catch %{ reg x '' } # Save previous line indent in register x - try %[ execute-keys -draft k ^x(for|function|if|while) J}iJ ^x(else|end|elseif)$ # Validate previous line and that it is not closed yet - execute-keys -draft oxend ] # auto insert end - ] - ] -] - -# Initialization -# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ - -hook -group lua-highlight global WinSetOption filetype=lua %{ - add-highlighter window/lua ref lua - hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/lua } -} - -hook global WinSetOption filetype=lua %{ - hook window InsertChar .* -group lua-indent lua-indent-on-char - hook window InsertChar \n -group lua-indent lua-indent-on-new-line - hook window InsertChar \n -group lua-insert lua-insert-on-new-line - - alias window alt lua-alternative-file - - hook -once -always window WinSetOption filetype=.* %{ - remove-hooks window lua-.+ - unalias window alt lua-alternative-file - } -} diff --git a/rc/base/mail.kak b/rc/base/mail.kak deleted file mode 100644 index 4323d28c..00000000 --- a/rc/base/mail.kak +++ /dev/null @@ -1,13 +0,0 @@ -hook global BufCreate .+\.eml %{ - set-option buffer filetype mail -} - -add-highlighter shared/mail group -add-highlighter shared/mail/ regex ^(From|To|Cc|Bcc|Subject|Reply-To|In-Reply-To|Date):([^\n]*(?:\n\h+[^\n]+)*)$ 1:keyword 2:attribute -add-highlighter shared/mail/ regex <[^@>]+@.*?> 0:string -add-highlighter shared/mail/ regex ^>.*?$ 0:comment - -hook -group mail-highlight global WinSetOption filetype=mail %{ - add-highlighter window/mail ref mail - hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/mail } -} diff --git a/rc/base/markdown.kak b/rc/base/markdown.kak deleted file mode 100644 index 18f3ccf6..00000000 --- a/rc/base/markdown.kak +++ /dev/null @@ -1,85 +0,0 @@ -# http://daringfireball.net/projects/markdown -# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ - -# Detection -# ‾‾‾‾‾‾‾‾‾ - -hook global BufCreate .*[.](markdown|md|mkd) %{ - set-option buffer filetype markdown -} - -# Highlighters -# ‾‾‾‾‾‾‾‾‾‾‾‾ - -add-highlighter shared/markdown regions -add-highlighter shared/markdown/inline default-region regions -add-highlighter shared/markdown/inline/text default-region group - -evaluate-commands %sh{ - languages=" - c cabal clojure coffee cpp css cucumber d diff dockerfile fish gas go - haml haskell html ini java javascript json julia kak kickstart latex - lisp lua makefile markdown moon objc perl pug python ragel ruby rust - sass scala scss sh swift toml tupfile typescript yaml sql - " - for lang in ${languages}; do - printf 'add-highlighter shared/markdown/%s region -match-capture ^(\h*)```\h*%s\\b ^(\h*)``` regions\n' "${lang}" "${lang}" - printf 'add-highlighter shared/markdown/%s/ default-region fill meta\n' "${lang}" - [ "${lang}" = kak ] && ref=kakrc || ref="${lang}" - printf 'add-highlighter shared/markdown/%s/inner region \A```[^\\n]*\K (?=```) ref %s\n' "${lang}" "${ref}" - done -} - -add-highlighter shared/markdown/codeblock region -match-capture \ - ^(\h*)```\h* \ - ^(\h*)```\h*$ \ - fill meta - -add-highlighter shared/markdown/listblock region ^\h*[-*]\s ^\h*((?=[-*])|$) regions -add-highlighter shared/markdown/listblock/marker region \A [-*]\s fill bullet -add-highlighter shared/markdown/listblock/content default-region ref markdown/inline - -add-highlighter shared/markdown/inline/code region -match-capture (`+) (`+) fill mono - -# Setext-style header -add-highlighter shared/markdown/inline/text/ regex (\A|\n\n)[^\n]+\n={2,}\h*\n\h*$ 0:title -add-highlighter shared/markdown/inline/text/ regex (\A|\n\n)[^\n]+\n-{2,}\h*\n\h*$ 0:header - -# Atx-style header -add-highlighter shared/markdown/inline/text/ regex ^#[^\n]* 0:header - -add-highlighter shared/markdown/inline/text/ regex (? 0:link -add-highlighter shared/markdown/inline/text/ regex ^\[[^\]\n]*\]:\h*([^\n]*) 1:link -add-highlighter shared/markdown/inline/text/ regex ^\h*(>\h*)+ 0:comment -add-highlighter shared/markdown/inline/text/ regex \H\K\h\h$ 0:PrimarySelection - -# Commands -# ‾‾‾‾‾‾‾‾ - -define-command -hidden markdown-indent-on-new-line %{ - evaluate-commands -draft -itersel %{ - # copy block quote(s), list item prefix and following white spaces - try %{ execute-keys -draft k s ^\h*\K((>\h*)+([*+-]\h)?|(>\h*)*[*+-]\h)\h* y gh j P } - # preserve previous line indent - try %{ execute-keys -draft \; K } - # remove trailing white spaces - try %{ execute-keys -draft -itersel %{ k s \h+$ d } } - } -} - -# Initialization -# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ - -hook -group markdown-highlight global WinSetOption filetype=markdown %{ - add-highlighter window/markdown ref markdown - hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/markdown } -} - -hook global WinSetOption filetype=markdown %{ - hook window InsertChar \n -group markdown-indent markdown-indent-on-new-line - hook -once -always window WinSetOption filetype=.* %{ remove-hooks window markdown-.+ } -} diff --git a/rc/base/mercurial.kak b/rc/base/mercurial.kak deleted file mode 100644 index 3f84eea2..00000000 --- a/rc/base/mercurial.kak +++ /dev/null @@ -1,18 +0,0 @@ -# https://www.mercurial-scm.org/ -# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ - -# Detection -# ‾‾‾‾‾‾‾‾‾ - -hook global BufCreate .*hg-editor-\w+\.txt$ %{ - set-option buffer filetype hg-commit -} - -# Highlighters -# ‾‾‾‾‾‾‾‾‾‾‾‾ - -hook -group hg-commit-highlight global WinSetOption filetype=hg-commit %{ - add-highlighter window/ group hg-commit-highlight - add-highlighter window/hg-commit-highlight regex '^HG:[^\n]*' 0:comment - hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/hg-commit-highlight } -} diff --git a/rc/base/new-client.kak b/rc/base/new-client.kak deleted file mode 100644 index 6ec538a9..00000000 --- a/rc/base/new-client.kak +++ /dev/null @@ -1,12 +0,0 @@ -define-command new -params .. -command-completion -docstring ' -new []: create a new kakoune client -The ''terminal'' alias is being used to determine the user''s preferred terminal emulator -The optional arguments are passed as commands to the new client' \ -%{ - try %{ - terminal kak -c %val{session} -e "%arg{@}" - } catch %{ - fail "The 'terminal' alias must be defined to use this command" - } -} - diff --git a/rc/base/ocaml.kak b/rc/base/ocaml.kak deleted file mode 100644 index 0a3d49bf..00000000 --- a/rc/base/ocaml.kak +++ /dev/null @@ -1,38 +0,0 @@ -# http://ocaml.org -# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ - -# Detection -# ‾‾‾‾‾‾‾‾‾ - -hook global BufCreate .*\.mli? %{ - set-option buffer filetype ocaml -} - -# Highlighters -# ‾‾‾‾‾‾‾‾‾‾‾‾ - -add-highlighter shared/ocaml regions -add-highlighter shared/ocaml/code default-region group -add-highlighter shared/ocaml/string region '"' (?|\$\?|\$@|\$\[|\$\\|\$\]|\$\^|\$\||\$~|%!|@\+|@-|@_} 0:value -add-highlighter shared/perl/code/ regex (%ENV|%INC|%OVERLOAD|%SIG|@ARGV|@INC|@LAST_MATCH_START) 0:value -add-highlighter shared/perl/code/ regex %{%\^(H)\b} 0:value -add-highlighter shared/perl/code/ regex \$\^(S|T|V|W|X|A|C|D|E|F|H|I|L|M|N|O|P|R)\b 0:value -add-highlighter shared/perl/code/ regex \$\^(RE_TRIE_MAXBUF|TAINT|UNICODE|UTF8LOCALE|WARNING_BITS|WIDE_SYSTEM_CALLS|CHILD_ERROR_NATIVE|ENCODING|OPEN|RE_DEBUG_FLAGS)\b 0:value - -add-highlighter shared/perl/code/ regex \$[0-9]+ 0:attribute -add-highlighter shared/perl/code/ regex \b-(B|b|C|c|d|e|f|g|k|l|M|O|o|p|r|R|S|s|T|t|u|w|W|X|x|z)\b 0:attribute - -add-highlighter shared/perl/code/ regex \$[a-zA-Z_][a-zA-Z0-9_]* 0:variable - -add-highlighter shared/perl/code/ regex \$(a|b|LAST_REGEXP_CODE_RESULT|LIST_SEPARATOR|MATCH|MULTILINE_MATCHING|NR|OFMT|OFS|ORS|OS_ERROR|OSNAME|OUTPUT_AUTO_FLUSH|OUTPUT_FIELD_SEPARATOR|OUTPUT_RECORD_SEPARATOR)\b 0:value -add-highlighter shared/perl/code/ regex \$(LAST_REGEXP_CODE_RESULT|LIST_SEPARATOR|MATCH|MULTILINE_MATCHING|NR|OFMT|OFS|ORS|OS_ERROR|OSNAME|OUTPUT_AUTO_FLUSH|OUTPUT_FIELD_SEPARATOR|OUTPUT_RECORD_SEPARATOR|PERL_VERSION|ACCUMULATOR|PERLDB|ARG|PID|ARGV|POSTMATCH|PREMATCH|BASETIME|PROCESS_ID|CHILD_ERROR|PROGRAM_NAME|COMPILING|REAL_GROUP_ID|DEBUGGING|REAL_USER_ID|EFFECTIVE_GROUP_ID|RS|EFFECTIVE_USER_ID|SUBSCRIPT_SEPARATOR|EGID|SUBSEP|ERRNO|SYSTEM_FD_MAX|EUID|UID|EVAL_ERROR|WARNING|EXCEPTIONS_BEING_CAUGHT|EXECUTABLE_NAME|EXTENDED_OS_ERROR|FORMAT_FORMFEED|FORMAT_LINE_BREAK_CHARACTERS|FORMAT_LINES_LEFT|FORMAT_LINES_PER_PAGE|FORMAT_NAME|FORMAT_PAGE_NUMBER|FORMAT_TOP_NAME|GID|INPLACE_EDIT|INPUT_LINE_NUMBER|INPUT_RECORD_SEPARATOR|LAST_MATCH_END|LAST_PAREN_MATCH)\b 0:value - -# Commands -# ‾‾‾‾‾‾‾‾ - -define-command -hidden perl-indent-on-new-line %~ - evaluate-commands -draft -itersel %= - # preserve previous line indent - try %{ execute-keys -draft \;K } - # indent after lines ending with { or ( - try %[ execute-keys -draft k [{(]\h*$ j ] - # cleanup trailing white spaces on the previous line - try %{ execute-keys -draft k s \h+$ d } - # align to opening paren of previous line - try %{ execute-keys -draft [( \A\([^\n]+\n[^\n]*\n?\z s \A\(\h*.|.\z '' & } - # copy // comments prefix - try %{ execute-keys -draft \;k s ^\h*\K/{2,} yP } - # indent after a switch's case/default statements - try %[ execute-keys -draft k ^\h*(case|default).*:$ j ] - # indent after if|else|while|for - try %[ execute-keys -draft \;)MB \A(if|else|while|for)\h*\(.*\)\h*\n\h*\n?\z s \A|.\z 11 ] - = -~ - -define-command -hidden perl-indent-on-opening-curly-brace %[ - # align indent with opening paren when { is entered on a new line after the closing paren - try %[ execute-keys -draft -itersel h)M \A\(.*\)\h*\n\h*\{) s \A|.\z 1 ] -] - -define-command -hidden perl-indent-on-closing-curly-brace %[ - # align to opening curly brace when alone on a line - try %[ execute-keys -itersel -draft ^\h+\}$hms\A|.\z1 ] -] - -# Initialization -# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ - -hook -group perl-highlight global WinSetOption filetype=perl %{ - add-highlighter window/perl ref perl - hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/perl } -} - -hook global WinSetOption filetype=perl %{ - # cleanup trailing whitespaces when exiting insert mode - hook window ModeChange insert:.* -group perl-trim-indent %{ try %{ execute-keys -draft s^\h+$d } } - hook window InsertChar \n -group perl-indent perl-indent-on-new-line - hook window InsertChar \{ -group perl-indent perl-indent-on-opening-curly-brace - hook window InsertChar \} -group perl-indent perl-indent-on-closing-curly-brace - - hook -once -always window WinSetOption filetype=.* %{ remove-hooks window perl-.+ } -} diff --git a/rc/base/restructuredtext.kak b/rc/base/restructuredtext.kak deleted file mode 100644 index 1eaf4bfc..00000000 --- a/rc/base/restructuredtext.kak +++ /dev/null @@ -1,74 +0,0 @@ -# Detection -# ‾‾‾‾‾‾‾‾‾ - -hook global BufCreate .*[.](rst) %{ - set-option buffer filetype restructuredtext -} - -# Highlighters -# ‾‾‾‾‾‾‾‾‾‾‾‾ - -add-highlighter shared/restructuredtext regions -add-highlighter shared/restructuredtext/content default-region group -add-highlighter shared/restructuredtext/code region ::\h*\n ^[^\s] fill meta - -evaluate-commands %sh{ - for ft in c cabal clojure coffee cpp css cucumber ddiff dockerfile \ - fish gas go haml haskell html ini java javascript json \ - julia kak kickstart latex lisp lua makefile moon objc \ - perl pug python ragel ruby rust sass scala scss sh swift \ - tupfile yaml; do - if [ "$ft" = kak ]; then ref="kakrc"; else ref="$ft"; fi - printf 'add-highlighter shared/restructuredtext/%s region %s %s ref %s\n' "$ft" '\.\.\h*'$ft'::\h*c\h*\n' '^\S' "$ref" - done -} - -# Setext-style header -# Valid header characters: -# # ! " $ % & ' ( ) * + , - . / : ; < = > ? @ [ \ ] ^ _ ` { | } ~ - -add-highlighter shared/restructuredtext/content/ regex (\A|\n\n)(#{3,}\n)?[^\n]+\n(#{3,})$ 0:title -add-highlighter shared/restructuredtext/content/ regex (\A|\n\n)(!{3,}\n)?[^\n]+\n(!{3,})$ 0:header -add-highlighter shared/restructuredtext/content/ regex (\A|\n\n)("{3,}\n)?[^\n]+\n("{3,})$ 0:header -add-highlighter shared/restructuredtext/content/ regex (\A|\n\n)(\${3,}\n)?[^\n]+\n(\${3,})$ 0:header -add-highlighter shared/restructuredtext/content/ regex (\A|\n\n)(%{3,}\n)?[^\n]+\n(%{3,})$ 0:header -add-highlighter shared/restructuredtext/content/ regex (\A|\n\n)(&{3,}\n)?[^\n]+\n(&{3,})$ 0:header -add-highlighter shared/restructuredtext/content/ regex (\A|\n\n)('{3,}\n)?[^\n]+\n('{3,})$ 0:header -add-highlighter shared/restructuredtext/content/ regex (\A|\n\n)(\({3,}\n)?[^\n]+\n(\({3,})$ 0:header -add-highlighter shared/restructuredtext/content/ regex (\A|\n\n)(\){3,}\n)?[^\n]+\n(\){3,})$ 0:header -add-highlighter shared/restructuredtext/content/ regex (\A|\n\n)(\*{3,}\n)?[^\n]+\n(\*{3,})$ 0:header -add-highlighter shared/restructuredtext/content/ regex (\A|\n\n)(\+{3,}\n)?[^\n]+\n(\+{3,})$ 0:header -add-highlighter shared/restructuredtext/content/ regex (\A|\n\n)(,{3,}\n)?[^\n]+\n(,{3,})$ 0:header -add-highlighter shared/restructuredtext/content/ regex (\A|\n\n)(-{3,}\n)?[^\n]+\n(-{3,})$ 0:header -add-highlighter shared/restructuredtext/content/ regex (\A|\n\n)(\.{3,}\n)?[^\n]+\n(\.{3,})$ 0:header -add-highlighter shared/restructuredtext/content/ regex (\A|\n\n)(/{3,}\n)?[^\n]+\n(/{3,})$ 0:header -add-highlighter shared/restructuredtext/content/ regex (\A|\n\n)(:{3,}\n)?[^\n]+\n(:{3,})$ 0:header -add-highlighter shared/restructuredtext/content/ regex (\A|\n\n)(\;{3,}\n)?[^\n]+\n(\;{3,})$ 0:header -add-highlighter shared/restructuredtext/content/ regex (\A|\n\n)(<{3,}\n)?[^\n]+\n(<{3,})$ 0:header -add-highlighter shared/restructuredtext/content/ regex (\A|\n\n)(={3,}\n)?[^\n]+\n(={3,})$ 0:header -add-highlighter shared/restructuredtext/content/ regex (\A|\n\n)(>{3,}\n)?[^\n]+\n(>{3,})$ 0:header -add-highlighter shared/restructuredtext/content/ regex (\A|\n\n)(\?{3,}\n)?[^\n]+\n(\?{3,})$ 0:header -add-highlighter shared/restructuredtext/content/ regex (\A|\n\n)(@{3,}\n)?[^\n]+\n(@{3,})$ 0:header -add-highlighter shared/restructuredtext/content/ regex (\A|\n\n)(\[{3,}\n)?[^\n]+\n(\[{3,})$ 0:header -add-highlighter shared/restructuredtext/content/ regex (\A|\n\n)(\\{3,}\n)?[^\n]+\n(\\{3,})$ 0:header -add-highlighter shared/restructuredtext/content/ regex (\A|\n\n)(\]{3,}\n)?[^\n]+\n(\]{3,})$ 0:header -add-highlighter shared/restructuredtext/content/ regex (\A|\n\n)(\^{3,}\n)?[^\n]+\n(\^{3,})$ 0:header -add-highlighter shared/restructuredtext/content/ regex (\A|\n\n)(_{3,}\n)?[^\n]+\n(_{3,})$ 0:header -add-highlighter shared/restructuredtext/content/ regex (\A|\n\n)(`{3,}\n)?[^\n]+\n(`{3,})$ 0:header -add-highlighter shared/restructuredtext/content/ regex (\A|\n\n)(\{{3,}\n)?[^\n]+\n(\{{3,})$ 0:header -add-highlighter shared/restructuredtext/content/ regex (\A|\n\n)(\|{3,}\n)?[^\n]+\n(\|{3,})$ 0:header -add-highlighter shared/restructuredtext/content/ regex (\A|\n\n)(\}{3,}\n)?[^\n]+\n(\}{3,})$ 0:header -add-highlighter shared/restructuredtext/content/ regex (\A|\n\n)(~{3,}\n)?[^\n]+\n(~{3,})$ 0:header - -# Inline markup -add-highlighter shared/restructuredtext/content/ regex [^*](\*\*([^\s*]|([^\s*][^*]*[^\s*]))\*\*)[^*] 1:bold -add-highlighter shared/restructuredtext/content/ regex [^*](\*([^\s*]|([^\s*][^*]*[^\s*]))\*)[^*] 1:italic -add-highlighter shared/restructuredtext/content/ regex [^`](``([^\s`]|([^\s`][^`]*[^\s`]))``)[^`] 1:mono - -# Initialization -# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ - -hook -group restructuredtext-highlight global WinSetOption filetype=restructuredtext %{ - add-highlighter window/restructuredtext ref restructuredtext - hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/restructuredtext } -} diff --git a/rc/base/ruby.kak b/rc/base/ruby.kak deleted file mode 100644 index 3e5cfcfa..00000000 --- a/rc/base/ruby.kak +++ /dev/null @@ -1,168 +0,0 @@ -# http://ruby-lang.org -# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ - -# Detection -# ‾‾‾‾‾‾‾‾‾ - -hook global BufCreate .*(([.](rb))|(irbrc)|(pryrc)|(Brewfile)|(Capfile|[.]cap)|(Gemfile|[.]gemspec)|(Guardfile)|(Rakefile|[.]rake)|(Thorfile|[.]thor)|(Vagrantfile)) %{ - set-option buffer filetype ruby -} - -# Highlighters -# ‾‾‾‾‾‾‾‾‾‾‾‾ - -add-highlighter shared/ruby regions -add-highlighter shared/ruby/code default-region group -add-highlighter shared/ruby/double_symbol region ':"' (? fill meta -add-highlighter shared/ruby/heredoc region '<<[-~]?(?!self)(\w+)' '^\h*(\w+)$' fill string -add-highlighter shared/ruby/division region '[\w\)\]](/|(\h+/\h+))' '\w' group # Help Kakoune to better detect /…/ literals - -# Regular expression flags are: i → ignore case, m → multi-lines, o → only interpolate #{} blocks once, x → extended mode (ignore white spaces) -# Literals are: i → array of symbols, q → string, r → regular expression, s → symbol, w → array of words, x → capture shell result - -add-highlighter shared/ruby/double_string/ default-region fill string -add-highlighter shared/ruby/double_string/interpolation region -recurse \{ \Q#{ \} fill meta - -add-highlighter shared/ruby/double_symbol/ default-region fill variable -add-highlighter shared/ruby/double_symbol/interpolation region -recurse \{ \Q#{ \} fill meta - -add-highlighter shared/ruby/backtick/ default-region fill meta -add-highlighter shared/ruby/backtick/interpolation region -recurse \{ \Q#{ \} fill meta - -add-highlighter shared/ruby/regex/ default-region fill meta -add-highlighter shared/ruby/regex/interpolation region -recurse \{ \Q#{ \} fill meta - -evaluate-commands %sh{ - # Grammar - # Keywords are collected searching for keywords at - # https://github.com/ruby/ruby/blob/trunk/parse.y - keywords="alias|and|begin|break|case|class|def|defined|do|else|elsif|end" - keywords="${keywords}|ensure|false|for|if|in|module|next|nil|not|or|private|protected|public|redo" - keywords="${keywords}|rescue|retry|return|self|super|then|true|undef|unless|until|when|while|yield" - attributes="attr_reader|attr_writer|attr_accessor" - values="false|true|nil" - meta="require|include|extend" - - # Add the language's grammar to the static completion list - printf %s\\n "hook global WinSetOption filetype=ruby %{ - set-option window static_words ${keywords} ${attributes} ${values} ${meta} - }" | tr '|' ' ' - - # Highlight keywords - printf %s " - add-highlighter shared/ruby/code/ regex \b(${keywords})\b 0:keyword - add-highlighter shared/ruby/code/ regex \b(${attributes})\b 0:attribute - add-highlighter shared/ruby/code/ regex \b(${values})\b 0:value - add-highlighter shared/ruby/code/ regex \b(${meta})\b 0:meta - " -} - -add-highlighter shared/ruby/code/ regex \b(\w+:(?!:))|(:?(\$(-[0FIKWadilpvw]|["'`/~&+=!$*,:.\;<>?@\\])|(\$|@@?)\w+))|((?[=>]?|<((=>?)|<)?|[+\-]@?|\*\*?|===?|[/`%&!^|~]|(\w+[=?!]?)|(\[\]=?)))|([A-Z]\w*|^|\h)\K::(?=[A-Z]) 0:variable - -# Commands -# ‾‾‾‾‾‾‾‾ - -define-command ruby-alternative-file -docstring 'Jump to the alternate file (implementation ↔ test)' %{ evaluate-commands %sh{ - case $kak_buffile in - *spec/*_spec.rb) - altfile=$(eval echo $(echo $kak_buffile | sed s+spec/+'*'/+';'s/_spec//)) - [ ! -f $altfile ] && echo "echo -markup '{Error}implementation file not found'" && exit - ;; - *.rb) - path=$kak_buffile - dirs=$(while [ $path ]; do echo $path; path=${path%/*}; done | tail -n +2) - for dir in $dirs; do - altdir=$dir/spec - if [ -d $altdir ]; then - altfile=$altdir/$(realpath $kak_buffile --relative-to $dir | sed s+[^/]'*'/++';'s/.rb$/_spec.rb/) - break - fi - done - [ ! -d $altdir ] && echo "echo -markup '{Error}spec/ not found'" && exit - ;; - *) - echo "echo -markup '{Error}alternative file not found'" && exit - ;; - esac - echo "edit $altfile" -}} - -define-command -hidden ruby-trim-indent %{ - evaluate-commands -no-hooks -draft -itersel %{ - execute-keys - # remove trailing white spaces - try %{ execute-keys -draft s \h + $ d } - } -} - -define-command -hidden ruby-indent-on-char %{ - evaluate-commands -no-hooks -draft -itersel %{ - # align middle and end structures to start - try %{ execute-keys -draft ^ \h * (else|elsif) $ ^ \h * (if) s \A | \z ) } - try %{ execute-keys -draft ^ \h * (when) $ ^ \h * (case) s \A | \z ) } - try %{ execute-keys -draft ^ \h * (rescue) $ ^ \h * (begin) s \A | \z ) } - try %{ execute-keys -draft ^ \h * (end) $ ^ \h * (begin|case|class|def|do|for|if|module|unless|until|while) s \A | \z ) } - } -} - -define-command -hidden ruby-indent-on-new-line %{ - evaluate-commands -no-hooks -draft -itersel %{ - # preserve previous line indent - try %{ execute-keys -draft K } - # filter previous line - try %{ execute-keys -draft k : ruby-trim-indent } - # indent after start structure - try %{ execute-keys -draft k ^ \h * (begin|case|class|def|do|else|elsif|ensure|for|if|module|rescue|unless|until|when|while) \b j } - } -} - -define-command -hidden ruby-insert-on-new-line %[ - evaluate-commands -no-hooks -draft -itersel %[ - # copy _#_ comment prefix and following white spaces - try %{ execute-keys -draft k s '^\h*\K#\h*' y gh j P } - # wisely add end structure - evaluate-commands -save-regs x %[ - try %{ execute-keys -draft k s ^ \h + \" x y } catch %{ reg x '' } - try %[ - evaluate-commands -draft %[ - execute-keys -draft k ^x(begin|case|class|def|do|for|if|module|unless|until|while) # Check if previous line opens a block - # Check that we do not already have an end for this indent level, or that we have another block opening at that indent level first - execute-keys -draft Ge \A(^\n|^x(?!begin)(?!case)(?!class)(?!def)(?!do)(?!for)(?!if)(?!module)(?!unless)(?!until)(?!while)[^\n]*\n)+xend$ - ] - execute-keys -draft oxend # insert a new line with containing end - ] - ] - ] -] - -# Initialization -# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ - -hook -group ruby-highlight global WinSetOption filetype=ruby %{ - add-highlighter window/ruby ref ruby - hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/ruby } -} - -hook global WinSetOption filetype=ruby %{ - hook window InsertChar .* -group ruby-indent ruby-indent-on-char - hook window InsertChar \n -group ruby-insert ruby-insert-on-new-line - hook window InsertChar \n -group ruby-indent ruby-indent-on-new-line - - alias window alt ruby-alternative-file - - hook -once -always window WinSetOption filetype=.* %{ - remove-hooks window ruby-.+ - unalias window alt ruby-alternative-file - } -} diff --git a/rc/base/rust.kak b/rc/base/rust.kak deleted file mode 100644 index 9cbca842..00000000 --- a/rc/base/rust.kak +++ /dev/null @@ -1,88 +0,0 @@ -# http://rust-lang.org -# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ - -# Detection -# ‾‾‾‾‾‾‾‾‾ - -hook global BufCreate .*[.](rust|rs) %{ - set-option buffer filetype rust -} - -# Highlighters -# ‾‾‾‾‾‾‾‾‾‾‾‾ - -add-highlighter shared/rust regions -add-highlighter shared/rust/code default-region group -add-highlighter shared/rust/string region %{(? s \h+$ d } -} - -define-command -hidden rust-indent-on-new-line %~ - evaluate-commands -draft -itersel %< - # copy // comments prefix and following white spaces - try %{ execute-keys -draft k s ^\h*\K//[!/]?\h* y gh j P } - # preserve previous line indent - try %{ execute-keys -draft \; K } - # filter previous line - try %{ execute-keys -draft k : rust-trim-indent } - # indent after lines ending with { or ( - try %[ execute-keys -draft k [{(]\h*$ j ] - # align to opening paren of previous line - try %{ execute-keys -draft [( \A\([^\n]+\n[^\n]*\n?\z s \A\(\h*.|.\z & } - > -~ - -define-command -hidden rust-indent-on-opening-curly-brace %[ - evaluate-commands -draft -itersel %_ - # align indent with opening paren when { is entered on a new line after the closing paren - try %[ execute-keys -draft h ) M \A\(.*\)\h*\n\h*\{\z s \A|.\z 1 ] - _ -] - -define-command -hidden rust-indent-on-closing-curly-brace %[ - evaluate-commands -draft -itersel %_ - # align to opening curly brace when alone on a line - try %[ execute-keys -draft ^\h+\}$ h m s \A|.\z 1 ] - _ -] - -# Initialization -# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ - -hook -group rust-highlight global WinSetOption filetype=rust %{ - add-highlighter window/rust ref rust - hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/rust } -} - -hook global WinSetOption filetype=rust %[ - hook window ModeChange insert:.* -group rust-trim-indent rust-trim-indent - hook window InsertChar \n -group rust-indent rust-indent-on-new-line - hook window InsertChar \{ -group rust-indent rust-indent-on-opening-curly-brace - hook window InsertChar \} -group rust-indent rust-indent-on-closing-curly-brace - hook -once -always window WinSetOption filetype=.* %{ remove-hooks window rust-.+ } -] diff --git a/rc/base/scala.kak b/rc/base/scala.kak deleted file mode 100644 index 1e62e2ad..00000000 --- a/rc/base/scala.kak +++ /dev/null @@ -1,75 +0,0 @@ -# http://scala-lang.org -# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ - -# Detection -# ‾‾‾‾‾‾‾‾‾ - -hook global BufCreate .*[.](scala) %{ - set-option buffer filetype scala -} - -# Highlighters -# ‾‾‾‾‾‾‾‾‾‾‾‾ - -add-highlighter shared/scala regions -add-highlighter shared/scala/code default-region group -add-highlighter shared/scala/string region '"' (?|<:|:>|=:=|::|&&|\|\|) 0:operator - -# Commands -# ‾‾‾‾‾‾‾‾ - -define-command -hidden scala-trim-indent %{ - # remove trailing white spaces - try %{ execute-keys -draft -itersel s \h+$ d } -} - -define-command -hidden scala-indent-on-new-line %[ - evaluate-commands -draft -itersel %[ - # copy // comments prefix and following white spaces - try %[ execute-keys -draft k s ^\h*\K#\h* y gh j P ] - # preserve previous line indent - try %[ execute-keys -draft \; K ] - # filter previous line - try %[ execute-keys -draft k : scala-trim-indent ] - # indent after lines ending with { - try %[ execute-keys -draft k \{$ j ] - ] -] - -define-command -hidden scala-indent-on-closing-curly-brace %[ - evaluate-commands -draft -itersel %[ - # align to opening curly brace when alone on a line - try %[ execute-keys -draft ^\h+\}$ m s \A|.\z 1 ] - ] -] - -# Initialization -# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ - -hook -group scala-highlight global WinSetOption filetype=scala %{ - add-highlighter window/scala ref scala - hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/scala } -} - -hook global WinSetOption filetype=scala %[ - hook window ModeChange insert:.* -group scala-trim-indent scala-trim-indent - hook window InsertChar \n -group scala-indent scala-indent-on-new-line - hook window InsertChar \} -group scala-indent scala-indent-on-closing-curly-brace - - hook -once -always window WinSetOption filetype=.* %{ remove-hooks window scala-.+ } -] diff --git a/rc/base/screen.kak b/rc/base/screen.kak deleted file mode 100644 index e4ddd2e9..00000000 --- a/rc/base/screen.kak +++ /dev/null @@ -1,69 +0,0 @@ -# http://gnu.org/software/screen/ -# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ - -hook -group GNUscreen global KakBegin .* %sh{ - [ -z "${STY}" ] && exit - echo " - alias global focus screen-focus - alias global terminal screen-terminal-vertical - " -} - -define-command screen-terminal-impl -hidden -params 3.. %{ - nop %sh{ - tty="$(ps -o tty ${kak_client_pid} | tail -n 1)" - screen -X eval "$1" "$2" - shift 2 - # see x11.kak for what this achieves - args=$( - for i in "$@"; do - if [ "$i" = '' ]; then - printf "'' " - else - printf %s "$i" | sed -e "s|'|'\\\\''|g; s|^|'|; s|$|' |" - fi - done - ) - screen -X screen sh -c "${args} ; screen -X remove" < "/dev/$tty" - } -} - -define-command screen-terminal-vertical -params 1.. -shell-completion -docstring ' -screen-terminal-vertical [] []: create a new terminal as a screen pane -The current pane is split into two, left and right -The program passed as argument will be executed in the new terminal' \ -%{ - screen-terminal-impl 'split -v' 'focus right' %arg{@} -} -define-command screen-terminal-horizontal -params 1.. -shell-completion -docstring ' -screen-terminal-horizontal []: create a new terminal as a screen pane -The current pane is split into two, top and bottom -The program passed as argument will be executed in the new terminal' \ -%{ - screen-terminal-impl 'split -h' 'focus down' %arg{@} -} -define-command screen-terminal-window -params 1.. -shell-completion -docstring ' -screen-terminal-window []: create a new terminal as a screen window -The program passed as argument will be executed in the new terminal' \ -%{ - nop %sh{ - tty="$(ps -o tty ${kak_client_pid} | tail -n 1)" - screen -X screen "$@" < "/dev/$tty" - } -} - -define-command screen-focus -params ..1 -client-completion -docstring ' -screen-focus []: focus the given client -If no client is passed then the current one is used' \ -%{ - evaluate-commands %sh{ - if [ $# -eq 1 ]; then - printf %s\\n " - evaluate-commands -client '$1' focus - " - elif [ -n "${kak_client_env_STY}" ]; then - tty="$(ps -o tty ${kak_client_pid} | tail -n 1)" - screen -X select "${kak_client_env_WINDOW}" < "/dev/$tty" - fi - } -} diff --git a/rc/base/spell.kak b/rc/base/spell.kak deleted file mode 100644 index 10c0f915..00000000 --- a/rc/base/spell.kak +++ /dev/null @@ -1,121 +0,0 @@ -declare-option -hidden range-specs spell_regions -declare-option -hidden str spell_lang -declare-option -hidden str spell_tmp_file - -define-command -params ..1 \ - -docstring %{spell []: spell check the current buffer -The first optional argument is the language against which the check will be performed -Formats of language supported: - - ISO language code, e.g. 'en' - - language code above followed by a dash or underscore with an ISO country code, e.g. 'en-US'} \ - spell %{ - try %{ add-highlighter window/ ranges 'spell_regions' } - evaluate-commands %sh{ - file=$(mktemp -d "${TMPDIR:-/tmp}"/kak-spell.XXXXXXXX)/buffer - printf 'eval -no-hooks write -sync %s\n' "${file}" - printf 'set-option buffer spell_tmp_file %s\n' "${file}" - } - evaluate-commands %sh{ - if [ $# -ge 1 ]; then - if [ ${#1} -ne 2 ] && [ ${#1} -ne 5 ]; then - echo "echo -markup '{Error}Invalid language code (examples of expected format: en, en_US, en-US)'" - rm -rf "$(dirname "$kak_opt_spell_tmp_file")" - exit 1 - else - options="-l '$1'" - printf 'set-option buffer spell_lang %s\n' "$1" - fi - fi - - { - sed 's/^/^/' "$kak_opt_spell_tmp_file" | eval "aspell --byte-offsets -a $options" 2>&1 | { - line_num=1 - regions=$kak_timestamp - read line # drop the identification message - while read -r line; do - case "$line" in - [\#\&]*) - if expr "$line" : '^&' >/dev/null; then - pos=$(printf %s\\n "$line" | cut -d ' ' -f 4 | sed 's/:$//') - else - pos=$(printf %s\\n "$line" | cut -d ' ' -f 3) - fi - word=$(printf %s\\n "$line" | cut -d ' ' -f 2) - len=$(printf %s "$word" | wc -c) - regions="$regions $line_num.$pos+${len}|Error" - ;; - '') line_num=$((line_num + 1));; - \*) ;; - *) printf 'echo -markup %%{{Error}%s}\n' "${line}" | kak -p "${kak_session}";; - esac - done - printf 'set-option "buffer=%s" spell_regions %s' "${kak_bufname}" "${regions}" \ - | kak -p "${kak_session}" - } - rm -rf $(dirname "$kak_opt_spell_tmp_file") - } /dev/null 2>&1 & - } -} - -define-command spell-clear %{ - unset-option buffer spell_regions -} - -define-command spell-next %{ evaluate-commands %sh{ - anchor_line="${kak_selection_desc%%.*}" - anchor_col="${kak_selection_desc%%,*}" - anchor_col="${anchor_col##*.}" - - start_first="${kak_opt_spell_regions#* }" - start_first="${start_first%%|*}" - start_first="${start_first#\'}" - - find_next_word_desc() { - ## XXX: the `spell` command adds sorted selection descriptions to the range - printf %s\\n "${1}" \ - | sed -e "s/'//g" -e 's/^[0-9]* //' -e 's/|[^ ]*//g' \ - | tr ' ' '\n' \ - | while IFS=, read -r start end; do - start_line="${start%.*}" - start_col="${start#*.}" - end_line="${end%.*}" - end_col="${end#*.}" - - if [ "${start_line}" -lt "${anchor_line}" ]; then - continue - elif [ "${start_line}" -eq "${anchor_line}" ] \ - && [ "${start_col}" -le "${anchor_col}" ]; then - continue - fi - - printf 'select %s,%s\n' "${start}" "${end}" - break - done - } - - # no selection descriptions are in `spell_regions` - if ! expr "${start_first}" : '[0-9][0-9]*\.[0-9][0-9]*,[0-9][0-9]*\.[0-9]' >/dev/null; then - exit - fi - - next_word_desc=$(find_next_word_desc "${kak_opt_spell_regions}") - if [ -n "${next_word_desc}" ]; then - printf %s\\n "${next_word_desc}" - else - printf 'select %s\n' "${start_first}" - fi -} } - -define-command spell-replace %{ evaluate-commands %sh{ - if [ -n "$kak_opt_spell_lang" ]; then - options="-l '$kak_opt_spell_lang'" - fi - suggestions=$(printf %s "$kak_selection" | eval "aspell -a $options" | grep '^&' | cut -d: -f2) - menu=$(printf %s "${suggestions#?}" | awk -F', ' ' - { - for (i=1; i<=NF; i++) - printf "%s", "%{"$i"}" "%{execute-keys -itersel %{c"$i"be}}" - } - ') - printf 'try %%{ menu -auto-single %s }' "${menu}" -} } diff --git a/rc/base/sql.kak b/rc/base/sql.kak deleted file mode 100644 index dbecea9c..00000000 --- a/rc/base/sql.kak +++ /dev/null @@ -1,107 +0,0 @@ -# https://www.w3schools.com/sql/default.asp -# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ - -# Detection -# ‾‾‾‾‾‾‾‾‾ - -hook global BufCreate .*/?(?i)sql %{ - set-option buffer filetype sql -} - -# Highlighters -# ‾‾‾‾‾‾‾‾‾‾‾‾ - -add-highlighter shared/sql regions -add-highlighter shared/sql/code default-region group -add-highlighter shared/sql/double_string region '"' (?|<|>=|<=|<>|\+=|-=|\*=|/=|%=|&=|^-=|\|\*=' 0:operator -add-highlighter shared/sql/code/ regex \bNULL\b 0:value -add-highlighter shared/sql/code/ regex \b\d+(?:\.\d+)?\b 0:value - -# Initialization -# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ - -hook -group sql-highlight global WinSetOption filetype=sql %{ - add-highlighter window/sql ref sql - hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/sql } -} diff --git a/rc/base/swift.kak b/rc/base/swift.kak deleted file mode 100644 index 1526cadb..00000000 --- a/rc/base/swift.kak +++ /dev/null @@ -1,28 +0,0 @@ -hook global BufCreate .*\.(swift) %{ - set-option buffer filetype swift -} - -add-highlighter shared/swift regions -add-highlighter shared/swift/code default-region group -add-highlighter shared/swift/string region %{(? /dev/null 2>&1 & - } -} - -define-command tmux-terminal-vertical -params 1.. -shell-completion -docstring ' -tmux-terminal-vertical []: create a new terminal as a tmux pane -The current pane is split into two, top and bottom -The program passed as argument will be executed in the new terminal' \ -%{ - tmux-terminal-impl 'split-window -v' %arg{@} -} -define-command tmux-terminal-horizontal -params 1.. -shell-completion -docstring ' -tmux-terminal-horizontal []: create a new terminal as a tmux pane -The current pane is split into two, left and right -The program passed as argument will be executed in the new terminal' \ -%{ - tmux-terminal-impl 'split-window -h' %arg{@} -} -define-command tmux-terminal-window -params 1.. -shell-completion -docstring ' -tmux-terminal-window [] []: create a new terminal as a tmux window -The program passed as argument will be executed in the new terminal' \ -%{ - tmux-terminal-impl 'new-window' %arg{@} -} - -define-command tmux-focus -params ..1 -client-completion -docstring ' -tmux-focus []: focus the given client -If no client is passed then the current one is used' \ -%{ - evaluate-commands %sh{ - if [ $# -eq 1 ]; then - printf "evaluate-commands -client '%s' focus" "$1" - elif [ -n "${kak_client_env_TMUX}" ]; then - TMUX="${kak_client_env_TMUX}" tmux select-pane -t "${kak_client_env_TMUX_PANE}" > /dev/null - fi - } -} diff --git a/rc/base/x11.kak b/rc/base/x11.kak deleted file mode 100644 index 27b637ae..00000000 --- a/rc/base/x11.kak +++ /dev/null @@ -1,73 +0,0 @@ -# termcmd should be set such as the next argument is the whole -# command line to execute -declare-option -docstring %{shell command run to spawn a new terminal -A shell command is appended to the one set in this option at runtime} \ - str termcmd %sh{ - for termcmd in 'alacritty -e sh -c' \ - 'kitty sh -c' \ - 'termite -e ' \ - 'urxvt -e sh -c' \ - 'rxvt -e sh -c' \ - 'xterm -e sh -c' \ - 'roxterm -e sh -c' \ - 'mintty -e sh -c' \ - 'sakura -x ' \ - 'gnome-terminal -e ' \ - 'xfce4-terminal -e ' \ - 'konsole -e '; do - terminal=${termcmd%% *} - if command -v $terminal >/dev/null 2>&1; then - printf %s\\n "$termcmd" - exit - fi - done -} - -define-command x11-terminal -params 1.. -shell-completion -docstring ' -x11-terminal []: create a new terminal as an x11 window -The program passed as argument will be executed in the new terminal' \ -%{ - evaluate-commands %sh{ - if [ -z "${kak_opt_termcmd}" ]; then - echo "fail 'termcmd option is not set'" - exit - fi - # join arguments into a single string, in which they're delimited - # by single quotes, and with single quotes inside transformed to '\'' - # so that sh -c "$args" will re-split the arguments properly - # example: - # $1 = ab - # $2 = foo bar - # $3 = - # $4 = foo'bar - # $args = 'ab' 'foo bar' '' 'foo'\''bar' - # would be nicer to do in a single sed/awk call but that's difficult - args=$( - for i in "$@"; do - # special case to preserve empty variables as sed won't touch these - if [ "$i" = '' ]; then - printf "'' " - else - printf %s "$i" | sed -e "s|'|'\\\\''|g; s|^|'|; s|$|' |" - fi - done - ) - setsid ${kak_opt_termcmd} "$args" < /dev/null > /dev/null 2>&1 & - } -} - -define-command x11-focus -params ..1 -client-completion -docstring ' -x11-focus []: focus a given client''s window -If no client is passed, then the current client is used' \ -%{ - evaluate-commands %sh{ - if [ $# -eq 1 ]; then - printf "evaluate-commands -client '%s' focus" "$1" - else - xdotool windowactivate $kak_client_env_WINDOWID > /dev/null - fi - } -} - -alias global focus x11-focus -alias global terminal x11-terminal diff --git a/rc/base/yaml.kak b/rc/base/yaml.kak deleted file mode 100644 index 7076e13d..00000000 --- a/rc/base/yaml.kak +++ /dev/null @@ -1,58 +0,0 @@ -# http://yaml.org -# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ - -# Detection -# ‾‾‾‾‾‾‾‾‾ - -hook global BufCreate .*[.](ya?ml) %{ - set-option buffer filetype yaml -} - -# Highlighters -# ‾‾‾‾‾‾‾‾‾‾‾‾ - -add-highlighter shared/yaml regions -add-highlighter shared/yaml/code default-region group -add-highlighter shared/yaml/double_string region '"' (? s \h+$ d } -} - -define-command -hidden yaml-indent-on-new-line %{ - evaluate-commands -draft -itersel %{ - # copy '#' comment prefix and following white spaces - try %{ execute-keys -draft k s ^\h*\K#\h* y gh j P } - # preserve previous line indent - try %{ execute-keys -draft \; K } - # filter previous line - try %{ execute-keys -draft k : yaml-trim-indent } - # indent after : - try %{ execute-keys -draft k x :$ j } - } -} - -# Initialization -# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ - -hook -group yaml-highlight global WinSetOption filetype=yaml %{ - add-highlighter window/yaml ref yaml - hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/yaml } -} - -hook global WinSetOption filetype=yaml %{ - hook window ModeChange insert:.* -group yaml-trim-indent yaml-trim-indent - hook window InsertChar \n -group yaml-indent yaml-indent-on-new-line - hook -once -always window WinSetOption filetype=.* %{ remove-hooks window yaml-.+ } -} diff --git a/rc/core/asciidoc.kak b/rc/core/asciidoc.kak deleted file mode 100644 index 8bdcce07..00000000 --- a/rc/core/asciidoc.kak +++ /dev/null @@ -1,43 +0,0 @@ -# http://asciidoc.org/ -# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ - -# Detection -# ‾‾‾‾‾‾‾‾‾ - -hook global BufCreate .+\.(a(scii)?doc|asc) %{ - set-option buffer filetype asciidoc -} - -# Highlighters -# ‾‾‾‾‾‾‾‾‾‾‾‾ - -add-highlighter shared/asciidoc group - -add-highlighter shared/asciidoc/ regex (\A|\n\n)[^\n]+\n={2,}\h*$ 0:title -add-highlighter shared/asciidoc/ regex (\A|\n\n)[^\n]+\n-{2,}\h*$ 0:header -add-highlighter shared/asciidoc/ regex (\A|\n\n)[^\n]+\n~{2,}\h*$ 0:header -add-highlighter shared/asciidoc/ regex (\A|\n\n)[^\n]+\n\^{2,}\h*$ 0:header - -add-highlighter shared/asciidoc/ regex (\A|\n\n)=\h+[^\n]+$ 0:title -add-highlighter shared/asciidoc/ regex (\A|\n\n)={2,}\h+[^\n]+$ 0:header - -add-highlighter shared/asciidoc/ regex ^\h+([-\*])\h+[^\n]*(\n\h+[^-\*]\S+[^\n]*)*$ 0:list 1:bullet -add-highlighter shared/asciidoc/ regex ^(-{3,})\n[^\n\h].*?\n(-{3,})$ 0:block -add-highlighter shared/asciidoc/ regex ^(={3,})\n[^\n\h].*?\n(={3,})$ 0:block -add-highlighter shared/asciidoc/ regex ^(~{3,})\n[^\n\h].*?\n(~{3,})$ 0:block -add-highlighter shared/asciidoc/ regex ^(\*{3,})\n[^\n\h].*?\n(\*{3,})$ 0:block -add-highlighter shared/asciidoc/ regex \B(?:\+[^\n]+?\+|`[^\n]+?`)\B 0:mono -add-highlighter shared/asciidoc/ regex \b_[^\n]+?_\b 0:italic -add-highlighter shared/asciidoc/ regex \B\*[^\n]+?\*\B 0:bold -add-highlighter shared/asciidoc/ regex ^:[-\w]+: 0:meta - -# Commands -# ‾‾‾‾‾‾‾‾ - -# Initialization -# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ - -hook -group asciidoc-highlight global WinSetOption filetype=asciidoc %{ - add-highlighter window/asciidoc ref asciidoc - hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/asciidoc } -} diff --git a/rc/core/c-family.kak b/rc/core/c-family.kak deleted file mode 100644 index 461545fb..00000000 --- a/rc/core/c-family.kak +++ /dev/null @@ -1,437 +0,0 @@ -hook global BufCreate .*\.(cc|cpp|cxx|C|hh|hpp|hxx|H)$ %{ - set-option buffer filetype cpp -} - -hook global BufSetOption filetype=c\+\+ %{ - hook -once buffer NormalIdle '' "set-option buffer filetype cpp" -} - -hook global BufCreate .*\.c$ %{ - set-option buffer filetype c -} - -hook global BufCreate .*\.h$ %{ - try %{ - execute-keys -draft %{%s\b::\b|\btemplate\h*|\bclass\h+\w+|\b(typename|namespace)\b|\b(public|private|protected)\h*:} - set-option buffer filetype cpp - } catch %{ - set-option buffer filetype c - } -} - -hook global BufCreate .*\.m %{ - set-option buffer filetype objc -} - -define-command -hidden c-family-trim-indent %{ - # remove the line if it's empty when leaving the insert mode - try %{ execute-keys -draft 1s^(\h+)$ d } -} - -define-command -hidden c-family-indent-on-newline %< evaluate-commands -draft -itersel %< - execute-keys \; - try %< - # if previous line is part of a comment, do nothing - execute-keys -draft /\* ^\h*[^/*\h] - > catch %< - # else if previous line closed a paren (possibly followed by words and a comment), - # copy indent of the opening paren line - execute-keys -draft k 1s(\))(\h+\w+)*\h*(\;\h*)?(?://[^\n]+)?\n\z mJ 1 - > catch %< - # else indent new lines with the same level as the previous one - execute-keys -draft K - > - # remove previous empty lines resulting from the automatic indent - try %< execute-keys -draft k ^\h+$ Hd > - # indent after an opening brace or parenthesis at end of line - try %< execute-keys -draft k s[{(]\h*$ j > - # indent after a label - try %< execute-keys -draft k s[a-zA-Z0-9_-]+:\h*$ j > - # indent after a statement not followed by an opening brace - try %< execute-keys -draft k s\)\h*(?://[^\n]+)?\n\z \ - mB \A\b(if|for|while)\b j > - try %< execute-keys -draft k s \belse\b\h*(?://[^\n]+)?\n\z \ - j > - # deindent after a single line statement end - try %< execute-keys -draft K \;\h*(//[^\n]+)?$ \ - K s\)(\h+\w+)*\h*(//[^\n]+)?\n([^\n]*\n){2}\z \ - MB \A\b(if|for|while)\b 1 > - try %< execute-keys -draft K \;\h*(//[^\n]+)?$ \ - K s \belse\b\h*(?://[^\n]+)?\n([^\n]*\n){2}\z \ - 1 > - # align to the opening parenthesis or opening brace (whichever is first) - # on a previous line if its followed by text on the same line - try %< evaluate-commands -draft %< - # Go to opening parenthesis and opening brace, then select the most nested one - try %< execute-keys [c [({],[)}] > - # Validate selection and get first and last char - execute-keys \A[{(](\h*\S+)+\n L - # Remove eventual indent from new line - try %< execute-keys -draft s\h+ d > - # Now align that new line with the opening parenthesis/brace - execute-keys & - > > -> > - -define-command -hidden c-family-indent-on-opening-curly-brace %[ - # align indent with opening paren when { is entered on a new line after the closing paren - try %[ execute-keys -draft -itersel h)M \A\(.*\)\h*\n\h*\{\z 1 ] -] - -define-command -hidden c-family-indent-on-closing-curly-brace %[ - # align to opening curly brace when alone on a line - try %[ execute-keys -itersel -draft ^\h+\}$hm1 ] -] - -define-command -hidden c-family-insert-on-closing-curly-brace %[ - # add a semicolon after a closing brace if part of a class, union or struct definition - try %[ execute-keys -itersel -draft hmB\A\h*(class|struct|union|enum) ';i;' ] -] - -define-command -hidden c-family-insert-on-newline %[ evaluate-commands -itersel -draft %[ - execute-keys \; - try %[ - evaluate-commands -draft -save-regs '/"' %[ - # copy the commenting prefix - execute-keys -save-regs '' k 1s^\h*(//+\h*) y - try %[ - # if the previous comment isn't empty, create a new one - execute-keys ^\h*//+\h*$ js^\h*P - ] catch %[ - # if there is no text in the previous comment, remove it completely - execute-keys d - ] - ] - ] - try %[ - # if the previous line isn't within a comment scope, break - execute-keys -draft k ^(\h*/\*|\h+\*(?!/)) - - # find comment opening, validate it was not closed, and check its using star prefixes - execute-keys -draft /\* \*/ \A\h*/\*([^\n]*\n\h*\*)*[^\n]*\n\h*.\z - - try %[ - # if the previous line is opening the comment, insert star preceeded by space - execute-keys -draft k^\h*/\* - execute-keys -draft i* - ] catch %[ - try %[ - # if the next line is a comment line insert a star - execute-keys -draft j^\h+\* - execute-keys -draft i* - ] catch %[ - try %[ - # if the previous line is an empty comment line, close the comment scope - execute-keys -draft k^\h+\*\h+$ 1s\*(\h*)c/ - ] catch %[ - # if the previous line is a non-empty comment line, add a star - execute-keys -draft i* - ] - ] - ] - - # trim trailing whitespace on the previous line - try %[ execute-keys -draft s\h+$ d ] - # align the new star with the previous one - execute-keys K1s^[^*]*(\*)& - ] -] ] - -# Regions definition are the same between c++ and objective-c -evaluate-commands %sh{ - for ft in c cpp objc; do - if [ "${ft}" = "objc" ]; then - maybe_at='@?' - else - maybe_at='' - fi - - cat <<-EOF - add-highlighter shared/$ft regions - add-highlighter shared/$ft/code default-region group - add-highlighter shared/$ft/string region %{$maybe_at(?%ggxs\.c_A_INCLUDEDggxyppI#ifndefjI#definejI#endif//O' - ;; - pragma) - echo 'execute-keys ggi#pragmaonce' - ;; - *);; - esac - } -} - -hook -group c-family-insert global BufNewFile .*\.(h|hh|hpp|hxx|H) c-family-insert-include-guards - -declare-option -docstring "colon separated list of path in which header files will be looked for" \ - str-list alt_dirs '.' '..' - -define-command -hidden c-family-alternative-file %{ - evaluate-commands %sh{ - file="${kak_buffile##*/}" - file_noext="${file%.*}" - dir=$(dirname "${kak_buffile}") - - # Set $@ to alt_dirs - eval "set -- ${kak_opt_alt_dirs}" - - case ${file} in - *.c|*.cc|*.cpp|*.cxx|*.C|*.inl|*.m) - for alt_dir in "$@"; do - for ext in h hh hpp hxx H; do - altname="${dir}/${alt_dir}/${file_noext}.${ext}" - if [ -f ${altname} ]; then - printf 'edit %%{%s}\n' "${altname}" - exit - fi - done - done - ;; - *.h|*.hh|*.hpp|*.hxx|*.H) - for alt_dir in "$@"; do - for ext in c cc cpp cxx C m; do - altname="${dir}/${alt_dir}/${file_noext}.${ext}" - if [ -f ${altname} ]; then - printf 'edit %%{%s}\n' "${altname}" - exit - fi - done - done - ;; - *) - echo "echo -markup '{Error}extension not recognized'" - exit - ;; - esac - echo "echo -markup '{Error}alternative file not found'" - } -} - -define-command c-alternative-file -docstring "Jump to the alternate c file (header/implementation)" %{ - c-family-alternative-file -} -define-command cpp-alternative-file -docstring "Jump to the alternate cpp file (header/implementation)" %{ - c-family-alternative-file -} -define-command objc-alternative-file -docstring "Jump to the alternate objc file (header/implementation)" %{ - c-family-alternative-file -} diff --git a/rc/core/comment.kak b/rc/core/comment.kak deleted file mode 100644 index fbfb8267..00000000 --- a/rc/core/comment.kak +++ /dev/null @@ -1,180 +0,0 @@ -# Line comments -declare-option -docstring "characters inserted at the beginning of a commented line" \ - str comment_line '#' - -# Block comments -declare-option -docstring "characters inserted before a commented block" \ - str comment_block_begin -declare-option -docstring "characters inserted after a commented block" \ - str comment_block_end - -# Default comments for all languages -hook global BufSetOption filetype=asciidoc %{ - set-option buffer comment_block_begin '///' - set-option buffer comment_block_end '///' -} - -hook global BufSetOption filetype=(c|cpp|dart|go|java|javascript|objc|php|rust|sass|scala|scss|swift|typescript) %{ - set-option buffer comment_line '//' - set-option buffer comment_block_begin '/*' - set-option buffer comment_block_end '*/' -} - -hook global BufSetOption filetype=(cabal|haskell|moon|idris|elm) %{ - set-option buffer comment_line '--' - set-option buffer comment_block_begin '{-' - set-option buffer comment_block_end '-}' -} - -hook global BufSetOption filetype=clojure %{ - set-option buffer comment_line '#_' - set-option buffer comment_block_begin '(comment ' - set-option buffer comment_block_end ')' -} - -hook global BufSetOption filetype=coffee %{ - set-option buffer comment_block_begin '###' - set-option buffer comment_block_end '###' -} - -hook global BufSetOption filetype=css %{ - set-option buffer comment_line '' - set-option buffer comment_block_begin '/*' - set-option buffer comment_block_end '*/' -} - -hook global BufSetOption filetype=d %{ - set-option buffer comment_line '//' - set-option buffer comment_block_begin '/+' - set-option buffer comment_block_end '+/' -} - -hook global BufSetOption filetype=(gas|ini) %{ - set-option buffer comment_line ';' -} - -hook global BufSetOption filetype=haml %{ - set-option buffer comment_line '-#' -} - -hook global BufSetOption filetype=(html|xml) %{ - set-option buffer comment_line '' - set-option buffer comment_block_begin '' -} - -hook global BufSetOption filetype=latex %{ - set-option buffer comment_line '%' -} - -hook global BufSetOption filetype=lisp %{ - set-option buffer comment_line ';' - set-option buffer comment_block_begin '#|' - set-option buffer comment_block_end '|#' -} - -hook global BufSetOption filetype=lua %{ - set-option buffer comment_line '--' - set-option buffer comment_block_begin '--[[' - set-option buffer comment_block_end ']]' -} - -hook global BufSetOption filetype=markdown %{ - set-option buffer comment_line '' - set-option buffer comment_block_begin '[//]' - set-option buffer comment_block_end '# (:)' -} - -hook global BufSetOption filetype=perl %{ - set-option buffer comment_block_begin '#[' - set-option buffer comment_block_end ']' -} - -hook global BufSetOption filetype=pug %{ - set-option buffer comment_line '//' -} - -hook global BufSetOption filetype=python %{ - set-option buffer comment_block_begin "'''" - set-option buffer comment_block_end "'''" -} - -hook global BufSetOption filetype=ragel %{ - set-option buffer comment_line '%%' - set-option buffer comment_block_begin '%%{' - set-option buffer comment_block_end '}%%' -} - -hook global BufSetOption filetype=ruby %{ - set-option buffer comment_block_begin '^begin=' - set-option buffer comment_block_end '^=end' -} - -define-command comment-block -docstring '(un)comment selections using block comments' %{ - evaluate-commands %sh{ - if [ -z "${kak_opt_comment_block_begin}" ] || [ -z "${kak_opt_comment_block_end}" ]; then - echo "fail \"The 'comment_block' options are empty, could not comment the selection\"" - fi - } - evaluate-commands -save-regs '"/' -draft %{ - # Keep non-empty selections - execute-keys \A\s*\z - - try %{ - # Assert that the selection has been commented - set-register / "\A\Q%opt{comment_block_begin}\E.*\Q%opt{comment_block_end}\E\n*\z" - execute-keys "s" - # Uncomment it - set-register / "\A\Q%opt{comment_block_begin}\E|\Q%opt{comment_block_end}\E\n*\z" - execute-keys sd - } catch %{ - # Comment the selection - set-register '"' "%opt{comment_block_begin}" - execute-keys P - set-register '"' "%opt{comment_block_end}" - execute-keys p - } - } -} - -define-command comment-line -docstring '(un)comment selected lines using line comments' %{ - evaluate-commands %sh{ - if [ -z "${kak_opt_comment_line}" ]; then - echo "fail \"The 'comment_line' option is empty, could not comment the line\"" - fi - } - evaluate-commands -save-regs '"/' -draft %{ - # Select the content of the lines, without indentation - execute-keys gi - - try %{ - # Keep non-empty lines - execute-keys \A\s*\z - } - - try %{ - set-register / "\A\Q%opt{comment_line}\E\h?" - - try %{ - # See if there are any uncommented lines in the selection - execute-keys -draft - - # There are uncommented lines, so comment everything - set-register '"' "%opt{comment_line} " - align-selections-left - execute-keys P - } catch %{ - # All lines were commented, so uncomment everything - execute-keys sd - } - } - } -} - -define-command align-selections-left -docstring 'extend selections to the left to align with the leftmost selected column' %{ - evaluate-commands %sh{ - leftmost_column=$(echo "$kak_selections_desc" | tr ' ' '\n' | cut -d',' -f1 | cut -d'.' -f2 | sort -n | head -n1) - aligned_selections=$(echo "$kak_selections_desc" | sed -E "s/\.[0-9]+,/.$leftmost_column,/g") - echo "select $aligned_selections" - } -} diff --git a/rc/core/diff.kak b/rc/core/diff.kak deleted file mode 100644 index 5b4e065b..00000000 --- a/rc/core/diff.kak +++ /dev/null @@ -1,13 +0,0 @@ -hook global BufCreate .*\.(diff|patch) %{ - set-option buffer filetype diff -} - -add-highlighter shared/diff group -add-highlighter shared/diff/ regex "^\+[^\n]*\n" 0:green,default -add-highlighter shared/diff/ regex "^-[^\n]*\n" 0:red,default -add-highlighter shared/diff/ regex "^@@[^\n]*@@" 0:cyan,default - -hook -group diff-highlight global WinSetOption filetype=diff %{ - add-highlighter window/diff ref diff - hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/diff } -} diff --git a/rc/core/doc.kak b/rc/core/doc.kak deleted file mode 100644 index f1dbc850..00000000 --- a/rc/core/doc.kak +++ /dev/null @@ -1,165 +0,0 @@ -declare-option -docstring "name of the client in which documentation is to be displayed" \ - str docsclient - -declare-option -hidden range-specs doc_render_ranges -declare-option -hidden range-specs doc_render_links -declare-option -hidden range-specs doc_links -declare-option -hidden range-specs doc_anchors - -define-command -hidden -params 4 doc-render-regex %{ - evaluate-commands -draft %{ try %{ - execute-keys \%s %arg{1} - execute-keys -draft s %arg{2} d - execute-keys "%arg{3}" - evaluate-commands %sh{ - face="$4" - eval "set -- $kak_selections_desc" - for desc in "$@"; do ranges="$ranges '$desc|$face'"; done - echo "update-option buffer doc_render_ranges" - echo "set-option -add buffer doc_render_ranges $ranges" - } - } } -} - -define-command -hidden doc-parse-links %{ - evaluate-commands -draft %{ try %{ - execute-keys \%s (.*?),.*? - execute-keys -draft s .*,| d - execute-keys H - set-option buffer doc_links %val{timestamp} - set-option buffer doc_render_links %val{timestamp} - evaluate-commands -itersel %{ - set-option -add buffer doc_links "%val{selection_desc}|%reg{1}" - set-option -add buffer doc_render_links "%val{selection_desc}|default+u" - } - } } -} - -define-command -hidden doc-parse-anchors %{ - evaluate-commands -draft %{ try %{ - set-option buffer doc_anchors %val{timestamp} - # Find sections as add them as imlicit anchors - execute-keys \%s ^={2,}\h+([^\n]+)$ - evaluate-commands -itersel %{ - set-option -add buffer doc_anchors "%val{selection_desc}|%sh{printf '%s' ""$kak_main_reg_1"" | tr '[A-Z ]' '[a-z-]'}" - } - - # Parse explicit anchors and remove their text - execute-keys \%s \[\[(.*?)\]\]\s* - evaluate-commands -itersel %{ - set-option -add buffer doc_anchors "%val{selection_desc}|%reg{1}" - } - execute-keys d - update-option buffer doc_anchors - } } -} - -define-command doc-jump-to-anchor -params 1 %{ - update-option buffer doc_anchors - evaluate-commands %sh{ - anchor="$1" - eval "set -- $kak_opt_doc_anchors" - - shift - for range in "$@"; do - if [ "${range#*|}" = "$anchor" ]; then - printf '%s\n' "select '${range%|*}'; execute-keys vv" - exit - fi - done - printf "echo -markup {Error}No such anchor '%s'" "${anchor}" - } -} - -define-command doc-follow-link %{ - update-option buffer doc_links - evaluate-commands %sh{ - eval "set -- $kak_opt_doc_links" - for link in "$@"; do - printf '%s\n' "$link" - done | awk -v FS='[.,|#]' ' - BEGIN { - l=ENVIRON["kak_cursor_line"]; - c=ENVIRON["kak_cursor_column"]; - } - l >= $1 && c >= $2 && l <= $3 && c <= $4 { - if (NF == 6) { - print "doc " $5 - if ($6 != "") { - print "doc-jump-to-anchor %{" $6 "}" - } - } else { - print "doc-jump-to-anchor %{" $5 "}" - } - exit - } - ' - } -} - -define-command -params 1 -hidden doc-render %{ - edit! -scratch "*doc-%sh{basename $1 .asciidoc}*" - execute-keys "!cat %arg{1}gg" - - doc-parse-anchors - - # Join paragraphs together - try %{ - execute-keys -draft '%S\n{2,}|(?<=\+)\n|^[^\n]+::\n|^\h*[*-]\h+' \ - ^\h*-{2,}(\n|\z) S\n\z \n - } - - # Remove some line end markers - try %{ execute-keys -draft \%s \h*(\+|:{2,})$ d } - - # Setup the doc_render_ranges option - set-option buffer doc_render_ranges %val{timestamp} - doc-render-regex \B(? d } - - set-option buffer readonly true - add-highlighter buffer/ ranges doc_render_ranges - add-highlighter buffer/ ranges doc_render_links - add-highlighter buffer/ wrap -word -indent - map buffer normal ': doc-follow-link' -} - -define-command -params 1..2 \ - -shell-script-candidates %{ - if [ "$kak_token_to_complete" -eq 0 ]; then - find "${kak_runtime}/doc/" -type f -name "*.asciidoc" | sed 's,.*/,,; s/\.[^/]*$//' - elif [ "$kak_token_to_complete" -eq 1 ]; then - readonly page="${kak_runtime}/doc/${1}.asciidoc" - if [ -f "${page}" ]; then - awk ' - /^==+ +/ { sub(/^==+ +/, ""); print } - /^\[\[[^\]]+\]\]/ { sub(/^\[\[/, ""); sub(/\]\].*/, ""); print } - ' < $page | tr '[A-Z ]' '[a-z-]' - fi - fi - } \ - doc -docstring %{doc []: open a buffer containing documentation about a given topic -An optional keyword argument can be passed to the function, which will be automatically selected in the documentation} %{ - evaluate-commands %sh{ - readonly page="${kak_runtime}/doc/${1}.asciidoc" - if [ -f "${page}" ]; then - if [ $# -eq 2 ]; then - jump_cmd="doc-jump-to-anchor '$2'" - fi - printf %s\\n "evaluate-commands -try-client %opt{docsclient} %{ doc-render ${page}; ${jump_cmd} }" - else - printf %s\\n "echo -markup '{Error}No such doc file: ${page}'" - fi - } -} - -alias global help doc diff --git a/rc/core/formatter.kak b/rc/core/formatter.kak deleted file mode 100644 index 40c38444..00000000 --- a/rc/core/formatter.kak +++ /dev/null @@ -1,31 +0,0 @@ -declare-option -docstring "shell command to which the contents of the current buffer is piped" \ - str formatcmd - -define-command format -docstring "Format the contents of the current buffer" %{ evaluate-commands -draft -no-hooks %{ - evaluate-commands %sh{ - if [ -n "${kak_opt_formatcmd}" ]; then - path_file_tmp=$(mktemp "${TMPDIR:-/tmp}"/kak-formatter-XXXXXX) - printf %s\\n " - write -sync \"${path_file_tmp}\" - - evaluate-commands %sh{ - readonly path_file_out=\$(mktemp \"${TMPDIR:-/tmp}\"/kak-formatter-XXXXXX) - - if cat \"${path_file_tmp}\" | eval \"${kak_opt_formatcmd}\" > \"\${path_file_out}\"; then - printf '%s\\n' \"execute-keys \\%|cat'\${path_file_out}'\" - printf '%s\\n' \"nop %sh{ rm -f '\${path_file_out}' }\" - else - printf '%s\\n' \" - evaluate-commands -client '${kak_client}' echo -markup '{Error}formatter returned an error (\$?)' - \" - rm -f \"\${path_file_out}\" - fi - - rm -f \"${path_file_tmp}\" - } - " - else - printf '%s\n' "evaluate-commands -client '${kak_client}' echo -markup '{Error}formatcmd option not specified'" - fi - } -} } diff --git a/rc/core/grep.kak b/rc/core/grep.kak deleted file mode 100644 index 9e6ed5ab..00000000 --- a/rc/core/grep.kak +++ /dev/null @@ -1,73 +0,0 @@ -declare-option -docstring "shell command run to search for subtext in a file/directory" \ - str grepcmd 'grep -RHn' -declare-option -docstring "name of the client in which utilities display information" \ - str toolsclient -declare-option -hidden int grep_current_line 0 - -define-command -params .. -file-completion \ - -docstring %{grep []: grep utility wrapper -All the optional arguments are forwarded to the grep utility} \ - grep %{ evaluate-commands %sh{ - output=$(mktemp -d "${TMPDIR:-/tmp}"/kak-grep.XXXXXXXX)/fifo - mkfifo ${output} - if [ $# -gt 0 ]; then - ( ${kak_opt_grepcmd} "$@" | tr -d '\r' > ${output} 2>&1 ) > /dev/null 2>&1 < /dev/null & - else - ( ${kak_opt_grepcmd} "${kak_selection}" | tr -d '\r' > ${output} 2>&1 ) > /dev/null 2>&1 < /dev/null & - fi - - printf %s\\n "evaluate-commands -try-client '$kak_opt_toolsclient' %{ - edit! -fifo ${output} -scroll *grep* - set-option buffer filetype grep - set-option buffer grep_current_line 0 - hook -always -once buffer BufCloseFifo .* %{ nop %sh{ rm -r $(dirname ${output}) } } - }" -}} - -hook -group grep-highlight global WinSetOption filetype=grep %{ - add-highlighter window/grep group - add-highlighter window/grep/ regex "^((?:\w:)?[^:\n]+):(\d+):(\d+)?" 1:cyan 2:green 3:green - add-highlighter window/grep/ line %{%opt{grep_current_line}} default+b - hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/grep } -} - -hook global WinSetOption filetype=grep %{ - hook buffer -group grep-hooks NormalKey grep-jump - hook -once -always window WinSetOption filetype=.* %{ remove-hooks buffer grep-hooks } -} - -declare-option -docstring "name of the client in which all source code jumps will be executed" \ - str jumpclient - -define-command -hidden grep-jump %{ - evaluate-commands %{ # use evaluate-commands to ensure jumps are collapsed - try %{ - execute-keys 's^((?:\w:)?[^:]+):(\d+):(\d+)?' - set-option buffer grep_current_line %val{cursor_line} - evaluate-commands -try-client %opt{jumpclient} edit -existing %reg{1} %reg{2} %reg{3} - try %{ focus %opt{jumpclient} } - } - } -} - -define-command grep-next-match -docstring 'Jump to the next grep match' %{ - evaluate-commands -try-client %opt{jumpclient} %{ - buffer '*grep*' - # First jump to enf of buffer so that if grep_current_line == 0 - # 0g will be a no-op and we'll jump to the first result. - # Yeah, thats ugly... - execute-keys "ge %opt{grep_current_line}g /^[^:]+:\d+:" - grep-jump - } - try %{ evaluate-commands -client %opt{toolsclient} %{ execute-keys gg %opt{grep_current_line}g } } -} - -define-command grep-previous-match -docstring 'Jump to the previous grep match' %{ - evaluate-commands -try-client %opt{jumpclient} %{ - buffer '*grep*' - # See comment in grep-next-match - execute-keys "ge %opt{grep_current_line}g ^[^:]+:\d+:" - grep-jump - } - try %{ evaluate-commands -client %opt{toolsclient} %{ execute-keys gg %opt{grep_current_line}g } } -} diff --git a/rc/core/kakrc.kak b/rc/core/kakrc.kak deleted file mode 100644 index 7a9af989..00000000 --- a/rc/core/kakrc.kak +++ /dev/null @@ -1,110 +0,0 @@ -# http://kakoune.org -# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ - -# Detection -# ‾‾‾‾‾‾‾‾‾ - -hook global BufCreate (.*/)?(kakrc|.*.kak) %{ - set-option buffer filetype kak -} - -# Highlighters & Completion -# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ - -add-highlighter shared/kakrc regions -add-highlighter shared/kakrc/code default-region group -add-highlighter shared/kakrc/comment region (^|\h)\K# $ fill comment -add-highlighter shared/kakrc/double_string region -recurse %{(?' ref sh -add-highlighter shared/kakrc/shell5 region -recurse '\{' '(^|\h)\K-shell-script-(completion|candidates)\h+%\{' '\}' ref sh -add-highlighter shared/kakrc/shell6 region -recurse '\(' '(^|\h)\K-shell-script-(completion|candidates)\h+%\(' '\)' ref sh -add-highlighter shared/kakrc/shell7 region -recurse '\[' '(^|\h)\K-shell-script-(completion|candidates)\h+%\[' '\]' ref sh -add-highlighter shared/kakrc/shell8 region -recurse '<' '(^|\h)\K-shell-script-(completion|candidates)\h+%<' '>' ref sh - -evaluate-commands %sh{ - # Grammar - keywords="edit write write-all kill quit write-quit write-all-quit map unmap alias unalias - buffer buffer-next buffer-previous delete-buffer add-highlighter remove-highlighter - hook remove-hooks define-command echo debug source try catch fail nop - set-option unset-option update-option declare-option execute-keys evaluate-commands - prompt menu on-key info set-face unset-face rename-client set-register select - change-directory rename-session colorscheme declare-user-mode enter-user-mode - edit! write! kill! quit! write-quit! delete-buffer!" - attributes="global buffer window current - normal insert menu prompt goto view user object - number-lines show-matching show-whitespaces fill regex dynregex group flag-lines - ranges line column wrap ref regions region default-region replace-ranges" - types="int bool str regex int-list str-list completions line-specs range-specs" - values="default black red green yellow blue magenta cyan white yes no false true" - - join() { sep=$2; eval set -- $1; IFS="$sep"; echo "$*"; } - - # Add the language's grammar to the static completion list - printf '%s\n' "hook global WinSetOption filetype=kak %{ - set-option window static_words $(join "${keywords} ${attributes} ${types} ${values}" ' ')' - set-option -- window extra_word_chars '_' '-' - }" - - # Highlight keywords (which are always surrounded by whitespace) - printf '%s\n' "add-highlighter shared/kakrc/code/keywords regex (?:\s|\A)\K($(join "${keywords}" '|'))(?:(?=\s)|\z) 0:keyword - add-highlighter shared/kakrc/code/attributes regex (?:\s|\A)\K($(join "${attributes}" '|'))(?:(?=\s)|\z) 0:attribute - add-highlighter shared/kakrc/code/types regex (?:\s|\A)\K($(join "${types}" '|'))(?:(?=\s)|\z) 0:type - add-highlighter shared/kakrc/code/values regex (?:\s|\A)\K($(join "${values}" '|'))(?:(?=\s)|\z) 0:value" -} - -add-highlighter shared/kakrc/code/colors regex \brgb:[0-9a-fA-F]{6}\b 0:value -add-highlighter shared/kakrc/code/scopes regex \b(global|shared|buffer|window)(?:\b|/) 0:value - -add-highlighter shared/kakrc/double_string/fill fill string -add-highlighter shared/kakrc/double_string/escape regex '""' 0:default+b -add-highlighter shared/kakrc/single_string/fill fill string -add-highlighter shared/kakrc/single_string/escape regex "''" 0:default+b - -# Commands -# ‾‾‾‾‾‾‾‾ - -define-command -hidden kak-indent-on-new-line %{ - evaluate-commands -draft -itersel %{ - # copy '#' comment prefix and following white spaces - try %{ execute-keys -draft k s ^\h*#\h* y jgh P } - # preserve previous line indent - try %{ execute-keys -draft \; K } - # cleanup trailing whitespaces from previous line - try %{ execute-keys -draft k s \h+$ d } - # indent after line ending with %\w*[^\s\w] - try %{ execute-keys -draft k \%\w*[^\s\w]$ j } - } -} - -define-command -hidden kak-indent-on-closing-matching %~ - # align to opening matching brace when alone on a line - try %= execute-keys -draft -itersel ^\h*\Q %val{hook_param} \E$ mGi s \A|.\z 1 = -~ - -define-command -hidden kak-indent-on-closing-char %{ - # align to opening matching character when alone on a line - try %{ execute-keys -draft -itersel ^\h*\Q %val{hook_param} \E$gi %val{hook_param} %\w*\Q %val{hook_param} \E$ s \A|.\z gi 1 } -} - -# Initialization -# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ - -hook -group kak-highlight global WinSetOption filetype=kak %{ - add-highlighter window/kakrc ref kakrc - hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/kakrc } -} - -hook global WinSetOption filetype=kak %~ - hook window InsertChar \n -group kak-indent kak-indent-on-new-line - hook window InsertChar [>)}\]] -group kak-indent kak-indent-on-closing-matching - hook window InsertChar (?![[{(<>)}\]])[^\s\w] -group kak-indent kak-indent-on-closing-char - # cleanup trailing whitespaces on current line insert end - hook window ModeChange insert:.* -group kak-trim-indent %{ try %{ execute-keys -draft \; s ^\h+$ d } } - set-option buffer extra_word_chars '_' '-' - - hook -once -always window WinSetOption filetype=.* %{ remove-hooks window kak-.+ } -~ diff --git a/rc/core/make.kak b/rc/core/make.kak deleted file mode 100644 index 89533a59..00000000 --- a/rc/core/make.kak +++ /dev/null @@ -1,84 +0,0 @@ -declare-option -docstring "shell command run to build the project" \ - str makecmd make -declare-option -docstring "pattern that describes lines containing information about errors in the output of the `makecmd` command" \ - str make_error_pattern " (?:fatal )?error:" - -declare-option -docstring "name of the client in which utilities display information" \ - str toolsclient -declare-option -hidden int make_current_error_line - -define-command -params .. \ - -docstring %{make []: make utility wrapper -All the optional arguments are forwarded to the make utility} \ - make %{ evaluate-commands %sh{ - output=$(mktemp -d "${TMPDIR:-/tmp}"/kak-make.XXXXXXXX)/fifo - mkfifo ${output} - ( eval ${kak_opt_makecmd} "$@" > ${output} 2>&1 ) > /dev/null 2>&1 < /dev/null & - - printf %s\\n "evaluate-commands -try-client '$kak_opt_toolsclient' %{ - edit! -fifo ${output} -scroll *make* - set-option buffer filetype make - set-option buffer make_current_error_line 0 - hook -always -once buffer BufCloseFifo .* %{ nop %sh{ rm -r $(dirname ${output}) } } - }" -}} - -add-highlighter shared/make group -add-highlighter shared/make/ regex "^((?:\w:)?[^:\n]+):(\d+):(?:(\d+):)?\h+(?:((?:fatal )?error)|(warning)|(note)|(required from(?: here)?))?.*?$" 1:cyan 2:green 3:green 4:red 5:yellow 6:blue 7:yellow -add-highlighter shared/make/ regex "^\h*(~*(?:(\^)~*)?)$" 1:green 2:cyan+b -add-highlighter shared/make/ line '%opt{make_current_error_line}' default+b - -hook -group make-highlight global WinSetOption filetype=make %{ - add-highlighter window/make ref make - hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/make } -} - -hook global WinSetOption filetype=make %{ - hook buffer -group make-hooks NormalKey make-jump - hook -once -always window WinSetOption filetype=.* %{ remove-hooks buffer make-hooks } -} - -declare-option -docstring "name of the client in which all source code jumps will be executed" \ - str jumpclient - -define-command -hidden make-open-error -params 4 %{ - evaluate-commands -try-client %opt{jumpclient} %{ - edit -existing "%arg{1}" %arg{2} %arg{3} - echo -markup "{Information}%arg{4}" - try %{ focus } - } -} - -define-command -hidden make-jump %{ - evaluate-commands %{ - try %{ - execute-keys gl "Entering directory" - # Try to parse the error into capture groups, failing on absolute paths - execute-keys s "Entering directory [`']([^']+)'.*\n([^:/][^:]*):(\d+):(?:(\d+):)?([^\n]+)\z" l - set-option buffer make_current_error_line %val{cursor_line} - make-open-error "%reg{1}/%reg{2}" "%reg{3}" "%reg{4}" "%reg{5}" - } catch %{ - execute-keys s "((?:\w:)?[^:]+):(\d+):(?:(\d+):)?([^\n]+)\z" l - set-option buffer make_current_error_line %val{cursor_line} - make-open-error "%reg{1}" "%reg{2}" "%reg{3}" "%reg{4}" - } - } -} - -define-command make-next-error -docstring 'Jump to the next make error' %{ - evaluate-commands -try-client %opt{jumpclient} %{ - buffer '*make*' - execute-keys "%opt{make_current_error_line}ggl" "/^(?:\w:)?[^:\n]+:\d+:(?:\d+:)?%opt{make_error_pattern}" - make-jump - } - try %{ evaluate-commands -client %opt{toolsclient} %{ execute-keys %opt{make_current_error_line}g } } -} - -define-command make-previous-error -docstring 'Jump to the previous make error' %{ - evaluate-commands -try-client %opt{jumpclient} %{ - buffer '*make*' - execute-keys "%opt{make_current_error_line}g" "^(?:\w:)?[^:\n]+:\d+:(?:\d+:)?%opt{make_error_pattern}" - make-jump - } - try %{ evaluate-commands -client %opt{toolsclient} %{ execute-keys %opt{make_current_error_line}g } } -} diff --git a/rc/core/makefile.kak b/rc/core/makefile.kak deleted file mode 100644 index 569d51f9..00000000 --- a/rc/core/makefile.kak +++ /dev/null @@ -1,60 +0,0 @@ -# Detection -# ‾‾‾‾‾‾‾‾‾ - -hook global BufCreate .*(/?[mM]akefile|\.mk) %{ - set-option buffer filetype makefile -} - -# Highlighters -# ‾‾‾‾‾‾‾‾‾‾‾‾ - -add-highlighter shared/makefile regions - -add-highlighter shared/makefile/content default-region group -add-highlighter shared/makefile/comment region '#' '$' fill comment -add-highlighter shared/makefile/evaluate-commands region -recurse '\(' '\$\(' '\)' fill value - -add-highlighter shared/makefile/content/ regex ^[\w.%-]+\h*:\s 0:variable -add-highlighter shared/makefile/content/ regex [+?:]= 0:operator - -evaluate-commands %sh{ - # Grammar - keywords="ifeq|ifneq|ifdef|ifndef|else|endif|define|endef" - - # Add the language's grammar to the static completion list - printf %s\\n "hook global WinSetOption filetype=makefile %{ - set-option window static_words ${keywords} - }" | tr '|' ' ' - - # Highlight keywords - printf %s "add-highlighter shared/makefile/content/ regex \b(${keywords})\b 0:keyword" -} - -# Commands -# ‾‾‾‾‾‾‾‾ - -define-command -hidden makefile-indent-on-new-line %{ - evaluate-commands -draft -itersel %{ - # preserve previous line indent - try %{ execute-keys -draft \;K } - ## If the line above is a target indent with a tab - try %{ execute-keys -draft Z k ^[^:]+:\s z i } - # cleanup trailing white space son previous line - try %{ execute-keys -draft k s \h+$ d } - # indent after some keywords - try %{ execute-keys -draft Z k ^\h*(ifeq|ifneq|ifdef|ifndef|else|define)\b z } - } -} - -# Initialization -# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ - -hook -group makefile-highlight global WinSetOption filetype=makefile %{ - add-highlighter window/makefile ref makefile - hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/makefile } -} - -hook global WinSetOption filetype=makefile %{ - hook window InsertChar \n -group makefile-indent makefile-indent-on-new-line - hook -once -always window WinSetOption filetype=.* %{ remove-hooks window makefile-.+ } -} diff --git a/rc/core/man.kak b/rc/core/man.kak deleted file mode 100644 index 41d91104..00000000 --- a/rc/core/man.kak +++ /dev/null @@ -1,68 +0,0 @@ -declare-option -docstring "name of the client in which documentation is to be displayed" \ - str docsclient - -declare-option -hidden str manpage - -hook -group man-highlight global WinSetOption filetype=man %{ - add-highlighter window/man-highlight group - # Sections - add-highlighter window/man-highlight/ regex ^\S.*?$ 0:title - # Subsections - add-highlighter window/man-highlight/ regex '^ {3}\S.*?$' 0:default+b - # Command line options - add-highlighter window/man-highlight/ regex '^ {7}-[^\s,]+(,\s+-[^\s,]+)*' 0:list - # References to other manpages - add-highlighter window/man-highlight/ regex [-a-zA-Z0-9_.]+\([a-z0-9]+\) 0:header - - hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/man-highlight } -} - -hook global WinSetOption filetype=man %{ - hook -group man-hooks window WinResize .* %{ man-impl %val{bufname} %opt{manpage} } - hook -once -always window WinSetOption filetype=.* %{ remove-hooks window man-hooks } -} - -define-command -hidden -params 2..3 man-impl %{ evaluate-commands %sh{ - buffer_name="$1" - shift - manout=$(mktemp "${TMPDIR:-/tmp}"/kak-man-XXXXXX) - colout=$(mktemp "${TMPDIR:-/tmp}"/kak-man-XXXXXX) - MANWIDTH=${kak_window_width} man "$@" > $manout 2>/dev/null - retval=$? - col -b -x > ${colout} < ${manout} - rm ${manout} - if [ "${retval}" -eq 0 ]; then - printf %s\\n " - edit -scratch '$buffer_name' - execute-keys '%|cat${colout}gk' - nop %sh{rm ${colout}} - set-option buffer filetype man - set-option window manpage '$@' - " - else - printf %s\\n "echo -markup %{{Error}man '$@' failed: see *debug* buffer for details}" - rm ${colout} - fi -} } - -define-command -params ..1 \ - -shell-script-candidates %{ - find /usr/share/man/ -name '*.[1-8]*' | sed 's,^.*/\(.*\)\.\([1-8][a-zA-Z]*\).*$,\1(\2),' - } \ - -docstring %{man []: manpage viewer wrapper -If no argument is passed to the command, the selection will be used as page -The page can be a word, or a word directly followed by a section number between parenthesis, e.g. kak(1)} \ - man %{ evaluate-commands %sh{ - subject=${1-$kak_selection} - - ## The completion suggestions display the page number, strip them if present - case "${subject}" in - *\([1-8]*\)) - pagenum="${subject##*(}" - pagenum="${pagenum%)}" - subject="${subject%%(*}" - ;; - esac - - printf %s\\n "evaluate-commands -try-client %opt{docsclient} man-impl *man* $pagenum $subject" -} } diff --git a/rc/core/python.kak b/rc/core/python.kak deleted file mode 100644 index fb9477b9..00000000 --- a/rc/core/python.kak +++ /dev/null @@ -1,148 +0,0 @@ -# http://python.org -# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ - -# Detection -# ‾‾‾‾‾‾‾‾‾ - -hook global BufCreate .*[.](py) %{ - set-option buffer filetype python -} - -# Highlighters & Completion -# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ - -add-highlighter shared/python regions -add-highlighter shared/python/code default-region group -add-highlighter shared/python/docstring region -match-capture ("""|''') ("""|''') regions -add-highlighter shared/python/double_string region '"' (?>> \K' '\z' ref python -add-highlighter shared/python/docstring/ region '\.\.\. \K' '\z' ref python - -evaluate-commands %sh{ - # Grammar - values="True|False|None|self|inf" - meta="import|from" - - # attributes and methods list based on https://docs.python.org/3/reference/datamodel.html - attributes="__annotations__|__closure__|__code__|__defaults__|__dict__|__doc__" - attributes="${attributes}|__globals__|__kwdefaults__|__module__|__name__|__qualname__" - methods="__abs__|__add__|__aenter__|__aexit__|__aiter__|__and__|__anext__" - methods="${methods}|__await__|__bool__|__bytes__|__call__|__complex__|__contains__" - methods="${methods}|__del__|__delattr__|__delete__|__delitem__|__dir__|__divmod__" - methods="${methods}|__enter__|__eq__|__exit__|__float__|__floordiv__|__format__" - methods="${methods}|__ge__|__get__|__getattr__|__getattribute__|__getitem__" - methods="${methods}|__gt__|__hash__|__iadd__|__iand__|__ifloordiv__|__ilshift__" - methods="${methods}|__imatmul__|__imod__|__imul__|__index__|__init__" - methods="${methods}|__init_subclass__|__int__|__invert__|__ior__|__ipow__" - methods="${methods}|__irshift__|__isub__|__iter__|__itruediv__|__ixor__|__le__" - methods="${methods}|__len__|__length_hint__|__lshift__|__lt__|__matmul__" - methods="${methods}|__missing__|__mod__|__mul__|__ne__|__neg__|__new__|__or__" - methods="${methods}|__pos__|__pow__|__radd__|__rand__|__rdivmod__|__repr__" - methods="${methods}|__reversed__|__rfloordiv__|__rlshift__|__rmatmul__|__rmod__" - methods="${methods}|__rmul__|__ror__|__round__|__rpow__|__rrshift__|__rshift__" - methods="${methods}|__rsub__|__rtruediv__|__rxor__|__set__|__setattr__" - methods="${methods}|__setitem__|__set_name__|__slots__|__str__|__sub__" - methods="${methods}|__truediv__|__xor__" - - # built-in exceptions https://docs.python.org/3/library/exceptions.html - exceptions="ArithmeticError|AssertionError|AttributeError|BaseException|BlockingIOError" - exceptions="${exceptions}|BrokenPipeError|BufferError|BytesWarning|ChildProcessError" - exceptions="${exceptions}|ConnectionAbortedError|ConnectionError|ConnectionRefusedError" - exceptions="${exceptions}|ConnectionResetError|DeprecationWarning|EOFError|Exception" - exceptions="${exceptions}|FileExistsError|FileNotFoundError|FloatingPointError|FutureWarning" - exceptions="${exceptions}|GeneratorExit|ImportError|ImportWarning|IndentationError" - exceptions="${exceptions}|IndexError|InterruptedError|IsADirectoryError|KeyboardInterrupt" - exceptions="${exceptions}|KeyError|LookupError|MemoryError|ModuleNotFoundError|NameError" - exceptions="${exceptions}|NotADirectoryError|NotImplementedError|OSError|OverflowError" - exceptions="${exceptions}|PendingDeprecationWarning|PermissionError|ProcessLookupError" - exceptions="${exceptions}|RecursionError|ReferenceError|ResourceWarning|RuntimeError" - exceptions="${exceptions}|RuntimeWarning|StopAsyncIteration|StopIteration|SyntaxError" - exceptions="${exceptions}|SyntaxWarning|SystemError|SystemExit|TabError|TimeoutError|TypeError" - exceptions="${exceptions}|UnboundLocalError|UnicodeDecodeError|UnicodeEncodeError|UnicodeError" - exceptions="${exceptions}|UnicodeTranslateError|UnicodeWarning|UserWarning|ValueError|Warning" - exceptions="${exceptions}|ZeroDivisionError" - - # Keyword list is collected using `keyword.kwlist` from `keyword` - keywords="and|as|assert|async|await|break|class|continue|def|del|elif|else|except|exec" - keywords="${keywords}|finally|for|global|if|in|is|lambda|nonlocal|not|or|pass|print" - keywords="${keywords}|raise|return|try|while|with|yield" - - types="bool|buffer|bytearray|bytes|complex|dict|file|float|frozenset|int" - types="${types}|list|long|memoryview|object|set|str|tuple|unicode|xrange" - - functions="abs|all|any|ascii|bin|callable|chr|classmethod|compile|complex" - functions="${functions}|delattr|dict|dir|divmod|enumerate|eval|exec|filter" - functions="${functions}|format|frozenset|getattr|globals|hasattr|hash|help" - functions="${functions}|hex|id|__import__|input|isinstance|issubclass|iter" - functions="${functions}|len|locals|map|max|memoryview|min|next|oct|open|ord" - functions="${functions}|pow|print|property|range|repr|reversed|round" - functions="${functions}|setattr|slice|sorted|staticmethod|sum|super|type|vars|zip" - - # Add the language's grammar to the static completion list - printf %s\\n "hook global WinSetOption filetype=python %{ - set-option window static_words ${values} ${meta} ${attributes} ${methods} ${exceptions} ${keywords} ${types} ${functions} - }" | tr '|' ' ' - - # Highlight keywords - printf %s " - add-highlighter shared/python/code/ regex '\b(${values})\b' 0:value - add-highlighter shared/python/code/ regex '\b(${meta})\b' 0:meta - add-highlighter shared/python/code/ regex '\b(${attribute})\b' 0:attribute - add-highlighter shared/python/code/ regex '\bdef\s+(${methods})\b' 1:function - add-highlighter shared/python/code/ regex '\b(${exceptions})\b' 0:function - add-highlighter shared/python/code/ regex '\b(${keywords})\b' 0:keyword - add-highlighter shared/python/code/ regex '\b(${functions})\b\(' 1:builtin - add-highlighter shared/python/code/ regex '\b(${types})\b' 0:type - add-highlighter shared/python/code/ regex '@[\w_]+\b' 0:attribute - " -} - -add-highlighter shared/python/code/ regex (?<=[\w\s\d'"_])(<=|<<|>>|>=|<>|<|>|!=|==|\||\^|&|\+|-|\*\*|\*|//|/|%|~) 0:operator -add-highlighter shared/python/code/ regex (?<=[\w\s\d'"_])((?!])=(?![=])|[+*-]=) 0:builtin - -# Commands -# ‾‾‾‾‾‾‾‾ - -define-command -hidden python-indent-on-new-line %{ - evaluate-commands -draft -itersel %{ - # copy '#' comment prefix and following white spaces - try %{ execute-keys -draft k s ^\h*#\h* y jgh P } - # preserve previous line indent - try %{ execute-keys -draft \; K } - # cleanup trailing whitespaces from previous line - try %{ execute-keys -draft k s \h+$ d } - # indent after line ending with : - try %{ execute-keys -draft k :$ j } - } -} - -# Initialization -# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ - -hook -group python-highlight global WinSetOption filetype=python %{ - add-highlighter window/python ref python - hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/python } -} - -hook global WinSetOption filetype=python %{ - hook window InsertChar \n -group python-indent python-indent-on-new-line - # cleanup trailing whitespaces on current line insert end - hook window ModeChange insert:.* -group python-trim-indent %{ try %{ execute-keys -draft \; s ^\h+$ d } } - hook -once -always window WinSetOption filetype=.* %{ remove-hooks window python-.+ } -} diff --git a/rc/core/sh.kak b/rc/core/sh.kak deleted file mode 100644 index 517f6a18..00000000 --- a/rc/core/sh.kak +++ /dev/null @@ -1,43 +0,0 @@ -hook global BufCreate .*\.(z|ba|c|k|mk)?sh(rc|_profile)? %{ - set-option buffer filetype sh -} - -add-highlighter shared/sh regions -add-highlighter shared/sh/code default-region group -add-highlighter shared/sh/double_string region %{(?/dev/null 2>&1 || { echo 'echo -markup "{Error}editorconfig could not be found"'; exit 1; } + editorconfig "${1:-$kak_buffile}" | awk -F= -- ' + /indent_style=/ { indent_style = $2 } + /indent_size=/ { indent_size = $2 == "tab" ? 4 : $2 } + /tab_width=/ { tab_width = $2 } + /end_of_line=/ { end_of_line = $2 } + /charset=/ { charset = $2 } + /trim_trailing_whitespace=/ { trim_trailing_whitespace = $2 } + + END { + if (indent_style == "tab") { + print "set-option buffer indentwidth 0" + print "set-option buffer aligntab true" + } + if (indent_style == "space") { + print "set-option buffer indentwidth " (indent_size == "tab" ? 4 : indent_size) + print "set-option buffer aligntab false" + } + if (indent_size || tab_width) { + print "set-option buffer tabstop " (tab_width ? tab_width : indent_size) + } + if (end_of_line == "lf" || end_of_line == "crlf") { + print "set-option buffer eolformat " end_of_line + } + if (charset == "utf-8-bom") { + print "set-option buffer BOM utf8" + } + if (trim_trailing_whitespace == "true") { + print "set-option buffer editorconfig_trim_trailing_whitespace true" + } + } + ' + } + hook buffer BufWritePre %val{buffile} -group editorconfig-hooks %{ evaluate-commands %sh{ + if [ ${kak_opt_editorconfig_trim_trailing_whitespace} = "true" ]; then + printf %s\\n "try %{ execute-keys -draft %{ %s\h+$d } }" + fi + } } +} diff --git a/rc/detection/file.kak b/rc/detection/file.kak new file mode 100644 index 00000000..073e9ce0 --- /dev/null +++ b/rc/detection/file.kak @@ -0,0 +1,17 @@ +hook global BufOpenFile .* %{ evaluate-commands %sh{ + if [ -z "${kak_opt_filetype}" ]; then + mime=$(file -b --mime-type "${kak_buffile}") + case "${mime}" in + application/*+xml) filetype="xml" ;; + image/*+xml) filetype="xml" ;; #SVG + message/rfc822) filetype="mail" ;; + text/x-shellscript) filetype="sh" ;; + text/x-*) filetype="${mime#text/x-}" ;; + text/*) filetype="${mime#text/}" ;; + application/*) filetype="${mime#application/}" ;; + esac + if [ -n "${filetype}" ]; then + printf "set-option buffer filetype '%s'\n" "${filetype}" + fi + fi +} } diff --git a/rc/detection/modeline.kak b/rc/detection/modeline.kak new file mode 100644 index 00000000..ece6d97a --- /dev/null +++ b/rc/detection/modeline.kak @@ -0,0 +1,102 @@ +## +## modeline.kak by lenormf +## + +## Currently supported modeline format: vim +## Also supports kakoune options with a 'kak' or 'kakoune' prefix +## Only a few options are supported, in order to prevent the +## buffers from poking around the configuration too much + +declare-option -docstring "amount of lines that will be checked at the beginning and the end of the buffer" \ + int modelines 5 + +define-command -hidden modeline-parse-impl %{ + evaluate-commands %sh{ + # Translate a vim option into the corresponding kakoune one + translate_opt_vim() { + readonly key="$1" + readonly value="$2" + tr="" + + case "${key}" in + so|scrolloff) tr="scrolloff ${value},${kak_opt_scrolloff##*,}";; + siso|sidescrolloff) tr="scrolloff ${kak_opt_scrolloff%%,*},${value}";; + ts|tabstop) tr="tabstop ${value}";; + sw|shiftwidth) tr="indentwidth ${value}";; + tw|textwidth) tr="autowrap_column ${value}";; + ff|fileformat) + case "${value}" in + unix) tr="eolformat lf";; + dos) tr="eolformat crlf";; + *) printf %s\\n "echo -debug 'Unsupported file format: ${value}'";; + esac + ;; + ft|filetype) tr="filetype ${value}";; + bomb) tr="BOM utf8";; + nobomb) tr="BOM none";; + *) printf %s\\n "echo -debug 'Unsupported vim variable: ${key}'";; + esac + + [ -n "${tr}" ] && printf %s\\n "set-option buffer ${tr}" + } + + # Pass a few whitelisted options to kakoune directly + translate_opt_kakoune() { + readonly key="$1" + readonly value="$2" + + case "${key}" in + scrolloff|tabstop|indentwidth|autowrap_column|eolformat|filetype|BOM);; + *) printf %s\\n "echo -debug 'Unsupported kakoune variable: ${key}'" + return;; + esac + + printf %s\\n "set-option buffer ${key} ${value}" + } + + case "${kak_selection}" in + *vi:*|*vim:*) type_selection="vim";; + *kak:*|*kakoune:*) type_selection="kakoune";; + *) echo "echo -debug Unsupported modeline format";; + esac + [ -n "${type_selection}" ] || exit 1 + + # The following subshell will keep the actual options of the modeline, and strip: + # - the text that leads the first option, according to the official vim modeline format + # - the trailing text after the last option, and an optional ':' sign before it + # It will also convert the ':' seperators beween the option=value pairs + # More info: http://vimdoc.sourceforge.net/htmldoc/options.html#modeline + printf %s "${kak_selection}" | sed \ + -e 's/^[^:]\{1,\}://' \ + -e 's/[ \t]*set\{0,1\}[ \t]//' \ + -e 's/:[^a-zA-Z0-9_=-]*$//' \ + -e 's/:/ /g' \ + | tr ' ' '\n' \ + | while read -r option; do + name_option="${option%%=*}" + value_option="${option#*=}" + + [ -z "${option}" ] && continue + + case "${type_selection}" in + vim) tr=$(translate_opt_vim "${name_option}" "${value_option}");; + kakoune) tr=$(translate_opt_kakoune "${name_option}" "${value_option}");; + esac + + [ -n "${tr}" ] && printf %s\\n "${tr}" + done + } +} + +# Add the following function to a hook on BufOpenFile to automatically parse modelines +# Select the first and last `modelines` lines in the buffer, only keep modelines +# ref. options.txt (in vim `:help options`) : 2 forms of modelines: +# [text]{white}{vi:|vim:|ex:}[white]{options} +# [text]{white}{vi:|vim:|Vim:|ex:}[white]se[t] {options}:[text] +define-command modeline-parse -docstring "Read and interpret vi-format modelines at the beginning/end of the buffer" %{ + try %{ evaluate-commands -draft %{ + execute-keys \%s\A|.\z %opt{modelines}k %opt{modelines}X \ + s^\S*?\s+?(vim?|kak(oune)?):\s?[^\n]+ + evaluate-commands -draft -itersel modeline-parse-impl + } } +} diff --git a/rc/extra/arch-linux.kak b/rc/extra/arch-linux.kak deleted file mode 100644 index 08135a76..00000000 --- a/rc/extra/arch-linux.kak +++ /dev/null @@ -1,4 +0,0 @@ -# package build description file -hook global BufCreate (.*/)?PKGBUILD %{ - set-option buffer filetype sh -} diff --git a/rc/extra/autorestore.kak b/rc/extra/autorestore.kak deleted file mode 100644 index f8e3e14d..00000000 --- a/rc/extra/autorestore.kak +++ /dev/null @@ -1,71 +0,0 @@ -declare-option -docstring "remove backups once they've been restored" \ - bool autorestore_purge_restored true - -## Insert the content of the backup file into the current buffer, if a suitable one is found -define-command autorestore-restore-buffer -docstring "Restore the backup for the current file if it exists" %{ - evaluate-commands %sh{ - buffer_basename="${kak_buffile##*/}" - buffer_dirname=$(dirname "${kak_buffile}") - - if [ -f "${kak_buffile}" ]; then - newer=$(find "${buffer_dirname}"/".${buffer_basename}.kak."* -newer "${kak_buffile}" -exec ls -1t {} + 2>/dev/null | head -n 1) - - older=$(find "${buffer_dirname}"/".${buffer_basename}.kak."* \! -newer "${kak_buffile}" -exec ls -1t {} + 2>/dev/null | head -n 1) - else - # New buffers that were never written to disk. - newer=$(ls -1t "${buffer_dirname}"/".${buffer_basename}.kak."* 2>/dev/null | head -n 1) - fi - - if [ -z "${newer}" ]; then - if [ -n "${older}" ]; then - printf %s\\n " - echo -debug Old backup file(s) found: will not restore ${older} . - " - fi - exit - fi - - printf %s\\n " - ## Replace the content of the buffer with the content of the backup file - echo -debug Restoring file: ${newer} - - execute-keys -draft %{ %d!cat\"${newer}\"d } - - ## If the backup file has to be removed, issue the command once - ## the current buffer has been saved - ## If the autorestore_purge_restored option has been unset right after the - ## buffer was restored, do not remove the backup - hook -group autorestore buffer BufWritePost '${kak_buffile}' %{ - nop %sh{ - if [ \"\${kak_opt_autorestore_purge_restored}\" = true ]; - then - rm -f \"${buffer_dirname}/.${buffer_basename}.kak.\"* - fi - } - } - " - } -} - -## Remove all the backups that have been created for the current buffer -define-command autorestore-purge-backups -docstring "Remove all the backups of the current buffer" %{ - evaluate-commands %sh{ - [ ! -f "${kak_buffile}" ] && exit - - buffer_basename="${kak_bufname##*/}" - buffer_dirname=$(dirname "${kak_bufname}") - - rm -f "${buffer_dirname}/.${buffer_basename}.kak."* - - printf %s\\n " - echo -markup {Information}Backup files removed. - " - } -} - -## If for some reason, backup files need to be ignored -define-command autorestore-disable -docstring "Disable automatic backup recovering" %{ - remove-hooks global autorestore -} - -hook -group autorestore global BufCreate .* %{ autorestore-restore-buffer } diff --git a/rc/extra/cabal.kak b/rc/extra/cabal.kak deleted file mode 100644 index b3e7e58c..00000000 --- a/rc/extra/cabal.kak +++ /dev/null @@ -1,74 +0,0 @@ -# http://haskell.org/cabal -# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ - -# Detection -# ‾‾‾‾‾‾‾‾‾ - -hook global BufCreate .*[.](cabal) %{ - set-option buffer filetype cabal -} - -# Highlighters -# ‾‾‾‾‾‾‾‾‾‾‾‾ - -add-highlighter shared/cabal regions -add-highlighter shared/cabal/code default-region group -add-highlighter shared/cabal/line_comment region (--) $ fill comment -add-highlighter shared/cabal/comment region -recurse \{- \{- -\} fill comment - -add-highlighter shared/cabal/code/ regex \b(true|false)\b|(([<>]?=?)?\d+(\.\d+)+) 0:value -add-highlighter shared/cabal/code/ regex \b(if|else)\b 0:keyword -add-highlighter shared/cabal/code/ regex ^\h*([A-Za-z][A-Za-z0-9_-]*)\h*: 1:variable - -# Commands -# ‾‾‾‾‾‾‾‾ - -define-command -hidden cabal-trim-indent %{ - # remove trailing white spaces - try %{ execute-keys -draft -itersel s \h+$ d } -} - -define-command -hidden cabal-indent-on-new-line %[ - evaluate-commands -draft -itersel %[ - # copy '#' comment prefix and following white spaces - try %[ execute-keys -draft k s ^\h*\K#\h* y gh j P ] - # preserve previous line indent - try %[ execute-keys -draft \; K ] - # filter previous line - try %[ execute-keys -draft k : cabal-trim-indent ] - # indent after lines ending with { or : - try %[ execute-keys -draft k [:{]$ j ] - ] -] - -define-command -hidden cabal-indent-on-opening-curly-brace %[ - evaluate-commands -draft -itersel %[ - # align indent with opening paren when { is entered on a new line after the closing paren - try %[ execute-keys -draft h ) M \A\(.*\)\h*\n\h*\{\z s \A|.\z 1 ] - ] -] - -define-command -hidden cabal-indent-on-closing-curly-brace %[ - evaluate-commands -draft -itersel %[ - # align to opening curly brace when alone on a line - try %[ execute-keys -draft ^\h+\}$ h m s \A|.\z 1 ] - ] -] - -# Initialization -# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ - -hook -group cabal-highlight global WinSetOption filetype=cabal %{ - add-highlighter window/cabal ref cabal - hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/cabal } - -} - -hook global WinSetOption filetype=cabal %[ - hook window ModeChange insert:.* -group cabal-trim-indent cabal-trim-indent - hook window InsertChar \n -group cabal-indent cabal-indent-on-new-line - hook window InsertChar \{ -group cabal-indent cabal-indent-on-opening-curly-brace - hook window InsertChar \} -group cabal-indent cabal-indent-on-closing-curly-brace - - hook -once -always window WinSetOption filetype=.* %{ remove-hooks window cabal-.+ } -] diff --git a/rc/extra/clang.kak b/rc/extra/clang.kak deleted file mode 100644 index 3386073b..00000000 --- a/rc/extra/clang.kak +++ /dev/null @@ -1,180 +0,0 @@ -declare-option -docstring "options to pass to the `clang` shell command" \ - str clang_options - -declare-option -hidden str clang_tmp_dir -declare-option -hidden completions clang_completions -declare-option -hidden line-specs clang_flags -declare-option -hidden line-specs clang_errors - -define-command -params ..1 \ - -docstring %{Parse the contents of the current buffer -The syntaxic errors detected during parsing are shown when auto-diagnostics are enabled} \ - clang-parse %{ - evaluate-commands %sh{ - dir=$(mktemp -d "${TMPDIR:-/tmp}"/kak-clang.XXXXXXXX) - mkfifo ${dir}/fifo - printf %s\\n "set-option buffer clang_tmp_dir ${dir}" - printf %s\\n "evaluate-commands -no-hooks write -sync ${dir}/buf" - } - # end the previous %sh{} so that its output gets interpreted by kakoune - # before launching the following as a background task. - evaluate-commands %sh{ - dir=${kak_opt_clang_tmp_dir} - printf %s\\n "evaluate-commands -draft %{ - edit! -fifo ${dir}/fifo -debug *clang-output* - set-option buffer filetype make - set-option buffer make_current_error_line 0 - hook -once -always buffer BufCloseFifo .* %{ nop %sh{ rm -r ${dir} } } - }" - # this runs in a detached shell, asynchronously, so that kakoune does - # not hang while clang is running. As completions references a cursor - # position and a buffer timestamp, only valid completions should be - # displayed. - ( - case ${kak_opt_filetype} in - c) ft=c ;; - cpp) ft=c++ ;; - obj-c) ft=objective-c ;; - *) ft=c++ ;; - esac - - if [ "$1" = "-complete" ]; then - pos=-:${kak_cursor_line}:${kak_cursor_column} - header="${kak_cursor_line}.${kak_cursor_column}@${kak_timestamp}" - compl=$(clang++ -x ${ft} -fsyntax-only ${kak_opt_clang_options} \ - -Xclang -code-completion-brief-comments -Xclang -code-completion-at=${pos} - < ${dir}/buf 2> ${dir}/stderr | - awk -F ': ' ' - /^COMPLETION:/ && ! /\(Hidden\)/ { - id=$2 - gsub(/ +$/, "", id) - gsub(/~/, "~~", id) - gsub(/\|/, "\\|", id) - - gsub(/[[{<]#|#[}>]/, "", $3) - gsub(/#]/, " ", $3) - gsub(/:: /, "::", $3) - gsub(/ +$/, "", $3) - desc=$4 ? $3 "\n" $4 : $3 - - gsub(/~/, "~~", desc) - gsub(/\|/, "\\|", desc) - if (id in docstrings) - docstrings[id]=docstrings[id] "\n" desc - else - docstrings[id]=desc - } - END { - for (id in docstrings) { - menu=id - gsub(/(^|[^[:alnum:]_])(operator|new|delete)($|[^{}_[:alnum:]]+)/, "{keyword}&{}", menu) - gsub(/(^|[[:space:]])(int|size_t|bool|char|unsigned|signed|long)($|[[:space:]])/, "{type}&{}", menu) - gsub(/[^{}_[:alnum:]]+/, "{operator}&{}", menu) - printf "%%~%s|%s|%s~ ", id, docstrings[id], menu - } - }') - printf %s\\n "evaluate-commands -client ${kak_client} echo 'clang completion done' - set-option 'buffer=${kak_buffile}' clang_completions ${header} ${compl}" | kak -p ${kak_session} - else - clang++ -x ${ft} -fsyntax-only ${kak_opt_clang_options} - < ${dir}/buf 2> ${dir}/stderr - printf %s\\n "evaluate-commands -client ${kak_client} echo 'clang parsing done'" | kak -p ${kak_session} - fi - - flags=$(cat ${dir}/stderr | sed -rne " - /^:[0-9]+:([0-9]+:)? (fatal )?error/ { s/^:([0-9]+):.*/'\1|{red}█'/; p } - /^:[0-9]+:([0-9]+:)? warning/ { s/^:([0-9]+):.*/'\1|{yellow}█'/; p } - " | paste -s -d ' ' -) - - errors=$(cat ${dir}/stderr | sed -rne " - /^:[0-9]+:([0-9]+:)? ((fatal )?error|warning)/ { - s/'/''/g; s/^:([0-9]+):([0-9]+:)? (.*)/'\1|\3'/; p - }" | sort -n | paste -s -d ' ' -) - - sed -e "s||${kak_bufname}|g" < ${dir}/stderr > ${dir}/fifo - - printf %s\\n "set-option 'buffer=${kak_buffile}' clang_flags ${kak_timestamp} ${flags} - set-option 'buffer=${kak_buffile}' clang_errors ${kak_timestamp} ${errors}" | kak -p ${kak_session} - ) > /dev/null 2>&1 < /dev/null & - } -} - -define-command clang-complete -docstring "Complete the current selection" %{ clang-parse -complete } - -define-command -hidden clang-show-completion-info %[ try %[ - evaluate-commands -draft %[ - execute-keys {( ^\( b \A\w+\z - evaluate-commands %sh[ - desc=$(printf %s\\n "${kak_opt_clang_completions}" | sed -e "{ s/\([^\\]\):/\1\n/g }" | sed -ne "/^${kak_selection}|/ { s/^[^|]\+|//; s/|.*$//; s/\\\:/:/g; p }") - if [ -n "$desc" ]; then - printf %s\\n "evaluate-commands -client $kak_client %{info -anchor ${kak_cursor_line}.${kak_cursor_column} -placement above %{${desc}}}" - fi - ] ] -] ] - -define-command clang-enable-autocomplete -docstring "Enable automatic clang completion" %{ - set-option window completers "option=clang_completions" %opt{completers} - hook window -group clang-autocomplete InsertIdle .* %{ - try %{ - execute-keys -draft (\.|->|::).\z - echo 'completing...' - clang-complete - } - clang-show-completion-info - } - alias window complete clang-complete -} - -define-command clang-disable-autocomplete -docstring "Disable automatic clang completion" %{ - evaluate-commands %sh{ printf "set-option window completers %s\n" $(printf %s "${kak_opt_completers}" | sed -e "s/'option=clang_completions'//g") } - remove-hooks window clang-autocomplete - unalias window complete clang-complete -} - -define-command -hidden clang-show-error-info %{ - update-option buffer clang_errors # Ensure we are up to date with buffer changes - evaluate-commands %sh{ - eval "set -- ${kak_opt_clang_errors}" - shift # skip timestamp - desc=$(for error in "$@"; do - if [ "${error%%|*}" = "$kak_cursor_line" ]; then - printf '%s\n' "${error##*|}" - fi - done) - if [ -n "$desc" ]; then - desc=$(printf %s "${desc}" | sed "s/'/''/g") - printf "info -anchor %d.%d '%s'\n" "${kak_cursor_line}" "${kak_cursor_column}" "${desc}" - fi - } } - -define-command clang-enable-diagnostics -docstring %{Activate automatic error reporting and diagnostics -Information about the analysis are showned after the buffer has been parsed with the clang-parse function} \ -%{ - add-highlighter window/clang_flags flag-lines default clang_flags - hook window -group clang-diagnostics NormalIdle .* %{ clang-show-error-info } - hook window -group clang-diagnostics WinSetOption ^clang_errors=.* %{ info; clang-show-error-info } -} - -define-command clang-disable-diagnostics -docstring "Disable automatic error reporting and diagnostics" %{ - remove-highlighter window/clang_flags - remove-hooks window clang-diagnostics -} - -define-command clang-diagnostics-next -docstring "Jump to the next line that contains an error" %{ - update-option buffer clang_errors # Ensure we are up to date with buffer changes - evaluate-commands %sh{ - eval "set -- ${kak_opt_clang_errors}" - shift # skip timestamp - for error in "$@"; do - candidate=${error%%|*} - first_line=${first_line-$candidate} - if [ "$candidate" -gt $kak_cursor_line ]; then - line=$candidate - break - fi - done - line=${line-$first_line} - if [ -n "$line" ]; then - printf %s\\n "execute-keys ${line} g" - else - echo "echo -markup '{Error}no next clang diagnostic'" - fi - } } diff --git a/rc/extra/cmake.kak b/rc/extra/cmake.kak deleted file mode 100644 index 77ec18c5..00000000 --- a/rc/extra/cmake.kak +++ /dev/null @@ -1,27 +0,0 @@ -hook global BufCreate .+\.cmake|.*/CMakeLists.txt %{ - set-option buffer filetype cmake -} - -hook global BufCreate .*/CMakeCache.txt %{ - set-option buffer filetype ini -} - -add-highlighter shared/cmake regions -add-highlighter shared/cmake/code default-region group -add-highlighter shared/cmake/comment region '#' '$' fill comment -add-highlighter shared/cmake/argument region -recurse '\(' '\w+\h*\(\K' '(?=\))' regions - -add-highlighter shared/cmake/code/ regex '\w+\h*(?=\()' 0:meta - -add-highlighter shared/cmake/argument/args default-region regex '\$\{\w+\}' 0:variable -add-highlighter shared/cmake/argument/quoted region '"' '(? - # remove trailing white spaces - try %{ execute-keys -draft s \h + $ d } - } -} - -define-command -hidden coffee-indent-on-new-line %{ - evaluate-commands -draft -itersel %{ - # copy '#' comment prefix and following white spaces - try %{ execute-keys -draft k s '^\h*\K#\h*' y gh j P } - # preserve previous line indent - try %{ execute-keys -draft \; K } - # filter previous line - try %{ execute-keys -draft k : coffee-trim-indent } - # indent after start structure - try %{ execute-keys -draft k ^ \h * (case|catch|class|else|finally|for|function|if|switch|try|while|with) \b | (=|->) $ j } - } -} - -# Initialization -# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ - -hook -group coffee-highlight global WinSetOption filetype=coffee %{ - add-highlighter window/coffee ref coffee - hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/coffee } -} - -hook global WinSetOption filetype=coffee %{ - hook window ModeChange insert:.* -group coffee-trim-indent coffee-trim-indent - hook window InsertChar \n -group coffee-indent coffee-indent-on-new-line - - hook -once -always window WinSetOption filetype=.* %{ remove-hooks window coffee-.+ } -} diff --git a/rc/extra/cucumber.kak b/rc/extra/cucumber.kak deleted file mode 100644 index 180da7d0..00000000 --- a/rc/extra/cucumber.kak +++ /dev/null @@ -1,89 +0,0 @@ -# http://cukes.info -# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ - -# Detection -# ‾‾‾‾‾‾‾‾‾ - -hook global BufCreate .*[.](feature|story) %{ - set-option buffer filetype cucumber -} - -# Highlighters -# ‾‾‾‾‾‾‾‾‾‾‾‾ - -add-highlighter shared/cucumber regions -add-highlighter shared/cucumber/code default-region group -add-highlighter shared/cucumber/language region ^\h*#\h*language: $ group -add-highlighter shared/cucumber/comment region ^\h*# $ fill comment - -add-highlighter shared/cucumber/language/ fill meta -add-highlighter shared/cucumber/language/ regex \S+$ 0:value - -# Spoken languages -# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ -# https://github.com/cucumber/cucumber/wiki/Spoken-languages -# -# curl --location https://github.com/cucumber/gherkin/raw/master/lib/gherkin/i18n.json -# -# { -# "en": { -# "name": "English", -# "native": "English", -# "feature": "Feature|Business Need|Ability", -# "background": "Background", -# "scenario": "Scenario", -# "scenario_outline": "Scenario Outline|Scenario Template", -# "examples": "Examples|Scenarios", -# "given": "*|Given", -# "when": "*|When", -# "then": "*|Then", -# "and": "*|And", -# "but": "*|But" -# }, -# … -# } -# -# jq 'with_entries({ key: .key, value: .value | del(.name) | del(.native) | join("|") })' -# -# { -# "en": "Feature|Business Need|Ability|Background|Scenario|Scenario Outline|Scenario Template|Examples|Scenarios|*|Given|*|When|*|Then|*|And|*|But", -# … -# } - -add-highlighter shared/cucumber/code/ regex \b(Feature|Business\h+Need|Ability|Background|Scenario|Scenario\h+Outline|Scenario\h+Template|Examples|Scenarios|Given|When|Then|And|But)\b 0:keyword - -# Commands -# ‾‾‾‾‾‾‾‾ - -define-command -hidden cucumber-trim-indent %{ - # remove trailing white spaces - try %{ execute-keys -draft -itersel s \h+$ d } -} - -define-command -hidden cucumber-indent-on-new-line %{ - evaluate-commands -draft -itersel %{ - # copy '#' comment prefix and following white spaces - try %{ execute-keys -draft k s ^\h*\K#\h* y gh j P } - # preserve previous line indent - try %{ execute-keys -draft \; K } - # filter previous line - try %{ execute-keys -draft k : cucumber-trim-indent } - # indent after lines containing : - try %{ execute-keys -draft k x : j } - } -} - -# Initialization -# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ - -hook -group cucumber-highlight global WinSetOption filetype=cucumber %{ - add-highlighter window/cucumber ref cucumber - hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/cucumber } -} - -hook global WinSetOption filetype=cucumber %{ - hook window ModeChange insert:.* -group cucumber-trim-indent cucumber-trim-indent - hook window InsertChar \n -group cucumber-indent cucumber-indent-on-new-line - - hook -once -always window WinSetOption filetype=.* %{ remove-hooks window cucumber-.+ } -} diff --git a/rc/extra/dart.kak b/rc/extra/dart.kak deleted file mode 100644 index 5b5600cb..00000000 --- a/rc/extra/dart.kak +++ /dev/null @@ -1,106 +0,0 @@ -# https://dartlang.org/ -# - -# Detection -# ‾‾‾‾‾‾‾‾‾ - -hook global BufCreate .*\.dart %{ - set-option buffer filetype dart -} - -# Highlighters -# ‾‾‾‾‾‾‾‾‾‾‾‾ - -add-highlighter shared/dart regions -add-highlighter shared/dart/code default-region group -add-highlighter shared/dart/back_string region '`' '`' fill string -add-highlighter shared/dart/double_string region '"' (?)" - classes="[A-Z][a-zA-Z0-9]*" - - # Add the language's grammar to the static completion list - printf %s\\n "hook global WinSetOption filetype=dart %{ - set-option window static_words ${keywords} ${attributes} ${types} ${values} - }" | tr '|' ' ' - - # Highlight keywords - printf %s " - add-highlighter shared/dart/code/ regex \b(${keywords})\b 0:keyword - add-highlighter shared/dart/code/ regex \b(${generator_keywords}) 0:keyword - add-highlighter shared/dart/code/ regex \b(${attributes})\b 0:attribute - add-highlighter shared/dart/code/ regex \b(${types})\b 0:type - add-highlighter shared/dart/code/ regex \b(${values})\b 0:value - add-highlighter shared/dart/code/ regex \b(${functions}) 2:function - add-highlighter shared/dart/code/ regex \b(${annotations})\b 0:meta - add-highlighter shared/dart/code/ regex \b(${classes})\b 0:module - " -} - -# Commands -# ‾‾‾‾‾‾‾‾ - -define-command -hidden dart-indent-on-new-line %~ - evaluate-commands -draft -itersel %= - # preserve previous line indent - try %{ execute-keys -draft \;K } - # indent after lines ending with { or ( - try %[ execute-keys -draft k [{(]\h*$ j ] - # cleanup trailing white spaces on the previous line - try %{ execute-keys -draft k s \h+$ d } - # align to opening paren of previous line - try %{ execute-keys -draft [( \A\([^\n]+\n[^\n]*\n?\z s \A\(\h*.|.\z '' & } - # copy // comments prefix - try %{ execute-keys -draft \;k s ^\h*\K/{2,} yP } - # indent after a switch's case/default statements - try %[ execute-keys -draft k ^\h*(case|default).*:$ j ] - # indent after if|else|while|for - try %[ execute-keys -draft \;)MB \A(if|else|while|for)\h*\(.*\)\h*\n\h*\n?\z s \A|.\z 11 ] - = -~ - -define-command -hidden dart-indent-on-opening-curly-brace %[ - # align indent with opening paren when { is entered on a new line after the closing paren - try %[ execute-keys -draft -itersel h)M \A\(.*\)\h*\n\h*\{\z s \A|.\z 1 ] -] - -define-command -hidden dart-indent-on-closing-curly-brace %[ - # align to opening curly brace when alone on a line - try %[ execute-keys -itersel -draft ^\h+\}$hms\A|.\z1 ] -] - -# Initialization -# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ - -hook -group dart-highlight global WinSetOption filetype=dart %{ - add-highlighter window/dart ref dart - hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/dart } -} - -hook global WinSetOption filetype=dart %{ - # cleanup trailing whitespaces when exiting insert mode - hook window ModeChange insert:.* -group dart-trim-indent %{ try %{ execute-keys -draft s^\h+$d } } - hook window InsertChar \n -group dart-indent dart-indent-on-new-line - hook window InsertChar \{ -group dart-indent dart-indent-on-opening-curly-brace - hook window InsertChar \} -group dart-indent dart-indent-on-closing-curly-brace - - hook -once -always window WinSetOption filetype=.* %{ remove-hooks window dart-.+ } -} diff --git a/rc/extra/dockerfile.kak b/rc/extra/dockerfile.kak deleted file mode 100644 index 07da2347..00000000 --- a/rc/extra/dockerfile.kak +++ /dev/null @@ -1,48 +0,0 @@ -# http://docker.com -# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ - -# See https://docs.docker.com/reference/builder - -# Detection -# ‾‾‾‾‾‾‾‾‾ - -hook global BufCreate .*/?Dockerfile(\.\w+)?$ %{ - set-option buffer filetype dockerfile -} - -# Highlighters -# ‾‾‾‾‾‾‾‾‾‾‾‾ - -add-highlighter shared/dockerfile regions -add-highlighter shared/dockerfile/code default-region group -add-highlighter shared/dockerfile/double_string region '"' '(?/dev/null 2>&1 || { echo 'echo -markup "{Error}editorconfig could not be found"'; exit 1; } - editorconfig "${1:-$kak_buffile}" | awk -F= -- ' - /indent_style=/ { indent_style = $2 } - /indent_size=/ { indent_size = $2 == "tab" ? 4 : $2 } - /tab_width=/ { tab_width = $2 } - /end_of_line=/ { end_of_line = $2 } - /charset=/ { charset = $2 } - /trim_trailing_whitespace=/ { trim_trailing_whitespace = $2 } - - END { - if (indent_style == "tab") { - print "set-option buffer indentwidth 0" - print "set-option buffer aligntab true" - } - if (indent_style == "space") { - print "set-option buffer indentwidth " (indent_size == "tab" ? 4 : indent_size) - print "set-option buffer aligntab false" - } - if (indent_size || tab_width) { - print "set-option buffer tabstop " (tab_width ? tab_width : indent_size) - } - if (end_of_line == "lf" || end_of_line == "crlf") { - print "set-option buffer eolformat " end_of_line - } - if (charset == "utf-8-bom") { - print "set-option buffer BOM utf8" - } - if (trim_trailing_whitespace == "true") { - print "set-option buffer editorconfig_trim_trailing_whitespace true" - } - } - ' - } - hook buffer BufWritePre %val{buffile} -group editorconfig-hooks %{ evaluate-commands %sh{ - if [ ${kak_opt_editorconfig_trim_trailing_whitespace} = "true" ]; then - printf %s\\n "try %{ execute-keys -draft %{ %s\h+$d } }" - fi - } } -} diff --git a/rc/extra/elixir.kak b/rc/extra/elixir.kak deleted file mode 100644 index a2587d1e..00000000 --- a/rc/extra/elixir.kak +++ /dev/null @@ -1,77 +0,0 @@ -# http://elixir-lang.org -# ---------------------- - -# Detection -# ‾‾‾‾‾‾‾‾‾ - -hook global BufCreate .*[.](ex|exs) %{ - set-option buffer filetype elixir -} - - -# Highlighters -# ‾‾‾‾‾‾‾‾‾‾‾‾ - -add-highlighter shared/elixir regions -add-highlighter shared/elixir/code default-region group -add-highlighter shared/elixir/double_string region '"' (?|<-|<<|>>|=>) 0:builtin -add-highlighter shared/elixir/code/ regex \b(require|alias|use|import)\b 0:keyword -add-highlighter shared/elixir/code/ regex \b(__MODULE__|__DIR__|__ENV__|__CALLER__)\b 0:value -add-highlighter shared/elixir/code/ regex \b(def|defp|defmacro|defmacrop|defstruct|defmodule|defimpl|defprotocol|defoverridable)\b 0:keyword -add-highlighter shared/elixir/code/ regex \b(fn|do|end|when|case|if|else|unless|var!|for|cond|quote|unquote|receive|with|raise|reraise|try|catch)\b 0:keyword -add-highlighter shared/elixir/code/ regex '@[\w_]+\b' 0:attribute -add-highlighter shared/elixir/code/ regex '\b\d+[\d_]*\b' 0:value - -# Commands -# ‾‾‾‾‾‾‾‾ - -define-command -hidden elixir-trim-indent %{ - # remove trailing white spaces - try %{ execute-keys -draft -itersel s \h+$ d } -} - -define-command -hidden elixir-indent-on-new-line %{ - evaluate-commands -draft -itersel %{ - # copy -- comments prefix and following white spaces - try %{ execute-keys -draft k s ^\h*\K--\h* y gh j P } - # preserve previous line indent - try %{ execute-keys -draft \; K } - # indent after line ending with: - # try %{ execute-keys -draft k x (do|else|->)$ & } - # filter previous line - try %{ execute-keys -draft k : elixir-trim-indent } - # indent after lines ending with do or -> - try %{ execute-keys -draft \\; k x ^.+(do|->)$ j } - } -} - -# Initialization -# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ - -hook -group elixir-highlight global WinSetOption filetype=elixir %{ - add-highlighter window/elixir ref elixir - hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/elixir } -} - -hook global WinSetOption filetype=elixir %{ - hook window ModeChange insert:.* -group elixir-trim-indent elixir-trim-indent - hook window InsertChar \n -group elixir-indent elixir-indent-on-new-line - - hook -once -always window WinSetOption filetype=.* %{ remove-hooks window elixir-.+ } -} diff --git a/rc/extra/elm.kak b/rc/extra/elm.kak deleted file mode 100644 index 05d1248b..00000000 --- a/rc/extra/elm.kak +++ /dev/null @@ -1,67 +0,0 @@ -# http://elm-lang.org -# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ - -# Detection -# ‾‾‾‾‾‾‾‾‾ - -hook global BufCreate .*[.](elm) %{ - set-option buffer filetype elm -} - -# Highlighters -# ‾‾‾‾‾‾‾‾‾‾‾‾ - -add-highlighter shared/elm regions -add-highlighter shared/elm/code default-region group -add-highlighter shared/elm/string region '"' (? s \h+$ d } -} - -define-command -hidden elm-indent-after " - execute-keys -draft \\; k x ^\\h*(if)|(case\\h+[\\w']+\\h+of|let|in|\\{\\h+\\w+|\\w+\\h+->|[=(])$ j -" - -define-command -hidden elm-indent-on-new-line %{ - evaluate-commands -draft -itersel %{ - # copy -- comments prefix and following white spaces - try %{ execute-keys -draft k s ^\h*\K--\h* y gh j P } - # preserve previous line indent - try %{ execute-keys -draft \; K } - # align to first clause - try %{ execute-keys -draft \; k x X s ^\h*(if|then|else)?\h*(([\w']+\h+)+=)?\h*(case\h+[\w']+\h+of|let)\h+\K.* s \A|.\z & } - # filter previous line - try %{ execute-keys -draft k : elm-trim-indent } - # indent after lines beginning with condition or ending with expression or =( - try %{ elm-indent-after } - } -} - -# Initialization -# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ - -hook -group elm-highlight global WinSetOption filetype=elm %{ - add-highlighter window/elm ref elm - hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/elm } -} - -hook global WinSetOption filetype=elm %{ - hook window ModeChange insert:.* -group elm-trim-indent elm-trim-indent - hook window InsertChar \n -group elm-indent elm-indent-on-new-line - - hook -once -always window WinSetOption filetype=.* %{ remove-hooks window elm-.+ } -} diff --git a/rc/extra/exherbo.kak b/rc/extra/exherbo.kak deleted file mode 100644 index 42cc618c..00000000 --- a/rc/extra/exherbo.kak +++ /dev/null @@ -1,121 +0,0 @@ -## Repository metadata files -hook global BufCreate .*/metadata/mirrors\.conf %{ set-option buffer filetype paludis-mirrors-conf } -hook global BufCreate .*/metadata/licence_groups.conf %{ set-option buffer filetype exheres-0-licence-groups } -hook global BufCreate .*/metadata/options/descriptions/.*\.conf %{ set-option buffer filetype exheres-0-licence-groups } -hook global BufCreate .*/metadata/.*\.conf %{ set-option buffer filetype exheres-0-metadata } - -## News items -hook global BufCreate .*/metadata/news/.*/.*\.txt %{ set-option buffer filetype glep42 } - -## exheres-0, exlib -hook global BufCreate .*\.(exheres-0|exlib) %{ set-option buffer filetype sh } - -# Paludis configurations -hook global BufCreate .*/etc/paludis(-.*)?/bashrc %{ set-option buffer filetype sh } -hook global BufCreate .*/etc/paludis(-.*)?/general(\.conf.d/.*.conf|\.conf) %{ set-option buffer filetype paludis-key-value-conf } -hook global BufCreate .*/etc/paludis(-.*)?/licences(\.conf.d/.*.conf|\.conf) %{ set-option buffer filetype paludis-options-conf } -hook global BufCreate .*/etc/paludis(-.*)?/mirrors(\.conf.d/.*.conf|\.conf) %{ set-option buffer filetype paludis-mirrors-conf } -hook global BufCreate .*/etc/paludis(-.*)?/options(\.conf.d/.*.conf|\.conf) %{ set-option buffer filetype paludis-options-conf } -hook global BufCreate .*/etc/paludis(-.*)?/output(\.conf.d/.*.conf|\.conf) %{ set-option buffer filetype paludis-key-value-conf } -hook global BufCreate .*/etc/paludis(-.*)?/package_(unmask|mask)(\.conf.d/.*.conf|\.conf) %{ set-option buffer filetype paludis-specs-conf } -hook global BufCreate .*/etc/paludis(-.*)?/platforms(\.conf.d/.*.conf|\.conf) %{ set-option buffer filetype paludis-specs-conf } -hook global BufCreate .*/etc/paludis(-.*)?/repositories/.*\.conf %{ set-option buffer filetype paludis-key-value-conf } -hook global BufCreate .*/etc/paludis(-.*)?/repository\.template %{ set-option buffer filetype paludis-key-value-conf } -hook global BufCreate .*/etc/paludis(-.*)?/repository_defaults\.conf %{ set-option buffer filetype paludis-key-value-conf } -hook global BufCreate .*/etc/paludis(-.*)?/specpath\.conf %{ set-option buffer filetype paludis-key-value-conf } -hook global BufCreate .*/etc/paludis(-.*)?/suggestions(\.conf.d/.*.conf|\.conf) %{ set-option buffer filetype paludis-specs-conf } - -# Highlighters -## exheres-0 Repository metadata files -add-highlighter shared/exheres-0-metadata group -add-highlighter shared/exheres-0-metadata/ regex ^#.*?$ 0:comment -add-highlighter shared/exheres-0-metadata/ regex ^(?:[\s\t]+)?(\*)?(\S+)(?:[\s\t]+)?=(?:[\s\t]+)?(.+?)?$ 1:type 2:attribute 3:string -add-highlighter shared/exheres-0-metadata/ regex ^(?:[\s\t]+)?[\S]+[\s\t]+=[\s\t]+\[.+?[\s\t]+\] 0:string -add-highlighter shared/exheres-0-metadata/ regex ^(?:[\s\t]+)?(\S+)\s\[\[$ 0:type -add-highlighter shared/exheres-0-metadata/ regex ^(?:[\s\t]+)?\]\]$ 0:type - -hook -group exheres-0-metadata-highlight global WinSetOption filetype=exheres-0-metadata %{ - add-highlighter window/exheres-0-metadata ref exheres-0-metadata - hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/exheres-0-metadata } -} - -## exheres-0 options descriptions -add-highlighter shared/exheres-0-options-descriptions group -add-highlighter shared/exheres-0-options-descriptions/ regex ^#.*?$ 0:comment -add-highlighter shared/exheres-0-options-descriptions/ regex ^(?:[\s\t]+)?[\S]+[\s\t]+-[\s\t]+\[.+?[\s\t]+\] 0:string -add-highlighter shared/exheres-0-options-descriptions/ regex ^(?:[\s\t]+)?(\S+)\s\[\[$ 0:type -add-highlighter shared/exheres-0-options-descriptions/ regex ^(?:[\s\t]+)?\]\]$ 0:type - -hook -group exheres-0-options-descriptions-highlight global WinSetOption filetype=exheres-0-options-descriptions %{ - add-highlighter window/exheres-0-options-descriptions ref exheres-0-options-descriptions - hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/exheres-0-options-descriptions } -} - -## metadata/licence_groups.conf -add-highlighter shared/exheres-0-licence-groups group -add-highlighter shared/exheres-0-licence-groups/ regex [\s\t]+(\S+(?:[\s\t]+))*$ 0:attribute -add-highlighter shared/exheres-0-licence-groups/ regex ^(\S+) 0:type -add-highlighter shared/exheres-0-licence-groups/ regex ^#.*?$ 0:comment - -hook -group exheres-0-licence-groups-highlight global WinSetOption filetype=exheres-0-licence-groups %{ - add-highlighter window/exheres-0-licence-groups ref exheres-0-licence-groups - hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/exheres-0-licence-groups } -} - -## Paludis configurations -### options.conf -add-highlighter shared/paludis-options-conf group -add-highlighter shared/paludis-options-conf/ regex [\s\t]+(\S+(?:[\s\t]+))*$ 0:attribute -add-highlighter shared/paludis-options-conf/ regex (?::)(?:[\s\t]+)(.*?$) 1:attribute -add-highlighter shared/paludis-options-conf/ regex [\s\t]+(\S+=)(\S+) 1:attribute 2:value -add-highlighter shared/paludis-options-conf/ regex [\s\t](\S+:) 0:keyword -add-highlighter shared/paludis-options-conf/ regex [\s\t](-\S+)(.*?) 1:red -add-highlighter shared/paludis-options-conf/ regex ^(\S+/\S+) 0:type -add-highlighter shared/paludis-options-conf/ regex ^#.*?$ 0:comment - -hook -group paludis-options-conf-highlight global WinSetOption filetype=paludis-options-conf %{ - add-highlighter window/paludis-options-conf ref paludis-options-conf - hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/paludis-options-conf } -} - -## general.conf, repository.template -add-highlighter shared/paludis-key-value-conf group -add-highlighter shared/paludis-key-value-conf/ regex ^[\s\t]?(\S+)[\s\t+]=[\s\t+](.*?)$ 1:attribute 2:value -add-highlighter shared/paludis-key-value-conf/ regex ^#.*?$ 0:comment - -hook -group paludis-key-value-conf-highlight global WinSetOption filetype=paludis-key-value-conf %{ - add-highlighter window/paludis-key-value-conf ref paludis-key-value-conf - hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/paludis-key-value-conf } -} - -## mirrors.conf -add-highlighter shared/paludis-mirrors-conf group -add-highlighter shared/paludis-mirrors-conf/ regex ^[\s\t+]?(\S+)[\s\t+](.*?)$ 1:type 2:value -add-highlighter shared/paludis-mirrors-conf/ regex ^#.*?$ 0:comment - -hook -group paludis-mirrors-conf-highlight global WinSetOption filetype=paludis-mirrors-conf %{ - add-highlighter window/paludis-mirrors-conf ref paludis-mirrors-conf - hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/paludis-mirrors-conf } -} - -## package_(unmask|mask).conf, platforms.conf -add-highlighter shared/paludis-specs-conf group -add-highlighter shared/paludis-specs-conf/ regex [\s\t]+(\S+(?:[\s\t]+))*$ 0:attribute -add-highlighter shared/paludis-specs-conf/ regex ^(\S+/\S+) 0:type -add-highlighter shared/paludis-specs-conf/ regex ^#.*?$ 0:comment - -hook -group paludis-specs-conf-highlight global WinSetOption filetype=paludis-specs-conf %{ - add-highlighter window/paludis-specs-conf ref paludis-specs-conf - hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/paludis-specs-conf } -} - -## News items (GLEP42) -add-highlighter shared/glep42 group -add-highlighter shared/glep42/ regex ^(Title|Author|Translator|Content-Type|Posted|Revision|News-Item-Format|Display-If-Installed|Display-If-Keyword|Display-If-Profile):([^\n]*(?:\n\h+[^\n]+)*)$ 1:keyword 2:attribute -add-highlighter shared/glep42/ regex <[^@>]+@.*?> 0:string -add-highlighter shared/glep42/ regex ^>.*?$ 0:comment - -hook -group glep42-highlight global WinSetOption filetype=glep42 %{ - add-highlighter window/glep42 ref glep42 - hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/glep42 } -} diff --git a/rc/extra/git-tools.kak b/rc/extra/git-tools.kak deleted file mode 100644 index 21b5627b..00000000 --- a/rc/extra/git-tools.kak +++ /dev/null @@ -1,214 +0,0 @@ -declare-option -docstring "name of the client in which documentation is to be displayed" \ - str docsclient - -hook -group git-log-highlight global WinSetOption filetype=git-log %{ - add-highlighter window/git-log group - add-highlighter window/git-log/ regex '^(commit) ([0-9a-f]+)$' 1:keyword 2:meta - add-highlighter window/git-log/ regex '^([a-zA-Z_-]+:) (.*?)$' 1:variable 2:value - add-highlighter window/git-log/ ref diff # highlight potential diffs from the -p option - - hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/git-log } -} - - -hook -group git-status-highlight global WinSetOption filetype=git-status %{ - add-highlighter window/git-status group - add-highlighter window/git-status/ regex '^\h+(?:((?:both )?modified:)|(added:|new file:)|(deleted(?: by \w+)?:)|(renamed:)|(copied:))(?:.*?)$' 1:yellow 2:green 3:red 4:cyan 5:blue 6:magenta - - hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/git-status } -} - - -declare-option -hidden line-specs git_blame_flags -declare-option -hidden line-specs git_diff_flags - -define-command -params 1.. \ - -docstring %sh{printf 'git []: git wrapping helper -All the optional arguments are forwarded to the git utility -Available commands:\n add\n rm\n blame\n commit\n checkout\n diff\n hide-blame\n hide-diff\n log\n show\n show-diff\n status\n update-diff'} \ - -shell-script-candidates %{ - if [ $kak_token_to_complete -eq 0 ]; then - printf "add\nrm\nblame\ncommit\ncheckout\ndiff\nhide-blame\nhide-diff\nlog\nshow\nshow-diff\nstatus\nupdate-diff\n" - else - case "$1" in - commit) printf -- "--amend\n--no-edit\n--all\n--reset-author\n--fixup\n--squash\n"; git ls-files -m ;; - add) git ls-files -dmo --exclude-standard ;; - rm) git ls-files -c ;; - esac - fi - } \ - git %{ evaluate-commands %sh{ - show_git_cmd_output() { - local filetype - case "$1" in - show|diff) filetype=diff ;; - log) filetype=git-log ;; - status) filetype=git-status ;; - esac - output=$(mktemp -d "${TMPDIR:-/tmp}"/kak-git.XXXXXXXX)/fifo - mkfifo ${output} - ( git "$@" > ${output} 2>&1 ) > /dev/null 2>&1 < /dev/null & - - printf %s "evaluate-commands -try-client '$kak_opt_docsclient' %{ - edit! -fifo ${output} *git* - set-option buffer filetype '${filetype}' - hook -always -once buffer BufCloseFifo .* %{ nop %sh{ rm -r $(dirname ${output}) } } - }" - } - - run_git_blame() { - ( - printf %s "evaluate-commands -client '$kak_client' %{ - try %{ add-highlighter window/git-blame flag-lines Information git_blame_flags } - set-option buffer=$kak_bufname git_blame_flags '$kak_timestamp' - }" | kak -p ${kak_session} - git blame "$@" --incremental ${kak_buffile} | awk ' - function send_flags(text, flag, i) { - if (line == "") { return; } - text=substr(sha,1,8) " " dates[sha] " " authors[sha] - # gsub("|", "\\|", text) - gsub("~", "~~", text) - flag="%~" line "|" text "~" - for ( i=1; i < count; i++ ) { - flag=flag " %~" line+i "|" text "~" - } - cmd = "kak -p " ENVIRON["kak_session"] - print "set-option -add buffer=" ENVIRON["kak_bufname"] " git_blame_flags " flag | cmd - close(cmd) - } - /^([0-9a-f]{40}) ([0-9]+) ([0-9]+) ([0-9]+)/ { - send_flags() - sha=$1 - line=$3 - count=$4 - } - /^author / { authors[sha]=substr($0,8) } - /^author-time ([0-9]*)/ { - cmd = "date -d @" $2 " +\"%F %T\"" - cmd | getline dates[sha] - close(cmd) - } - END { send_flags(); }' - ) > /dev/null 2>&1 < /dev/null & - } - - update_diff() { - git --no-pager diff -U0 "$kak_buffile" | perl -e ' - $flags = $ENV{"kak_timestamp"}; - foreach $line () { - if ($line =~ /@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))?/) { - $from_line = $1; - $from_count = ($2 eq "" ? 1 : $2); - $to_line = $3; - $to_count = ($4 eq "" ? 1 : $4); - - if ($from_count == 0 and $to_count > 0) { - for $i (0..$to_count - 1) { - $line = $to_line + $i; - $flags .= " $line|\{green\}+"; - } - } - elsif ($from_count > 0 and $to_count == 0) { - if ($to_line == 0) { - $flags .= " 1|\{red\}‾"; - } else { - $flags .= " $to_line|\{red\}_"; - } - } - elsif ($from_count > 0 and $from_count == $to_count) { - for $i (0..$to_count - 1) { - $line = $to_line + $i; - $flags .= " $line|\{blue\}~"; - } - } - elsif ($from_count > 0 and $from_count < $to_count) { - for $i (0..$from_count - 1) { - $line = $to_line + $i; - $flags .= " $line|\{blue\}~"; - } - for $i ($from_count..$to_count - 1) { - $line = $to_line + $i; - $flags .= " $line|\{green\}+"; - } - } - elsif ($to_count > 0 and $from_count > $to_count) { - for $i (0..$to_count - 2) { - $line = $to_line + $i; - $flags .= " $line|\{blue\}~"; - } - $last = $to_line + $to_count - 1; - $flags .= " $last|\{blue+u\}~"; - } - } - } - print "set-option buffer git_diff_flags $flags" - ' - } - - commit() { - # Handle case where message needs not to be edited - if grep -E -q -e "-m|-F|-C|--message=.*|--file=.*|--reuse-message=.*|--no-edit|--fixup.*|--squash.*"; then - if git commit "$@" > /dev/null 2>&1; then - echo 'echo -markup "{Information}Commit succeeded"' - else - echo 'echo -markup "{Error}Commit failed"' - fi - exit - fi <<-EOF - $@ - EOF - - # fails, and generate COMMIT_EDITMSG - GIT_EDITOR='' EDITOR='' git commit "$@" > /dev/null 2>&1 - msgfile="$(git rev-parse --git-dir)/COMMIT_EDITMSG" - printf %s "edit '$msgfile' - hook buffer BufWritePost '.*\Q$msgfile\E' %{ evaluate-commands %sh{ - if git commit -F '$msgfile' --cleanup=strip $* > /dev/null; then - printf %s 'evaluate-commands -client $kak_client echo -markup %{{Information}Commit succeeded}; delete-buffer' - else - printf %s 'evaluate-commands -client $kak_client echo -markup %{{Error}Commit failed}' - fi - } }" - } - - case "$1" in - show|log|diff|status) show_git_cmd_output "$@" ;; - blame) shift; run_git_blame "$@" ;; - hide-blame) - printf %s "try %{ - set-option buffer=$kak_bufname git_blame_flags $kak_timestamp - remove-highlighter window/git-blame - }" - ;; - show-diff) - echo 'try %{ add-highlighter window/git-diff flag-lines Default git_diff_flags }' - update_diff - ;; - hide-diff) - echo 'try %{ remove-highlighter window/git-diff }' - ;; - update-diff) update_diff ;; - commit) shift; commit "$@" ;; - checkout) - name="${2:-${kak_buffile}}" - git checkout "${name}" > /dev/null 2>&1 - ;; - add) - name="${2:-${kak_buffile}}" - if git add -- "${name}" > /dev/null 2>&1; then - printf %s "echo -markup '{Information}git: added ${name}'" - else - printf %s "echo -markup '{Error}git: unable to add ${name}'" - fi - ;; - rm) - name="${2:-${kak_buffile}}" - if git rm -- "${name}" > /dev/null 2>&1; then - printf %s "echo -markup '{Information}git: removed ${name}'" - else - printf %s "echo -markup '{Error}git: unable to remove ${name}'" - fi - ;; - *) printf %s "echo -markup %{{Error}unknown git command '$1'}"; exit ;; - esac -}} diff --git a/rc/extra/go-tools.kak b/rc/extra/go-tools.kak deleted file mode 100644 index ee26698e..00000000 --- a/rc/extra/go-tools.kak +++ /dev/null @@ -1,182 +0,0 @@ -# Provides integration of the following tools: -# - gocode for code completion (github.com/nsf/gocode) -# - goimports for code formatting on save -# - gogetdoc for documentation display and source jump (needs jq) (github.com/zmb3/gogetdoc) -# Needs the following tools in the path: -# - jq for json deserializaton - -evaluate-commands %sh{ - for dep in gocode goimports gogetdoc jq; do - if ! command -v $dep > /dev/null 2>&1; then - echo "echo -debug %{Dependency unmet: $dep, please install it to use go-tools}" - fi - done -} - -# Auto-completion -# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ - -declare-option -hidden str go_complete_tmp_dir -declare-option -hidden completions gocode_completions - -define-command go-complete -docstring "Complete the current selection with gocode" %{ - evaluate-commands %sh{ - dir=$(mktemp -d "${TMPDIR:-/tmp}"/kak-go.XXXXXXXX) - printf %s\\n "set-option buffer go_complete_tmp_dir ${dir}" - printf %s\\n "evaluate-commands -no-hooks write ${dir}/buf" - } - nop %sh{ - dir=${kak_opt_go_complete_tmp_dir} - ( - gocode_data=$(gocode -f=godit --in=${dir}/buf autocomplete ${kak_cursor_byte_offset}) - rm -r ${dir} - column_offset=$(printf %s "${gocode_data}" | head -n1 | cut -d, -f1) - - header="${kak_cursor_line}.$((${kak_cursor_column} - $column_offset))@${kak_timestamp}" - compl=$(echo "${gocode_data}" | sed 1d | awk -F ",," '{ - gsub(/~/, "~~", $1) - gsub(/~/, "~~", $2) - print "%~" $2 "||" $1 "~" - }' | paste -s -) - printf %s\\n "evaluate-commands -client '${kak_client}' %{ - set-option 'buffer=${kak_bufname}' gocode_completions ${header} ${compl} - }" | kak -p ${kak_session} - ) > /dev/null 2>&1 < /dev/null & - } -} - -define-command go-enable-autocomplete -docstring "Add gocode completion candidates to the completer" %{ - set-option window completers "option=gocode_completions" %opt{completers} - hook window -group go-autocomplete InsertIdle .* %{ try %{ - execute-keys -draft [\w\.].\z - go-complete - } } - alias window complete go-complete -} - -define-command go-disable-autocomplete -docstring "Disable gocode completion" %{ - set-option window completers %sh{ printf %s\\n "${kak_opt_completers}" | sed "s/'option=gocode_completions'//g" } - remove-hooks window go-autocomplete - unalias window complete go-complete -} - -# Auto-format -# ‾‾‾‾‾‾‾‾‾‾‾ - -declare-option -hidden str go_format_tmp_dir - -define-command -params ..1 go-format \ - -docstring "go-format [-use-goimports]: custom formatter for go files" %{ - evaluate-commands %sh{ - dir=$(mktemp -d "${TMPDIR:-/tmp}"/kak-go.XXXXXXXX) - printf %s\\n "set-option buffer go_format_tmp_dir ${dir}" - printf %s\\n "evaluate-commands -no-hooks write ${dir}/buf" - } - evaluate-commands %sh{ - dir=${kak_opt_go_format_tmp_dir} - if [ "$1" = "-use-goimports" ]; then - fmt_cmd="goimports -srcdir '${kak_buffile}'" - else - fmt_cmd="gofmt -s" - fi - eval "${fmt_cmd} -e -w ${dir}/buf 2> ${dir}/stderr" - if [ $? ]; then - cp ${dir}/buf "${kak_buffile}" - else - # we should report error if linting isn't active - printf %s\\n "echo -debug '$(cat ${dir}/stderr)'" - fi - rm -r ${dir} - } - edit! -} - -# Documentation -# ‾‾‾‾‾‾‾‾‾‾‾‾‾ - -declare-option -hidden str go_doc_tmp_dir - -# FIXME text escaping -define-command -hidden -params 1..2 gogetdoc-cmd %{ - evaluate-commands %sh{ - dir=$(mktemp -d "${TMPDIR:-/tmp}"/kak-go.XXXXXXXX) - printf %s\\n "set-option buffer go_doc_tmp_dir ${dir}" - printf %s\\n "evaluate-commands -no-hooks write ${dir}/buf" - } - evaluate-commands %sh{ - dir=${kak_opt_go_doc_tmp_dir} - ( - printf %s\\n "${kak_buffile}" > ${dir}/modified - cat ${dir}/buf | wc -c >> ${dir}/modified - cat ${dir}/buf >> ${dir}/modified - - if [ "$2" = "1" ]; then - args="-json" - fi - output=$(cat ${dir}/modified \ - | gogetdoc $args -pos "${kak_buffile}:#${kak_cursor_byte_offset}" -modified \ - | sed 's/%/%%/g') - rm -r ${dir} - printf %s "${output}" | grep -v -q "^gogetdoc: " - status=$? - - case "$1" in - "info") - if [ ${status} -eq 0 ]; then - printf %s\\n "evaluate-commands -client '${kak_client}' %{ - info -anchor ${kak_cursor_line}.${kak_cursor_column} %@${output}@ - }" | kak -p ${kak_session} - else - msg=$(printf %s "${output}" | cut -d' ' -f2-) - printf %s\\n "evaluate-commands -client '${kak_client}' %{ - echo '${msg}' - }" | kak -p ${kak_session} - fi - ;; - "echo") - if [ ${status} -eq 0 ]; then - signature=$(printf %s "${output}" | sed -n 3p) - printf %s\\n "evaluate-commands -client '${kak_client}' %{ - echo '${signature}' - }" | kak -p ${kak_session} - fi - ;; - "jump") - if [ ${status} -eq 0 ]; then - pos=$(printf %s "${output}" | jq -r .pos) - file=$(printf %s "${pos}" | cut -d: -f1) - line=$(printf %s "${pos}" | cut -d: -f2) - col=$(printf %s "${pos}" | cut -d: -f3) - printf %s\\n "evaluate-commands -client '${kak_client}' %{ - evaluate-commands -try-client '${kak_opt_jumpclient}' edit -existing ${file} ${line} ${col} - try %{ focus '${kak_opt_jumpclient}' } - }" | kak -p ${kak_session} - fi - ;; - *) - printf %s\\n "evaluate-commands -client '${kak_client}' %{ - echo -error %{unkown command '$1'} - }" | kak -p ${kak_session} - ;; - - esac - ) > /dev/null 2>&1 < /dev/null & - } -} - -define-command go-doc-info -docstring "Show the documention of the symbol under the cursor" %{ - gogetdoc-cmd "info" -} - -define-command go-print-signature -docstring "Print the signature of the symbol under the cursor" %{ - gogetdoc-cmd "echo" -} - -define-command go-jump -docstring "Jump to the symbol definition" %{ - gogetdoc-cmd "jump" 1 -} - -define-command go-share-selection -docstring "Share the selection using the Go Playground" %{ evaluate-commands %sh{ - snippet_id=$(printf %s\\n "${kak_selection}" | curl -s https://play.golang.org/share --data-binary @-) - printf "echo https://play.golang.org/p/%s" ${snippet_id} -} } diff --git a/rc/extra/haml.kak b/rc/extra/haml.kak deleted file mode 100644 index e3e7f593..00000000 --- a/rc/extra/haml.kak +++ /dev/null @@ -1,62 +0,0 @@ -# http://haml.info -# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ - -# Detection -# ‾‾‾‾‾‾‾‾‾ - -hook global BufCreate .*[.](haml) %{ - set-option buffer filetype haml -} - -# Highlighters -# ‾‾‾‾‾‾‾‾‾‾‾‾ - -add-highlighter shared/haml regions -add-highlighter shared/haml/code default-region group -add-highlighter shared/haml/comment region ^\h*/ $ fill comment - -# Filters -# http://haml.info/docs/yardoc/file.REFERENCE.html#filters -add-highlighter shared/haml/eval1 region -recurse \{ ^\h*%([A-Za-z][A-Za-z0-9_-]*)([#.][A-Za-z][A-Za-z0-9_-]*)?\{\K|#\{\K (?=\}) ref ruby -add-highlighter shared/haml/eval2 region ^\h*[=-]\K (? s \h+$ d } -} - -define-command -hidden haml-indent-on-new-line %{ - evaluate-commands -draft -itersel %{ - # copy '/' comment prefix and following white spaces - try %{ execute-keys -draft k s ^\h*\K/\h* y gh j P } - # preserve previous line indent - try %{ execute-keys -draft \; K } - # filter previous line - try %{ execute-keys -draft k : haml-trim-indent } - # indent after lines beginning with : or - - try %{ execute-keys -draft k ^\h*[:-] j } - } -} - -# Initialization -# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ - -hook -group haml-highlight global WinSetOption filetype=haml %{ - add-highlighter window/haml ref haml - hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/haml } -} - -hook global WinSetOption filetype=haml %{ - hook window ModeChange insert:.* -group haml-trim-indent haml-trim-indent - hook window InsertChar \n -group haml-indent haml-indent-on-new-line - - hook -once -always window WinSetOption filetype=.* %{ remove-hooks window haml-.+ } -} diff --git a/rc/extra/hbs.kak b/rc/extra/hbs.kak deleted file mode 100644 index a0948e6f..00000000 --- a/rc/extra/hbs.kak +++ /dev/null @@ -1,97 +0,0 @@ -# http://handlebarsjs.com/ -# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ - -# Detection -# ‾‾‾‾‾‾‾‾‾ - -hook global BufCreate .*[.](hbs) %{ - set-option buffer filetype hbs -} - -# Highlighters -# ‾‾‾‾‾‾‾‾‾‾‾‾ - -add-highlighter shared/hbs regions -add-highlighter shared/hbs/comment region \{\{!-- --\}\} fill comment -add-highlighter shared/hbs/comment_alt region \{\{! \}\} fill comment -add-highlighter shared/hbs/block-expression region \{\{[#/] \}\} regions -add-highlighter shared/hbs/expression region \{\{ \}\} regions - -define-command -hidden add-mutual-highlighters -params 1 %~ - add-highlighter "shared/hbs/%arg{1}/code" default-region group - add-highlighter "shared/hbs/%arg{1}/single-quote" region '"' (? s \h+$ d } -} - -define-command -hidden hbs-indent-on-char %[ - evaluate-commands -draft -itersel %[ - # de-indent after closing a yielded block tag - try %[ execute-keys -draft s ^\h+\{\{/([\w-.]+(?:/[\w-.]+)*)\}\}$ {c\{\{#1,\{\{/1\}\} s \A|.\z 1 ] - ] -] - -define-command -hidden hbs-indent-on-new-line %{ - evaluate-commands -draft -itersel %{ - # copy '/' comment prefix and following white spaces - try %{ execute-keys -draft k s ^\h*\K/\h* y j p } - # preserve previous line indent - try %{ execute-keys -draft \; K } - # filter previous line - try %{ execute-keys -draft k : hbs-trim-indent } - # indent after lines beginning with : or - - try %{ execute-keys -draft k ^\h*[:-] j } - } -} - -# Initialization -# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ - -declare-option bool hbs_highlighters_enabled false - -define-command -hidden maybe-add-hbs-to-html %{ evaluate-commands %sh{ - if [ "$kak_opt_hbs_highlighters_enabled" == "false" ]; then - printf %s " - add-highlighter shared/html/hbs region '\{\{' '\}\}' ref hbs - add-highlighter shared/html/tag/hbs region '\{\{' '\}\}' ref hbs - set-option global hbs_highlighters_enabled true - " - fi -} } - -hook -group hbs-highlight global WinSetOption filetype=hbs %{ - maybe-add-hbs-to-html - add-highlighter window/hbs-file ref hbs-file - hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/hbs-file } -} - -hook global WinSetOption filetype=hbs %{ - hook window ModeChange insert:.* -group hbs-trim-indent hbs-trim-indent - hook window InsertChar \n -group hbs-indent hbs-indent-on-new-line - hook window InsertChar .* -group hbs-indent hbs-indent-on-char - hook window InsertChar '>' -group hbs-indent html-indent-on-greater-than - hook window InsertChar \n -group hbs-indent html-indent-on-new-line - - hook -once -always window WinSetOption filetype=.* %{ remove-hooks window hbs-.+ } -} diff --git a/rc/extra/i3.kak b/rc/extra/i3.kak deleted file mode 100644 index e661fcd7..00000000 --- a/rc/extra/i3.kak +++ /dev/null @@ -1,81 +0,0 @@ -hook global BufCreate .*(sway|i3)/config %{ - set buffer filetype i3 -} - -add-highlighter shared/i3 regions -add-highlighter shared/i3/code default-region group -add-highlighter shared/i3/double_string region %{"} %{"} group -add-highlighter shared/i3/single_string region %{'} %{'} group -add-highlighter shared/i3/exec region %{((?<=exec )|(?<=--no-startup-id ))(?!--no-startup-id)} "$" fill string -add-highlighter shared/i3/comment region "#" "$" fill comment - -add-highlighter shared/i3/double_string/ fill string -add-highlighter shared/i3/single_string/ fill string - -# Symbols -add-highlighter shared/i3/code/ regex "[+|→]" 0:operator -add-highlighter shared/i3/code/ regex "\$\w+" 0:variable - -# keys -add-highlighter shared/i3/code/ regex "\b(Shift|Control|Ctrl|Mod1|Mod2|Mod3|Mod4|Mod5|Mode_switch|Return|Escape|Print)\b" 0:value - -# keywords -add-highlighter shared/i3/code/ regex "\b(bind|bindcode|bindsym|assign|new_window|default_(floating_)?border|popup_during_fullscreen|font|floating_modifier|default_orientation|workspace_layout|for_window|focus_follows_mouse|bar|position|colors|output|tray_output|workspace_buttons|workspace_auto_back_and_forth|binding_mode_indicator|debuglog|floating_minimum_size|floating_maximum_size|force_focus_wrapping|force_xinerama|force_display_urgency_hint|hidden_state|modifier|new_float|shmlog|socket_path|verbose|mouse_warping|strip_workspace_numbers|focus_on_window_activation|no_focus|set|mode|set_from_resource)\b" 0:keyword -# function keywords -add-highlighter shared/i3/code/ regex "\b(exit|reload|restart|kill|fullscreen|global|layout|border|focus|move|open|split|append_layout|mark|unmark|resize|grow|shrink|show|nop|rename|title_format|sticky)\b" 0:function -add-highlighter shared/i3/code/ regex "\b(exec|exec_always|i3bar_command|status_command)\b" 0:function -# " these are not keywords but we add them for consistency -add-highlighter shared/i3/code/ regex "\b(no|false|inactive)\b" 0:value - -# values -add-highlighter shared/i3/code/ regex "\b(1pixel|default|stacked|tabbed|normal|none|tiling|stacking|floating|enable|disable|up|down|horizontal|vertical|auto|up|down|left|right|parent|child|px|or|ppt|leave_fullscreen|toggle|mode_toggle|scratchpad|width|height|top|bottom|client|hide|primary|yes|all|active|window|container|to|absolute|center|on|off|ms|smart|ignore|pixel|splith|splitv|output|true)\b" 0:value -add-highlighter shared/i3/code/ regex "\b(next|prev|next_on_output|prev_on_output|back_and_forth|current|number|none|vertical|horizontal|both|dock|hide|invisible|gaps|smart_gaps|smart_borders|inner|outer|current|all|plus|minus|no_gaps)\b" 0:value - -# double-dash arguments -add-highlighter shared/i3/code/ regex "--(release|border|whole-window|toggle|no-startup-id)" 0:attribute - -# color -add-highlighter shared/i3/double_string/ regex "#[0-9a-fA-F]{6}" 0:value -add-highlighter shared/i3/single_string/ regex "#[0-9a-fA-F]{6}" 0:value - -# attributes -add-highlighter shared/i3/code/ regex "client\.(background|statusline|background|separator|statusline)" 1:attribute -add-highlighter shared/i3/code/ regex "client\.(focused_inactive|focused|unfocused|urgent|inactive_workspace|urgent_workspace|focused_workspace|active_workspace|placeholder)" 1:attribute - -# Commands -# ‾‾‾‾‾‾‾‾ - -define-command -hidden i3-indent-on-new-line %~ - evaluate-commands -draft -itersel %= - # copy # comments prefix - try %{ execute-keys -draft k s ^\h*#\h* y jgh P } - # preserve previous line indent - try %{ execute-keys -draft \;K } - # indent after lines ending with { - try %[ execute-keys -draft k \{\h*$ j ] - # cleanup trailing white spaces on the previous line - try %{ execute-keys -draft k s \h+$ d } - = -~ - -define-command -hidden i3-indent-on-closing-curly-brace %[ - # align to opening curly brace when alone on a line - try %[ execute-keys -itersel -draft ^\h+\}$hms\A|.\z1 ] -] - -# Initialization -# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ - -hook -group i3-highlight global WinSetOption filetype=i3 %{ - add-highlighter window/i3 ref i3 - hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/i3 } -} - -hook global WinSetOption filetype=i3 %[ - # cleanup trailing whitespaces when exiting insert mode - hook window ModeChange insert:.* -group i3-trim-indent %{ try %{ execute-keys -draft s^\h+$d } } - hook window InsertChar \n -group i3-indent i3-indent-on-new-line - hook window InsertChar \} -group i3-indent i3-indent-on-closing-curly-brace - - hook -once -always window WinSetOption filetype=.* %{ remove-hooks window i3-.+ } -] diff --git a/rc/extra/iterm.kak b/rc/extra/iterm.kak deleted file mode 100644 index 7518d2d0..00000000 --- a/rc/extra/iterm.kak +++ /dev/null @@ -1,131 +0,0 @@ -# https://www.iterm2.com -# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ - -## The default behaviour for the `terminal` command is to open a vertical pane in -## an iTerm session if not in a tmux session. -hook global KakBegin .* %sh{ - if [ "$TERM_PROGRAM" = "iTerm.app" ] && [ -z "$TMUX" ]; then - echo " - alias global focus iterm-focus - alias global terminal iterm-terminal-vertical - " - fi -} - -define-command -hidden -params 2.. iterm-terminal-split-impl %{ - nop %sh{ - direction="$1" - shift - # join the arguments as one string for the shell execution (see x11.kak) - args=$( - for i in "$@"; do - if [ "$i" = '' ]; then - printf "'' " - else - printf %s "$i" | sed -e "s|'|'\\\\''|g; s|^|'|; s|$|' |" - fi - done - ) - # go through another round of escaping for osascript - # \ -> \\ - # " -> \" - escaped=$(printf %s "$args" | sed -e 's|\\|\\\\|g; s|"|\\"|g') - cmd="env PATH='${PATH}' TMPDIR='${TMPDIR}' $escaped" - osascript \ - -e "tell application \"iTerm\"" \ - -e " tell current session of current window" \ - -e " tell (split ${direction} with same profile command \"${cmd}\") to select" \ - -e " end tell" \ - -e "end tell" >/dev/null - } -} - -define-command iterm-terminal-vertical -params 1.. -shell-completion -docstring ' -iterm-terminal-vertical []: create a new terminal as an iterm pane -The current pane is split into two, left and right -The program passed as argument will be executed in the new terminal'\ -%{ - iterm-terminal-split-impl 'vertically' %arg{@} -} -define-command iterm-terminal-horizontal -params 1.. -shell-completion -docstring ' -iterm-terminal-horizontal []: create a new terminal as an iterm pane -The current pane is split into two, top and bottom -The program passed as argument will be executed in the new terminal'\ -%{ - iterm-terminal-split-impl 'horizontally' %arg{@} -} - -define-command iterm-terminal-tab -params 1.. -shell-completion -docstring ' -iterm-terminal-tab []: create a new terminal as an iterm tab -The program passed as argument will be executed in the new terminal'\ -%{ - nop %sh{ - # see above - args=$( - for i in "$@"; do - if [ "$i" = '' ]; then - printf "'' " - else - printf %s "$i" | sed -e "s|'|'\\\\''|g; s|^|'|; s|$|' |" - fi - done - ) - escaped=$(printf %s "$args" | sed -e 's|\\|\\\\|g; s|"|\\"|g') - cmd="env PATH='${PATH}' TMPDIR='${TMPDIR}' $escaped" - osascript \ - -e "tell application \"iTerm\"" \ - -e " tell current window" \ - -e " create tab with default profile command \"${cmd}\"" \ - -e " end tell" \ - -e "end tell" >/dev/null - } -} - -define-command iterm-terminal-window -params 1.. -shell-completion -docstring ' -iterm-terminal-window []: create a new terminal as an iterm window -The program passed as argument will be executed in the new terminal'\ -%{ - nop %sh{ - # see above - args=$( - for i in "$@"; do - if [ "$i" = '' ]; then - printf "'' " - else - printf %s "$i" | sed -e "s|'|'\\\\''|g; s|^|'|; s|$|' |" - fi - done - ) - escaped=$(printf %s "$args" | sed -e 's|\\|\\\\|g; s|"|\\"|g') - cmd="env PATH='${PATH}' TMPDIR='${TMPDIR}' $escaped" - osascript \ - -e "tell application \"iTerm\"" \ - -e " create window with default profile command \"${cmd}\"" \ - -e "end tell" >/dev/null - } -} - -define-command iterm-focus -params ..1 -client-completion -docstring ' -iterm-focus []: focus the given client -If no client is passed then the current one is used' \ -%{ - evaluate-commands %sh{ - if [ $# -eq 1 ]; then - printf %s\\n "evaluate-commands -client '$1' focus" - else - session="${kak_client_env_ITERM_SESSION_ID#*:}" - osascript \ - -e "tell application \"iTerm\" to repeat with aWin in windows" \ - -e " tell aWin to repeat with aTab in tabs" \ - -e " tell aTab to repeat with aSession in sessions" \ - -e " tell aSession" \ - -e " if (unique id = \"${session}\") then" \ - -e " select" \ - -e " end if" \ - -e " end tell" \ - -e " end repeat" \ - -e " end repeat" \ - -e "end repeat" - fi - } -} diff --git a/rc/extra/jedi.kak b/rc/extra/jedi.kak deleted file mode 100644 index a0fe9449..00000000 --- a/rc/extra/jedi.kak +++ /dev/null @@ -1,47 +0,0 @@ -declare-option -hidden str jedi_tmp_dir -declare-option -hidden completions jedi_completions -declare-option -docstring "colon separated list of path added to `python`'s $PYTHONPATH environment variable" \ - str jedi_python_path - -define-command jedi-complete -docstring "Complete the current selection" %{ - evaluate-commands %sh{ - dir=$(mktemp -d "${TMPDIR:-/tmp}"/kak-jedi.XXXXXXXX) - mkfifo ${dir}/fifo - printf %s\\n "set-option buffer jedi_tmp_dir ${dir}" - printf %s\\n "evaluate-commands -no-hooks write -sync ${dir}/buf" - } - evaluate-commands %sh{ - dir=${kak_opt_jedi_tmp_dir} - printf %s\\n "evaluate-commands -draft %{ edit! -fifo ${dir}/fifo *jedi-output* }" - ( - cd $(dirname ${kak_buffile}) - header="${kak_cursor_line}.${kak_cursor_column}@${kak_timestamp}" - - export PYTHONPATH="$kak_opt_jedi_python_path:$PYTHONPATH" - compl=$(python 2> "${dir}/fifo" <<-END - import jedi - script=jedi.Script(open('$dir/buf', 'r').read(), $kak_cursor_line, $kak_cursor_column - 1, '$kak_buffile') - print(' '.join(["'" + (str(c.name).replace("|", "\\|") + "|" + str(c.docstring()).replace("|", "\\|") + "|" + str(c.name).replace("|", "\\|")).replace("~", "~~").replace("'", "''") + "'" for c in script.completions()])) - END - ) - printf %s\\n "evaluate-commands -client ${kak_client} %~echo completed; set-option %{buffer=${kak_buffile}} jedi_completions ${header} ${compl}~" | kak -p ${kak_session} - rm -r ${dir} - ) > /dev/null 2>&1 < /dev/null & - } -} - -define-command jedi-enable-autocomplete -docstring "Add jedi completion candidates to the completer" %{ - set-option window completers option=jedi_completions %opt{completers} - hook window -group jedi-autocomplete InsertIdle .* %{ try %{ - execute-keys -draft \..\z - echo 'completing...' - jedi-complete - } } - alias window complete jedi-complete -} - -define-command jedi-disable-autocomplete -docstring "Disable jedi completion" %{ - set-option window completers %sh{ printf %s\\n "'${kak_opt_completers}'" | sed -e 's/option=jedi_completions://g' } - remove-hooks window jedi-autocomplete - unalias window complete jedi-complete -} diff --git a/rc/extra/just.kak b/rc/extra/just.kak deleted file mode 100644 index 201bfc3d..00000000 --- a/rc/extra/just.kak +++ /dev/null @@ -1,48 +0,0 @@ -# Detection -# ‾‾‾‾‾‾‾‾‾ - -hook global BufCreate .*/?[jJ]ustfile %{ - set-option buffer filetype justfile -} - -# Indentation -# ‾‾‾‾‾‾‾‾‾‾‾ - -define-command -hidden just-indent-on-new-line %{ - evaluate-commands -draft -itersel %{ - # preserve previous line indent - try %{ execute-keys -draft \;K } - # cleanup trailing white spaces on previous line - try %{ execute-keys -draft k s \h+$ "_d } - # copy '#' comment prefix and following white spaces - try %{ execute-keys -draft k s ^\h*//\h* y jgh P } - } -} - -# Highlighters -# ‾‾‾‾‾‾‾‾‾‾‾‾ - -add-highlighter shared/justfile regions -add-highlighter shared/justfile/content default-region group -add-highlighter shared/justfile/comment region '#' '$' fill comment -add-highlighter shared/justfile/double_string region '"' (? []: create a new terminal as a kitty window -The program passed as argument will be executed in the new terminal' \ -%{ - nop %sh{ - kitty @ new-window --no-response --window-type $kak_opt_kitty_window_type "$@" - } -} - -define-command kitty-terminal-tab -params 1.. -shell-completion -docstring ' -kitty-terminal-tab []: create a new terminal as kitty tab -The program passed as argument will be executed in the new terminal' \ -%{ - nop %sh{ - kitty @ new-window --no-response --new-tab "$@" - } -} - -define-command kitty-focus -params ..1 -client-completion -docstring ' -kitty-focus []: focus the given client -If no client is passed then the current one is used' \ -%{ - evaluate-commands %sh{ - if [ $# -eq 1 ]; then - printf "evaluate-commands -client '%s' focus" "$1" - else - kitty @ focus-tab --no-response -m=id:$kak_client_env_KITTY_WINDOW_ID - kitty @ focus-window --no-response -m=id:$kak_client_env_KITTY_WINDOW_ID - fi - } -} - -define-command kitty-repl -params .. -shell-completion -docstring ' -kitty-repl []: create a new window for repl interaction -All optional parameters are forwarded to the new window' \ -%{ - nop %sh{ - if [ $# -eq 0 ]; then - cmd="${SHELL:-/bin/sh}" - else - cmd="$*" - fi - kitty @ new-window --no-response --window-type $kak_opt_kitty_window_type --title kak_repl_window --cwd "$PWD" $cmd < /dev/null > /dev/null 2>&1 & - } -} - -define-command kitty-send-text -docstring "send the selected text to the repl window" %{ - nop %sh{ - kitty @ send-text -m=title:kak_repl_window "${kak_selection}" - } -} diff --git a/rc/extra/latex.kak b/rc/extra/latex.kak deleted file mode 100644 index acb5c1fc..00000000 --- a/rc/extra/latex.kak +++ /dev/null @@ -1,35 +0,0 @@ -# https://www.latex-project.org/ -# - -# Detection -# ‾‾‾‾‾‾‾‾‾ - -hook global BufCreate .*\.tex %{ - set-option buffer filetype latex -} - -# Highlighters -# ‾‾‾‾‾‾‾‾‾‾‾‾ - -add-highlighter shared/latex regions -add-highlighter shared/latex/content default-region group -add-highlighter shared/latex/comment region '(? %opt{modelines}k %opt{modelines}X \ - s^\S*?\s+?(vim?|kak(oune)?):\s?[^\n]+ - evaluate-commands -draft -itersel modeline-parse-impl - } } -} diff --git a/rc/extra/moon.kak b/rc/extra/moon.kak deleted file mode 100644 index a1d2ecb8..00000000 --- a/rc/extra/moon.kak +++ /dev/null @@ -1,107 +0,0 @@ -# http://moonscript.org -# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ - -# Detection -# ‾‾‾‾‾‾‾‾‾ - -hook global BufCreate .*[.](moon) %{ - set-option buffer filetype moon -} - -# Highlighters -# ‾‾‾‾‾‾‾‾‾‾‾‾ - -add-highlighter shared/moon regions -add-highlighter shared/moon/code default-region group -add-highlighter shared/moon/double_string region '"' (? - # remove trailing white spaces - try %{ execute-keys -draft s \h + $ d } - } -} - -define-command -hidden moon-indent-on-char %{ - evaluate-commands -draft -itersel %{ - # align _else_ statements to start - try %{ execute-keys -draft ^ \h * (else(if)?) $ ^ \h * (if|unless|when) s \A | \z ) } - # align _when_ to _switch_ then indent - try %{ execute-keys -draft ^ \h * (when) $ ^ \h * (switch) s \A | \z ) ) } - # align _catch_ and _finally_ to _try_ - try %{ execute-keys -draft ^ \h * (catch|finally) $ ^ \h * (try) s \A | \z ) } - } -} - -define-command -hidden moon-indent-on-new-line %{ - evaluate-commands -draft -itersel %{ - # copy -- comment prefix and following white spaces - try %{ execute-keys -draft k s ^ \h * \K -- \h * y gh j P } - # preserve previous line indent - try %{ execute-keys -draft \; K } - # filter previous line - try %{ execute-keys -draft k : moon-trim-indent } - # indent after start structure - try %{ execute-keys -draft k ^ \h * (class|else(if)?|for|if|switch|unless|when|while|with) \b | ([:=]|[-=]>) $ j } - # deindent after return statements - try %{ execute-keys -draft k ^ \h * (break|return) \b j } - } -} - -# Initialization -# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ - -hook -group moon-highlight global WinSetOption filetype=moon %{ - add-highlighter window/moon ref moon - hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/moon } -} - -hook global WinSetOption filetype=moon %{ - hook window ModeChange insert:.* -group moon-trim-indent moon-trim-indent - hook window InsertChar .* -group moon-indent moon-indent-on-char - hook window InsertChar \n -group moon-indent moon-indent-on-new-line - - alias window alt moon-alternative-file - - hook -once -always window WinSetOption filetype=.* %{ - remove-hooks window moon-.+ - unalias window alt moon-alternative-file - } -} diff --git a/rc/extra/nim.kak b/rc/extra/nim.kak deleted file mode 100644 index 901ce68a..00000000 --- a/rc/extra/nim.kak +++ /dev/null @@ -1,112 +0,0 @@ -# https://nim-lang.org/ -# - -# Detection -# ‾‾‾‾‾‾‾‾‾ - -hook global BufCreate .*\.nim(s|ble)? %{ - set-option buffer filetype nim -} - -# Highlighters -# ‾‾‾‾‾‾‾‾‾‾‾‾ - -add-highlighter shared/nim regions -add-highlighter shared/nim/code default-region group -add-highlighter shared/nim/triple_string region '([A-Za-z](_?\w)*)?"""' '"""(?!")' fill string -add-highlighter shared/nim/raw_string region [A-Za-z](_?[A-Za-z])*" (?@$~&%|!?^.:\\*]' - opnocol='[=+-/<>@$~&%|!?^.\\*]' - suffix="('[iIuU](8|16|32|64)|'[fF](32|64)?|'[dDuU]|[fF])?" - floatsuffix="('[fF](32|64)?|'[dD]|[fF])?" - hexdigit='[0-9a-fA-F]' - octdigit='[0-7]' - bindigit='[01]' - hexlit="0[xX]${hexdigit}(_?${hexdigit})*" - declit="\d(_?\d)*" - octlit="0o${octdigit}(_?${octdigit})*" - binlit="0[bB]${bindigit}(_?${bindigit})*" - intlit="\b(${declit}|${hexlit}|${octlit}|${binlit})${suffix}\b" - exponent="([eE][+-]?${declit})" - floatlit="\b${declit}(\.${declit}${exponent}?|${exponent})${floatsuffix}\b" - - keywords="addr as asm bind block break case cast concept const continue - converter defer discard distinct do elif else end enum except export - finally for from func if import include interface iterator let macro - method mixin nil out proc ptr raise ref return static template try type - unsafeAddr using var when while yield with without atomic generic" - operators="or xor and is isnot in notin of div mod shl shr not" - types="int int8 int16 int32 int64 uint uint8 uint16 uint32 uint64 float - float32 float64 bool char object seq array cstring string tuple varargs - typedesc pointer byte set typed untyped void auto" - values="false true" - - join() { sep=$2; set -- $1; IFS="$sep"; echo "$*"; } - - static_words="$(join "${keywords} ${types} ${operator} ${values}" ' ')" - - # Add the language's grammar to the static completion list - printf %s "hook global WinSetOption filetype=nim %{ - set-option window static_words ${static_words} - }" - - keywords="$(join "${keywords}" '|')" - operators="$(join "${operators}" '|')" - types="$(join "${types}" '|')" - values="$(join "${values}" '|')" - - # Highlight keywords - printf %s " - add-highlighter shared/nim/code/ regex ${opchars}+ 0:operator - add-highlighter shared/nim/code/ regex (? s ^\h*#\h* y jgh P } - # preserve previous line indent - try %{ exec -draft \; K } - # cleanup trailing whitespaces from previous line - try %{ exec -draft k s \h+$ d } - # indent after line ending with type, import, export, const, let, var, ':' or '=' - try %{ exec -draft k x (:|=|const|let|var|import|export|type)$ j } - } -} - -# Initialization -# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ - -hook -group nim-highlight global WinSetOption filetype=nim %{ - add-highlighter window/nim ref nim - hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/nim } -} - -hook global WinSetOption filetype=nim %{ - hook window InsertChar \n -group nim-indent nim-indent-on-new-line - # cleanup trailing whitespaces on current line insert end - hook window ModeChange insert:.* -group nim-trim-indent %{ try %{ exec -draft \; s ^\h+$ d } } - - hook -once -always window WinSetOption filetype=.* %{ remove-hooks window nim-.+ } -} diff --git a/rc/extra/php.kak b/rc/extra/php.kak deleted file mode 100644 index 4acfde85..00000000 --- a/rc/extra/php.kak +++ /dev/null @@ -1,90 +0,0 @@ -# Detection -# ‾‾‾‾‾‾‾‾‾ - -hook global BufCreate .*[.](php) %{ - set-option buffer filetype php -} - -# Highlighters -# ‾‾‾‾‾‾‾‾‾‾‾‾ - -add-highlighter shared/php regions -add-highlighter shared/php/code default-region group -add-highlighter shared/php/double_string region '"' (?' 0:meta - -add-highlighter shared/php/double_string/ fill string -add-highlighter shared/php/double_string/ regex (?\w+)* 0:variable -add-highlighter shared/php/double_string/ regex \{(?\w+)*\} 0:variable - -# Highlight doc comments -add-highlighter shared/php/doc_comment/ fill string -add-highlighter shared/php/doc_comment/ regex '`.*`' 0:module -add-highlighter shared/php/doc_comment/ regex '@\w+' 0:meta - -# Keywords are collected at -# http://php.net/manual/en/reserved.keywords.php -add-highlighter shared/php/code/ regex \b(__halt_compiler|abstract|and|array|as|break|callable|case|catch|class|clone|const|continue|declare|default|die|do|echo|else|elseif|empty|enddeclare|endfor|endforeach|endif|endswitch|endwhile|eval|exit|extends|final|finally|for|foreach|function|global|goto|if|implements|include|include_once|instanceof|insteadof|interface|isset|list|namespace|new|or|print|private|protected|public|require|require_once|return|static|switch|throw|trait|try|unset|use|var|while|xor|yield|__CLASS__|__DIR__|__FILE__|__FUNCTION__|__LINE__|__METHOD__|__NAMESPACE__|__TRAIT__)\b 0:keyword - -# Highlighter for html with php tags in it, i.e. the structure of conventional php files -add-highlighter shared/php-file regions -add-highlighter shared/php-file/html default-region ref html -add-highlighter shared/php-file/php region '<\?(php)?' '\?>' ref php - -# Commands -# ‾‾‾‾‾‾‾‾ - -define-command -hidden php-trim-indent %{ - # remove trailing white spaces - try %{ execute-keys -draft -itersel s \h+$ d } -} - -define-command -hidden php-indent-on-char %< - evaluate-commands -draft -itersel %< - # align closer token to its opener when alone on a line - try %/ execute-keys -draft ^\h+[]}]$ m s \A|.\z 1 / - > -> - -define-command -hidden php-indent-on-new-line %< - evaluate-commands -draft -itersel %< - # copy // comments prefix and following white spaces - try %{ execute-keys -draft k s ^\h*\K#\h* y gh j P } - # preserve previous line indent - try %{ execute-keys -draft \; K } - # filter previous line - try %{ execute-keys -draft k : php-trim-indent } - # indent after lines beginning / ending with opener token - try %_ execute-keys -draft k ^\h*[[{]|[[{]$ j _ - > -> - -# Initialization -# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ - -hook -group php-highlight global WinSetOption filetype=php %{ - add-highlighter window/php-file ref php-file - hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/php-file } -} - -hook global WinSetOption filetype=php %{ - hook window ModeChange insert:.* -group php-trim-indent php-trim-indent - hook window InsertChar .* -group php-indent php-indent-on-char - hook window InsertChar \n -group php-indent php-indent-on-new-line - - hook -once -always window WinSetOption filetype=.* %{ remove-hooks window php-.+ } -} diff --git a/rc/extra/pony.kak b/rc/extra/pony.kak deleted file mode 100644 index 713cc295..00000000 --- a/rc/extra/pony.kak +++ /dev/null @@ -1,92 +0,0 @@ -# http://ponylang.org -# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ - -# Detection -# ‾‾‾‾‾‾‾‾‾ - -hook global BufCreate .*[.](pony) %{ - set-option buffer filetype pony -} - -# Highlighters & Completion -# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ - -add-highlighter shared/pony regions -add-highlighter shared/pony/code default-region group -add-highlighter shared/pony/triple_string region '"""' '"""' fill string -add-highlighter shared/pony/double_string region '"' (?' 0:type - add-highlighter shared/pony/code/ regex '\b(${keywords})\b' 0:keyword - add-highlighter shared/pony/code/ regex ';' 0:keyword - add-highlighter shared/pony/code/ regex '^\s*|' 0:keyword - add-highlighter shared/pony/code/ regex '\b(${struct})\b' 0:variable - add-highlighter shared/pony/code/ regex '\b(${capabilities})\b(!|^)?' 1:builtin 2:builtin - " - - # Highlight types and attributes - printf %s " - add-highlighter shared/pony/code/ regex '@[\w_]+\b' 0:attribute - " -} - -# Commands -# ‾‾‾‾‾‾‾‾ - -define-command -hidden pony-indent-on-new-line %{ - evaluate-commands -draft -itersel %{ - # preserve previous line indent - try %{ execute-keys -draft K } - # cleanup trailing whitespaces from previous line - try %{ execute-keys -draft k s \h+$ d } - # copy '//' comment prefix and following white spaces - # try %{ execute-keys -draft k x s ^\h*//\h* y jgh P } - # indent after line ending with : - try %{ execute-keys -draft k x (do|try|then|else|:|=>)$ j } - # else, end are always de-indented - try %{ execute-keys -draft k x (else|end):$ k x s ^\h* y j x ^" J } - } -} - -# Initialization -# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ - -hook -group pony-highlight global WinSetOption filetype=pony %{ - add-highlighter window/pony ref pony - hook -once -always window WinSetOption filetype=.* %{ remove-highlighter pony } -} - -hook global WinSetOption filetype=pony %{ - hook window InsertChar \n -group pony-indent pony-indent-on-new-line - # cleanup trailing whitespaces on current line insert end - hook window ModeChange insert:.* -group pony-trim-indent %{ try %{ execute-keys -draft \; s ^\h+$ d } } - - hook -once -always window WinSetOption filetype=.* %{ remove-hooks window pony-.+ } -} diff --git a/rc/extra/protobuf.kak b/rc/extra/protobuf.kak deleted file mode 100644 index 2ef10480..00000000 --- a/rc/extra/protobuf.kak +++ /dev/null @@ -1,85 +0,0 @@ -# https://developers.google.com/protocol-buffers/ - -# Detection -# ‾‾‾‾‾‾‾‾‾ - -hook global BufCreate .*\.proto$ %{ - set-option buffer filetype protobuf -} - -# Highlighters -# ‾‾‾‾‾‾‾‾‾‾‾‾ - -add-highlighter shared/protobuf regions -add-highlighter shared/protobuf/code default-region group -add-highlighter shared/protobuf/double_string region '"' (? } - # indent after lines ending with { - try %[ execute-keys -draft k \{\h*$ j ] - # cleanup trailing white spaces on the previous line - try %{ execute-keys -draft k s \h+$ d } - # copy // comments prefix - try %{ execute-keys -draft \;k s ^\h*\K/{2,}(\h*(?=\S))? yP } - ] -~ - -define-command -hidden protobuf-indent-on-opening-curly-brace %[ - # align indent with opening paren when { is entered on a new line after the closing paren - try %[ execute-keys -draft -itersel h)M \A\(.*\)\h*\n\h*\{\z s \A|.\z 1 ] -] - -define-command -hidden protobuf-indent-on-closing-curly-brace %[ - # align to opening curly brace when alone on a line - try %[ execute-keys -itersel -draft ^\h+\}$hms\A|.\z1 ] -] - -# Initialization -# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ - -hook -group protobuf-highlight global WinSetOption filetype=protobuf %{ - add-highlighter window/protobuf ref protobuf - hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/protobuf } -} - -hook global WinSetOption filetype=protobuf %[ - hook -group protobuf-indent window InsertChar \n protobuf-indent-on-newline - hook -group protobuf-indent window InsertChar \{ protobuf-indent-on-opening-curly-brace - hook -group protobuf-indent window InsertChar \} protobuf-indent-on-closing-curly-brace - - hook -once -always window WinSetOption filetype=.* %{ remove-hooks window protobuf-.+ } -] diff --git a/rc/extra/pug.kak b/rc/extra/pug.kak deleted file mode 100644 index 13aa839f..00000000 --- a/rc/extra/pug.kak +++ /dev/null @@ -1,74 +0,0 @@ -# Note: jade is changing its name to pug (https://github.com/pugjs/pug/issues/2184) -# This appears to be a work in progress -- the pug-lang domain is parked, while -# the jade-lang one is active. This highlighter will recognize .pug and .jade extensions, - -# http://jade-lang.com (will be http://pug-lang.com) -# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ - -# Detection -# ‾‾‾‾‾‾‾‾‾ - -hook global BufCreate .*[.](pug|jade) %{ - set-option buffer filetype pug -} - -# Highlighters -# ‾‾‾‾‾‾‾‾‾‾‾‾ - -add-highlighter shared/pug regions -add-highlighter shared/pug/code default-region group -add-highlighter shared/pug/text region ^\h*\|\s $ regex \h*(\|) 1:meta -add-highlighter shared/pug/text2 region '^\h*([A-Za-z][A-Za-z0-9_-]*)?(#[A-Za-z][A-Za-z0-9_-]*)?((?:\.[A-Za-z][A-Za-z0-9_-]*)*)?(? s \h+$ d } -} - -define-command -hidden pug-indent-on-new-line %{ - evaluate-commands -draft -itersel %{ - # preserve previous line indent - try %{ execute-keys -draft \; K } - # filter previous line - try %{ execute-keys -draft k : pug-trim-indent } - # copy '//', '|', '-' or '(!)=' prefix and following whitespace - try %{ execute-keys -draft k s ^\h*\K[/|!=-]{1,2}\h* y gh j P } - # indent unless we copied something above - try %{ execute-keys -draft b s \S g l } - } -} - -# Initialization -# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ - -hook -group pug-highlight global WinSetOption filetype=pug %{ - add-highlighter window/pug ref pug - hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/pug } -} - -hook global WinSetOption filetype=pug %{ - hook window ModeChange insert:.* -group pug-trim-indent pug-trim-indent - hook window InsertChar \n -group pug-indent pug-indent-on-new-line - - hook -once -always window WinSetOption filetype=.* %{ remove-hooks window pug-.+ } -} diff --git a/rc/extra/racer.kak b/rc/extra/racer.kak deleted file mode 100644 index 2371c597..00000000 --- a/rc/extra/racer.kak +++ /dev/null @@ -1,153 +0,0 @@ -declare-option -hidden str racer_tmp_dir -declare-option -hidden completions racer_completions - -define-command racer-complete -docstring "Complete the current selection with racer" %{ - evaluate-commands %sh{ - dir=$(mktemp -d "${TMPDIR:-/tmp}"/kak-racer.XXXXXXXX) - printf %s\\n "set-option buffer racer_tmp_dir ${dir}" - printf %s\\n "evaluate-commands -no-hooks %{ write ${dir}/buf }" - } - evaluate-commands %sh{ - dir=${kak_opt_racer_tmp_dir} - ( - cursor="${kak_cursor_line} $((${kak_cursor_column} - 1))" - racer_data=$(racer --interface tab-text complete-with-snippet ${cursor} ${kak_buffile} ${dir}/buf) - compl=$(printf %s\\n "${racer_data}" | awk ' - BEGIN { FS = "\t"; ORS = ":" } - /^PREFIX/ { - column = ENVIRON["kak_cursor_column"] + $2 - $3 - print ENVIRON["kak_cursor_line"] "." column "@@" ENVIRON["kak_timestamp"] - } - /^MATCH/ { - word = $2 - type = $7 - desc = substr($9, 2, length($9) - 2) - gsub(/\|/, "\\|", desc) - gsub(/\\n/, "\n", desc) - menu = $8 - sub(/^pub /, "", menu) - gsub(/\|/, "\\|", menu) - if (type == "Function") { - sub(word, "{default+F}" word "{default+d}", menu) - gsub(/^fn /, " fn ", menu) # The extra spaces are there to vertically align - # the type of element on the menu to make it easy - # to read - menu = "{default+d}" menu - } else if (type == "Enum") { - menu = substr(menu, 0, length(menu) - 2) - sub(word, "{default+F}" word "{default+d}", menu) - gsub(/^enum /, " enum ", menu) # The extra spaces are there to vertically align - # the type of element on the menu to make it easy - # to read - } else if (type == "Module") { - if (length(menu) > 30) { # The "menu" bit (as returned by racer), - # contains the path to the source file - # containing the module... - - menu = substr(menu, length(menu) - 29, 30) # ... trimming it, so the completion menu - # doesn''t get distorted if it''s too long - } - menu = " mod {default+F}" word "{default+d} .." menu # The extra spaces are there to vertically align - # the type of element on the menu to make it easy - # to read - } else if (type == "Trait") { - sub(word, "{default+F}" word "{default+d}", menu) - gsub(/^trait /, " trait ", menu) # The extra spaces are there to vertically align - # the type of element on the menu to make it easy - # to read - } else if (type == "Type") { - sub(word, "{default+F}" word "{default+d}", menu) - gsub(/^type /, " type ", menu) # The extra spaces are there to vertically align - # the type of element on the menu to make it easy - # to read - } else if (type == "Struct") { - sub(word, "{default+F}" word "{default+d}", menu) # Struct doesn''t have extra spaces because it''s - # the longest keyword - } else { - menu = "{default+F}" word "{default+d} " menu - } - candidate = word "|" desc "|" menu - gsub(/:/, "\\:", candidate) - print candidate - }' - ) - printf %s\\n "evaluate-commands -client '${kak_client}' %{ - set-option buffer=${kak_bufname} racer_completions %@${compl%?}@ - }" | kak -p ${kak_session} - rm -r ${dir} - ) > /dev/null 2>&1 < /dev/null & - } -} - -define-command racer-enable-autocomplete -docstring "Add racer completion candidates to the completer" %{ - set-option window completers option=racer_completions %opt{completers} - hook window -group racer-autocomplete InsertIdle .* %{ try %{ - execute-keys -draft ([\w\.]|::).\z - racer-complete - } } - alias window complete racer-complete -} - -define-command racer-disable-autocomplete -docstring "Disable racer completion" %{ - evaluate-commands %sh{ printf "set-option window completers %s\n" $(printf %s "${kak_opt_completers}" | sed -e "s/'option=racer_completions'//g") } - remove-hooks window racer-autocomplete - unalias window complete racer-complete -} - -define-command racer-go-definition -docstring "Jump to where the rust identifier below the cursor is defined" %{ - evaluate-commands %sh{ - dir=$(mktemp -d "${TMPDIR:-/tmp}"/kak-racer.XXXXXXXX) - printf %s\\n "set-option buffer racer_tmp_dir ${dir}" - printf %s\\n "evaluate-commands -no-hooks %{ write ${dir}/buf }" - } - evaluate-commands %sh{ - dir=${kak_opt_racer_tmp_dir} - cursor="${kak_cursor_line} $((${kak_cursor_column} - 1))" - racer_data=$(racer --interface tab-text find-definition ${cursor} "${kak_buffile}" "${dir}/buf" | head -n 1) - - racer_match=$(printf %s\\n "$racer_data" | cut -f1 ) - if [ "$racer_match" = "MATCH" ]; then - racer_line=$(printf %s\\n "$racer_data" | cut -f3 ) - racer_column=$(printf %s\\n "$racer_data" | cut -f4 ) - racer_file=$(printf %s\\n "$racer_data" | cut -f5 ) - printf %s\\n "edit -existing '$racer_file' $racer_line $racer_column" - case ${racer_file} in - "${RUST_SRC_PATH}"* | "${CARGO_HOME:-$HOME/.cargo}"/registry/src/*) - printf %s\\n "set-option buffer readonly true";; - esac - else - printf %s\\n "echo -debug 'racer could not find a definition'" - fi - } -} - -define-command racer-show-doc -docstring "Show the documentation about the rust identifier below the cursor" %{ - evaluate-commands %sh{ - dir=$(mktemp -d "${TMPDIR:-/tmp}"/kak-racer.XXXXXXXX) - printf %s\\n "set-option buffer racer_tmp_dir ${dir}" - printf %s\\n "evaluate-commands -no-hooks %{ write ${dir}/buf }" - } - evaluate-commands %sh{ - dir=${kak_opt_racer_tmp_dir} - cursor="${kak_cursor_line} ${kak_cursor_column}" - racer_data=$(racer --interface tab-text complete-with-snippet ${cursor} "${kak_buffile}" "${dir}/buf" | sed -n 2p ) - racer_match=$(printf %s\\n "$racer_data" | cut -f1) - if [ "$racer_match" = "MATCH" ]; then - racer_doc=$( - printf %s\\n "$racer_data" | - cut -f9 | - sed -e ' - - # Remove leading and trailing quotes - s/^"\(.*\)"$/\1/g - - # Escape all @ so that it can be properly used in the string expansion - s/@/\\@/g - - ') - printf "info %%@$racer_doc@" - else - printf %s\\n "echo -debug 'racer could not find a definition'" - fi - } -} diff --git a/rc/extra/ragel.kak b/rc/extra/ragel.kak deleted file mode 100644 index b6e8dd4c..00000000 --- a/rc/extra/ragel.kak +++ /dev/null @@ -1,70 +0,0 @@ -# http://complang.org/ragel -# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ - -# ragel.kak does not try to detect host language. - -# Detection -# ‾‾‾‾‾‾‾‾‾ - -hook global BufCreate .*[.](ragel|rl) %{ - set-option buffer filetype ragel -} - -# Highlighters -# ‾‾‾‾‾‾‾‾‾‾‾‾ - -add-highlighter shared/ragel regions -add-highlighter shared/ragel/code default-region group -add-highlighter shared/ragel/double_string region '"' (?' 0:variable -add-highlighter shared/ragel/code/ regex :=|=>|->|:>|:>>|<: 0:operator -add-highlighter shared/ragel/code/ regex \b(action|alnum|alpha|any|ascii|case|cntrl|contained|context|data|digit|empty|eof|err|error|exec|export|exports|extend|fblen|fbreak|fbuf|fc|fcall|fcurs|fentry|fexec|fgoto|fhold|first_final|fnext|fpc|fret|from|fstack|ftargs|graph|import|include|init|inwhen|lerr|lower|machine|nocs|noend|noerror|nofinal|noprefix|outwhen|postpop|prepush|print|punct|range|space|start|to|upper|when|write|xdigit|zlen)\b 0:keyword - -# Commands -# ‾‾‾‾‾‾‾‾ - -define-command -hidden ragel-trim-indent %{ - # remove trailing white spaces - try %{ execute-keys -draft -itersel s \h+$ d } -} - -define-command -hidden ragel-indent-on-char %< - evaluate-commands -draft -itersel %< - # align closer token to its opener when alone on a line - try %< execute-keys -draft ^\h+[]})]$ m s \A|.\z 1 > - try %< execute-keys -draft ^\h+ [*]$ [*]$ s \A|.\z 1 > - > -> - -define-command -hidden ragel-indent-on-new-line %< - evaluate-commands -draft -itersel %< - # copy _#_ comment prefix and following white spaces - try %{ execute-keys -draft k s ^\h*\K#\h* y gh j P } - # preserve previous line indent - try %{ execute-keys -draft \; K } - # filter previous line - try %{ execute-keys -draft k : ragel-trim-indent } - # indent after lines ending with opener token - try %< execute-keys -draft k [[{(*]$ j > - > -> - -# Initialization -# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ - -hook -group ragel-highlight global WinSetOption filetype=ragel %{ - add-highlighter window/ragel ref ragel - hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/ragel } -} - -hook global WinSetOption filetype=ragel %{ - hook window ModeChange insert:.* -group ragel-trim-indent ragel-trim-indent - hook window InsertChar .* -group ragel-indent ragel-indent-on-char - hook window InsertChar \n -group ragel-indent ragel-indent-on-new-line - - hook -once -always window WinSetOption filetype=.* %{ remove-hooks window ragel-.+ } -} diff --git a/rc/extra/ranger.kak b/rc/extra/ranger.kak deleted file mode 100644 index 4bb49a7b..00000000 --- a/rc/extra/ranger.kak +++ /dev/null @@ -1,59 +0,0 @@ -# http://ranger.nongnu.org -# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ - -define-command ranger-open-on-edit-directory \ - -docstring 'Start the ranger file system explorer when trying to edit a directory' %{ - hook global RuntimeError "\d+:\d+: '\w+' (.*): is a directory" %{ evaluate-commands %sh{ - directory=$kak_hook_param_capture_1 - echo ranger $directory - }} -} - -define-command \ - -params .. -file-completion \ - -docstring %{ranger []: open the file system explorer to select buffers to open - All the optional arguments are forwarded to the ranger utility} \ - ranger %{ evaluate-commands %sh{ - if [ -n "${TMUX}" ]; then - tmux split-window -h \ - ranger $@ --cmd " \ - map eval \ - fm.execute_console('shell \ - echo evaluate-commands -client ' + ranger.ext.shell_escape.shell_escape('$kak_client') + ' edit {file} | \ - kak -p '.format(file=fm.thisfile.path) + ranger.ext.shell_escape.shell_escape('$kak_session') + '; \ - tmux select-pane -t $kak_client_env_TMUX_PANE') \ - if fm.thisfile.is_file else fm.execute_console('move right=1')" - - elif [ -n "${STY}" ]; then - - script="/tmp/kak-ranger-${kak_client}-${kak_session}.sh" - selections="/tmp/kak-ranger-${kak_client}-${kak_session}.txt" - cat > "$script" << EOF -#! /usr/bin/env sh -cd "$PWD" -ranger --choosefiles="$selections" $@ -while read -r f; do - printf %s "evaluate-commands -client '${kak_client}' edit '\"\$f\"'" | kak -p '${kak_session}' -done < "$selections" -screen -X remove -rm -f "$selections" "$script" -EOF - - tty="$(ps -o tty ${kak_client_pid} | tail -n 1)" - screen -X eval \ - 'split -h' \ - 'focus down' \ - "screen sh '$script'" \ - < "/dev/$tty" - - elif [ -n "$WINDOWID" ]; then - setsid $kak_opt_termcmd " \ - ranger $@ --cmd "'"'" \ - map eval \ - fm.execute_console('shell \ - echo evaluate-commands -client ' + ranger.ext.shell_escape.shell_escape('$kak_client') + ' edit {file} | \ - kak -p '.format(file=fm.thisfile.path) + ranger.ext.shell_escape.shell_escape('$kak_session') + '; \ - xdotool windowactivate $kak_client_env_WINDOWID') \ - if fm.thisfile.is_file else fm.execute_console('move right=1')"'"' < /dev/null > /dev/null 2>&1 & - fi -}} diff --git a/rc/extra/sass.kak b/rc/extra/sass.kak deleted file mode 100644 index d23a7b81..00000000 --- a/rc/extra/sass.kak +++ /dev/null @@ -1,62 +0,0 @@ -# http://sass-lang.com -# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ - -# Detection -# ‾‾‾‾‾‾‾‾‾ - -hook global BufCreate .*[.](sass) %{ - set-option buffer filetype sass -} - -# Highlighters -# ‾‾‾‾‾‾‾‾‾‾‾‾ - -add-highlighter shared/sass regions -add-highlighter shared/sass/code default-region group -add-highlighter shared/sass/single_string region '"' (? s \h+$ d } -} - -define-command -hidden sass-indent-on-new-line %{ - evaluate-commands -draft -itersel %{ - # copy '/' comment prefix and following white spaces - try %{ execute-keys -draft k s ^\h*\K/\h* y gh j P } - # preserve previous line indent - try %{ execute-keys -draft \; K } - # filter previous line - try %{ execute-keys -draft k : sass-trim-indent } - # avoid indent after properties and comments - try %{ execute-keys -draft k [:/] j } - } -} - -# Initialization -# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ - -hook -group sass-highlight global WinSetOption filetype=sass %{ - add-highlighter window/sass ref sass - hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/sass } -} - -hook global WinSetOption filetype=sass %{ - hook window ModeChange insert:.* -group sass-trim-indent sass-trim-indent - hook window InsertChar \n -group sass-indent sass-indent-on-new-line - set-option buffer extra_word_chars '_' '-' - - hook -once -always window WinSetOption filetype=.* %{ remove-hooks window sass-.+ } -} diff --git a/rc/extra/scheme.kak b/rc/extra/scheme.kak deleted file mode 100644 index ec86638b..00000000 --- a/rc/extra/scheme.kak +++ /dev/null @@ -1,133 +0,0 @@ -# http://www.scheme-reports.org -# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ - -# require lisp.kak - -# Detection -# ‾‾‾‾‾‾‾‾‾ - -hook global BufCreate (.*/)?(.*\.(scm|ss|sld)) %{ - set-option buffer filetype scheme -} - -# Highlighters -# ‾‾‾‾‾‾‾‾‾‾‾‾ - -add-highlighter shared/scheme regions -add-highlighter shared/scheme/code default-region group - -add-highlighter shared/scheme/string region '"' (? > >=", operators); - - # Procedures that create a base type and their predicates (for easier type checking) - split("list vector bytevector cons string boolean? list? pair? "\ - "vector? bytevector? string? char? complex? eof-object? input-port? "\ - "null? number? output-port? procedure? symbol?", types); - - # R5RS available procedures - split("abs acos angle append apply asin assoc assq assv atan "\ - "caaaar caaadr caaar caadar caaddr caadr "\ - "caar cadaar cadadr cadar caddar cadddr caddr cadr "\ - "call-with-current-continuation call-with-input-file "\ - "call-with-output-file call-with-values car cdaaar cdaadr cdaar "\ - "cdadar cdaddr cdadr cdar cddaar cddadr cddar cdddar cddddr cdddr "\ - "cddr cdr ceiling char->integer char-alphabetic? char-ci<=? "\ - "char-ci=? char-ci>? char-downcase "\ - "char-lower-case? char-numeric? char-ready? char-upcase "\ - "char-upper-case? char-whitespace? char<=? char=? char>? close-input-port close-output-port cons cos "\ - "current-input-port current-output-port denominator display "\ - "dynamic-wind else eq? equal? eqv? eval even? exact->inexact "\ - "exact? exp expt floor for-each force gcd imag-part inexact->exact "\ - "inexact? integer->char integer? interaction-environment lcm "\ - "length list list->string list->vector list-ref list-tail load log "\ - "magnitude make-polar make-rectangular make-string make-vector "\ - "map max member memq memv min modulo negative? newline not "\ - "null-environment number->string numerator odd? open-input-file "\ - "open-output-file or peek-char positive? quasiquote quote quotient "\ - "rational? rationalize read read-char real-part real? remainder "\ - "reverse round scheme-report-environment set-car! set-cdr! sin "\ - "sqrt string->list string->number string->symbol string-append "\ - "string-ci<=? string-ci=? "\ - "string-ci>? string-copy string-fill! string-length string-ref "\ - "string-set! string<=? string=? string>? "\ - "substring symbol->string tan truncate values vector "\ - "vector->list vector-fill! vector-length vector-ref vector-set! "\ - "with-input-from-file with-output-to-file write write-char zero?", - builtins); - - non_word_chars="[\\s\\(\\)\\[\\]\\{\\};\\|]"; - - normal_identifiers="-!$%&\\*\\+\\./:<=>\\?\\^_~a-zA-Z0-9"; - identifier_chars="[" normal_identifiers "][" normal_identifiers ",#]*"; - } - function add_highlighter(regex, highlight) { - printf("add-highlighter shared/scheme/code/ regex \"%s\" %s\n", regex, highlight); - } - function quoted_join(words, quoted, first) { - first=1 - for (i in words) { - if (!first) { quoted=quoted "|"; } - quoted=quoted "\\Q" words[i] "\\E"; - first=0; - } - return quoted; - } - function add_word_highlighter(words, face, regex) { - regex = non_word_chars "+(" quoted_join(words) ")" non_word_chars - add_highlighter(regex, "1:" face) - } - function print_words(words) { - for (i in words) { printf(" %s", words[i]); } - } - - BEGIN { - printf("hook global WinSetOption filetype=scheme %%{ set-option window static_words "); - print_words(keywords); print_words(meta); print_words(operators); print_words(builtins); - printf(" }\n") - - add_word_highlighter(keywords, "keyword"); - add_word_highlighter(meta, "meta"); - add_word_highlighter(operators, "operator"); - add_word_highlighter(builtins, "builtin"); - add_word_highlighter(types, "type"); - add_highlighter(non_word_chars "+('" identifier_chars ")", "1:attribute"); - add_highlighter("\\(define\\W+\\((" identifier_chars ")", "1:function"); - add_highlighter("\\(define\\W+(" identifier_chars ")\\W+\\(lambda", "1:function"); - } -EOF -} - -# Initialization -# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ - -hook -group scheme-highlight global WinSetOption filetype=scheme %{ - add-highlighter window/scheme ref scheme - hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/scheme } -} - - -hook global WinSetOption filetype=scheme %{ - set-option buffer extra_word_chars '_' '-' '!' '%' '?' '<' '>' '=' - hook window InsertEnd .* -group scheme-trim-indent lisp-trim-indent - hook window InsertChar \n -group scheme-indent lisp-indent-on-new-line - - hook -once -always window WinSetOption filetype=.* %{ remove-hooks window scheme-.+ } -} diff --git a/rc/extra/scss.kak b/rc/extra/scss.kak deleted file mode 100644 index bb720db5..00000000 --- a/rc/extra/scss.kak +++ /dev/null @@ -1,45 +0,0 @@ -# http://sass-lang.com -# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ - -# require css.kak - -# Detection -# ‾‾‾‾‾‾‾‾‾ - -hook global BufCreate .*[.](scss) %{ - set-option buffer filetype scss -} - -# Highlighters -# ‾‾‾‾‾‾‾‾‾‾‾‾ - -add-highlighter shared/scss regions -add-highlighter shared/scss/core default-region group -add-highlighter shared/scss/comment region // $ fill comment - -add-highlighter shared/scss/core/ ref css -add-highlighter shared/scss/core/ regex @[A-Za-z][A-Za-z0-9_-]* 0:meta - -# Commands -# ‾‾‾‾‾‾‾‾ - -define-command -hidden scss-trim-indent css-trim-indent -define-command -hidden scss-indent-on-new-line css-indent-on-new-line -define-command -hidden scss-indent-on-closing-curly-brace css-indent-on-closing-curly-brace - -# Initialization -# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ - -hook -group scss-highlight global WinSetOption filetype=scss %{ - add-highlighter window/scss ref scss - hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/scss } -} - -hook global WinSetOption filetype=scss %[ - hook window ModeChange insert:.* -group scss-trim-indent scss-trim-indent - hook window InsertChar \n -group scss-indent scss-indent-on-new-line - hook window InsertChar \} -group scss-indent scss-indent-on-closing-curly-brace - set-option buffer extra_word_chars '_' '-' - - hook -once -always window WinSetOption filetype=.* %{ remove-hooks window scss-.+ } -] diff --git a/rc/extra/systemd.kak b/rc/extra/systemd.kak deleted file mode 100644 index 3810d005..00000000 --- a/rc/extra/systemd.kak +++ /dev/null @@ -1,14 +0,0 @@ -# https://freedesktop.org/wiki/Software/systemd/ -# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ - -# Detection -# ‾‾‾‾‾‾‾‾‾ - -hook global BufCreate .*/systemd/.+\.(automount|conf|link|mount|network|path|service|slice|socket|target|timer) %{ - set-option buffer filetype ini - - # NOTE: INI files define the commenting character to be `;`, which won't work in `systemd` files - hook -once buffer BufSetOption comment_line=.+ %{ - set-option buffer comment_line "#" - } -} diff --git a/rc/extra/taskpaper.kak b/rc/extra/taskpaper.kak deleted file mode 100644 index dca5de1e..00000000 --- a/rc/extra/taskpaper.kak +++ /dev/null @@ -1,47 +0,0 @@ -# https://www.taskpaper.com -# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ - -# Detection -# ‾‾‾‾‾‾‾‾‾ - -hook global BufCreate .*\.taskpaper %{ - set-option buffer filetype taskpaper -} - -# Highlighters -# ‾‾‾‾‾‾‾‾‾‾‾‾ - -add-highlighter shared/taskpaper group - -add-highlighter shared/taskpaper/ regex ^\h*([^:\n]+):\h*\n 1:header -add-highlighter shared/taskpaper/ regex \h@\w+(?:\(([^)]*)\))? 0:variable 1:value -add-highlighter shared/taskpaper/ regex ^\h*([^-:\n]+)\n 1:+i -add-highlighter shared/taskpaper/ regex ^\h*-\h+[^\n]*@done[^\n]* 0:+d -add-highlighter shared/taskpaper/ regex (([a-z]+://\S+)|((mailto:)[\w+-]+@\S+)) 0:link - -# Commands -# ‾‾‾‾‾‾‾‾ - -define-command -hidden taskpaper-indent-on-new-line %{ - evaluate-commands -draft -itersel %{ - # preserve previous line indent - try %{ execute-keys -draft \;K } - ## If the line above is a project indent with a tab - try %{ execute-keys -draft Z k ^\h*([^:\n]+): z i } - # cleanup trailing white spaces on previous line - try %{ execute-keys -draft k s \h+$ d } - } -} - -# Initialization -# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ - -hook -group taskpaper-highlight global WinSetOption filetype=taskpaper %{ - add-highlighter window/taskpaper ref taskpaper - hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/taskpaper } -} - -hook global WinSetOption filetype=taskpaper %{ - hook window InsertChar \n -group taskpaper-indent taskpaper-indent-on-new-line - hook -once -always window WinSetOption filetype=.* %{ remove-hooks window taskpaper-.+ } -} diff --git a/rc/extra/tmux-repl.kak b/rc/extra/tmux-repl.kak deleted file mode 100644 index a176f5f5..00000000 --- a/rc/extra/tmux-repl.kak +++ /dev/null @@ -1,67 +0,0 @@ -# http://tmux.github.io/ -# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ - -declare-option -docstring "tmux pane id in which the REPL is running" str tmux_repl_id - -hook global KakBegin .* %sh{ - if [ -n "$TMUX" ]; then - VERSION_TMUX=$(tmux -V | cut -d' ' -f2) - VERSION_TMUX=${VERSION_TMUX%%.*} - - if [ "${VERSION_TMUX}" = "master" ] \ - || [ "${VERSION_TMUX}" -ge 2 ]; then - echo " - alias global repl tmux-repl-horizontal - alias global send-text tmux-send-text - " - else - echo " - alias global repl tmux-repl-disabled - alias global send-text tmux-repl-disabled - " - fi - fi -} - -define-command -hidden -params 1..2 tmux-repl-impl %{ - evaluate-commands %sh{ - if [ -z "$TMUX" ]; then - echo "echo -markup '{Error}This command is only available in a tmux session'" - exit - fi - tmux_args="$1" - shift - tmux_cmd="$@" - tmux $tmux_args $tmux_cmd - printf "set-option global tmux_repl_id '%s'" $(tmux display-message -p '#{session_id}:#{window_id}.#{pane_id}') - } -} - -define-command tmux-repl-vertical -params 0..1 -command-completion -docstring "Create a new vertical pane for repl interaction" %{ - tmux-repl-impl 'split-window -v' %arg{@} -} - -define-command tmux-repl-horizontal -params 0..1 -command-completion -docstring "Create a new horizontal pane for repl interaction" %{ - tmux-repl-impl 'split-window -h' %arg{@} -} - -define-command tmux-repl-window -params 0..1 -command-completion -docstring "Create a new window for repl interaction" %{ - tmux-repl-impl 'new-window' %arg{@} -} - -define-command -hidden tmux-send-text -params 0..1 -docstring "tmux-send-text [text]: Send text(append new line) to the REPL pane. - If no text is passed, then the selection is used" %{ - nop %sh{ - if [ $# -eq 0 ]; then - tmux set-buffer -b kak_selection "${kak_selection}" - else - tmux set-buffer -b kak_selection "$1" - fi - tmux paste-buffer -b kak_selection -t "$kak_opt_tmux_repl_id" - } -} - -define-command -hidden tmux-repl-disabled %{ evaluate-commands %sh{ - VERSION_TMUX=$(tmux -V) - printf %s "echo -markup %{{Error}The version of tmux is too old: got ${VERSION_TMUX}, expected >= 2.x}" -} } diff --git a/rc/extra/toml.kak b/rc/extra/toml.kak deleted file mode 100644 index f95fbb9d..00000000 --- a/rc/extra/toml.kak +++ /dev/null @@ -1,63 +0,0 @@ -# https://github.com/toml-lang/toml/tree/v0.4.0 -# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ - -# Detection -# ‾‾‾‾‾‾‾‾‾ - -hook global BufCreate .*\.(toml) %{ - set-option buffer filetype toml -} - -# Highlighters -# ‾‾‾‾‾‾‾‾‾‾‾‾ - -add-highlighter shared/toml regions -add-highlighter shared/toml/code default-region group -add-highlighter shared/toml/comment region '#' $ fill comment -add-highlighter shared/toml/string1 region '"""' (? s \h+$ d } -} - -define-command -hidden toml-indent-on-new-line %{ - evaluate-commands -draft -itersel %{ - # copy comment prefix and following white spaces - try %{ execute-keys -draft k s ^\h*\K#\h* y gh j P } - # preserve previous line indent - try %{ execute-keys -draft \; K } - # filter previous line - try %{ execute-keys -draft k : toml-trim-indent } - } -} - -# Initialization -# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ - -hook -group toml-highlight global WinSetOption filetype=toml %{ - add-highlighter window/toml ref toml - hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/toml } -} - -hook global WinSetOption filetype=toml %{ - hook window ModeChange insert:.* -group toml-trim-indent toml-trim-indent - hook window InsertChar \n -group toml-indent toml-indent-on-new-line - - hook -once -always window WinSetOption filetype=.* %{ remove-hooks window toml-.+ } -} diff --git a/rc/extra/troff.kak b/rc/extra/troff.kak deleted file mode 100644 index 072cc3d1..00000000 --- a/rc/extra/troff.kak +++ /dev/null @@ -1,30 +0,0 @@ -# Detection -# ‾‾‾‾‾‾‾‾‾ - -hook global BufCreate .*\.\d+ %{ - set-option buffer filetype troff -} - -# Highlighters -# ‾‾‾‾‾‾‾‾‾‾‾‾ - -add-highlighter shared/troff group -add-highlighter shared/troff/ regex '\\f[A-Z]' 0:attribute -add-highlighter shared/troff/ regex '\\fB(.+?)\\f[A-Z]' 1:+b -add-highlighter shared/troff/ regex '\\fI(.+?)\\f[A-Z]' 1:+i - -add-highlighter shared/troff/ regex '^\.[a-zA-Z]{1,2}\b' 0:meta -add-highlighter shared/troff/ regex '^\.TH\s+[^\n]+' 0:title -add-highlighter shared/troff/ regex '^\.SH\s+[^\n]+' 0:header -add-highlighter shared/troff/ regex '^\.IR\s+(\S+)' 1:+i -add-highlighter shared/troff/ regex '^\.BR\s+(\S+)' 1:+b -add-highlighter shared/troff/ regex '^\.I\s+([^\n]+)' 1:+i -add-highlighter shared/troff/ regex '^\.B\s+([^\n]+)' 1:+b - -# Initialization -# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ - -hook -group troff-highlight global WinSetOption filetype=troff %{ - add-highlighter window/troff ref troff - hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/troff } -} diff --git a/rc/extra/tupfile.kak b/rc/extra/tupfile.kak deleted file mode 100644 index e7ba0d52..00000000 --- a/rc/extra/tupfile.kak +++ /dev/null @@ -1,33 +0,0 @@ -# http://gittup.org/tup/ -# - -# Detection -# ‾‾‾‾‾‾‾‾‾ - -hook global BufCreate .*/?Tup(file|rules)(\.\w+)?$ %{ - set-option buffer filetype tupfile -} - -# Highlighters -# ‾‾‾‾‾‾‾‾‾‾‾‾ - -add-highlighter shared/tupfile regions -add-highlighter shared/tupfile/code default-region group -add-highlighter shared/tupfile/string region '"' (?]: create a new window for repl interaction -All optional parameters are forwarded to the new window} \ - -params .. \ - -shell-completion \ - x11-repl %{ evaluate-commands %sh{ - if [ -z "${kak_opt_termcmd}" ]; then - echo "echo -markup '{Error}termcmd option is not set'" - exit - fi - if [ $# -eq 0 ]; then cmd="${SHELL:-sh}"; else cmd="$@"; fi - setsid ${kak_opt_termcmd} ${cmd} -t kak_repl_window < /dev/null > /dev/null 2>&1 & -}} - -define-command x11-send-text -docstring "send the selected text to the repl window" %{ - nop %sh{ - printf %s\\n "${kak_selection}" | xsel -i - wid=$(xdotool getactivewindow) - xdotool search --name kak_repl_window windowactivate - xdotool key --clearmodifiers "Shift+Insert" - xdotool windowactivate $wid - } -} - -alias global repl x11-repl -alias global send-text x11-send-text diff --git a/rc/filetype/arch-linux.kak b/rc/filetype/arch-linux.kak new file mode 100644 index 00000000..08135a76 --- /dev/null +++ b/rc/filetype/arch-linux.kak @@ -0,0 +1,4 @@ +# package build description file +hook global BufCreate (.*/)?PKGBUILD %{ + set-option buffer filetype sh +} diff --git a/rc/filetype/asciidoc.kak b/rc/filetype/asciidoc.kak new file mode 100644 index 00000000..8bdcce07 --- /dev/null +++ b/rc/filetype/asciidoc.kak @@ -0,0 +1,43 @@ +# http://asciidoc.org/ +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +# Detection +# ‾‾‾‾‾‾‾‾‾ + +hook global BufCreate .+\.(a(scii)?doc|asc) %{ + set-option buffer filetype asciidoc +} + +# Highlighters +# ‾‾‾‾‾‾‾‾‾‾‾‾ + +add-highlighter shared/asciidoc group + +add-highlighter shared/asciidoc/ regex (\A|\n\n)[^\n]+\n={2,}\h*$ 0:title +add-highlighter shared/asciidoc/ regex (\A|\n\n)[^\n]+\n-{2,}\h*$ 0:header +add-highlighter shared/asciidoc/ regex (\A|\n\n)[^\n]+\n~{2,}\h*$ 0:header +add-highlighter shared/asciidoc/ regex (\A|\n\n)[^\n]+\n\^{2,}\h*$ 0:header + +add-highlighter shared/asciidoc/ regex (\A|\n\n)=\h+[^\n]+$ 0:title +add-highlighter shared/asciidoc/ regex (\A|\n\n)={2,}\h+[^\n]+$ 0:header + +add-highlighter shared/asciidoc/ regex ^\h+([-\*])\h+[^\n]*(\n\h+[^-\*]\S+[^\n]*)*$ 0:list 1:bullet +add-highlighter shared/asciidoc/ regex ^(-{3,})\n[^\n\h].*?\n(-{3,})$ 0:block +add-highlighter shared/asciidoc/ regex ^(={3,})\n[^\n\h].*?\n(={3,})$ 0:block +add-highlighter shared/asciidoc/ regex ^(~{3,})\n[^\n\h].*?\n(~{3,})$ 0:block +add-highlighter shared/asciidoc/ regex ^(\*{3,})\n[^\n\h].*?\n(\*{3,})$ 0:block +add-highlighter shared/asciidoc/ regex \B(?:\+[^\n]+?\+|`[^\n]+?`)\B 0:mono +add-highlighter shared/asciidoc/ regex \b_[^\n]+?_\b 0:italic +add-highlighter shared/asciidoc/ regex \B\*[^\n]+?\*\B 0:bold +add-highlighter shared/asciidoc/ regex ^:[-\w]+: 0:meta + +# Commands +# ‾‾‾‾‾‾‾‾ + +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook -group asciidoc-highlight global WinSetOption filetype=asciidoc %{ + add-highlighter window/asciidoc ref asciidoc + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/asciidoc } +} diff --git a/rc/filetype/c-family.kak b/rc/filetype/c-family.kak new file mode 100644 index 00000000..461545fb --- /dev/null +++ b/rc/filetype/c-family.kak @@ -0,0 +1,437 @@ +hook global BufCreate .*\.(cc|cpp|cxx|C|hh|hpp|hxx|H)$ %{ + set-option buffer filetype cpp +} + +hook global BufSetOption filetype=c\+\+ %{ + hook -once buffer NormalIdle '' "set-option buffer filetype cpp" +} + +hook global BufCreate .*\.c$ %{ + set-option buffer filetype c +} + +hook global BufCreate .*\.h$ %{ + try %{ + execute-keys -draft %{%s\b::\b|\btemplate\h*|\bclass\h+\w+|\b(typename|namespace)\b|\b(public|private|protected)\h*:} + set-option buffer filetype cpp + } catch %{ + set-option buffer filetype c + } +} + +hook global BufCreate .*\.m %{ + set-option buffer filetype objc +} + +define-command -hidden c-family-trim-indent %{ + # remove the line if it's empty when leaving the insert mode + try %{ execute-keys -draft 1s^(\h+)$ d } +} + +define-command -hidden c-family-indent-on-newline %< evaluate-commands -draft -itersel %< + execute-keys \; + try %< + # if previous line is part of a comment, do nothing + execute-keys -draft /\* ^\h*[^/*\h] + > catch %< + # else if previous line closed a paren (possibly followed by words and a comment), + # copy indent of the opening paren line + execute-keys -draft k 1s(\))(\h+\w+)*\h*(\;\h*)?(?://[^\n]+)?\n\z mJ 1 + > catch %< + # else indent new lines with the same level as the previous one + execute-keys -draft K + > + # remove previous empty lines resulting from the automatic indent + try %< execute-keys -draft k ^\h+$ Hd > + # indent after an opening brace or parenthesis at end of line + try %< execute-keys -draft k s[{(]\h*$ j > + # indent after a label + try %< execute-keys -draft k s[a-zA-Z0-9_-]+:\h*$ j > + # indent after a statement not followed by an opening brace + try %< execute-keys -draft k s\)\h*(?://[^\n]+)?\n\z \ + mB \A\b(if|for|while)\b j > + try %< execute-keys -draft k s \belse\b\h*(?://[^\n]+)?\n\z \ + j > + # deindent after a single line statement end + try %< execute-keys -draft K \;\h*(//[^\n]+)?$ \ + K s\)(\h+\w+)*\h*(//[^\n]+)?\n([^\n]*\n){2}\z \ + MB \A\b(if|for|while)\b 1 > + try %< execute-keys -draft K \;\h*(//[^\n]+)?$ \ + K s \belse\b\h*(?://[^\n]+)?\n([^\n]*\n){2}\z \ + 1 > + # align to the opening parenthesis or opening brace (whichever is first) + # on a previous line if its followed by text on the same line + try %< evaluate-commands -draft %< + # Go to opening parenthesis and opening brace, then select the most nested one + try %< execute-keys [c [({],[)}] > + # Validate selection and get first and last char + execute-keys \A[{(](\h*\S+)+\n L + # Remove eventual indent from new line + try %< execute-keys -draft s\h+ d > + # Now align that new line with the opening parenthesis/brace + execute-keys & + > > +> > + +define-command -hidden c-family-indent-on-opening-curly-brace %[ + # align indent with opening paren when { is entered on a new line after the closing paren + try %[ execute-keys -draft -itersel h)M \A\(.*\)\h*\n\h*\{\z 1 ] +] + +define-command -hidden c-family-indent-on-closing-curly-brace %[ + # align to opening curly brace when alone on a line + try %[ execute-keys -itersel -draft ^\h+\}$hm1 ] +] + +define-command -hidden c-family-insert-on-closing-curly-brace %[ + # add a semicolon after a closing brace if part of a class, union or struct definition + try %[ execute-keys -itersel -draft hmB\A\h*(class|struct|union|enum) ';i;' ] +] + +define-command -hidden c-family-insert-on-newline %[ evaluate-commands -itersel -draft %[ + execute-keys \; + try %[ + evaluate-commands -draft -save-regs '/"' %[ + # copy the commenting prefix + execute-keys -save-regs '' k 1s^\h*(//+\h*) y + try %[ + # if the previous comment isn't empty, create a new one + execute-keys ^\h*//+\h*$ js^\h*P + ] catch %[ + # if there is no text in the previous comment, remove it completely + execute-keys d + ] + ] + ] + try %[ + # if the previous line isn't within a comment scope, break + execute-keys -draft k ^(\h*/\*|\h+\*(?!/)) + + # find comment opening, validate it was not closed, and check its using star prefixes + execute-keys -draft /\* \*/ \A\h*/\*([^\n]*\n\h*\*)*[^\n]*\n\h*.\z + + try %[ + # if the previous line is opening the comment, insert star preceeded by space + execute-keys -draft k^\h*/\* + execute-keys -draft i* + ] catch %[ + try %[ + # if the next line is a comment line insert a star + execute-keys -draft j^\h+\* + execute-keys -draft i* + ] catch %[ + try %[ + # if the previous line is an empty comment line, close the comment scope + execute-keys -draft k^\h+\*\h+$ 1s\*(\h*)c/ + ] catch %[ + # if the previous line is a non-empty comment line, add a star + execute-keys -draft i* + ] + ] + ] + + # trim trailing whitespace on the previous line + try %[ execute-keys -draft s\h+$ d ] + # align the new star with the previous one + execute-keys K1s^[^*]*(\*)& + ] +] ] + +# Regions definition are the same between c++ and objective-c +evaluate-commands %sh{ + for ft in c cpp objc; do + if [ "${ft}" = "objc" ]; then + maybe_at='@?' + else + maybe_at='' + fi + + cat <<-EOF + add-highlighter shared/$ft regions + add-highlighter shared/$ft/code default-region group + add-highlighter shared/$ft/string region %{$maybe_at(?%ggxs\.c_A_INCLUDEDggxyppI#ifndefjI#definejI#endif//O' + ;; + pragma) + echo 'execute-keys ggi#pragmaonce' + ;; + *);; + esac + } +} + +hook -group c-family-insert global BufNewFile .*\.(h|hh|hpp|hxx|H) c-family-insert-include-guards + +declare-option -docstring "colon separated list of path in which header files will be looked for" \ + str-list alt_dirs '.' '..' + +define-command -hidden c-family-alternative-file %{ + evaluate-commands %sh{ + file="${kak_buffile##*/}" + file_noext="${file%.*}" + dir=$(dirname "${kak_buffile}") + + # Set $@ to alt_dirs + eval "set -- ${kak_opt_alt_dirs}" + + case ${file} in + *.c|*.cc|*.cpp|*.cxx|*.C|*.inl|*.m) + for alt_dir in "$@"; do + for ext in h hh hpp hxx H; do + altname="${dir}/${alt_dir}/${file_noext}.${ext}" + if [ -f ${altname} ]; then + printf 'edit %%{%s}\n' "${altname}" + exit + fi + done + done + ;; + *.h|*.hh|*.hpp|*.hxx|*.H) + for alt_dir in "$@"; do + for ext in c cc cpp cxx C m; do + altname="${dir}/${alt_dir}/${file_noext}.${ext}" + if [ -f ${altname} ]; then + printf 'edit %%{%s}\n' "${altname}" + exit + fi + done + done + ;; + *) + echo "echo -markup '{Error}extension not recognized'" + exit + ;; + esac + echo "echo -markup '{Error}alternative file not found'" + } +} + +define-command c-alternative-file -docstring "Jump to the alternate c file (header/implementation)" %{ + c-family-alternative-file +} +define-command cpp-alternative-file -docstring "Jump to the alternate cpp file (header/implementation)" %{ + c-family-alternative-file +} +define-command objc-alternative-file -docstring "Jump to the alternate objc file (header/implementation)" %{ + c-family-alternative-file +} diff --git a/rc/filetype/cabal.kak b/rc/filetype/cabal.kak new file mode 100644 index 00000000..b3e7e58c --- /dev/null +++ b/rc/filetype/cabal.kak @@ -0,0 +1,74 @@ +# http://haskell.org/cabal +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +# Detection +# ‾‾‾‾‾‾‾‾‾ + +hook global BufCreate .*[.](cabal) %{ + set-option buffer filetype cabal +} + +# Highlighters +# ‾‾‾‾‾‾‾‾‾‾‾‾ + +add-highlighter shared/cabal regions +add-highlighter shared/cabal/code default-region group +add-highlighter shared/cabal/line_comment region (--) $ fill comment +add-highlighter shared/cabal/comment region -recurse \{- \{- -\} fill comment + +add-highlighter shared/cabal/code/ regex \b(true|false)\b|(([<>]?=?)?\d+(\.\d+)+) 0:value +add-highlighter shared/cabal/code/ regex \b(if|else)\b 0:keyword +add-highlighter shared/cabal/code/ regex ^\h*([A-Za-z][A-Za-z0-9_-]*)\h*: 1:variable + +# Commands +# ‾‾‾‾‾‾‾‾ + +define-command -hidden cabal-trim-indent %{ + # remove trailing white spaces + try %{ execute-keys -draft -itersel s \h+$ d } +} + +define-command -hidden cabal-indent-on-new-line %[ + evaluate-commands -draft -itersel %[ + # copy '#' comment prefix and following white spaces + try %[ execute-keys -draft k s ^\h*\K#\h* y gh j P ] + # preserve previous line indent + try %[ execute-keys -draft \; K ] + # filter previous line + try %[ execute-keys -draft k : cabal-trim-indent ] + # indent after lines ending with { or : + try %[ execute-keys -draft k [:{]$ j ] + ] +] + +define-command -hidden cabal-indent-on-opening-curly-brace %[ + evaluate-commands -draft -itersel %[ + # align indent with opening paren when { is entered on a new line after the closing paren + try %[ execute-keys -draft h ) M \A\(.*\)\h*\n\h*\{\z s \A|.\z 1 ] + ] +] + +define-command -hidden cabal-indent-on-closing-curly-brace %[ + evaluate-commands -draft -itersel %[ + # align to opening curly brace when alone on a line + try %[ execute-keys -draft ^\h+\}$ h m s \A|.\z 1 ] + ] +] + +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook -group cabal-highlight global WinSetOption filetype=cabal %{ + add-highlighter window/cabal ref cabal + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/cabal } + +} + +hook global WinSetOption filetype=cabal %[ + hook window ModeChange insert:.* -group cabal-trim-indent cabal-trim-indent + hook window InsertChar \n -group cabal-indent cabal-indent-on-new-line + hook window InsertChar \{ -group cabal-indent cabal-indent-on-opening-curly-brace + hook window InsertChar \} -group cabal-indent cabal-indent-on-closing-curly-brace + + hook -once -always window WinSetOption filetype=.* %{ remove-hooks window cabal-.+ } +] diff --git a/rc/filetype/clojure.kak b/rc/filetype/clojure.kak new file mode 100644 index 00000000..da6134a6 --- /dev/null +++ b/rc/filetype/clojure.kak @@ -0,0 +1,208 @@ +# http://clojure.org +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +# require lisp.kak + +# Detection +# ‾‾‾‾‾‾‾‾‾ + +hook global BufCreate .*[.](clj|cljc|cljs|cljx|edn) %{ + set-option buffer filetype clojure +} + +# Highlighters +# ‾‾‾‾‾‾‾‾‾‾‾‾ + +add-highlighter shared/clojure regions +add-highlighter shared/clojure/code default-region group +add-highlighter shared/clojure/comment region '(? ! : "'" +} + +evaluate-commands %sh{ + exec awk -f - <<'EOF' + BEGIN{ + symbol_char="[^\\s()\\[\\]{}\"\\;@^`~\\\\%/]"; + in_core="(clojure\\.core/|(? cond->> def definline definterface defmacro defmethod "\ + "defmulti defn defn- defonce defprotocol defrecord defstruct deftype fn if "\ + "if-let if-not if-some let letfn new ns when when-first when-let when-not "\ + "when-some . ..", keywords); + + split( \ + "* *' + +' - -' -> ->> ->ArrayChunk ->Eduction ->Vec ->VecNode ->VecSeq / < "\ + "<= = == > >= StackTraceElement->vec Throwable->map accessor aclone "\ + "add-classpath add-watch agent agent-error agent-errors aget alength alias "\ + "all-ns alter alter-meta! alter-var-root amap ancestors and any? apply "\ + "areduce array-map as-> aset aset-boolean aset-byte aset-char aset-double "\ + "aset-float aset-int aset-long aset-short assert assoc assoc! assoc-in "\ + "associative? atom await await-for bases bean bigdec bigint biginteger "\ + "binding bit-and bit-and-not bit-clear bit-flip bit-not bit-or bit-set "\ + "bit-shift-left bit-shift-right bit-test bit-xor boolean boolean-array "\ + "boolean? booleans bound-fn bound-fn* bound? bounded-count butlast byte "\ + "byte-array bytes bytes? cast cat catch char char-array char-escape-string "\ + "char-name-string char? chars class class? clear-agent-errors "\ + "clojure-version coll? comment commute comp comparator compare "\ + "compare-and-set! compile complement completing concat conj conj! cons "\ + "constantly construct-proxy contains? count counted? create-ns "\ + "create-struct cycle dec dec' decimal? declare dedupe default-data-readers "\ + "delay delay? deliver denominator deref derive descendants disj disj! "\ + "dissoc dissoc! distinct distinct? do doall dorun doseq dosync dotimes doto "\ + "double double-array double? doubles drop drop-last drop-while eduction "\ + "empty empty? ensure ensure-reduced enumeration-seq error-handler "\ + "error-mode eval even? every-pred every? ex-data ex-info extend "\ + "extend-protocol extend-type extenders extends? false? ffirst file-seq "\ + "filter filterv finally find find-keyword find-ns find-var first flatten "\ + "float float-array float? floats flush fn? fnext fnil for force format "\ + "frequencies future future-call future-cancel future-cancelled? "\ + "future-done? future? gen-class gen-interface gensym get get-in get-method "\ + "get-proxy-class get-thread-bindings get-validator group-by halt-when hash "\ + "hash-map hash-ordered-coll hash-set hash-unordered-coll ident? identical? "\ + "identity ifn? import in-ns inc inc' indexed? init-proxy inst-ms inst? "\ + "instance? int int-array int? integer? interleave intern interpose into "\ + "into-array ints io! isa? iterate iterator-seq juxt keep keep-indexed key "\ + "keys keyword keyword? last lazy-cat lazy-seq line-seq list list* list? "\ + "load load-file load-reader load-string loaded-libs locking long long-array "\ + "longs loop macroexpand macroexpand-1 make-array make-hierarchy map "\ + "map-entry? map-indexed map? mapcat mapv max max-key memfn memoize merge "\ + "merge-with meta methods min min-key mix-collection-hash mod monitor-enter "\ + "monitor-exit name namespace namespace-munge nat-int? neg-int? neg? newline "\ + "next nfirst nil? nnext not not-any? not-empty not-every? not= ns-aliases "\ + "ns-imports ns-interns ns-map ns-name ns-publics ns-refers ns-resolve "\ + "ns-unalias ns-unmap nth nthnext nthrest num number? numerator object-array "\ + "odd? or parents partial partition partition-all partition-by pcalls peek "\ + "persistent! pmap pop pop! pop-thread-bindings pos-int? pos? pr pr-str "\ + "prefer-method prefers print print-str printf println println-str prn "\ + "prn-str promise proxy proxy-mappings proxy-super push-thread-bindings "\ + "pvalues qualified-ident? qualified-keyword? qualified-symbol? quot quote "\ + "rand rand-int rand-nth random-sample range ratio? rational? rationalize "\ + "re-find re-groups re-matcher re-matches re-pattern re-seq read read-line "\ + "read-string reader-conditional reader-conditional? realized? record? recur "\ + "reduce reduce-kv reduced reduced? reductions ref ref-history-count "\ + "ref-max-history ref-min-history ref-set refer refer-clojure reify "\ + "release-pending-sends rem remove remove-all-methods remove-method "\ + "remove-ns remove-watch repeat repeatedly replace replicate require reset! "\ + "reset-meta! reset-vals! resolve rest restart-agent resultset-seq reverse "\ + "reversible? rseq rsubseq run! satisfies? second select-keys send send-off "\ + "send-via seq seq? seqable? seque sequence sequential? set set! "\ + "set-agent-send-executor! set-agent-send-off-executor! set-error-handler! "\ + "set-error-mode! set-validator! set? short short-array shorts shuffle "\ + "shutdown-agents simple-ident? simple-keyword? simple-symbol? slurp some "\ + "some-> some->> some-fn some? sort sort-by sorted-map sorted-map-by "\ + "sorted-set sorted-set-by sorted? special-symbol? spit split-at split-with "\ + "str string? struct struct-map subs subseq subvec supers swap! swap-vals! "\ + "symbol symbol? sync tagged-literal tagged-literal? take take-last take-nth "\ + "take-while test the-ns thread-bound? throw time to-array to-array-2d "\ + "trampoline transduce transient tree-seq true? try type unchecked-add "\ + "unchecked-add-int unchecked-byte unchecked-char unchecked-dec "\ + "unchecked-dec-int unchecked-divide-int unchecked-double unchecked-float "\ + "unchecked-inc unchecked-inc-int unchecked-int unchecked-long "\ + "unchecked-multiply unchecked-multiply-int unchecked-negate "\ + "unchecked-negate-int unchecked-remainder-int unchecked-short "\ + "unchecked-subtract unchecked-subtract-int underive unreduced "\ + "unsigned-bit-shift-right update update-in update-proxy uri? use uuid? val "\ + "vals var var-get var-set var? vary-meta vec vector vector-of vector? "\ + "volatile! volatile? vreset! vswap! while with-bindings with-bindings* "\ + "with-in-str with-local-vars with-meta with-open with-out-str "\ + "with-precision with-redefs with-redefs-fn xml-seq zero? zipmap", core_fns); + + split( \ + "*1 *2 *3 *agent* *clojure-version* *command-line-args* *compile-files* "\ + "*compile-path* *compiler-options* *data-readers* *default-data-reader-fn* "\ + "*e *err* *file* *flush-on-newline* *in* *ns* *out* *print-dup* "\ + "*print-length* *print-level* *print-meta* *print-namespace-maps* "\ + "*print-readably* *read-eval* *unchecked-math* *warn-on-reflection*", core_vars); + } + function print_word_highlighter(words, face, first) { + printf("add-highlighter shared/clojure/code/ regex (?"wZ' + + try %{ + # If a special form, indent another (indentwidth - 1) spaces + execute-keys -draft '"wze\A' %opt{clojure_special_indent_forms} '\z' + execute-keys -draft '"wzes.{' %sh{printf $(( kak_opt_indentwidth - 1 ))} '}\K.*;"i' + } catch %{ + # If not special and parameter appears on line 1, indent to parameter + execute-keys -draft '"wzes\h\K[^\s].*;"i' + } + } + try %{ execute-keys -draft '[rl"i' } + try %{ execute-keys -draft '[Bl"i' } + execute-keys -draft ';"ia&' + } +} + +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ +hook -group clojure-highlight global WinSetOption filetype=clojure %{ + add-highlighter window/clojure ref clojure + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/clojure } +} + +hook global WinSetOption filetype=clojure %[ + hook window ModeChange insert:.* -group clojure-trim-indent clojure-trim-indent + hook window InsertChar \n -group clojure-indent clojure-indent-on-new-line + + hook -once -always window WinSetOption filetype=.* %{ remove-hooks window clojure-.+ } +] diff --git a/rc/filetype/cmake.kak b/rc/filetype/cmake.kak new file mode 100644 index 00000000..77ec18c5 --- /dev/null +++ b/rc/filetype/cmake.kak @@ -0,0 +1,27 @@ +hook global BufCreate .+\.cmake|.*/CMakeLists.txt %{ + set-option buffer filetype cmake +} + +hook global BufCreate .*/CMakeCache.txt %{ + set-option buffer filetype ini +} + +add-highlighter shared/cmake regions +add-highlighter shared/cmake/code default-region group +add-highlighter shared/cmake/comment region '#' '$' fill comment +add-highlighter shared/cmake/argument region -recurse '\(' '\w+\h*\(\K' '(?=\))' regions + +add-highlighter shared/cmake/code/ regex '\w+\h*(?=\()' 0:meta + +add-highlighter shared/cmake/argument/args default-region regex '\$\{\w+\}' 0:variable +add-highlighter shared/cmake/argument/quoted region '"' '(? + # remove trailing white spaces + try %{ execute-keys -draft s \h + $ d } + } +} + +define-command -hidden coffee-indent-on-new-line %{ + evaluate-commands -draft -itersel %{ + # copy '#' comment prefix and following white spaces + try %{ execute-keys -draft k s '^\h*\K#\h*' y gh j P } + # preserve previous line indent + try %{ execute-keys -draft \; K } + # filter previous line + try %{ execute-keys -draft k : coffee-trim-indent } + # indent after start structure + try %{ execute-keys -draft k ^ \h * (case|catch|class|else|finally|for|function|if|switch|try|while|with) \b | (=|->) $ j } + } +} + +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook -group coffee-highlight global WinSetOption filetype=coffee %{ + add-highlighter window/coffee ref coffee + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/coffee } +} + +hook global WinSetOption filetype=coffee %{ + hook window ModeChange insert:.* -group coffee-trim-indent coffee-trim-indent + hook window InsertChar \n -group coffee-indent coffee-indent-on-new-line + + hook -once -always window WinSetOption filetype=.* %{ remove-hooks window coffee-.+ } +} diff --git a/rc/filetype/css.kak b/rc/filetype/css.kak new file mode 100644 index 00000000..ecc456ed --- /dev/null +++ b/rc/filetype/css.kak @@ -0,0 +1,76 @@ +# http://w3.org/Style/CSS +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +# Detection +# ‾‾‾‾‾‾‾‾‾ + +hook global BufCreate .*[.](css) %{ + set-option buffer filetype css +} + +# Highlighters +# ‾‾‾‾‾‾‾‾‾‾‾‾ + +add-highlighter shared/css regions +add-highlighter shared/css/selector default-region group +add-highlighter shared/css/declaration region [{] [}] regions +add-highlighter shared/css/comment region /[*] [*]/ fill comment + +add-highlighter shared/css/declaration/base default-region group +add-highlighter shared/css/declaration/double_string region '"' (? s \h+$ d } +} + +define-command -hidden css-indent-on-new-line %[ + evaluate-commands -draft -itersel %[ + # preserve previous line indent + try %[ execute-keys -draft \; K ] + # filter previous line + try %[ execute-keys -draft k : css-trim-indent ] + # indent after lines ending with with { + try %[ execute-keys -draft k \{$ j ] + ] +] + +define-command -hidden css-indent-on-closing-curly-brace %[ + evaluate-commands -draft -itersel %[ + # align to opening curly brace when alone on a line + try %[ execute-keys -draft ^\h+\}$ m s \A|.\z 1 ] + ] +] + +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook -group css-highlight global WinSetOption filetype=css %{ + add-highlighter window/css ref css + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/css } +} + +hook global WinSetOption filetype=css %[ + hook window ModeChange insert:.* -group css-trim-indent css-trim-indent + hook window InsertChar \n -group css-indent css-indent-on-new-line + hook window InsertChar \} -group css-indent css-indent-on-closing-curly-brace + set-option buffer extra_word_chars '_' '-' + + hook -once -always window WinSetOption filetype=.* %{ remove-hooks window css-.+ } +] diff --git a/rc/filetype/cucumber.kak b/rc/filetype/cucumber.kak new file mode 100644 index 00000000..180da7d0 --- /dev/null +++ b/rc/filetype/cucumber.kak @@ -0,0 +1,89 @@ +# http://cukes.info +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +# Detection +# ‾‾‾‾‾‾‾‾‾ + +hook global BufCreate .*[.](feature|story) %{ + set-option buffer filetype cucumber +} + +# Highlighters +# ‾‾‾‾‾‾‾‾‾‾‾‾ + +add-highlighter shared/cucumber regions +add-highlighter shared/cucumber/code default-region group +add-highlighter shared/cucumber/language region ^\h*#\h*language: $ group +add-highlighter shared/cucumber/comment region ^\h*# $ fill comment + +add-highlighter shared/cucumber/language/ fill meta +add-highlighter shared/cucumber/language/ regex \S+$ 0:value + +# Spoken languages +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ +# https://github.com/cucumber/cucumber/wiki/Spoken-languages +# +# curl --location https://github.com/cucumber/gherkin/raw/master/lib/gherkin/i18n.json +# +# { +# "en": { +# "name": "English", +# "native": "English", +# "feature": "Feature|Business Need|Ability", +# "background": "Background", +# "scenario": "Scenario", +# "scenario_outline": "Scenario Outline|Scenario Template", +# "examples": "Examples|Scenarios", +# "given": "*|Given", +# "when": "*|When", +# "then": "*|Then", +# "and": "*|And", +# "but": "*|But" +# }, +# … +# } +# +# jq 'with_entries({ key: .key, value: .value | del(.name) | del(.native) | join("|") })' +# +# { +# "en": "Feature|Business Need|Ability|Background|Scenario|Scenario Outline|Scenario Template|Examples|Scenarios|*|Given|*|When|*|Then|*|And|*|But", +# … +# } + +add-highlighter shared/cucumber/code/ regex \b(Feature|Business\h+Need|Ability|Background|Scenario|Scenario\h+Outline|Scenario\h+Template|Examples|Scenarios|Given|When|Then|And|But)\b 0:keyword + +# Commands +# ‾‾‾‾‾‾‾‾ + +define-command -hidden cucumber-trim-indent %{ + # remove trailing white spaces + try %{ execute-keys -draft -itersel s \h+$ d } +} + +define-command -hidden cucumber-indent-on-new-line %{ + evaluate-commands -draft -itersel %{ + # copy '#' comment prefix and following white spaces + try %{ execute-keys -draft k s ^\h*\K#\h* y gh j P } + # preserve previous line indent + try %{ execute-keys -draft \; K } + # filter previous line + try %{ execute-keys -draft k : cucumber-trim-indent } + # indent after lines containing : + try %{ execute-keys -draft k x : j } + } +} + +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook -group cucumber-highlight global WinSetOption filetype=cucumber %{ + add-highlighter window/cucumber ref cucumber + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/cucumber } +} + +hook global WinSetOption filetype=cucumber %{ + hook window ModeChange insert:.* -group cucumber-trim-indent cucumber-trim-indent + hook window InsertChar \n -group cucumber-indent cucumber-indent-on-new-line + + hook -once -always window WinSetOption filetype=.* %{ remove-hooks window cucumber-.+ } +} diff --git a/rc/filetype/d.kak b/rc/filetype/d.kak new file mode 100644 index 00000000..f0f08248 --- /dev/null +++ b/rc/filetype/d.kak @@ -0,0 +1,132 @@ +# http://dlang.org/ +# + +# Detection +# ‾‾‾‾‾‾‾‾‾ + +hook global BufCreate .*\.di? %{ + set-option buffer filetype d +} + +# Highlighters +# ‾‾‾‾‾‾‾‾‾‾‾‾ + +add-highlighter shared/d regions +add-highlighter shared/d/code default-region group +add-highlighter shared/d/string region %{(? } + # indent after lines ending with { or ( + try %[ execute-keys -draft k [{(]\h*$ j ] + # cleanup trailing white spaces on the previous line + try %{ execute-keys -draft k s \h+$ d } + # align to opening paren of previous line + try %{ execute-keys -draft [( \A\([^\n]+\n[^\n]*\n?\z s \A\(\h*.|.\z '' & } + # copy // comments prefix + try %{ execute-keys -draft \;k s ^\h*\K/{2,} yP } + # indent after a switch's case/default statements + try %[ execute-keys -draft k ^\h*(case|default).*:$ j ] + # indent after if|else|while|for + try %[ execute-keys -draft \;)MB \A(if|else|while|for)\h*\(.*\)\h*\n\h*\n?\z s \A|.\z 11 ] + = +~ + +define-command -hidden d-indent-on-opening-curly-brace %[ + # align indent with opening paren when { is entered on a new line after the closing paren + try %[ execute-keys -draft -itersel h)M \A\(.*\)\h*\n\h*\{\z s \A|.\z 1 ] +] + +define-command -hidden d-indent-on-closing-curly-brace %[ + # align to opening curly brace when alone on a line + try %[ execute-keys -itersel -draft ^\h+\}$hms\A|.\z1 ] +] + +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook -group d-highlight global WinSetOption filetype=d %{ + add-highlighter window/d ref d + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/d } +} + +hook global WinSetOption filetype=d %{ + # cleanup trailing whitespaces when exiting insert mode + hook window ModeChange insert:.* -group d-trim-indent %{ try %{ execute-keys -draft s^\h+$d } } + hook window InsertChar \n -group d-indent d-indent-on-new-line + hook window InsertChar \{ -group d-indent d-indent-on-opening-curly-brace + hook window InsertChar \} -group d-indent d-indent-on-closing-curly-brace + + hook -once -always window WinSetOption filetype=.* %{ remove-hooks window d-.+ } +} diff --git a/rc/filetype/dart.kak b/rc/filetype/dart.kak new file mode 100644 index 00000000..5b5600cb --- /dev/null +++ b/rc/filetype/dart.kak @@ -0,0 +1,106 @@ +# https://dartlang.org/ +# + +# Detection +# ‾‾‾‾‾‾‾‾‾ + +hook global BufCreate .*\.dart %{ + set-option buffer filetype dart +} + +# Highlighters +# ‾‾‾‾‾‾‾‾‾‾‾‾ + +add-highlighter shared/dart regions +add-highlighter shared/dart/code default-region group +add-highlighter shared/dart/back_string region '`' '`' fill string +add-highlighter shared/dart/double_string region '"' (?)" + classes="[A-Z][a-zA-Z0-9]*" + + # Add the language's grammar to the static completion list + printf %s\\n "hook global WinSetOption filetype=dart %{ + set-option window static_words ${keywords} ${attributes} ${types} ${values} + }" | tr '|' ' ' + + # Highlight keywords + printf %s " + add-highlighter shared/dart/code/ regex \b(${keywords})\b 0:keyword + add-highlighter shared/dart/code/ regex \b(${generator_keywords}) 0:keyword + add-highlighter shared/dart/code/ regex \b(${attributes})\b 0:attribute + add-highlighter shared/dart/code/ regex \b(${types})\b 0:type + add-highlighter shared/dart/code/ regex \b(${values})\b 0:value + add-highlighter shared/dart/code/ regex \b(${functions}) 2:function + add-highlighter shared/dart/code/ regex \b(${annotations})\b 0:meta + add-highlighter shared/dart/code/ regex \b(${classes})\b 0:module + " +} + +# Commands +# ‾‾‾‾‾‾‾‾ + +define-command -hidden dart-indent-on-new-line %~ + evaluate-commands -draft -itersel %= + # preserve previous line indent + try %{ execute-keys -draft \;K } + # indent after lines ending with { or ( + try %[ execute-keys -draft k [{(]\h*$ j ] + # cleanup trailing white spaces on the previous line + try %{ execute-keys -draft k s \h+$ d } + # align to opening paren of previous line + try %{ execute-keys -draft [( \A\([^\n]+\n[^\n]*\n?\z s \A\(\h*.|.\z '' & } + # copy // comments prefix + try %{ execute-keys -draft \;k s ^\h*\K/{2,} yP } + # indent after a switch's case/default statements + try %[ execute-keys -draft k ^\h*(case|default).*:$ j ] + # indent after if|else|while|for + try %[ execute-keys -draft \;)MB \A(if|else|while|for)\h*\(.*\)\h*\n\h*\n?\z s \A|.\z 11 ] + = +~ + +define-command -hidden dart-indent-on-opening-curly-brace %[ + # align indent with opening paren when { is entered on a new line after the closing paren + try %[ execute-keys -draft -itersel h)M \A\(.*\)\h*\n\h*\{\z s \A|.\z 1 ] +] + +define-command -hidden dart-indent-on-closing-curly-brace %[ + # align to opening curly brace when alone on a line + try %[ execute-keys -itersel -draft ^\h+\}$hms\A|.\z1 ] +] + +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook -group dart-highlight global WinSetOption filetype=dart %{ + add-highlighter window/dart ref dart + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/dart } +} + +hook global WinSetOption filetype=dart %{ + # cleanup trailing whitespaces when exiting insert mode + hook window ModeChange insert:.* -group dart-trim-indent %{ try %{ execute-keys -draft s^\h+$d } } + hook window InsertChar \n -group dart-indent dart-indent-on-new-line + hook window InsertChar \{ -group dart-indent dart-indent-on-opening-curly-brace + hook window InsertChar \} -group dart-indent dart-indent-on-closing-curly-brace + + hook -once -always window WinSetOption filetype=.* %{ remove-hooks window dart-.+ } +} diff --git a/rc/filetype/diff.kak b/rc/filetype/diff.kak new file mode 100644 index 00000000..5b4e065b --- /dev/null +++ b/rc/filetype/diff.kak @@ -0,0 +1,13 @@ +hook global BufCreate .*\.(diff|patch) %{ + set-option buffer filetype diff +} + +add-highlighter shared/diff group +add-highlighter shared/diff/ regex "^\+[^\n]*\n" 0:green,default +add-highlighter shared/diff/ regex "^-[^\n]*\n" 0:red,default +add-highlighter shared/diff/ regex "^@@[^\n]*@@" 0:cyan,default + +hook -group diff-highlight global WinSetOption filetype=diff %{ + add-highlighter window/diff ref diff + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/diff } +} diff --git a/rc/filetype/dockerfile.kak b/rc/filetype/dockerfile.kak new file mode 100644 index 00000000..07da2347 --- /dev/null +++ b/rc/filetype/dockerfile.kak @@ -0,0 +1,48 @@ +# http://docker.com +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +# See https://docs.docker.com/reference/builder + +# Detection +# ‾‾‾‾‾‾‾‾‾ + +hook global BufCreate .*/?Dockerfile(\.\w+)?$ %{ + set-option buffer filetype dockerfile +} + +# Highlighters +# ‾‾‾‾‾‾‾‾‾‾‾‾ + +add-highlighter shared/dockerfile regions +add-highlighter shared/dockerfile/code default-region group +add-highlighter shared/dockerfile/double_string region '"' '(?|<-|<<|>>|=>) 0:builtin +add-highlighter shared/elixir/code/ regex \b(require|alias|use|import)\b 0:keyword +add-highlighter shared/elixir/code/ regex \b(__MODULE__|__DIR__|__ENV__|__CALLER__)\b 0:value +add-highlighter shared/elixir/code/ regex \b(def|defp|defmacro|defmacrop|defstruct|defmodule|defimpl|defprotocol|defoverridable)\b 0:keyword +add-highlighter shared/elixir/code/ regex \b(fn|do|end|when|case|if|else|unless|var!|for|cond|quote|unquote|receive|with|raise|reraise|try|catch)\b 0:keyword +add-highlighter shared/elixir/code/ regex '@[\w_]+\b' 0:attribute +add-highlighter shared/elixir/code/ regex '\b\d+[\d_]*\b' 0:value + +# Commands +# ‾‾‾‾‾‾‾‾ + +define-command -hidden elixir-trim-indent %{ + # remove trailing white spaces + try %{ execute-keys -draft -itersel s \h+$ d } +} + +define-command -hidden elixir-indent-on-new-line %{ + evaluate-commands -draft -itersel %{ + # copy -- comments prefix and following white spaces + try %{ execute-keys -draft k s ^\h*\K--\h* y gh j P } + # preserve previous line indent + try %{ execute-keys -draft \; K } + # indent after line ending with: + # try %{ execute-keys -draft k x (do|else|->)$ & } + # filter previous line + try %{ execute-keys -draft k : elixir-trim-indent } + # indent after lines ending with do or -> + try %{ execute-keys -draft \\; k x ^.+(do|->)$ j } + } +} + +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook -group elixir-highlight global WinSetOption filetype=elixir %{ + add-highlighter window/elixir ref elixir + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/elixir } +} + +hook global WinSetOption filetype=elixir %{ + hook window ModeChange insert:.* -group elixir-trim-indent elixir-trim-indent + hook window InsertChar \n -group elixir-indent elixir-indent-on-new-line + + hook -once -always window WinSetOption filetype=.* %{ remove-hooks window elixir-.+ } +} diff --git a/rc/filetype/elm.kak b/rc/filetype/elm.kak new file mode 100644 index 00000000..05d1248b --- /dev/null +++ b/rc/filetype/elm.kak @@ -0,0 +1,67 @@ +# http://elm-lang.org +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +# Detection +# ‾‾‾‾‾‾‾‾‾ + +hook global BufCreate .*[.](elm) %{ + set-option buffer filetype elm +} + +# Highlighters +# ‾‾‾‾‾‾‾‾‾‾‾‾ + +add-highlighter shared/elm regions +add-highlighter shared/elm/code default-region group +add-highlighter shared/elm/string region '"' (? s \h+$ d } +} + +define-command -hidden elm-indent-after " + execute-keys -draft \\; k x ^\\h*(if)|(case\\h+[\\w']+\\h+of|let|in|\\{\\h+\\w+|\\w+\\h+->|[=(])$ j +" + +define-command -hidden elm-indent-on-new-line %{ + evaluate-commands -draft -itersel %{ + # copy -- comments prefix and following white spaces + try %{ execute-keys -draft k s ^\h*\K--\h* y gh j P } + # preserve previous line indent + try %{ execute-keys -draft \; K } + # align to first clause + try %{ execute-keys -draft \; k x X s ^\h*(if|then|else)?\h*(([\w']+\h+)+=)?\h*(case\h+[\w']+\h+of|let)\h+\K.* s \A|.\z & } + # filter previous line + try %{ execute-keys -draft k : elm-trim-indent } + # indent after lines beginning with condition or ending with expression or =( + try %{ elm-indent-after } + } +} + +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook -group elm-highlight global WinSetOption filetype=elm %{ + add-highlighter window/elm ref elm + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/elm } +} + +hook global WinSetOption filetype=elm %{ + hook window ModeChange insert:.* -group elm-trim-indent elm-trim-indent + hook window InsertChar \n -group elm-indent elm-indent-on-new-line + + hook -once -always window WinSetOption filetype=.* %{ remove-hooks window elm-.+ } +} diff --git a/rc/filetype/etc.kak b/rc/filetype/etc.kak new file mode 100644 index 00000000..1e2067fe --- /dev/null +++ b/rc/filetype/etc.kak @@ -0,0 +1,79 @@ +# Highlighting for common files in /etc +hook global BufCreate .*/etc/(hosts|networks|services) %{ set-option buffer filetype etc-hosts } +hook global BufCreate .*/etc/resolv.conf %{ set-option buffer filetype etc-resolv-conf } +hook global BufCreate .*/etc/shadow %{ set-option buffer filetype etc-shadow } +hook global BufCreate .*/etc/passwd %{ set-option buffer filetype etc-passwd } +hook global BufCreate .*/etc/gshadow %{ set-option buffer filetype etc-gshadow } +hook global BufCreate .*/etc/group %{ set-option buffer filetype etc-group } +hook global BufCreate .*/etc/(fs|m)tab %{ set-option buffer filetype etc-fstab } +hook global BufCreate .*/etc/environment %{ set-option buffer filetype sh } +hook global BufCreate .*/etc/env.d/.* %{ set-option buffer filetype sh } +hook global BufCreate .*/etc/profile(\.(csh|env))? %{ set-option buffer filetype sh } +hook global BufCreate .*/etc/profile\.d/.* %{ set-option buffer filetype sh } + +# Highlighters +## /etc/resolv.conf +add-highlighter shared/etc-resolv-conf group +add-highlighter shared/etc-resolv-conf/ regex ^#.*?$ 0:comment +add-highlighter shared/etc-resolv-conf/ regex ^(nameserver|server|domain|sortlist|options)[\s\t]+(.*?)$ 1:type 2:attribute + +hook -group etc-resolv-conf-highlight global WinSetOption filetype=etc-resolv-conf %{ + add-highlighter window/etc-resolv-conf ref etc-resolv-conf + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/etc-resolv-conf } +} + +## /etc/hosts +add-highlighter shared/etc-hosts group +add-highlighter shared/etc-hosts/ regex ^(.+?)[\s\t]+?(.*?)$ 1:type 2:attribute +add-highlighter shared/etc-hosts/ regex '#.*?$' 0:comment + +hook -group etc-hosts-highlight global WinSetOption filetype=etc-hosts %{ + add-highlighter window/etc-hosts ref etc-hosts + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/etc-hosts } +} + +## /etc/fstab +add-highlighter shared/etc-fstab group +add-highlighter shared/etc-fstab/ regex ^(\S{1,})\s+?(\S{1,})\s+?(\S{1,})\s+?(\S{1,})\s+?(\S{1,})\s+?(\S{1,})(?:\s+)?$ 1:keyword 2:value 3:type 4:string 5:attribute 6:attribute +add-highlighter shared/etc-fstab/ regex '#.*?$' 0:comment + +hook -group etc-fstab-highlight global WinSetOption filetype=etc-fstab %{ + add-highlighter window/etc-fstab ref etc-fstab + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/etc-fstab } +} + +## /etc/group +add-highlighter shared/etc-group group +add-highlighter shared/etc-group/ regex ^(\S+?):(\S+?)?:(\S+?)?:(\S+?)?$ 1:keyword 2:type 3:value 4:string + +hook -group etc-group-highlight global WinSetOption filetype=etc-group %{ + add-highlighter window/etc-group ref etc-group + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/etc-group } +} + +## /etc/gshadow +add-highlighter shared/etc-gshadow group +add-highlighter shared/etc-gshadow/ regex ^(\S+?):(\S+?)?:(\S+?)?:(\S+?)?$ 1:keyword 2:type 3:value 4:string + +hook -group etc-gshadow-highlight global WinSetOption filetype=etc-gshadow %{ + add-highlighter window/etc-gshadow ref etc-gshadow + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/etc-gshadow } +} + +## /etc/shadow +add-highlighter shared/etc-shadow group +add-highlighter shared/etc-shadow/ regex ^(\S+?):(\S+?):([0-9]+?):([0-9]+?)?:([0-9]+?)?:([0-9]+?)?:([0-9]+?)?:([0-9]+?)?:(.*?)?$ 1:keyword 2:type 3:value 4:value 5:value 6:value 7:value 8:value + +hook -group etc-shadow-highlight global WinSetOption filetype=etc-shadow %{ + add-highlighter window/etc-shadow ref etc-shadow + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/etc-shadow } +} + +## /etc/passwd +add-highlighter shared/etc-passwd group +add-highlighter shared/etc-passwd/ regex ^(\S+?):(\S+?):([0-9]+?):([0-9]+?):(.*?)?:(.+?):(.+?)$ 1:keyword 2:type 3:value 4:value 5:string 6:attribute 7:attribute + +hook -group etc-passwd-highlight global WinSetOption filetype=etc-passwd %{ + add-highlighter window/etc-passwd ref etc-passwd + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/etc-passwd } +} diff --git a/rc/filetype/exherbo.kak b/rc/filetype/exherbo.kak new file mode 100644 index 00000000..42cc618c --- /dev/null +++ b/rc/filetype/exherbo.kak @@ -0,0 +1,121 @@ +## Repository metadata files +hook global BufCreate .*/metadata/mirrors\.conf %{ set-option buffer filetype paludis-mirrors-conf } +hook global BufCreate .*/metadata/licence_groups.conf %{ set-option buffer filetype exheres-0-licence-groups } +hook global BufCreate .*/metadata/options/descriptions/.*\.conf %{ set-option buffer filetype exheres-0-licence-groups } +hook global BufCreate .*/metadata/.*\.conf %{ set-option buffer filetype exheres-0-metadata } + +## News items +hook global BufCreate .*/metadata/news/.*/.*\.txt %{ set-option buffer filetype glep42 } + +## exheres-0, exlib +hook global BufCreate .*\.(exheres-0|exlib) %{ set-option buffer filetype sh } + +# Paludis configurations +hook global BufCreate .*/etc/paludis(-.*)?/bashrc %{ set-option buffer filetype sh } +hook global BufCreate .*/etc/paludis(-.*)?/general(\.conf.d/.*.conf|\.conf) %{ set-option buffer filetype paludis-key-value-conf } +hook global BufCreate .*/etc/paludis(-.*)?/licences(\.conf.d/.*.conf|\.conf) %{ set-option buffer filetype paludis-options-conf } +hook global BufCreate .*/etc/paludis(-.*)?/mirrors(\.conf.d/.*.conf|\.conf) %{ set-option buffer filetype paludis-mirrors-conf } +hook global BufCreate .*/etc/paludis(-.*)?/options(\.conf.d/.*.conf|\.conf) %{ set-option buffer filetype paludis-options-conf } +hook global BufCreate .*/etc/paludis(-.*)?/output(\.conf.d/.*.conf|\.conf) %{ set-option buffer filetype paludis-key-value-conf } +hook global BufCreate .*/etc/paludis(-.*)?/package_(unmask|mask)(\.conf.d/.*.conf|\.conf) %{ set-option buffer filetype paludis-specs-conf } +hook global BufCreate .*/etc/paludis(-.*)?/platforms(\.conf.d/.*.conf|\.conf) %{ set-option buffer filetype paludis-specs-conf } +hook global BufCreate .*/etc/paludis(-.*)?/repositories/.*\.conf %{ set-option buffer filetype paludis-key-value-conf } +hook global BufCreate .*/etc/paludis(-.*)?/repository\.template %{ set-option buffer filetype paludis-key-value-conf } +hook global BufCreate .*/etc/paludis(-.*)?/repository_defaults\.conf %{ set-option buffer filetype paludis-key-value-conf } +hook global BufCreate .*/etc/paludis(-.*)?/specpath\.conf %{ set-option buffer filetype paludis-key-value-conf } +hook global BufCreate .*/etc/paludis(-.*)?/suggestions(\.conf.d/.*.conf|\.conf) %{ set-option buffer filetype paludis-specs-conf } + +# Highlighters +## exheres-0 Repository metadata files +add-highlighter shared/exheres-0-metadata group +add-highlighter shared/exheres-0-metadata/ regex ^#.*?$ 0:comment +add-highlighter shared/exheres-0-metadata/ regex ^(?:[\s\t]+)?(\*)?(\S+)(?:[\s\t]+)?=(?:[\s\t]+)?(.+?)?$ 1:type 2:attribute 3:string +add-highlighter shared/exheres-0-metadata/ regex ^(?:[\s\t]+)?[\S]+[\s\t]+=[\s\t]+\[.+?[\s\t]+\] 0:string +add-highlighter shared/exheres-0-metadata/ regex ^(?:[\s\t]+)?(\S+)\s\[\[$ 0:type +add-highlighter shared/exheres-0-metadata/ regex ^(?:[\s\t]+)?\]\]$ 0:type + +hook -group exheres-0-metadata-highlight global WinSetOption filetype=exheres-0-metadata %{ + add-highlighter window/exheres-0-metadata ref exheres-0-metadata + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/exheres-0-metadata } +} + +## exheres-0 options descriptions +add-highlighter shared/exheres-0-options-descriptions group +add-highlighter shared/exheres-0-options-descriptions/ regex ^#.*?$ 0:comment +add-highlighter shared/exheres-0-options-descriptions/ regex ^(?:[\s\t]+)?[\S]+[\s\t]+-[\s\t]+\[.+?[\s\t]+\] 0:string +add-highlighter shared/exheres-0-options-descriptions/ regex ^(?:[\s\t]+)?(\S+)\s\[\[$ 0:type +add-highlighter shared/exheres-0-options-descriptions/ regex ^(?:[\s\t]+)?\]\]$ 0:type + +hook -group exheres-0-options-descriptions-highlight global WinSetOption filetype=exheres-0-options-descriptions %{ + add-highlighter window/exheres-0-options-descriptions ref exheres-0-options-descriptions + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/exheres-0-options-descriptions } +} + +## metadata/licence_groups.conf +add-highlighter shared/exheres-0-licence-groups group +add-highlighter shared/exheres-0-licence-groups/ regex [\s\t]+(\S+(?:[\s\t]+))*$ 0:attribute +add-highlighter shared/exheres-0-licence-groups/ regex ^(\S+) 0:type +add-highlighter shared/exheres-0-licence-groups/ regex ^#.*?$ 0:comment + +hook -group exheres-0-licence-groups-highlight global WinSetOption filetype=exheres-0-licence-groups %{ + add-highlighter window/exheres-0-licence-groups ref exheres-0-licence-groups + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/exheres-0-licence-groups } +} + +## Paludis configurations +### options.conf +add-highlighter shared/paludis-options-conf group +add-highlighter shared/paludis-options-conf/ regex [\s\t]+(\S+(?:[\s\t]+))*$ 0:attribute +add-highlighter shared/paludis-options-conf/ regex (?::)(?:[\s\t]+)(.*?$) 1:attribute +add-highlighter shared/paludis-options-conf/ regex [\s\t]+(\S+=)(\S+) 1:attribute 2:value +add-highlighter shared/paludis-options-conf/ regex [\s\t](\S+:) 0:keyword +add-highlighter shared/paludis-options-conf/ regex [\s\t](-\S+)(.*?) 1:red +add-highlighter shared/paludis-options-conf/ regex ^(\S+/\S+) 0:type +add-highlighter shared/paludis-options-conf/ regex ^#.*?$ 0:comment + +hook -group paludis-options-conf-highlight global WinSetOption filetype=paludis-options-conf %{ + add-highlighter window/paludis-options-conf ref paludis-options-conf + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/paludis-options-conf } +} + +## general.conf, repository.template +add-highlighter shared/paludis-key-value-conf group +add-highlighter shared/paludis-key-value-conf/ regex ^[\s\t]?(\S+)[\s\t+]=[\s\t+](.*?)$ 1:attribute 2:value +add-highlighter shared/paludis-key-value-conf/ regex ^#.*?$ 0:comment + +hook -group paludis-key-value-conf-highlight global WinSetOption filetype=paludis-key-value-conf %{ + add-highlighter window/paludis-key-value-conf ref paludis-key-value-conf + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/paludis-key-value-conf } +} + +## mirrors.conf +add-highlighter shared/paludis-mirrors-conf group +add-highlighter shared/paludis-mirrors-conf/ regex ^[\s\t+]?(\S+)[\s\t+](.*?)$ 1:type 2:value +add-highlighter shared/paludis-mirrors-conf/ regex ^#.*?$ 0:comment + +hook -group paludis-mirrors-conf-highlight global WinSetOption filetype=paludis-mirrors-conf %{ + add-highlighter window/paludis-mirrors-conf ref paludis-mirrors-conf + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/paludis-mirrors-conf } +} + +## package_(unmask|mask).conf, platforms.conf +add-highlighter shared/paludis-specs-conf group +add-highlighter shared/paludis-specs-conf/ regex [\s\t]+(\S+(?:[\s\t]+))*$ 0:attribute +add-highlighter shared/paludis-specs-conf/ regex ^(\S+/\S+) 0:type +add-highlighter shared/paludis-specs-conf/ regex ^#.*?$ 0:comment + +hook -group paludis-specs-conf-highlight global WinSetOption filetype=paludis-specs-conf %{ + add-highlighter window/paludis-specs-conf ref paludis-specs-conf + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/paludis-specs-conf } +} + +## News items (GLEP42) +add-highlighter shared/glep42 group +add-highlighter shared/glep42/ regex ^(Title|Author|Translator|Content-Type|Posted|Revision|News-Item-Format|Display-If-Installed|Display-If-Keyword|Display-If-Profile):([^\n]*(?:\n\h+[^\n]+)*)$ 1:keyword 2:attribute +add-highlighter shared/glep42/ regex <[^@>]+@.*?> 0:string +add-highlighter shared/glep42/ regex ^>.*?$ 0:comment + +hook -group glep42-highlight global WinSetOption filetype=glep42 %{ + add-highlighter window/glep42 ref glep42 + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/glep42 } +} diff --git a/rc/filetype/fish.kak b/rc/filetype/fish.kak new file mode 100644 index 00000000..8e23ede4 --- /dev/null +++ b/rc/filetype/fish.kak @@ -0,0 +1,84 @@ +# http://fishshell.com +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +# Detection +# ‾‾‾‾‾‾‾‾‾ + +hook global BufCreate .*[.](fish) %{ + set-option buffer filetype fish +} + +# Highlighters +# ‾‾‾‾‾‾‾‾‾‾‾‾ + +add-highlighter shared/fish regions +add-highlighter shared/fish/code default-region group +add-highlighter shared/fish/double_string region '"' (?s\h+$d } + } +} + +define-command -hidden fish-indent-on-char %{ + evaluate-commands -no-hooks -draft -itersel %{ + # align middle and end structures to start and indent when necessary + try %{ execute-keys -draft ^\h*(else)$^\h*(if)s\A|\z) } + try %{ execute-keys -draft ^\h*(end)$^\h*(begin|for|function|if|switch|while)s\A|\z) } + try %{ execute-keys -draft ^\h*(case)$^\h*(switch)s\A|\z)) } + } +} + +define-command -hidden fish-indent-on-new-line %{ + evaluate-commands -no-hooks -draft -itersel %{ + # preserve previous line indent + try %{ execute-keys -draft K } + # filter previous line + try %{ execute-keys -draft k:fish-trim-indent } + # indent after start structure + try %{ execute-keys -draft k^\h*(begin|case|else|for|function|if|switch|while)\bj } + } +} + +define-command -hidden fish-insert-on-new-line %{ + evaluate-commands -no-hooks -draft -itersel %{ + # copy _#_ comment prefix and following white spaces + try %{ execute-keys -draft ks^\h*\K#\h*yjp } + # wisely add end structure + evaluate-commands -save-regs x %{ + try %{ execute-keys -draft ks^\h+"xy } catch %{ reg x '' } + try %{ execute-keys -draft k^x(begin|for|function|if|switch|while)jiXK^x(begin|for|function|if|switch|while).*\nxend$jxypjaend } + } + } +} + +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook -group fish-highlight global WinSetOption filetype=fish %{ + add-highlighter window/fish ref fish + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/fish } +} + +hook global WinSetOption filetype=fish %{ + hook window InsertChar .* -group fish-indent fish-indent-on-char + hook window InsertChar \n -group fish-insert fish-insert-on-new-line + hook window InsertChar \n -group fish-indent fish-indent-on-new-line + + hook -once -always window WinSetOption filetype=.* %{ remove-hooks window fish-.+ } +} diff --git a/rc/filetype/gas.kak b/rc/filetype/gas.kak new file mode 100644 index 00000000..0c1f79f8 --- /dev/null +++ b/rc/filetype/gas.kak @@ -0,0 +1,91 @@ +# Detection +# --------- +hook global BufCreate .*\.(s|S|asm)$ %{ + set-option buffer filetype gas +} + +add-highlighter shared/gas regions +add-highlighter shared/gas/code default-region group +add-highlighter shared/gas/string region '"' (? + # remove trailing white spaces + try %{ execute-keys -draft s \h+$ d } + } +} + +define-command -hidden gas-indent-on-new-line %~ + evaluate-commands -draft -itersel %< + # preserve previous line indent + try %{ execute-keys -draft \; K } + # filter previous line + try %{ execute-keys -draft k : gas-trim-indent } + # indent after label + try %[ execute-keys -draft k :$ j ] + > +~ + +hook -group gas-highlight global WinSetOption filetype=gas %{ + add-highlighter window/gas ref gas + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/gas } +} + +hook global WinSetOption filetype=gas %{ + hook window InsertChar \n -group gas-indent gas-indent-on-new-line + hook -once -always window WinSetOption filetype=.* %{ remove-hooks window gas-.+ } +} diff --git a/rc/filetype/git.kak b/rc/filetype/git.kak new file mode 100644 index 00000000..13d58f0a --- /dev/null +++ b/rc/filetype/git.kak @@ -0,0 +1,40 @@ +hook global BufCreate .*(COMMIT_EDITMSG|MERGE_MSG) %{ + set-option buffer filetype git-commit +} + +hook global BufCreate .*/NOTES_EDITMSG %{ + set-option buffer filetype git-notes +} + +hook global BufCreate .*(\.gitconfig|git/config) %{ + set-option buffer filetype ini +} + +hook -group git-commit-highlight global WinSetOption filetype=git-commit %{ + add-highlighter window/git-commit-highlight regions + add-highlighter window/git-commit-highlight/diff region '^diff --git' '^(?=diff --git)' ref diff # highlight potential diffs from the -v option + add-highlighter window/git-commit-highlight/comments region '^\h*#' '$' group + add-highlighter window/git-commit-highlight/comments/ fill comment + add-highlighter window/git-commit-highlight/comments/ regex "\b(?:(modified)|(deleted)|(new file)|(renamed|copied)):([^\n]*)$" 1:yellow 2:red 3:green 4:blue 5:magenta + + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/git-commit-highlight } +} + +hook -group git-commit-highlight global WinSetOption filetype=git-notes %{ + add-highlighter window/git-notes-highlight regex '^\h*#[^\n]*$' 0:comment + + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/git-notes-highlight } +} + + +hook global BufCreate .*git-rebase-todo %{ + set-option buffer filetype git-rebase +} + +hook -group git-rebase-highlight global WinSetOption filetype=git-rebase %{ + add-highlighter window/git-rebase-highlight group + add-highlighter window/git-rebase-highlight/ regex "#[^\n]*\n" 0:comment + add-highlighter window/git-rebase-highlight/ regex "^(pick|edit|reword|squash|fixup|exec|break|drop|label|reset|merge|[persfxbdltm]) (\w+)" 1:keyword 2:meta + + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/git-rebase-highlight } +} diff --git a/rc/filetype/go.kak b/rc/filetype/go.kak new file mode 100644 index 00000000..8aebe657 --- /dev/null +++ b/rc/filetype/go.kak @@ -0,0 +1,97 @@ +# https://golang.org/ +# + +# Detection +# ‾‾‾‾‾‾‾‾‾ + +hook global BufCreate .*\.go %{ + set-option buffer filetype go +} + +# Highlighters +# ‾‾‾‾‾‾‾‾‾‾‾‾ + +add-highlighter shared/go regions +add-highlighter shared/go/code default-region group +add-highlighter shared/go/back_string region '`' '`' fill string +add-highlighter shared/go/double_string region '"' (? } + # indent after lines ending with { or ( + try %[ execute-keys -draft k [{(]\h*$ j ] + # cleanup trailing white spaces on the previous line + try %{ execute-keys -draft k s \h+$ d } + # align to opening paren of previous line + try %{ execute-keys -draft [( \A\([^\n]+\n[^\n]*\n?\z s \A\(\h*.|.\z '' & } + # copy // comments prefix + try %{ execute-keys -draft \;k s ^\h*\K/{2,} yP } + # indent after a switch's case/default statements + try %[ execute-keys -draft k ^\h*(case|default).*:$ j ] + # indent after if|else|while|for + try %[ execute-keys -draft \;)MB \A(if|else|while|for)\h*\(.*\)\h*\n\h*\n?\z s \A|.\z 11 ] + = +~ + +define-command -hidden go-indent-on-opening-curly-brace %[ + # align indent with opening paren when { is entered on a new line after the closing paren + try %[ execute-keys -draft -itersel h)M \A\(.*\)\h*\n\h*\{\z s \A|.\z 1 ] +] + +define-command -hidden go-indent-on-closing-curly-brace %[ + # align to opening curly brace when alone on a line + try %[ execute-keys -itersel -draft ^\h+\}$hms\A|.\z1 ] +] + +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook -group go-highlight global WinSetOption filetype=go %{ + add-highlighter window/go ref go + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/go } +} + +hook global WinSetOption filetype=go %{ + # cleanup trailing whitespaces when exiting insert mode + hook window ModeChange insert:.* -group go-trim-indent %{ try %{ execute-keys -draft s^\h+$d } } + hook window InsertChar \n -group go-indent go-indent-on-new-line + hook window InsertChar \{ -group go-indent go-indent-on-opening-curly-brace + hook window InsertChar \} -group go-indent go-indent-on-closing-curly-brace + + hook -once -always window WinSetOption filetype=.* %{ remove-hooks window go-.+ } +} diff --git a/rc/filetype/haml.kak b/rc/filetype/haml.kak new file mode 100644 index 00000000..e3e7f593 --- /dev/null +++ b/rc/filetype/haml.kak @@ -0,0 +1,62 @@ +# http://haml.info +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +# Detection +# ‾‾‾‾‾‾‾‾‾ + +hook global BufCreate .*[.](haml) %{ + set-option buffer filetype haml +} + +# Highlighters +# ‾‾‾‾‾‾‾‾‾‾‾‾ + +add-highlighter shared/haml regions +add-highlighter shared/haml/code default-region group +add-highlighter shared/haml/comment region ^\h*/ $ fill comment + +# Filters +# http://haml.info/docs/yardoc/file.REFERENCE.html#filters +add-highlighter shared/haml/eval1 region -recurse \{ ^\h*%([A-Za-z][A-Za-z0-9_-]*)([#.][A-Za-z][A-Za-z0-9_-]*)?\{\K|#\{\K (?=\}) ref ruby +add-highlighter shared/haml/eval2 region ^\h*[=-]\K (? s \h+$ d } +} + +define-command -hidden haml-indent-on-new-line %{ + evaluate-commands -draft -itersel %{ + # copy '/' comment prefix and following white spaces + try %{ execute-keys -draft k s ^\h*\K/\h* y gh j P } + # preserve previous line indent + try %{ execute-keys -draft \; K } + # filter previous line + try %{ execute-keys -draft k : haml-trim-indent } + # indent after lines beginning with : or - + try %{ execute-keys -draft k ^\h*[:-] j } + } +} + +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook -group haml-highlight global WinSetOption filetype=haml %{ + add-highlighter window/haml ref haml + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/haml } +} + +hook global WinSetOption filetype=haml %{ + hook window ModeChange insert:.* -group haml-trim-indent haml-trim-indent + hook window InsertChar \n -group haml-indent haml-indent-on-new-line + + hook -once -always window WinSetOption filetype=.* %{ remove-hooks window haml-.+ } +} diff --git a/rc/filetype/haskell.kak b/rc/filetype/haskell.kak new file mode 100644 index 00000000..c51bcaf4 --- /dev/null +++ b/rc/filetype/haskell.kak @@ -0,0 +1,105 @@ +# http://haskell.org +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +# Detection +# ‾‾‾‾‾‾‾‾‾ + +hook global BufCreate .*[.](hs) %{ + set-option buffer filetype haskell +} + +# Highlighters +# ‾‾‾‾‾‾‾‾‾‾‾‾ + +add-highlighter shared/haskell regions +add-highlighter shared/haskell/code default-region group +add-highlighter shared/haskell/string region (??@\\\^|~=]|$) $ fill comment + +add-highlighter shared/haskell/code/ regex (?" +# Quantifier separator in "forall a . [a] -> [a]" +# Enum comprehensions like "[1..]" and "[a..b]" (making ".." and "Module..." illegal) + +# matches uppercase identifiers: Monad Control.Monad +# not non-space separated dot: Just.const +add-highlighter shared/haskell/code/ regex \b([A-Z]['\w]*\.)*[A-Z]['\w]*(?!['\w])(?![.a-z]) 0:variable + +# matches infix identifier: `mod` `Apa._T'M` +add-highlighter shared/haskell/code/ regex `\b([A-Z]['\w]*\.)*[\w]['\w]*` 0:operator +# matches imported operators: M.! M.. Control.Monad.>> +# not operator keywords: M... M.-> +add-highlighter shared/haskell/code/ regex \b[A-Z]['\w]*\.[~<=>|:!?/.@$*&#%+\^\-\\]+ 0:operator +# matches dot: . +# not possibly incomplete import: a. +# not other operators: !. .! +add-highlighter shared/haskell/code/ regex (?|:!?/.@$*&#%+\^\-\\])\.(?![~<=>|:!?/.@$*&#%+\^\-\\]) 0:operator +# matches other operators: ... > < <= ^ <*> <$> etc +# not dot: . +# not operator keywords: @ .. -> :: ~ +add-highlighter shared/haskell/code/ regex (?|:!?/.@$*&#%+\^\-\\])[~<=>|:!?/.@$*&#%+\^\-\\]+ 0:operator + +# matches operator keywords: @ -> +add-highlighter shared/haskell/code/ regex (?|:!?/.@$*&#%+\^\-\\])(@|~|<-|->|=>|::|=|:|[|])(?![~<=>|:!?/.@$*&#%+\^\-\\]) 1:keyword +# matches: forall [..variables..] . +# not the variables +add-highlighter shared/haskell/code/ regex \b(forall)\b[^.\n]*?(\.) 1:keyword 2:keyword + +# matches 'x' '\\' '\'' '\n' '\0' +# not incomplete literals: '\' +# not valid identifiers: w' _' +add-highlighter shared/haskell/code/ regex \B'([^\\]|[\\]['"\w\d\\])' 0:string +# this has to come after operators so '-' etc is correct + +# Commands +# ‾‾‾‾‾‾‾‾ + +# http://en.wikibooks.org/wiki/Haskell/Indentation + +define-command -hidden haskell-trim-indent %{ + # remove trailing white spaces + try %{ execute-keys -draft -itersel s \h+$ d } +} + +define-command -hidden haskell-indent-on-new-line %{ + evaluate-commands -draft -itersel %{ + # copy -- comments prefix and following white spaces + try %{ execute-keys -draft k s ^\h*\K--\h* y gh j P } + # preserve previous line indent + try %{ execute-keys -draft \; K } + # align to first clause + try %{ execute-keys -draft \; k x X s ^\h*(if|then|else)?\h*(([\w']+\h+)+=)?\h*(case\h+[\w']+\h+of|do|let|where)\h+\K.* s \A|.\z & } + # filter previous line + try %{ execute-keys -draft k : haskell-trim-indent } + # indent after lines beginning with condition or ending with expression or =( + try %{ execute-keys -draft \; k x ^\h*(if)|(case\h+[\w']+\h+of|do|let|where|[=(])$ j } + } +} + +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook -group haskell-highlight global WinSetOption filetype=haskell %{ + add-highlighter window/haskell ref haskell + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/haskell } +} + +hook global WinSetOption filetype=haskell %{ + set-option window extra_word_chars '_' "'" + hook window ModeChange insert:.* -group haskell-trim-indent haskell-trim-indent + hook window InsertChar \n -group haskell-indent haskell-indent-on-new-line + + hook -once -always window WinSetOption filetype=.* %{ remove-hooks window haskell-.+ } +} diff --git a/rc/filetype/hbs.kak b/rc/filetype/hbs.kak new file mode 100644 index 00000000..a0948e6f --- /dev/null +++ b/rc/filetype/hbs.kak @@ -0,0 +1,97 @@ +# http://handlebarsjs.com/ +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +# Detection +# ‾‾‾‾‾‾‾‾‾ + +hook global BufCreate .*[.](hbs) %{ + set-option buffer filetype hbs +} + +# Highlighters +# ‾‾‾‾‾‾‾‾‾‾‾‾ + +add-highlighter shared/hbs regions +add-highlighter shared/hbs/comment region \{\{!-- --\}\} fill comment +add-highlighter shared/hbs/comment_alt region \{\{! \}\} fill comment +add-highlighter shared/hbs/block-expression region \{\{[#/] \}\} regions +add-highlighter shared/hbs/expression region \{\{ \}\} regions + +define-command -hidden add-mutual-highlighters -params 1 %~ + add-highlighter "shared/hbs/%arg{1}/code" default-region group + add-highlighter "shared/hbs/%arg{1}/single-quote" region '"' (? s \h+$ d } +} + +define-command -hidden hbs-indent-on-char %[ + evaluate-commands -draft -itersel %[ + # de-indent after closing a yielded block tag + try %[ execute-keys -draft s ^\h+\{\{/([\w-.]+(?:/[\w-.]+)*)\}\}$ {c\{\{#1,\{\{/1\}\} s \A|.\z 1 ] + ] +] + +define-command -hidden hbs-indent-on-new-line %{ + evaluate-commands -draft -itersel %{ + # copy '/' comment prefix and following white spaces + try %{ execute-keys -draft k s ^\h*\K/\h* y j p } + # preserve previous line indent + try %{ execute-keys -draft \; K } + # filter previous line + try %{ execute-keys -draft k : hbs-trim-indent } + # indent after lines beginning with : or - + try %{ execute-keys -draft k ^\h*[:-] j } + } +} + +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +declare-option bool hbs_highlighters_enabled false + +define-command -hidden maybe-add-hbs-to-html %{ evaluate-commands %sh{ + if [ "$kak_opt_hbs_highlighters_enabled" == "false" ]; then + printf %s " + add-highlighter shared/html/hbs region '\{\{' '\}\}' ref hbs + add-highlighter shared/html/tag/hbs region '\{\{' '\}\}' ref hbs + set-option global hbs_highlighters_enabled true + " + fi +} } + +hook -group hbs-highlight global WinSetOption filetype=hbs %{ + maybe-add-hbs-to-html + add-highlighter window/hbs-file ref hbs-file + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/hbs-file } +} + +hook global WinSetOption filetype=hbs %{ + hook window ModeChange insert:.* -group hbs-trim-indent hbs-trim-indent + hook window InsertChar \n -group hbs-indent hbs-indent-on-new-line + hook window InsertChar .* -group hbs-indent hbs-indent-on-char + hook window InsertChar '>' -group hbs-indent html-indent-on-greater-than + hook window InsertChar \n -group hbs-indent html-indent-on-new-line + + hook -once -always window WinSetOption filetype=.* %{ remove-hooks window hbs-.+ } +} diff --git a/rc/filetype/html.kak b/rc/filetype/html.kak new file mode 100644 index 00000000..5f76721d --- /dev/null +++ b/rc/filetype/html.kak @@ -0,0 +1,75 @@ +# http://w3.org/html +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +# Detection +# ‾‾‾‾‾‾‾‾‾ + +hook global BufCreate .*\.html %{ + set-option buffer filetype html +} + +hook global BufCreate .*\.xml %{ + set-option buffer filetype xml +} + +# Highlighters +# ‾‾‾‾‾‾‾‾‾‾‾‾ + +add-highlighter shared/html regions +add-highlighter shared/html/comment region fill comment +add-highlighter shared/html/tag region < > regions +add-highlighter shared/html/style region \K (?=) ref css +add-highlighter shared/html/script region \K (?=) ref javascript + +add-highlighter shared/html/tag/base default-region group +add-highlighter shared/html/tag/ region '"' (? s \h+$ d } +} + +define-command -hidden html-indent-on-greater-than %[ + evaluate-commands -draft -itersel %[ + # align closing tag to opening when alone on a line + try %[ execute-keys -draft s ^\h+/(\w+)$ {c1,/1 s \A|.\z 1 ] + ] +] + +define-command -hidden html-indent-on-new-line %{ + evaluate-commands -draft -itersel %{ + # preserve previous line indent + try %{ execute-keys -draft \; K } + # filter previous line + try %{ execute-keys -draft k : html-trim-indent } + # indent after lines ending with opening tag + try %{ execute-keys -draft k (?!area)(?!base)(?!br)(?!col)(?!command)(?!embed)(?!hr)(?!img)(?!input)(?!keygen)(?!link)(?!menuitem)(?!meta)(?!param)(?!source)(?!track)(?!wbr)(?!/)(?!>)[a-zA-Z0-9_-]+[^>]*?>$ j } } +} + +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook -group html-highlight global WinSetOption filetype=(html|xml) %{ + add-highlighter "window/%val{hook_param_capture_1}" ref html + hook -once -always window WinSetOption "filetype=.*" " + remove-highlighter ""window/%val{hook_param_capture_1}"" + " +} + +hook global WinSetOption filetype=(html|xml) %{ + hook window ModeChange insert:.* -group "%val{hook_param_capture_1}-trim-indent" html-trim-indent + hook window InsertChar '>' -group "%val{hook_param_capture_1}-indent" html-indent-on-greater-than + hook window InsertChar \n -group "%val{hook_param_capture_1}-indent" html-indent-on-new-line + + hook -once -always window WinSetOption "filetype=.*" " + remove-hooks window ""%val{hook_param_capture_1}-.+"" + " +} diff --git a/rc/filetype/i3.kak b/rc/filetype/i3.kak new file mode 100644 index 00000000..e661fcd7 --- /dev/null +++ b/rc/filetype/i3.kak @@ -0,0 +1,81 @@ +hook global BufCreate .*(sway|i3)/config %{ + set buffer filetype i3 +} + +add-highlighter shared/i3 regions +add-highlighter shared/i3/code default-region group +add-highlighter shared/i3/double_string region %{"} %{"} group +add-highlighter shared/i3/single_string region %{'} %{'} group +add-highlighter shared/i3/exec region %{((?<=exec )|(?<=--no-startup-id ))(?!--no-startup-id)} "$" fill string +add-highlighter shared/i3/comment region "#" "$" fill comment + +add-highlighter shared/i3/double_string/ fill string +add-highlighter shared/i3/single_string/ fill string + +# Symbols +add-highlighter shared/i3/code/ regex "[+|→]" 0:operator +add-highlighter shared/i3/code/ regex "\$\w+" 0:variable + +# keys +add-highlighter shared/i3/code/ regex "\b(Shift|Control|Ctrl|Mod1|Mod2|Mod3|Mod4|Mod5|Mode_switch|Return|Escape|Print)\b" 0:value + +# keywords +add-highlighter shared/i3/code/ regex "\b(bind|bindcode|bindsym|assign|new_window|default_(floating_)?border|popup_during_fullscreen|font|floating_modifier|default_orientation|workspace_layout|for_window|focus_follows_mouse|bar|position|colors|output|tray_output|workspace_buttons|workspace_auto_back_and_forth|binding_mode_indicator|debuglog|floating_minimum_size|floating_maximum_size|force_focus_wrapping|force_xinerama|force_display_urgency_hint|hidden_state|modifier|new_float|shmlog|socket_path|verbose|mouse_warping|strip_workspace_numbers|focus_on_window_activation|no_focus|set|mode|set_from_resource)\b" 0:keyword +# function keywords +add-highlighter shared/i3/code/ regex "\b(exit|reload|restart|kill|fullscreen|global|layout|border|focus|move|open|split|append_layout|mark|unmark|resize|grow|shrink|show|nop|rename|title_format|sticky)\b" 0:function +add-highlighter shared/i3/code/ regex "\b(exec|exec_always|i3bar_command|status_command)\b" 0:function +# " these are not keywords but we add them for consistency +add-highlighter shared/i3/code/ regex "\b(no|false|inactive)\b" 0:value + +# values +add-highlighter shared/i3/code/ regex "\b(1pixel|default|stacked|tabbed|normal|none|tiling|stacking|floating|enable|disable|up|down|horizontal|vertical|auto|up|down|left|right|parent|child|px|or|ppt|leave_fullscreen|toggle|mode_toggle|scratchpad|width|height|top|bottom|client|hide|primary|yes|all|active|window|container|to|absolute|center|on|off|ms|smart|ignore|pixel|splith|splitv|output|true)\b" 0:value +add-highlighter shared/i3/code/ regex "\b(next|prev|next_on_output|prev_on_output|back_and_forth|current|number|none|vertical|horizontal|both|dock|hide|invisible|gaps|smart_gaps|smart_borders|inner|outer|current|all|plus|minus|no_gaps)\b" 0:value + +# double-dash arguments +add-highlighter shared/i3/code/ regex "--(release|border|whole-window|toggle|no-startup-id)" 0:attribute + +# color +add-highlighter shared/i3/double_string/ regex "#[0-9a-fA-F]{6}" 0:value +add-highlighter shared/i3/single_string/ regex "#[0-9a-fA-F]{6}" 0:value + +# attributes +add-highlighter shared/i3/code/ regex "client\.(background|statusline|background|separator|statusline)" 1:attribute +add-highlighter shared/i3/code/ regex "client\.(focused_inactive|focused|unfocused|urgent|inactive_workspace|urgent_workspace|focused_workspace|active_workspace|placeholder)" 1:attribute + +# Commands +# ‾‾‾‾‾‾‾‾ + +define-command -hidden i3-indent-on-new-line %~ + evaluate-commands -draft -itersel %= + # copy # comments prefix + try %{ execute-keys -draft k s ^\h*#\h* y jgh P } + # preserve previous line indent + try %{ execute-keys -draft \;K } + # indent after lines ending with { + try %[ execute-keys -draft k \{\h*$ j ] + # cleanup trailing white spaces on the previous line + try %{ execute-keys -draft k s \h+$ d } + = +~ + +define-command -hidden i3-indent-on-closing-curly-brace %[ + # align to opening curly brace when alone on a line + try %[ execute-keys -itersel -draft ^\h+\}$hms\A|.\z1 ] +] + +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook -group i3-highlight global WinSetOption filetype=i3 %{ + add-highlighter window/i3 ref i3 + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/i3 } +} + +hook global WinSetOption filetype=i3 %[ + # cleanup trailing whitespaces when exiting insert mode + hook window ModeChange insert:.* -group i3-trim-indent %{ try %{ execute-keys -draft s^\h+$d } } + hook window InsertChar \n -group i3-indent i3-indent-on-new-line + hook window InsertChar \} -group i3-indent i3-indent-on-closing-curly-brace + + hook -once -always window WinSetOption filetype=.* %{ remove-hooks window i3-.+ } +] diff --git a/rc/filetype/ini.kak b/rc/filetype/ini.kak new file mode 100644 index 00000000..c03cae4e --- /dev/null +++ b/rc/filetype/ini.kak @@ -0,0 +1,15 @@ +hook global BufCreate .+\.(repo|ini|cfg|properties) %{ + set-option buffer filetype ini +} + +add-highlighter shared/ini regions +add-highlighter shared/ini/code default-region group +add-highlighter shared/ini/comment region '(^|\h)\K[#;]' $ fill comment + +add-highlighter shared/ini/code/ regex "^\h*\[[^\]]*\]" 0:title +add-highlighter shared/ini/code/ regex "^\h*([^\[][^=\n]*)=([^\n]*)" 1:variable 2:value + +hook -group ini-highlight global WinSetOption filetype=ini %{ + add-highlighter window/ini ref ini + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/ini } +} diff --git a/rc/filetype/java.kak b/rc/filetype/java.kak new file mode 100644 index 00000000..7caa5aee --- /dev/null +++ b/rc/filetype/java.kak @@ -0,0 +1,65 @@ +hook global BufCreate .*\.java %{ + set-option buffer filetype java +} + +add-highlighter shared/java regions +add-highlighter shared/java/code default-region group +add-highlighter shared/java/string region %{(? } + # indent after lines ending with { or ( + try %[ execute-keys -draft k [{(]\h*$ j ] + # cleanup trailing white spaces on the previous line + try %{ execute-keys -draft k s \h+$ d } + # align to opening paren of previous line + try %{ execute-keys -draft [( \A\([^\n]+\n[^\n]*\n?\z s \A\(\h*.|.\z '' & } + # copy // comments prefix + try %{ execute-keys -draft \;k s ^\h*\K/{2,} yP } + # indent after a switch's case/default statements + try %[ execute-keys -draft k ^\h*(case|default).*:$ j ] + # indent after keywords + try %[ execute-keys -draft \;)MB \A(if|else|while|for|try|catch)\h*\(.*\)\h*\n\h*\n?\z s \A|.\z 11 ] + = +~ + +define-command -hidden java-indent-on-opening-curly-brace %[ + # align indent with opening paren when { is entered on a new line after the closing paren + try %[ execute-keys -draft -itersel h)M \A\(.*\)\h*\n\h*\{\z s \A|.\z 1 ] +] + +define-command -hidden java-indent-on-closing-curly-brace %[ + # align to opening curly brace when alone on a line + try %[ execute-keys -itersel -draft ^\h+\}$hms\A|.\z1 ] +] + +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook -group java-highlight global WinSetOption filetype=java %{ + add-highlighter window/java ref java + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/java } +} + +hook global WinSetOption filetype=java %{ + # cleanup trailing whitespaces when exiting insert mode + hook window ModeChange insert:.* -group java-trim-indent %{ try %{ execute-keys -draft s^\h+$d } } + hook window InsertChar \n -group java-indent java-indent-on-new-line + hook window InsertChar \{ -group java-indent java-indent-on-opening-curly-brace + hook window InsertChar \} -group java-indent java-indent-on-closing-curly-brace + + hook -once -always window WinSetOption filetype=.* %{ remove-hooks window java-.+ } +} diff --git a/rc/filetype/javascript.kak b/rc/filetype/javascript.kak new file mode 100644 index 00000000..4d16ee68 --- /dev/null +++ b/rc/filetype/javascript.kak @@ -0,0 +1,117 @@ +# Detection +# ‾‾‾‾‾‾‾‾‾ + +hook global BufCreate .*[.](js)x? %{ + set-option buffer filetype javascript +} + +hook global BufCreate .*[.](ts)x? %{ + set-option buffer filetype typescript +} + +# Commands +# ‾‾‾‾‾‾‾‾ + +define-command -hidden javascript-trim-indent %{ + # remove trailing white spaces + try %{ execute-keys -draft -itersel s \h+$ d } +} + +define-command -hidden javascript-indent-on-char %< + evaluate-commands -draft -itersel %< + # align closer token to its opener when alone on a line + try %/ execute-keys -draft ^\h+[\]}]$ m s \A|.\z 1 / + > +> + +define-command -hidden javascript-indent-on-new-line %< + evaluate-commands -draft -itersel %< + # copy // comments prefix and following white spaces + try %{ execute-keys -draft k s ^\h*\K#\h* y gh j P } + # preserve previous line indent + try %{ execute-keys -draft \; K } + # filter previous line + try %{ execute-keys -draft k : javascript-trim-indent } + # indent after lines beginning / ending with opener token + try %_ execute-keys -draft k ^\h*[[{]|[[{]$ j _ + > +> + +# Highlighting and hooks bulder for JavaScript and TypeScript +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ +define-command -hidden init-javascript-filetype -params 1 %~ + # Highlighters + # ‾‾‾‾‾‾‾‾‾‾‾‾ + + add-highlighter "shared/%arg{1}" regions + add-highlighter "shared/%arg{1}/code" default-region group + add-highlighter "shared/%arg{1}/double_string" region '"' (?])(?!>\()) (|/>) regions + add-highlighter "shared/%arg{1}/division" region '[\w\)\]]\K(/|(\h+/\h+))' '(?=\w)' group # Help Kakoune to better detect /…/ literals + + # Regular expression flags are: g → global match, i → ignore case, m → multi-lines, u → unicode, y → sticky + # https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp + + add-highlighter "shared/%arg{1}/literal/" fill string + add-highlighter "shared/%arg{1}/literal/" regex \$\{.*?\} 0:value + + add-highlighter "shared/%arg{1}/code/" regex [^$_]\b(document|false|null|parent|self|this|true|undefined|window)\b 1:value + add-highlighter "shared/%arg{1}/code/" regex "-?\b[0-9]*\.?[0-9]+" 0:value + add-highlighter "shared/%arg{1}/code/" regex \b(Array|Boolean|Date|Function|Number|Object|RegExp|String|Symbol)\b 0:type + + # jsx: In well-formed xml the number of opening and closing tags match up regardless of tag name. + # + # We inline a small XML highlighter here since it anyway need to recurse back up to the starting highlighter. + # To make things simple we assume that jsx is always enabled. + + add-highlighter "shared/%arg{1}/jsx/tag" region -recurse < <(?=[/a-zA-Z]) (? regions + add-highlighter "shared/%arg{1}/jsx/expr" region -recurse \{ \{ \} ref %arg{1} + + add-highlighter "shared/%arg{1}/jsx/tag/base" default-region group + add-highlighter "shared/%arg{1}/jsx/tag/double_string" region =\K" (?) 0:meta + + add-highlighter "shared/%arg{1}/jsx/tag/expr/" ref %arg{1} + + # Keywords are collected at + # https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#Keywords + add-highlighter "shared/%arg{1}/code/" regex \b(async|await|break|case|catch|class|const|continue|debugger|default|delete|do|else|export|extends|finally|for|function|if|import|in|instanceof|let|new|of|return|static|super|switch|throw|try|typeof|var|void|while|with|yield)\b 0:keyword + + # Initialization + # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + + hook -group "%arg{1}-highlight" global WinSetOption "filetype=%arg{1}" " + add-highlighter window/%arg{1} ref %arg{1} + + hook -once -always window WinSetOption filetype=.* %%{ remove-highlighter window/%arg{1} } + " + + hook global WinSetOption "filetype=%arg{1}" " + hook window ModeChange insert:.* -group %arg{1}-trim-indent javascript-trim-indent + hook window InsertChar .* -group %arg{1}-indent javascript-indent-on-char + hook window InsertChar \n -group %arg{1}-indent javascript-indent-on-new-line + + hook -once -always window WinSetOption filetype=.* %%{ remove-hooks window %arg{1}-.+ } + " +~ + +init-javascript-filetype javascript +init-javascript-filetype typescript + +# Highlighting specific to TypeScript +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ +add-highlighter shared/typescript/code/ regex \b(array|boolean|date|number|object|regexp|string|symbol)\b 0:type + +# Keywords grabbed from https://github.com/Microsoft/TypeScript/issues/2536 +add-highlighter shared/typescript/code/ regex \b(as|constructor|declare|enum|from|implements|interface|module|namespace|package|private|protected|public|readonly|static|type)\b 0:keyword diff --git a/rc/filetype/json.kak b/rc/filetype/json.kak new file mode 100644 index 00000000..ae04c55a --- /dev/null +++ b/rc/filetype/json.kak @@ -0,0 +1,60 @@ +# http://json.org +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +# Detection +# ‾‾‾‾‾‾‾‾‾ + +hook global BufCreate .*[.](json) %{ + set-option buffer filetype json +} + +# Highlighters +# ‾‾‾‾‾‾‾‾‾‾‾‾ + +add-highlighter shared/json regions +add-highlighter shared/json/code default-region group +add-highlighter shared/json/string region '"' (? s \h+$ d } +} + +define-command -hidden json-indent-on-char %< + evaluate-commands -draft -itersel %< + # align closer token to its opener when alone on a line + try %< execute-keys -draft ^\h+[]}]$ m s \A|.\z 1 > + > +> + +define-command -hidden json-indent-on-new-line %< + evaluate-commands -draft -itersel %< + # preserve previous line indent + try %{ execute-keys -draft \; K } + # filter previous line + try %{ execute-keys -draft k : json-trim-indent } + # indent after lines beginning with opener token + try %< execute-keys -draft k ^\h*[[{] j > + > +> + +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook -group json-highlight global WinSetOption filetype=json %{ + add-highlighter window/json ref json + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/json } +} + +hook global WinSetOption filetype=json %{ + hook window ModeChange insert:.* -group json-trim-indent json-trim-indent + hook window InsertChar .* -group json-indent json-indent-on-char + hook window InsertChar \n -group json-indent json-indent-on-new-line + + hook -once -always window WinSetOption filetype=.* %{ remove-hooks window json-.+ } +} diff --git a/rc/filetype/julia.kak b/rc/filetype/julia.kak new file mode 100644 index 00000000..abdf547a --- /dev/null +++ b/rc/filetype/julia.kak @@ -0,0 +1,30 @@ +# http://julialang.org +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +# Detection +# ‾‾‾‾‾‾‾‾‾ + +hook global BufCreate .*\.(jl) %{ + set-option buffer filetype julia +} + +# Highlighters +# ‾‾‾‾‾‾‾‾‾‾‾‾ + +add-highlighter shared/julia regions +add-highlighter shared/julia/code default-region group +add-highlighter shared/julia/string region '"' (? } + # cleanup trailing white spaces on previous line + try %{ execute-keys -draft k s \h+$ "_d } + # copy '#' comment prefix and following white spaces + try %{ execute-keys -draft k s ^\h*//\h* y jgh P } + } +} + +# Highlighters +# ‾‾‾‾‾‾‾‾‾‾‾‾ + +add-highlighter shared/justfile regions +add-highlighter shared/justfile/content default-region group +add-highlighter shared/justfile/comment region '#' '$' fill comment +add-highlighter shared/justfile/double_string region '"' (?' ref sh +add-highlighter shared/kakrc/shell5 region -recurse '\{' '(^|\h)\K-shell-script-(completion|candidates)\h+%\{' '\}' ref sh +add-highlighter shared/kakrc/shell6 region -recurse '\(' '(^|\h)\K-shell-script-(completion|candidates)\h+%\(' '\)' ref sh +add-highlighter shared/kakrc/shell7 region -recurse '\[' '(^|\h)\K-shell-script-(completion|candidates)\h+%\[' '\]' ref sh +add-highlighter shared/kakrc/shell8 region -recurse '<' '(^|\h)\K-shell-script-(completion|candidates)\h+%<' '>' ref sh + +evaluate-commands %sh{ + # Grammar + keywords="edit write write-all kill quit write-quit write-all-quit map unmap alias unalias + buffer buffer-next buffer-previous delete-buffer add-highlighter remove-highlighter + hook remove-hooks define-command echo debug source try catch fail nop + set-option unset-option update-option declare-option execute-keys evaluate-commands + prompt menu on-key info set-face unset-face rename-client set-register select + change-directory rename-session colorscheme declare-user-mode enter-user-mode + edit! write! kill! quit! write-quit! delete-buffer!" + attributes="global buffer window current + normal insert menu prompt goto view user object + number-lines show-matching show-whitespaces fill regex dynregex group flag-lines + ranges line column wrap ref regions region default-region replace-ranges" + types="int bool str regex int-list str-list completions line-specs range-specs" + values="default black red green yellow blue magenta cyan white yes no false true" + + join() { sep=$2; eval set -- $1; IFS="$sep"; echo "$*"; } + + # Add the language's grammar to the static completion list + printf '%s\n' "hook global WinSetOption filetype=kak %{ + set-option window static_words $(join "${keywords} ${attributes} ${types} ${values}" ' ')' + set-option -- window extra_word_chars '_' '-' + }" + + # Highlight keywords (which are always surrounded by whitespace) + printf '%s\n' "add-highlighter shared/kakrc/code/keywords regex (?:\s|\A)\K($(join "${keywords}" '|'))(?:(?=\s)|\z) 0:keyword + add-highlighter shared/kakrc/code/attributes regex (?:\s|\A)\K($(join "${attributes}" '|'))(?:(?=\s)|\z) 0:attribute + add-highlighter shared/kakrc/code/types regex (?:\s|\A)\K($(join "${types}" '|'))(?:(?=\s)|\z) 0:type + add-highlighter shared/kakrc/code/values regex (?:\s|\A)\K($(join "${values}" '|'))(?:(?=\s)|\z) 0:value" +} + +add-highlighter shared/kakrc/code/colors regex \brgb:[0-9a-fA-F]{6}\b 0:value +add-highlighter shared/kakrc/code/scopes regex \b(global|shared|buffer|window)(?:\b|/) 0:value + +add-highlighter shared/kakrc/double_string/fill fill string +add-highlighter shared/kakrc/double_string/escape regex '""' 0:default+b +add-highlighter shared/kakrc/single_string/fill fill string +add-highlighter shared/kakrc/single_string/escape regex "''" 0:default+b + +# Commands +# ‾‾‾‾‾‾‾‾ + +define-command -hidden kak-indent-on-new-line %{ + evaluate-commands -draft -itersel %{ + # copy '#' comment prefix and following white spaces + try %{ execute-keys -draft k s ^\h*#\h* y jgh P } + # preserve previous line indent + try %{ execute-keys -draft \; K } + # cleanup trailing whitespaces from previous line + try %{ execute-keys -draft k s \h+$ d } + # indent after line ending with %\w*[^\s\w] + try %{ execute-keys -draft k \%\w*[^\s\w]$ j } + } +} + +define-command -hidden kak-indent-on-closing-matching %~ + # align to opening matching brace when alone on a line + try %= execute-keys -draft -itersel ^\h*\Q %val{hook_param} \E$ mGi s \A|.\z 1 = +~ + +define-command -hidden kak-indent-on-closing-char %{ + # align to opening matching character when alone on a line + try %{ execute-keys -draft -itersel ^\h*\Q %val{hook_param} \E$gi %val{hook_param} %\w*\Q %val{hook_param} \E$ s \A|.\z gi 1 } +} + +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook -group kak-highlight global WinSetOption filetype=kak %{ + add-highlighter window/kakrc ref kakrc + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/kakrc } +} + +hook global WinSetOption filetype=kak %~ + hook window InsertChar \n -group kak-indent kak-indent-on-new-line + hook window InsertChar [>)}\]] -group kak-indent kak-indent-on-closing-matching + hook window InsertChar (?![[{(<>)}\]])[^\s\w] -group kak-indent kak-indent-on-closing-char + # cleanup trailing whitespaces on current line insert end + hook window ModeChange insert:.* -group kak-trim-indent %{ try %{ execute-keys -draft \; s ^\h+$ d } } + set-option buffer extra_word_chars '_' '-' + + hook -once -always window WinSetOption filetype=.* %{ remove-hooks window kak-.+ } +~ diff --git a/rc/filetype/kickstart.kak b/rc/filetype/kickstart.kak new file mode 100644 index 00000000..6f30b4b8 --- /dev/null +++ b/rc/filetype/kickstart.kak @@ -0,0 +1,30 @@ +hook global BufCreate .*\.ks %{ + set-option buffer filetype kickstart +} + +add-highlighter shared/kickstart regions +add-highlighter shared/kickstart/code default-region group +add-highlighter shared/kickstart/comment region '(^|\h)\K#' $ fill comment +add-highlighter shared/kickstart/double_string region '"' (?|<=|=|>=) 0:operator +add-highlighter shared/lisp/code/ regex \b(def[a-z]+|if|do|let|lambda|catch|and|assert|while|def|do|fn|finally|let|loop|new|quote|recur|set!|throw|try|var|case|if-let|if-not|when|when-first|when-let|when-not|(cond(->|->>)?))\b 0:keyword +add-highlighter shared/lisp/code/ regex (#?(['`:]|,@?))?\b[a-zA-Z][\w!$%&*+./:<=>?@^_~-]* 0:variable +add-highlighter shared/lisp/code/ regex \*[a-zA-Z][\w!$%&*+./:<=>?@^_~-]*\* 0:variable +add-highlighter shared/lisp/code/ regex (\b\d+)?\.\d+([eEsSfFdDlL]\d+)?\b 0:value + +# Commands +# ‾‾‾‾‾‾‾‾ + +define-command -hidden lisp-trim-indent %{ + # remove trailing white spaces + try %{ execute-keys -draft -itersel s \h+$ d } +} + +declare-option \ + -docstring 'regex matching the head of forms which have options *and* indented bodies' \ + regex lisp_special_indent_forms \ + '(?:def.*|if(-.*|)|let.*|lambda|with-.*|when(-.*|))' + +define-command -hidden lisp-indent-on-new-line %{ + # registers: i = best align point so far; w = start of first word of form + evaluate-commands -draft -save-regs '/"|^@iw' -itersel %{ + execute-keys -draft 'gk"iZ' + try %{ + execute-keys -draft '[bl"i"wZ' + + try %{ + # If a special form, indent another (indentwidth - 1) spaces + execute-keys -draft '"wze\A' %opt{lisp_special_indent_forms} '\z' + execute-keys -draft '"wzes.{' %sh{printf $(( kak_opt_indentwidth - 1 ))} '}\K.*;"i' + } catch %{ + # If not "special" form and parameter appears on line 1, indent to parameter + execute-keys -draft '"wzes\h\K[^\s].*;"i' + } + } + try %{ execute-keys -draft '[rl"i' } + try %{ execute-keys -draft '[Bl"i' } + execute-keys -draft ';"ia&' + } +} + +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook -group lisp-highlight global WinSetOption filetype=lisp %{ + add-highlighter window/lisp ref lisp + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/lisp } +} + +hook global WinSetOption filetype=lisp %{ + hook window ModeChange insert:.* -group lisp-trim-indent lisp-trim-indent + hook window InsertChar \n -group lisp-indent lisp-indent-on-new-line + + hook -once -always window WinSetOption filetype=.* %{ remove-hooks window lisp-.+ } +} diff --git a/rc/filetype/lua.kak b/rc/filetype/lua.kak new file mode 100644 index 00000000..605148e0 --- /dev/null +++ b/rc/filetype/lua.kak @@ -0,0 +1,103 @@ +# http://lua.org +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +# Detection +# ‾‾‾‾‾‾‾‾‾ + +hook global BufCreate .*[.](lua) %{ + set-option buffer filetype lua +} + +# Highlighters +# ‾‾‾‾‾‾‾‾‾‾‾‾ + +add-highlighter shared/lua regions +add-highlighter shared/lua/code default-region group +add-highlighter shared/lua/raw_string region -match-capture '\[(=*)\[' '\](=*)\]' fill string +add-highlighter shared/lua/raw_comment region -match-capture '--\[(=*)\[' '\](=*)\]' fill comment +add-highlighter shared/lua/double_string region '"' (?^\h*(else)$^\h*(if)s\A|\z) } + try %{ execute-keys -draft ^\h*(end)$^\h*(for|function|if|while)s\A|\z) } + } +} + +define-command -hidden lua-indent-on-new-line %{ + evaluate-commands -no-hooks -draft -itersel %{ + # preserve previous line indent + try %{ execute-keys -draft K } + # remove trailing white spaces from previous line + try %{ execute-keys -draft ks\h+$d } + # indent after start structure + try %{ execute-keys -draft k^\h*(else|elseif|for|function|if|while)\bj } + } +} + +define-command -hidden lua-insert-on-new-line %[ + evaluate-commands -no-hooks -draft -itersel %[ + # copy -- comment prefix and following white spaces + try %{ execute-keys -draft ks^\h*\K--\h*yghjP } + # wisely add end structure + evaluate-commands -save-regs x %[ + try %{ execute-keys -draft ks^\h+"xy } catch %{ reg x '' } # Save previous line indent in register x + try %[ execute-keys -draft k ^x(for|function|if|while) J}iJ ^x(else|end|elseif)$ # Validate previous line and that it is not closed yet + execute-keys -draft oxend ] # auto insert end + ] + ] +] + +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook -group lua-highlight global WinSetOption filetype=lua %{ + add-highlighter window/lua ref lua + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/lua } +} + +hook global WinSetOption filetype=lua %{ + hook window InsertChar .* -group lua-indent lua-indent-on-char + hook window InsertChar \n -group lua-indent lua-indent-on-new-line + hook window InsertChar \n -group lua-insert lua-insert-on-new-line + + alias window alt lua-alternative-file + + hook -once -always window WinSetOption filetype=.* %{ + remove-hooks window lua-.+ + unalias window alt lua-alternative-file + } +} diff --git a/rc/filetype/mail.kak b/rc/filetype/mail.kak new file mode 100644 index 00000000..4323d28c --- /dev/null +++ b/rc/filetype/mail.kak @@ -0,0 +1,13 @@ +hook global BufCreate .+\.eml %{ + set-option buffer filetype mail +} + +add-highlighter shared/mail group +add-highlighter shared/mail/ regex ^(From|To|Cc|Bcc|Subject|Reply-To|In-Reply-To|Date):([^\n]*(?:\n\h+[^\n]+)*)$ 1:keyword 2:attribute +add-highlighter shared/mail/ regex <[^@>]+@.*?> 0:string +add-highlighter shared/mail/ regex ^>.*?$ 0:comment + +hook -group mail-highlight global WinSetOption filetype=mail %{ + add-highlighter window/mail ref mail + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/mail } +} diff --git a/rc/filetype/makefile.kak b/rc/filetype/makefile.kak new file mode 100644 index 00000000..569d51f9 --- /dev/null +++ b/rc/filetype/makefile.kak @@ -0,0 +1,60 @@ +# Detection +# ‾‾‾‾‾‾‾‾‾ + +hook global BufCreate .*(/?[mM]akefile|\.mk) %{ + set-option buffer filetype makefile +} + +# Highlighters +# ‾‾‾‾‾‾‾‾‾‾‾‾ + +add-highlighter shared/makefile regions + +add-highlighter shared/makefile/content default-region group +add-highlighter shared/makefile/comment region '#' '$' fill comment +add-highlighter shared/makefile/evaluate-commands region -recurse '\(' '\$\(' '\)' fill value + +add-highlighter shared/makefile/content/ regex ^[\w.%-]+\h*:\s 0:variable +add-highlighter shared/makefile/content/ regex [+?:]= 0:operator + +evaluate-commands %sh{ + # Grammar + keywords="ifeq|ifneq|ifdef|ifndef|else|endif|define|endef" + + # Add the language's grammar to the static completion list + printf %s\\n "hook global WinSetOption filetype=makefile %{ + set-option window static_words ${keywords} + }" | tr '|' ' ' + + # Highlight keywords + printf %s "add-highlighter shared/makefile/content/ regex \b(${keywords})\b 0:keyword" +} + +# Commands +# ‾‾‾‾‾‾‾‾ + +define-command -hidden makefile-indent-on-new-line %{ + evaluate-commands -draft -itersel %{ + # preserve previous line indent + try %{ execute-keys -draft \;K } + ## If the line above is a target indent with a tab + try %{ execute-keys -draft Z k ^[^:]+:\s z i } + # cleanup trailing white space son previous line + try %{ execute-keys -draft k s \h+$ d } + # indent after some keywords + try %{ execute-keys -draft Z k ^\h*(ifeq|ifneq|ifdef|ifndef|else|define)\b z } + } +} + +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook -group makefile-highlight global WinSetOption filetype=makefile %{ + add-highlighter window/makefile ref makefile + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/makefile } +} + +hook global WinSetOption filetype=makefile %{ + hook window InsertChar \n -group makefile-indent makefile-indent-on-new-line + hook -once -always window WinSetOption filetype=.* %{ remove-hooks window makefile-.+ } +} diff --git a/rc/filetype/markdown.kak b/rc/filetype/markdown.kak new file mode 100644 index 00000000..18f3ccf6 --- /dev/null +++ b/rc/filetype/markdown.kak @@ -0,0 +1,85 @@ +# http://daringfireball.net/projects/markdown +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +# Detection +# ‾‾‾‾‾‾‾‾‾ + +hook global BufCreate .*[.](markdown|md|mkd) %{ + set-option buffer filetype markdown +} + +# Highlighters +# ‾‾‾‾‾‾‾‾‾‾‾‾ + +add-highlighter shared/markdown regions +add-highlighter shared/markdown/inline default-region regions +add-highlighter shared/markdown/inline/text default-region group + +evaluate-commands %sh{ + languages=" + c cabal clojure coffee cpp css cucumber d diff dockerfile fish gas go + haml haskell html ini java javascript json julia kak kickstart latex + lisp lua makefile markdown moon objc perl pug python ragel ruby rust + sass scala scss sh swift toml tupfile typescript yaml sql + " + for lang in ${languages}; do + printf 'add-highlighter shared/markdown/%s region -match-capture ^(\h*)```\h*%s\\b ^(\h*)``` regions\n' "${lang}" "${lang}" + printf 'add-highlighter shared/markdown/%s/ default-region fill meta\n' "${lang}" + [ "${lang}" = kak ] && ref=kakrc || ref="${lang}" + printf 'add-highlighter shared/markdown/%s/inner region \A```[^\\n]*\K (?=```) ref %s\n' "${lang}" "${ref}" + done +} + +add-highlighter shared/markdown/codeblock region -match-capture \ + ^(\h*)```\h* \ + ^(\h*)```\h*$ \ + fill meta + +add-highlighter shared/markdown/listblock region ^\h*[-*]\s ^\h*((?=[-*])|$) regions +add-highlighter shared/markdown/listblock/marker region \A [-*]\s fill bullet +add-highlighter shared/markdown/listblock/content default-region ref markdown/inline + +add-highlighter shared/markdown/inline/code region -match-capture (`+) (`+) fill mono + +# Setext-style header +add-highlighter shared/markdown/inline/text/ regex (\A|\n\n)[^\n]+\n={2,}\h*\n\h*$ 0:title +add-highlighter shared/markdown/inline/text/ regex (\A|\n\n)[^\n]+\n-{2,}\h*\n\h*$ 0:header + +# Atx-style header +add-highlighter shared/markdown/inline/text/ regex ^#[^\n]* 0:header + +add-highlighter shared/markdown/inline/text/ regex (? 0:link +add-highlighter shared/markdown/inline/text/ regex ^\[[^\]\n]*\]:\h*([^\n]*) 1:link +add-highlighter shared/markdown/inline/text/ regex ^\h*(>\h*)+ 0:comment +add-highlighter shared/markdown/inline/text/ regex \H\K\h\h$ 0:PrimarySelection + +# Commands +# ‾‾‾‾‾‾‾‾ + +define-command -hidden markdown-indent-on-new-line %{ + evaluate-commands -draft -itersel %{ + # copy block quote(s), list item prefix and following white spaces + try %{ execute-keys -draft k s ^\h*\K((>\h*)+([*+-]\h)?|(>\h*)*[*+-]\h)\h* y gh j P } + # preserve previous line indent + try %{ execute-keys -draft \; K } + # remove trailing white spaces + try %{ execute-keys -draft -itersel %{ k s \h+$ d } } + } +} + +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook -group markdown-highlight global WinSetOption filetype=markdown %{ + add-highlighter window/markdown ref markdown + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/markdown } +} + +hook global WinSetOption filetype=markdown %{ + hook window InsertChar \n -group markdown-indent markdown-indent-on-new-line + hook -once -always window WinSetOption filetype=.* %{ remove-hooks window markdown-.+ } +} diff --git a/rc/filetype/mercurial.kak b/rc/filetype/mercurial.kak new file mode 100644 index 00000000..3f84eea2 --- /dev/null +++ b/rc/filetype/mercurial.kak @@ -0,0 +1,18 @@ +# https://www.mercurial-scm.org/ +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +# Detection +# ‾‾‾‾‾‾‾‾‾ + +hook global BufCreate .*hg-editor-\w+\.txt$ %{ + set-option buffer filetype hg-commit +} + +# Highlighters +# ‾‾‾‾‾‾‾‾‾‾‾‾ + +hook -group hg-commit-highlight global WinSetOption filetype=hg-commit %{ + add-highlighter window/ group hg-commit-highlight + add-highlighter window/hg-commit-highlight regex '^HG:[^\n]*' 0:comment + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/hg-commit-highlight } +} diff --git a/rc/filetype/moon.kak b/rc/filetype/moon.kak new file mode 100644 index 00000000..a1d2ecb8 --- /dev/null +++ b/rc/filetype/moon.kak @@ -0,0 +1,107 @@ +# http://moonscript.org +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +# Detection +# ‾‾‾‾‾‾‾‾‾ + +hook global BufCreate .*[.](moon) %{ + set-option buffer filetype moon +} + +# Highlighters +# ‾‾‾‾‾‾‾‾‾‾‾‾ + +add-highlighter shared/moon regions +add-highlighter shared/moon/code default-region group +add-highlighter shared/moon/double_string region '"' (? + # remove trailing white spaces + try %{ execute-keys -draft s \h + $ d } + } +} + +define-command -hidden moon-indent-on-char %{ + evaluate-commands -draft -itersel %{ + # align _else_ statements to start + try %{ execute-keys -draft ^ \h * (else(if)?) $ ^ \h * (if|unless|when) s \A | \z ) } + # align _when_ to _switch_ then indent + try %{ execute-keys -draft ^ \h * (when) $ ^ \h * (switch) s \A | \z ) ) } + # align _catch_ and _finally_ to _try_ + try %{ execute-keys -draft ^ \h * (catch|finally) $ ^ \h * (try) s \A | \z ) } + } +} + +define-command -hidden moon-indent-on-new-line %{ + evaluate-commands -draft -itersel %{ + # copy -- comment prefix and following white spaces + try %{ execute-keys -draft k s ^ \h * \K -- \h * y gh j P } + # preserve previous line indent + try %{ execute-keys -draft \; K } + # filter previous line + try %{ execute-keys -draft k : moon-trim-indent } + # indent after start structure + try %{ execute-keys -draft k ^ \h * (class|else(if)?|for|if|switch|unless|when|while|with) \b | ([:=]|[-=]>) $ j } + # deindent after return statements + try %{ execute-keys -draft k ^ \h * (break|return) \b j } + } +} + +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook -group moon-highlight global WinSetOption filetype=moon %{ + add-highlighter window/moon ref moon + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/moon } +} + +hook global WinSetOption filetype=moon %{ + hook window ModeChange insert:.* -group moon-trim-indent moon-trim-indent + hook window InsertChar .* -group moon-indent moon-indent-on-char + hook window InsertChar \n -group moon-indent moon-indent-on-new-line + + alias window alt moon-alternative-file + + hook -once -always window WinSetOption filetype=.* %{ + remove-hooks window moon-.+ + unalias window alt moon-alternative-file + } +} diff --git a/rc/filetype/nim.kak b/rc/filetype/nim.kak new file mode 100644 index 00000000..901ce68a --- /dev/null +++ b/rc/filetype/nim.kak @@ -0,0 +1,112 @@ +# https://nim-lang.org/ +# + +# Detection +# ‾‾‾‾‾‾‾‾‾ + +hook global BufCreate .*\.nim(s|ble)? %{ + set-option buffer filetype nim +} + +# Highlighters +# ‾‾‾‾‾‾‾‾‾‾‾‾ + +add-highlighter shared/nim regions +add-highlighter shared/nim/code default-region group +add-highlighter shared/nim/triple_string region '([A-Za-z](_?\w)*)?"""' '"""(?!")' fill string +add-highlighter shared/nim/raw_string region [A-Za-z](_?[A-Za-z])*" (?@$~&%|!?^.:\\*]' + opnocol='[=+-/<>@$~&%|!?^.\\*]' + suffix="('[iIuU](8|16|32|64)|'[fF](32|64)?|'[dDuU]|[fF])?" + floatsuffix="('[fF](32|64)?|'[dD]|[fF])?" + hexdigit='[0-9a-fA-F]' + octdigit='[0-7]' + bindigit='[01]' + hexlit="0[xX]${hexdigit}(_?${hexdigit})*" + declit="\d(_?\d)*" + octlit="0o${octdigit}(_?${octdigit})*" + binlit="0[bB]${bindigit}(_?${bindigit})*" + intlit="\b(${declit}|${hexlit}|${octlit}|${binlit})${suffix}\b" + exponent="([eE][+-]?${declit})" + floatlit="\b${declit}(\.${declit}${exponent}?|${exponent})${floatsuffix}\b" + + keywords="addr as asm bind block break case cast concept const continue + converter defer discard distinct do elif else end enum except export + finally for from func if import include interface iterator let macro + method mixin nil out proc ptr raise ref return static template try type + unsafeAddr using var when while yield with without atomic generic" + operators="or xor and is isnot in notin of div mod shl shr not" + types="int int8 int16 int32 int64 uint uint8 uint16 uint32 uint64 float + float32 float64 bool char object seq array cstring string tuple varargs + typedesc pointer byte set typed untyped void auto" + values="false true" + + join() { sep=$2; set -- $1; IFS="$sep"; echo "$*"; } + + static_words="$(join "${keywords} ${types} ${operator} ${values}" ' ')" + + # Add the language's grammar to the static completion list + printf %s "hook global WinSetOption filetype=nim %{ + set-option window static_words ${static_words} + }" + + keywords="$(join "${keywords}" '|')" + operators="$(join "${operators}" '|')" + types="$(join "${types}" '|')" + values="$(join "${values}" '|')" + + # Highlight keywords + printf %s " + add-highlighter shared/nim/code/ regex ${opchars}+ 0:operator + add-highlighter shared/nim/code/ regex (? s ^\h*#\h* y jgh P } + # preserve previous line indent + try %{ exec -draft \; K } + # cleanup trailing whitespaces from previous line + try %{ exec -draft k s \h+$ d } + # indent after line ending with type, import, export, const, let, var, ':' or '=' + try %{ exec -draft k x (:|=|const|let|var|import|export|type)$ j } + } +} + +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook -group nim-highlight global WinSetOption filetype=nim %{ + add-highlighter window/nim ref nim + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/nim } +} + +hook global WinSetOption filetype=nim %{ + hook window InsertChar \n -group nim-indent nim-indent-on-new-line + # cleanup trailing whitespaces on current line insert end + hook window ModeChange insert:.* -group nim-trim-indent %{ try %{ exec -draft \; s ^\h+$ d } } + + hook -once -always window WinSetOption filetype=.* %{ remove-hooks window nim-.+ } +} diff --git a/rc/filetype/ocaml.kak b/rc/filetype/ocaml.kak new file mode 100644 index 00000000..0a3d49bf --- /dev/null +++ b/rc/filetype/ocaml.kak @@ -0,0 +1,38 @@ +# http://ocaml.org +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +# Detection +# ‾‾‾‾‾‾‾‾‾ + +hook global BufCreate .*\.mli? %{ + set-option buffer filetype ocaml +} + +# Highlighters +# ‾‾‾‾‾‾‾‾‾‾‾‾ + +add-highlighter shared/ocaml regions +add-highlighter shared/ocaml/code default-region group +add-highlighter shared/ocaml/string region '"' (?|\$\?|\$@|\$\[|\$\\|\$\]|\$\^|\$\||\$~|%!|@\+|@-|@_} 0:value +add-highlighter shared/perl/code/ regex (%ENV|%INC|%OVERLOAD|%SIG|@ARGV|@INC|@LAST_MATCH_START) 0:value +add-highlighter shared/perl/code/ regex %{%\^(H)\b} 0:value +add-highlighter shared/perl/code/ regex \$\^(S|T|V|W|X|A|C|D|E|F|H|I|L|M|N|O|P|R)\b 0:value +add-highlighter shared/perl/code/ regex \$\^(RE_TRIE_MAXBUF|TAINT|UNICODE|UTF8LOCALE|WARNING_BITS|WIDE_SYSTEM_CALLS|CHILD_ERROR_NATIVE|ENCODING|OPEN|RE_DEBUG_FLAGS)\b 0:value + +add-highlighter shared/perl/code/ regex \$[0-9]+ 0:attribute +add-highlighter shared/perl/code/ regex \b-(B|b|C|c|d|e|f|g|k|l|M|O|o|p|r|R|S|s|T|t|u|w|W|X|x|z)\b 0:attribute + +add-highlighter shared/perl/code/ regex \$[a-zA-Z_][a-zA-Z0-9_]* 0:variable + +add-highlighter shared/perl/code/ regex \$(a|b|LAST_REGEXP_CODE_RESULT|LIST_SEPARATOR|MATCH|MULTILINE_MATCHING|NR|OFMT|OFS|ORS|OS_ERROR|OSNAME|OUTPUT_AUTO_FLUSH|OUTPUT_FIELD_SEPARATOR|OUTPUT_RECORD_SEPARATOR)\b 0:value +add-highlighter shared/perl/code/ regex \$(LAST_REGEXP_CODE_RESULT|LIST_SEPARATOR|MATCH|MULTILINE_MATCHING|NR|OFMT|OFS|ORS|OS_ERROR|OSNAME|OUTPUT_AUTO_FLUSH|OUTPUT_FIELD_SEPARATOR|OUTPUT_RECORD_SEPARATOR|PERL_VERSION|ACCUMULATOR|PERLDB|ARG|PID|ARGV|POSTMATCH|PREMATCH|BASETIME|PROCESS_ID|CHILD_ERROR|PROGRAM_NAME|COMPILING|REAL_GROUP_ID|DEBUGGING|REAL_USER_ID|EFFECTIVE_GROUP_ID|RS|EFFECTIVE_USER_ID|SUBSCRIPT_SEPARATOR|EGID|SUBSEP|ERRNO|SYSTEM_FD_MAX|EUID|UID|EVAL_ERROR|WARNING|EXCEPTIONS_BEING_CAUGHT|EXECUTABLE_NAME|EXTENDED_OS_ERROR|FORMAT_FORMFEED|FORMAT_LINE_BREAK_CHARACTERS|FORMAT_LINES_LEFT|FORMAT_LINES_PER_PAGE|FORMAT_NAME|FORMAT_PAGE_NUMBER|FORMAT_TOP_NAME|GID|INPLACE_EDIT|INPUT_LINE_NUMBER|INPUT_RECORD_SEPARATOR|LAST_MATCH_END|LAST_PAREN_MATCH)\b 0:value + +# Commands +# ‾‾‾‾‾‾‾‾ + +define-command -hidden perl-indent-on-new-line %~ + evaluate-commands -draft -itersel %= + # preserve previous line indent + try %{ execute-keys -draft \;K } + # indent after lines ending with { or ( + try %[ execute-keys -draft k [{(]\h*$ j ] + # cleanup trailing white spaces on the previous line + try %{ execute-keys -draft k s \h+$ d } + # align to opening paren of previous line + try %{ execute-keys -draft [( \A\([^\n]+\n[^\n]*\n?\z s \A\(\h*.|.\z '' & } + # copy // comments prefix + try %{ execute-keys -draft \;k s ^\h*\K/{2,} yP } + # indent after a switch's case/default statements + try %[ execute-keys -draft k ^\h*(case|default).*:$ j ] + # indent after if|else|while|for + try %[ execute-keys -draft \;)MB \A(if|else|while|for)\h*\(.*\)\h*\n\h*\n?\z s \A|.\z 11 ] + = +~ + +define-command -hidden perl-indent-on-opening-curly-brace %[ + # align indent with opening paren when { is entered on a new line after the closing paren + try %[ execute-keys -draft -itersel h)M \A\(.*\)\h*\n\h*\{) s \A|.\z 1 ] +] + +define-command -hidden perl-indent-on-closing-curly-brace %[ + # align to opening curly brace when alone on a line + try %[ execute-keys -itersel -draft ^\h+\}$hms\A|.\z1 ] +] + +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook -group perl-highlight global WinSetOption filetype=perl %{ + add-highlighter window/perl ref perl + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/perl } +} + +hook global WinSetOption filetype=perl %{ + # cleanup trailing whitespaces when exiting insert mode + hook window ModeChange insert:.* -group perl-trim-indent %{ try %{ execute-keys -draft s^\h+$d } } + hook window InsertChar \n -group perl-indent perl-indent-on-new-line + hook window InsertChar \{ -group perl-indent perl-indent-on-opening-curly-brace + hook window InsertChar \} -group perl-indent perl-indent-on-closing-curly-brace + + hook -once -always window WinSetOption filetype=.* %{ remove-hooks window perl-.+ } +} diff --git a/rc/filetype/php.kak b/rc/filetype/php.kak new file mode 100644 index 00000000..4acfde85 --- /dev/null +++ b/rc/filetype/php.kak @@ -0,0 +1,90 @@ +# Detection +# ‾‾‾‾‾‾‾‾‾ + +hook global BufCreate .*[.](php) %{ + set-option buffer filetype php +} + +# Highlighters +# ‾‾‾‾‾‾‾‾‾‾‾‾ + +add-highlighter shared/php regions +add-highlighter shared/php/code default-region group +add-highlighter shared/php/double_string region '"' (?' 0:meta + +add-highlighter shared/php/double_string/ fill string +add-highlighter shared/php/double_string/ regex (?\w+)* 0:variable +add-highlighter shared/php/double_string/ regex \{(?\w+)*\} 0:variable + +# Highlight doc comments +add-highlighter shared/php/doc_comment/ fill string +add-highlighter shared/php/doc_comment/ regex '`.*`' 0:module +add-highlighter shared/php/doc_comment/ regex '@\w+' 0:meta + +# Keywords are collected at +# http://php.net/manual/en/reserved.keywords.php +add-highlighter shared/php/code/ regex \b(__halt_compiler|abstract|and|array|as|break|callable|case|catch|class|clone|const|continue|declare|default|die|do|echo|else|elseif|empty|enddeclare|endfor|endforeach|endif|endswitch|endwhile|eval|exit|extends|final|finally|for|foreach|function|global|goto|if|implements|include|include_once|instanceof|insteadof|interface|isset|list|namespace|new|or|print|private|protected|public|require|require_once|return|static|switch|throw|trait|try|unset|use|var|while|xor|yield|__CLASS__|__DIR__|__FILE__|__FUNCTION__|__LINE__|__METHOD__|__NAMESPACE__|__TRAIT__)\b 0:keyword + +# Highlighter for html with php tags in it, i.e. the structure of conventional php files +add-highlighter shared/php-file regions +add-highlighter shared/php-file/html default-region ref html +add-highlighter shared/php-file/php region '<\?(php)?' '\?>' ref php + +# Commands +# ‾‾‾‾‾‾‾‾ + +define-command -hidden php-trim-indent %{ + # remove trailing white spaces + try %{ execute-keys -draft -itersel s \h+$ d } +} + +define-command -hidden php-indent-on-char %< + evaluate-commands -draft -itersel %< + # align closer token to its opener when alone on a line + try %/ execute-keys -draft ^\h+[]}]$ m s \A|.\z 1 / + > +> + +define-command -hidden php-indent-on-new-line %< + evaluate-commands -draft -itersel %< + # copy // comments prefix and following white spaces + try %{ execute-keys -draft k s ^\h*\K#\h* y gh j P } + # preserve previous line indent + try %{ execute-keys -draft \; K } + # filter previous line + try %{ execute-keys -draft k : php-trim-indent } + # indent after lines beginning / ending with opener token + try %_ execute-keys -draft k ^\h*[[{]|[[{]$ j _ + > +> + +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook -group php-highlight global WinSetOption filetype=php %{ + add-highlighter window/php-file ref php-file + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/php-file } +} + +hook global WinSetOption filetype=php %{ + hook window ModeChange insert:.* -group php-trim-indent php-trim-indent + hook window InsertChar .* -group php-indent php-indent-on-char + hook window InsertChar \n -group php-indent php-indent-on-new-line + + hook -once -always window WinSetOption filetype=.* %{ remove-hooks window php-.+ } +} diff --git a/rc/filetype/pony.kak b/rc/filetype/pony.kak new file mode 100644 index 00000000..713cc295 --- /dev/null +++ b/rc/filetype/pony.kak @@ -0,0 +1,92 @@ +# http://ponylang.org +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +# Detection +# ‾‾‾‾‾‾‾‾‾ + +hook global BufCreate .*[.](pony) %{ + set-option buffer filetype pony +} + +# Highlighters & Completion +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +add-highlighter shared/pony regions +add-highlighter shared/pony/code default-region group +add-highlighter shared/pony/triple_string region '"""' '"""' fill string +add-highlighter shared/pony/double_string region '"' (?' 0:type + add-highlighter shared/pony/code/ regex '\b(${keywords})\b' 0:keyword + add-highlighter shared/pony/code/ regex ';' 0:keyword + add-highlighter shared/pony/code/ regex '^\s*|' 0:keyword + add-highlighter shared/pony/code/ regex '\b(${struct})\b' 0:variable + add-highlighter shared/pony/code/ regex '\b(${capabilities})\b(!|^)?' 1:builtin 2:builtin + " + + # Highlight types and attributes + printf %s " + add-highlighter shared/pony/code/ regex '@[\w_]+\b' 0:attribute + " +} + +# Commands +# ‾‾‾‾‾‾‾‾ + +define-command -hidden pony-indent-on-new-line %{ + evaluate-commands -draft -itersel %{ + # preserve previous line indent + try %{ execute-keys -draft K } + # cleanup trailing whitespaces from previous line + try %{ execute-keys -draft k s \h+$ d } + # copy '//' comment prefix and following white spaces + # try %{ execute-keys -draft k x s ^\h*//\h* y jgh P } + # indent after line ending with : + try %{ execute-keys -draft k x (do|try|then|else|:|=>)$ j } + # else, end are always de-indented + try %{ execute-keys -draft k x (else|end):$ k x s ^\h* y j x ^" J } + } +} + +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook -group pony-highlight global WinSetOption filetype=pony %{ + add-highlighter window/pony ref pony + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter pony } +} + +hook global WinSetOption filetype=pony %{ + hook window InsertChar \n -group pony-indent pony-indent-on-new-line + # cleanup trailing whitespaces on current line insert end + hook window ModeChange insert:.* -group pony-trim-indent %{ try %{ execute-keys -draft \; s ^\h+$ d } } + + hook -once -always window WinSetOption filetype=.* %{ remove-hooks window pony-.+ } +} diff --git a/rc/filetype/protobuf.kak b/rc/filetype/protobuf.kak new file mode 100644 index 00000000..2ef10480 --- /dev/null +++ b/rc/filetype/protobuf.kak @@ -0,0 +1,85 @@ +# https://developers.google.com/protocol-buffers/ + +# Detection +# ‾‾‾‾‾‾‾‾‾ + +hook global BufCreate .*\.proto$ %{ + set-option buffer filetype protobuf +} + +# Highlighters +# ‾‾‾‾‾‾‾‾‾‾‾‾ + +add-highlighter shared/protobuf regions +add-highlighter shared/protobuf/code default-region group +add-highlighter shared/protobuf/double_string region '"' (? } + # indent after lines ending with { + try %[ execute-keys -draft k \{\h*$ j ] + # cleanup trailing white spaces on the previous line + try %{ execute-keys -draft k s \h+$ d } + # copy // comments prefix + try %{ execute-keys -draft \;k s ^\h*\K/{2,}(\h*(?=\S))? yP } + ] +~ + +define-command -hidden protobuf-indent-on-opening-curly-brace %[ + # align indent with opening paren when { is entered on a new line after the closing paren + try %[ execute-keys -draft -itersel h)M \A\(.*\)\h*\n\h*\{\z s \A|.\z 1 ] +] + +define-command -hidden protobuf-indent-on-closing-curly-brace %[ + # align to opening curly brace when alone on a line + try %[ execute-keys -itersel -draft ^\h+\}$hms\A|.\z1 ] +] + +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook -group protobuf-highlight global WinSetOption filetype=protobuf %{ + add-highlighter window/protobuf ref protobuf + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/protobuf } +} + +hook global WinSetOption filetype=protobuf %[ + hook -group protobuf-indent window InsertChar \n protobuf-indent-on-newline + hook -group protobuf-indent window InsertChar \{ protobuf-indent-on-opening-curly-brace + hook -group protobuf-indent window InsertChar \} protobuf-indent-on-closing-curly-brace + + hook -once -always window WinSetOption filetype=.* %{ remove-hooks window protobuf-.+ } +] diff --git a/rc/filetype/pug.kak b/rc/filetype/pug.kak new file mode 100644 index 00000000..13aa839f --- /dev/null +++ b/rc/filetype/pug.kak @@ -0,0 +1,74 @@ +# Note: jade is changing its name to pug (https://github.com/pugjs/pug/issues/2184) +# This appears to be a work in progress -- the pug-lang domain is parked, while +# the jade-lang one is active. This highlighter will recognize .pug and .jade extensions, + +# http://jade-lang.com (will be http://pug-lang.com) +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +# Detection +# ‾‾‾‾‾‾‾‾‾ + +hook global BufCreate .*[.](pug|jade) %{ + set-option buffer filetype pug +} + +# Highlighters +# ‾‾‾‾‾‾‾‾‾‾‾‾ + +add-highlighter shared/pug regions +add-highlighter shared/pug/code default-region group +add-highlighter shared/pug/text region ^\h*\|\s $ regex \h*(\|) 1:meta +add-highlighter shared/pug/text2 region '^\h*([A-Za-z][A-Za-z0-9_-]*)?(#[A-Za-z][A-Za-z0-9_-]*)?((?:\.[A-Za-z][A-Za-z0-9_-]*)*)?(? s \h+$ d } +} + +define-command -hidden pug-indent-on-new-line %{ + evaluate-commands -draft -itersel %{ + # preserve previous line indent + try %{ execute-keys -draft \; K } + # filter previous line + try %{ execute-keys -draft k : pug-trim-indent } + # copy '//', '|', '-' or '(!)=' prefix and following whitespace + try %{ execute-keys -draft k s ^\h*\K[/|!=-]{1,2}\h* y gh j P } + # indent unless we copied something above + try %{ execute-keys -draft b s \S g l } + } +} + +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook -group pug-highlight global WinSetOption filetype=pug %{ + add-highlighter window/pug ref pug + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/pug } +} + +hook global WinSetOption filetype=pug %{ + hook window ModeChange insert:.* -group pug-trim-indent pug-trim-indent + hook window InsertChar \n -group pug-indent pug-indent-on-new-line + + hook -once -always window WinSetOption filetype=.* %{ remove-hooks window pug-.+ } +} diff --git a/rc/filetype/python.kak b/rc/filetype/python.kak new file mode 100644 index 00000000..fb9477b9 --- /dev/null +++ b/rc/filetype/python.kak @@ -0,0 +1,148 @@ +# http://python.org +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +# Detection +# ‾‾‾‾‾‾‾‾‾ + +hook global BufCreate .*[.](py) %{ + set-option buffer filetype python +} + +# Highlighters & Completion +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +add-highlighter shared/python regions +add-highlighter shared/python/code default-region group +add-highlighter shared/python/docstring region -match-capture ("""|''') ("""|''') regions +add-highlighter shared/python/double_string region '"' (?>> \K' '\z' ref python +add-highlighter shared/python/docstring/ region '\.\.\. \K' '\z' ref python + +evaluate-commands %sh{ + # Grammar + values="True|False|None|self|inf" + meta="import|from" + + # attributes and methods list based on https://docs.python.org/3/reference/datamodel.html + attributes="__annotations__|__closure__|__code__|__defaults__|__dict__|__doc__" + attributes="${attributes}|__globals__|__kwdefaults__|__module__|__name__|__qualname__" + methods="__abs__|__add__|__aenter__|__aexit__|__aiter__|__and__|__anext__" + methods="${methods}|__await__|__bool__|__bytes__|__call__|__complex__|__contains__" + methods="${methods}|__del__|__delattr__|__delete__|__delitem__|__dir__|__divmod__" + methods="${methods}|__enter__|__eq__|__exit__|__float__|__floordiv__|__format__" + methods="${methods}|__ge__|__get__|__getattr__|__getattribute__|__getitem__" + methods="${methods}|__gt__|__hash__|__iadd__|__iand__|__ifloordiv__|__ilshift__" + methods="${methods}|__imatmul__|__imod__|__imul__|__index__|__init__" + methods="${methods}|__init_subclass__|__int__|__invert__|__ior__|__ipow__" + methods="${methods}|__irshift__|__isub__|__iter__|__itruediv__|__ixor__|__le__" + methods="${methods}|__len__|__length_hint__|__lshift__|__lt__|__matmul__" + methods="${methods}|__missing__|__mod__|__mul__|__ne__|__neg__|__new__|__or__" + methods="${methods}|__pos__|__pow__|__radd__|__rand__|__rdivmod__|__repr__" + methods="${methods}|__reversed__|__rfloordiv__|__rlshift__|__rmatmul__|__rmod__" + methods="${methods}|__rmul__|__ror__|__round__|__rpow__|__rrshift__|__rshift__" + methods="${methods}|__rsub__|__rtruediv__|__rxor__|__set__|__setattr__" + methods="${methods}|__setitem__|__set_name__|__slots__|__str__|__sub__" + methods="${methods}|__truediv__|__xor__" + + # built-in exceptions https://docs.python.org/3/library/exceptions.html + exceptions="ArithmeticError|AssertionError|AttributeError|BaseException|BlockingIOError" + exceptions="${exceptions}|BrokenPipeError|BufferError|BytesWarning|ChildProcessError" + exceptions="${exceptions}|ConnectionAbortedError|ConnectionError|ConnectionRefusedError" + exceptions="${exceptions}|ConnectionResetError|DeprecationWarning|EOFError|Exception" + exceptions="${exceptions}|FileExistsError|FileNotFoundError|FloatingPointError|FutureWarning" + exceptions="${exceptions}|GeneratorExit|ImportError|ImportWarning|IndentationError" + exceptions="${exceptions}|IndexError|InterruptedError|IsADirectoryError|KeyboardInterrupt" + exceptions="${exceptions}|KeyError|LookupError|MemoryError|ModuleNotFoundError|NameError" + exceptions="${exceptions}|NotADirectoryError|NotImplementedError|OSError|OverflowError" + exceptions="${exceptions}|PendingDeprecationWarning|PermissionError|ProcessLookupError" + exceptions="${exceptions}|RecursionError|ReferenceError|ResourceWarning|RuntimeError" + exceptions="${exceptions}|RuntimeWarning|StopAsyncIteration|StopIteration|SyntaxError" + exceptions="${exceptions}|SyntaxWarning|SystemError|SystemExit|TabError|TimeoutError|TypeError" + exceptions="${exceptions}|UnboundLocalError|UnicodeDecodeError|UnicodeEncodeError|UnicodeError" + exceptions="${exceptions}|UnicodeTranslateError|UnicodeWarning|UserWarning|ValueError|Warning" + exceptions="${exceptions}|ZeroDivisionError" + + # Keyword list is collected using `keyword.kwlist` from `keyword` + keywords="and|as|assert|async|await|break|class|continue|def|del|elif|else|except|exec" + keywords="${keywords}|finally|for|global|if|in|is|lambda|nonlocal|not|or|pass|print" + keywords="${keywords}|raise|return|try|while|with|yield" + + types="bool|buffer|bytearray|bytes|complex|dict|file|float|frozenset|int" + types="${types}|list|long|memoryview|object|set|str|tuple|unicode|xrange" + + functions="abs|all|any|ascii|bin|callable|chr|classmethod|compile|complex" + functions="${functions}|delattr|dict|dir|divmod|enumerate|eval|exec|filter" + functions="${functions}|format|frozenset|getattr|globals|hasattr|hash|help" + functions="${functions}|hex|id|__import__|input|isinstance|issubclass|iter" + functions="${functions}|len|locals|map|max|memoryview|min|next|oct|open|ord" + functions="${functions}|pow|print|property|range|repr|reversed|round" + functions="${functions}|setattr|slice|sorted|staticmethod|sum|super|type|vars|zip" + + # Add the language's grammar to the static completion list + printf %s\\n "hook global WinSetOption filetype=python %{ + set-option window static_words ${values} ${meta} ${attributes} ${methods} ${exceptions} ${keywords} ${types} ${functions} + }" | tr '|' ' ' + + # Highlight keywords + printf %s " + add-highlighter shared/python/code/ regex '\b(${values})\b' 0:value + add-highlighter shared/python/code/ regex '\b(${meta})\b' 0:meta + add-highlighter shared/python/code/ regex '\b(${attribute})\b' 0:attribute + add-highlighter shared/python/code/ regex '\bdef\s+(${methods})\b' 1:function + add-highlighter shared/python/code/ regex '\b(${exceptions})\b' 0:function + add-highlighter shared/python/code/ regex '\b(${keywords})\b' 0:keyword + add-highlighter shared/python/code/ regex '\b(${functions})\b\(' 1:builtin + add-highlighter shared/python/code/ regex '\b(${types})\b' 0:type + add-highlighter shared/python/code/ regex '@[\w_]+\b' 0:attribute + " +} + +add-highlighter shared/python/code/ regex (?<=[\w\s\d'"_])(<=|<<|>>|>=|<>|<|>|!=|==|\||\^|&|\+|-|\*\*|\*|//|/|%|~) 0:operator +add-highlighter shared/python/code/ regex (?<=[\w\s\d'"_])((?!])=(?![=])|[+*-]=) 0:builtin + +# Commands +# ‾‾‾‾‾‾‾‾ + +define-command -hidden python-indent-on-new-line %{ + evaluate-commands -draft -itersel %{ + # copy '#' comment prefix and following white spaces + try %{ execute-keys -draft k s ^\h*#\h* y jgh P } + # preserve previous line indent + try %{ execute-keys -draft \; K } + # cleanup trailing whitespaces from previous line + try %{ execute-keys -draft k s \h+$ d } + # indent after line ending with : + try %{ execute-keys -draft k :$ j } + } +} + +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook -group python-highlight global WinSetOption filetype=python %{ + add-highlighter window/python ref python + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/python } +} + +hook global WinSetOption filetype=python %{ + hook window InsertChar \n -group python-indent python-indent-on-new-line + # cleanup trailing whitespaces on current line insert end + hook window ModeChange insert:.* -group python-trim-indent %{ try %{ execute-keys -draft \; s ^\h+$ d } } + hook -once -always window WinSetOption filetype=.* %{ remove-hooks window python-.+ } +} diff --git a/rc/filetype/ragel.kak b/rc/filetype/ragel.kak new file mode 100644 index 00000000..b6e8dd4c --- /dev/null +++ b/rc/filetype/ragel.kak @@ -0,0 +1,70 @@ +# http://complang.org/ragel +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +# ragel.kak does not try to detect host language. + +# Detection +# ‾‾‾‾‾‾‾‾‾ + +hook global BufCreate .*[.](ragel|rl) %{ + set-option buffer filetype ragel +} + +# Highlighters +# ‾‾‾‾‾‾‾‾‾‾‾‾ + +add-highlighter shared/ragel regions +add-highlighter shared/ragel/code default-region group +add-highlighter shared/ragel/double_string region '"' (?' 0:variable +add-highlighter shared/ragel/code/ regex :=|=>|->|:>|:>>|<: 0:operator +add-highlighter shared/ragel/code/ regex \b(action|alnum|alpha|any|ascii|case|cntrl|contained|context|data|digit|empty|eof|err|error|exec|export|exports|extend|fblen|fbreak|fbuf|fc|fcall|fcurs|fentry|fexec|fgoto|fhold|first_final|fnext|fpc|fret|from|fstack|ftargs|graph|import|include|init|inwhen|lerr|lower|machine|nocs|noend|noerror|nofinal|noprefix|outwhen|postpop|prepush|print|punct|range|space|start|to|upper|when|write|xdigit|zlen)\b 0:keyword + +# Commands +# ‾‾‾‾‾‾‾‾ + +define-command -hidden ragel-trim-indent %{ + # remove trailing white spaces + try %{ execute-keys -draft -itersel s \h+$ d } +} + +define-command -hidden ragel-indent-on-char %< + evaluate-commands -draft -itersel %< + # align closer token to its opener when alone on a line + try %< execute-keys -draft ^\h+[]})]$ m s \A|.\z 1 > + try %< execute-keys -draft ^\h+ [*]$ [*]$ s \A|.\z 1 > + > +> + +define-command -hidden ragel-indent-on-new-line %< + evaluate-commands -draft -itersel %< + # copy _#_ comment prefix and following white spaces + try %{ execute-keys -draft k s ^\h*\K#\h* y gh j P } + # preserve previous line indent + try %{ execute-keys -draft \; K } + # filter previous line + try %{ execute-keys -draft k : ragel-trim-indent } + # indent after lines ending with opener token + try %< execute-keys -draft k [[{(*]$ j > + > +> + +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook -group ragel-highlight global WinSetOption filetype=ragel %{ + add-highlighter window/ragel ref ragel + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/ragel } +} + +hook global WinSetOption filetype=ragel %{ + hook window ModeChange insert:.* -group ragel-trim-indent ragel-trim-indent + hook window InsertChar .* -group ragel-indent ragel-indent-on-char + hook window InsertChar \n -group ragel-indent ragel-indent-on-new-line + + hook -once -always window WinSetOption filetype=.* %{ remove-hooks window ragel-.+ } +} diff --git a/rc/filetype/restructuredtext.kak b/rc/filetype/restructuredtext.kak new file mode 100644 index 00000000..1eaf4bfc --- /dev/null +++ b/rc/filetype/restructuredtext.kak @@ -0,0 +1,74 @@ +# Detection +# ‾‾‾‾‾‾‾‾‾ + +hook global BufCreate .*[.](rst) %{ + set-option buffer filetype restructuredtext +} + +# Highlighters +# ‾‾‾‾‾‾‾‾‾‾‾‾ + +add-highlighter shared/restructuredtext regions +add-highlighter shared/restructuredtext/content default-region group +add-highlighter shared/restructuredtext/code region ::\h*\n ^[^\s] fill meta + +evaluate-commands %sh{ + for ft in c cabal clojure coffee cpp css cucumber ddiff dockerfile \ + fish gas go haml haskell html ini java javascript json \ + julia kak kickstart latex lisp lua makefile moon objc \ + perl pug python ragel ruby rust sass scala scss sh swift \ + tupfile yaml; do + if [ "$ft" = kak ]; then ref="kakrc"; else ref="$ft"; fi + printf 'add-highlighter shared/restructuredtext/%s region %s %s ref %s\n' "$ft" '\.\.\h*'$ft'::\h*c\h*\n' '^\S' "$ref" + done +} + +# Setext-style header +# Valid header characters: +# # ! " $ % & ' ( ) * + , - . / : ; < = > ? @ [ \ ] ^ _ ` { | } ~ + +add-highlighter shared/restructuredtext/content/ regex (\A|\n\n)(#{3,}\n)?[^\n]+\n(#{3,})$ 0:title +add-highlighter shared/restructuredtext/content/ regex (\A|\n\n)(!{3,}\n)?[^\n]+\n(!{3,})$ 0:header +add-highlighter shared/restructuredtext/content/ regex (\A|\n\n)("{3,}\n)?[^\n]+\n("{3,})$ 0:header +add-highlighter shared/restructuredtext/content/ regex (\A|\n\n)(\${3,}\n)?[^\n]+\n(\${3,})$ 0:header +add-highlighter shared/restructuredtext/content/ regex (\A|\n\n)(%{3,}\n)?[^\n]+\n(%{3,})$ 0:header +add-highlighter shared/restructuredtext/content/ regex (\A|\n\n)(&{3,}\n)?[^\n]+\n(&{3,})$ 0:header +add-highlighter shared/restructuredtext/content/ regex (\A|\n\n)('{3,}\n)?[^\n]+\n('{3,})$ 0:header +add-highlighter shared/restructuredtext/content/ regex (\A|\n\n)(\({3,}\n)?[^\n]+\n(\({3,})$ 0:header +add-highlighter shared/restructuredtext/content/ regex (\A|\n\n)(\){3,}\n)?[^\n]+\n(\){3,})$ 0:header +add-highlighter shared/restructuredtext/content/ regex (\A|\n\n)(\*{3,}\n)?[^\n]+\n(\*{3,})$ 0:header +add-highlighter shared/restructuredtext/content/ regex (\A|\n\n)(\+{3,}\n)?[^\n]+\n(\+{3,})$ 0:header +add-highlighter shared/restructuredtext/content/ regex (\A|\n\n)(,{3,}\n)?[^\n]+\n(,{3,})$ 0:header +add-highlighter shared/restructuredtext/content/ regex (\A|\n\n)(-{3,}\n)?[^\n]+\n(-{3,})$ 0:header +add-highlighter shared/restructuredtext/content/ regex (\A|\n\n)(\.{3,}\n)?[^\n]+\n(\.{3,})$ 0:header +add-highlighter shared/restructuredtext/content/ regex (\A|\n\n)(/{3,}\n)?[^\n]+\n(/{3,})$ 0:header +add-highlighter shared/restructuredtext/content/ regex (\A|\n\n)(:{3,}\n)?[^\n]+\n(:{3,})$ 0:header +add-highlighter shared/restructuredtext/content/ regex (\A|\n\n)(\;{3,}\n)?[^\n]+\n(\;{3,})$ 0:header +add-highlighter shared/restructuredtext/content/ regex (\A|\n\n)(<{3,}\n)?[^\n]+\n(<{3,})$ 0:header +add-highlighter shared/restructuredtext/content/ regex (\A|\n\n)(={3,}\n)?[^\n]+\n(={3,})$ 0:header +add-highlighter shared/restructuredtext/content/ regex (\A|\n\n)(>{3,}\n)?[^\n]+\n(>{3,})$ 0:header +add-highlighter shared/restructuredtext/content/ regex (\A|\n\n)(\?{3,}\n)?[^\n]+\n(\?{3,})$ 0:header +add-highlighter shared/restructuredtext/content/ regex (\A|\n\n)(@{3,}\n)?[^\n]+\n(@{3,})$ 0:header +add-highlighter shared/restructuredtext/content/ regex (\A|\n\n)(\[{3,}\n)?[^\n]+\n(\[{3,})$ 0:header +add-highlighter shared/restructuredtext/content/ regex (\A|\n\n)(\\{3,}\n)?[^\n]+\n(\\{3,})$ 0:header +add-highlighter shared/restructuredtext/content/ regex (\A|\n\n)(\]{3,}\n)?[^\n]+\n(\]{3,})$ 0:header +add-highlighter shared/restructuredtext/content/ regex (\A|\n\n)(\^{3,}\n)?[^\n]+\n(\^{3,})$ 0:header +add-highlighter shared/restructuredtext/content/ regex (\A|\n\n)(_{3,}\n)?[^\n]+\n(_{3,})$ 0:header +add-highlighter shared/restructuredtext/content/ regex (\A|\n\n)(`{3,}\n)?[^\n]+\n(`{3,})$ 0:header +add-highlighter shared/restructuredtext/content/ regex (\A|\n\n)(\{{3,}\n)?[^\n]+\n(\{{3,})$ 0:header +add-highlighter shared/restructuredtext/content/ regex (\A|\n\n)(\|{3,}\n)?[^\n]+\n(\|{3,})$ 0:header +add-highlighter shared/restructuredtext/content/ regex (\A|\n\n)(\}{3,}\n)?[^\n]+\n(\}{3,})$ 0:header +add-highlighter shared/restructuredtext/content/ regex (\A|\n\n)(~{3,}\n)?[^\n]+\n(~{3,})$ 0:header + +# Inline markup +add-highlighter shared/restructuredtext/content/ regex [^*](\*\*([^\s*]|([^\s*][^*]*[^\s*]))\*\*)[^*] 1:bold +add-highlighter shared/restructuredtext/content/ regex [^*](\*([^\s*]|([^\s*][^*]*[^\s*]))\*)[^*] 1:italic +add-highlighter shared/restructuredtext/content/ regex [^`](``([^\s`]|([^\s`][^`]*[^\s`]))``)[^`] 1:mono + +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook -group restructuredtext-highlight global WinSetOption filetype=restructuredtext %{ + add-highlighter window/restructuredtext ref restructuredtext + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/restructuredtext } +} diff --git a/rc/filetype/ruby.kak b/rc/filetype/ruby.kak new file mode 100644 index 00000000..3e5cfcfa --- /dev/null +++ b/rc/filetype/ruby.kak @@ -0,0 +1,168 @@ +# http://ruby-lang.org +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +# Detection +# ‾‾‾‾‾‾‾‾‾ + +hook global BufCreate .*(([.](rb))|(irbrc)|(pryrc)|(Brewfile)|(Capfile|[.]cap)|(Gemfile|[.]gemspec)|(Guardfile)|(Rakefile|[.]rake)|(Thorfile|[.]thor)|(Vagrantfile)) %{ + set-option buffer filetype ruby +} + +# Highlighters +# ‾‾‾‾‾‾‾‾‾‾‾‾ + +add-highlighter shared/ruby regions +add-highlighter shared/ruby/code default-region group +add-highlighter shared/ruby/double_symbol region ':"' (? fill meta +add-highlighter shared/ruby/heredoc region '<<[-~]?(?!self)(\w+)' '^\h*(\w+)$' fill string +add-highlighter shared/ruby/division region '[\w\)\]](/|(\h+/\h+))' '\w' group # Help Kakoune to better detect /…/ literals + +# Regular expression flags are: i → ignore case, m → multi-lines, o → only interpolate #{} blocks once, x → extended mode (ignore white spaces) +# Literals are: i → array of symbols, q → string, r → regular expression, s → symbol, w → array of words, x → capture shell result + +add-highlighter shared/ruby/double_string/ default-region fill string +add-highlighter shared/ruby/double_string/interpolation region -recurse \{ \Q#{ \} fill meta + +add-highlighter shared/ruby/double_symbol/ default-region fill variable +add-highlighter shared/ruby/double_symbol/interpolation region -recurse \{ \Q#{ \} fill meta + +add-highlighter shared/ruby/backtick/ default-region fill meta +add-highlighter shared/ruby/backtick/interpolation region -recurse \{ \Q#{ \} fill meta + +add-highlighter shared/ruby/regex/ default-region fill meta +add-highlighter shared/ruby/regex/interpolation region -recurse \{ \Q#{ \} fill meta + +evaluate-commands %sh{ + # Grammar + # Keywords are collected searching for keywords at + # https://github.com/ruby/ruby/blob/trunk/parse.y + keywords="alias|and|begin|break|case|class|def|defined|do|else|elsif|end" + keywords="${keywords}|ensure|false|for|if|in|module|next|nil|not|or|private|protected|public|redo" + keywords="${keywords}|rescue|retry|return|self|super|then|true|undef|unless|until|when|while|yield" + attributes="attr_reader|attr_writer|attr_accessor" + values="false|true|nil" + meta="require|include|extend" + + # Add the language's grammar to the static completion list + printf %s\\n "hook global WinSetOption filetype=ruby %{ + set-option window static_words ${keywords} ${attributes} ${values} ${meta} + }" | tr '|' ' ' + + # Highlight keywords + printf %s " + add-highlighter shared/ruby/code/ regex \b(${keywords})\b 0:keyword + add-highlighter shared/ruby/code/ regex \b(${attributes})\b 0:attribute + add-highlighter shared/ruby/code/ regex \b(${values})\b 0:value + add-highlighter shared/ruby/code/ regex \b(${meta})\b 0:meta + " +} + +add-highlighter shared/ruby/code/ regex \b(\w+:(?!:))|(:?(\$(-[0FIKWadilpvw]|["'`/~&+=!$*,:.\;<>?@\\])|(\$|@@?)\w+))|((?[=>]?|<((=>?)|<)?|[+\-]@?|\*\*?|===?|[/`%&!^|~]|(\w+[=?!]?)|(\[\]=?)))|([A-Z]\w*|^|\h)\K::(?=[A-Z]) 0:variable + +# Commands +# ‾‾‾‾‾‾‾‾ + +define-command ruby-alternative-file -docstring 'Jump to the alternate file (implementation ↔ test)' %{ evaluate-commands %sh{ + case $kak_buffile in + *spec/*_spec.rb) + altfile=$(eval echo $(echo $kak_buffile | sed s+spec/+'*'/+';'s/_spec//)) + [ ! -f $altfile ] && echo "echo -markup '{Error}implementation file not found'" && exit + ;; + *.rb) + path=$kak_buffile + dirs=$(while [ $path ]; do echo $path; path=${path%/*}; done | tail -n +2) + for dir in $dirs; do + altdir=$dir/spec + if [ -d $altdir ]; then + altfile=$altdir/$(realpath $kak_buffile --relative-to $dir | sed s+[^/]'*'/++';'s/.rb$/_spec.rb/) + break + fi + done + [ ! -d $altdir ] && echo "echo -markup '{Error}spec/ not found'" && exit + ;; + *) + echo "echo -markup '{Error}alternative file not found'" && exit + ;; + esac + echo "edit $altfile" +}} + +define-command -hidden ruby-trim-indent %{ + evaluate-commands -no-hooks -draft -itersel %{ + execute-keys + # remove trailing white spaces + try %{ execute-keys -draft s \h + $ d } + } +} + +define-command -hidden ruby-indent-on-char %{ + evaluate-commands -no-hooks -draft -itersel %{ + # align middle and end structures to start + try %{ execute-keys -draft ^ \h * (else|elsif) $ ^ \h * (if) s \A | \z ) } + try %{ execute-keys -draft ^ \h * (when) $ ^ \h * (case) s \A | \z ) } + try %{ execute-keys -draft ^ \h * (rescue) $ ^ \h * (begin) s \A | \z ) } + try %{ execute-keys -draft ^ \h * (end) $ ^ \h * (begin|case|class|def|do|for|if|module|unless|until|while) s \A | \z ) } + } +} + +define-command -hidden ruby-indent-on-new-line %{ + evaluate-commands -no-hooks -draft -itersel %{ + # preserve previous line indent + try %{ execute-keys -draft K } + # filter previous line + try %{ execute-keys -draft k : ruby-trim-indent } + # indent after start structure + try %{ execute-keys -draft k ^ \h * (begin|case|class|def|do|else|elsif|ensure|for|if|module|rescue|unless|until|when|while) \b j } + } +} + +define-command -hidden ruby-insert-on-new-line %[ + evaluate-commands -no-hooks -draft -itersel %[ + # copy _#_ comment prefix and following white spaces + try %{ execute-keys -draft k s '^\h*\K#\h*' y gh j P } + # wisely add end structure + evaluate-commands -save-regs x %[ + try %{ execute-keys -draft k s ^ \h + \" x y } catch %{ reg x '' } + try %[ + evaluate-commands -draft %[ + execute-keys -draft k ^x(begin|case|class|def|do|for|if|module|unless|until|while) # Check if previous line opens a block + # Check that we do not already have an end for this indent level, or that we have another block opening at that indent level first + execute-keys -draft Ge \A(^\n|^x(?!begin)(?!case)(?!class)(?!def)(?!do)(?!for)(?!if)(?!module)(?!unless)(?!until)(?!while)[^\n]*\n)+xend$ + ] + execute-keys -draft oxend # insert a new line with containing end + ] + ] + ] +] + +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook -group ruby-highlight global WinSetOption filetype=ruby %{ + add-highlighter window/ruby ref ruby + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/ruby } +} + +hook global WinSetOption filetype=ruby %{ + hook window InsertChar .* -group ruby-indent ruby-indent-on-char + hook window InsertChar \n -group ruby-insert ruby-insert-on-new-line + hook window InsertChar \n -group ruby-indent ruby-indent-on-new-line + + alias window alt ruby-alternative-file + + hook -once -always window WinSetOption filetype=.* %{ + remove-hooks window ruby-.+ + unalias window alt ruby-alternative-file + } +} diff --git a/rc/filetype/rust.kak b/rc/filetype/rust.kak new file mode 100644 index 00000000..9cbca842 --- /dev/null +++ b/rc/filetype/rust.kak @@ -0,0 +1,88 @@ +# http://rust-lang.org +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +# Detection +# ‾‾‾‾‾‾‾‾‾ + +hook global BufCreate .*[.](rust|rs) %{ + set-option buffer filetype rust +} + +# Highlighters +# ‾‾‾‾‾‾‾‾‾‾‾‾ + +add-highlighter shared/rust regions +add-highlighter shared/rust/code default-region group +add-highlighter shared/rust/string region %{(? s \h+$ d } +} + +define-command -hidden rust-indent-on-new-line %~ + evaluate-commands -draft -itersel %< + # copy // comments prefix and following white spaces + try %{ execute-keys -draft k s ^\h*\K//[!/]?\h* y gh j P } + # preserve previous line indent + try %{ execute-keys -draft \; K } + # filter previous line + try %{ execute-keys -draft k : rust-trim-indent } + # indent after lines ending with { or ( + try %[ execute-keys -draft k [{(]\h*$ j ] + # align to opening paren of previous line + try %{ execute-keys -draft [( \A\([^\n]+\n[^\n]*\n?\z s \A\(\h*.|.\z & } + > +~ + +define-command -hidden rust-indent-on-opening-curly-brace %[ + evaluate-commands -draft -itersel %_ + # align indent with opening paren when { is entered on a new line after the closing paren + try %[ execute-keys -draft h ) M \A\(.*\)\h*\n\h*\{\z s \A|.\z 1 ] + _ +] + +define-command -hidden rust-indent-on-closing-curly-brace %[ + evaluate-commands -draft -itersel %_ + # align to opening curly brace when alone on a line + try %[ execute-keys -draft ^\h+\}$ h m s \A|.\z 1 ] + _ +] + +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook -group rust-highlight global WinSetOption filetype=rust %{ + add-highlighter window/rust ref rust + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/rust } +} + +hook global WinSetOption filetype=rust %[ + hook window ModeChange insert:.* -group rust-trim-indent rust-trim-indent + hook window InsertChar \n -group rust-indent rust-indent-on-new-line + hook window InsertChar \{ -group rust-indent rust-indent-on-opening-curly-brace + hook window InsertChar \} -group rust-indent rust-indent-on-closing-curly-brace + hook -once -always window WinSetOption filetype=.* %{ remove-hooks window rust-.+ } +] diff --git a/rc/filetype/sass.kak b/rc/filetype/sass.kak new file mode 100644 index 00000000..d23a7b81 --- /dev/null +++ b/rc/filetype/sass.kak @@ -0,0 +1,62 @@ +# http://sass-lang.com +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +# Detection +# ‾‾‾‾‾‾‾‾‾ + +hook global BufCreate .*[.](sass) %{ + set-option buffer filetype sass +} + +# Highlighters +# ‾‾‾‾‾‾‾‾‾‾‾‾ + +add-highlighter shared/sass regions +add-highlighter shared/sass/code default-region group +add-highlighter shared/sass/single_string region '"' (? s \h+$ d } +} + +define-command -hidden sass-indent-on-new-line %{ + evaluate-commands -draft -itersel %{ + # copy '/' comment prefix and following white spaces + try %{ execute-keys -draft k s ^\h*\K/\h* y gh j P } + # preserve previous line indent + try %{ execute-keys -draft \; K } + # filter previous line + try %{ execute-keys -draft k : sass-trim-indent } + # avoid indent after properties and comments + try %{ execute-keys -draft k [:/] j } + } +} + +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook -group sass-highlight global WinSetOption filetype=sass %{ + add-highlighter window/sass ref sass + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/sass } +} + +hook global WinSetOption filetype=sass %{ + hook window ModeChange insert:.* -group sass-trim-indent sass-trim-indent + hook window InsertChar \n -group sass-indent sass-indent-on-new-line + set-option buffer extra_word_chars '_' '-' + + hook -once -always window WinSetOption filetype=.* %{ remove-hooks window sass-.+ } +} diff --git a/rc/filetype/scala.kak b/rc/filetype/scala.kak new file mode 100644 index 00000000..1e62e2ad --- /dev/null +++ b/rc/filetype/scala.kak @@ -0,0 +1,75 @@ +# http://scala-lang.org +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +# Detection +# ‾‾‾‾‾‾‾‾‾ + +hook global BufCreate .*[.](scala) %{ + set-option buffer filetype scala +} + +# Highlighters +# ‾‾‾‾‾‾‾‾‾‾‾‾ + +add-highlighter shared/scala regions +add-highlighter shared/scala/code default-region group +add-highlighter shared/scala/string region '"' (?|<:|:>|=:=|::|&&|\|\|) 0:operator + +# Commands +# ‾‾‾‾‾‾‾‾ + +define-command -hidden scala-trim-indent %{ + # remove trailing white spaces + try %{ execute-keys -draft -itersel s \h+$ d } +} + +define-command -hidden scala-indent-on-new-line %[ + evaluate-commands -draft -itersel %[ + # copy // comments prefix and following white spaces + try %[ execute-keys -draft k s ^\h*\K#\h* y gh j P ] + # preserve previous line indent + try %[ execute-keys -draft \; K ] + # filter previous line + try %[ execute-keys -draft k : scala-trim-indent ] + # indent after lines ending with { + try %[ execute-keys -draft k \{$ j ] + ] +] + +define-command -hidden scala-indent-on-closing-curly-brace %[ + evaluate-commands -draft -itersel %[ + # align to opening curly brace when alone on a line + try %[ execute-keys -draft ^\h+\}$ m s \A|.\z 1 ] + ] +] + +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook -group scala-highlight global WinSetOption filetype=scala %{ + add-highlighter window/scala ref scala + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/scala } +} + +hook global WinSetOption filetype=scala %[ + hook window ModeChange insert:.* -group scala-trim-indent scala-trim-indent + hook window InsertChar \n -group scala-indent scala-indent-on-new-line + hook window InsertChar \} -group scala-indent scala-indent-on-closing-curly-brace + + hook -once -always window WinSetOption filetype=.* %{ remove-hooks window scala-.+ } +] diff --git a/rc/filetype/scheme.kak b/rc/filetype/scheme.kak new file mode 100644 index 00000000..ec86638b --- /dev/null +++ b/rc/filetype/scheme.kak @@ -0,0 +1,133 @@ +# http://www.scheme-reports.org +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +# require lisp.kak + +# Detection +# ‾‾‾‾‾‾‾‾‾ + +hook global BufCreate (.*/)?(.*\.(scm|ss|sld)) %{ + set-option buffer filetype scheme +} + +# Highlighters +# ‾‾‾‾‾‾‾‾‾‾‾‾ + +add-highlighter shared/scheme regions +add-highlighter shared/scheme/code default-region group + +add-highlighter shared/scheme/string region '"' (? > >=", operators); + + # Procedures that create a base type and their predicates (for easier type checking) + split("list vector bytevector cons string boolean? list? pair? "\ + "vector? bytevector? string? char? complex? eof-object? input-port? "\ + "null? number? output-port? procedure? symbol?", types); + + # R5RS available procedures + split("abs acos angle append apply asin assoc assq assv atan "\ + "caaaar caaadr caaar caadar caaddr caadr "\ + "caar cadaar cadadr cadar caddar cadddr caddr cadr "\ + "call-with-current-continuation call-with-input-file "\ + "call-with-output-file call-with-values car cdaaar cdaadr cdaar "\ + "cdadar cdaddr cdadr cdar cddaar cddadr cddar cdddar cddddr cdddr "\ + "cddr cdr ceiling char->integer char-alphabetic? char-ci<=? "\ + "char-ci=? char-ci>? char-downcase "\ + "char-lower-case? char-numeric? char-ready? char-upcase "\ + "char-upper-case? char-whitespace? char<=? char=? char>? close-input-port close-output-port cons cos "\ + "current-input-port current-output-port denominator display "\ + "dynamic-wind else eq? equal? eqv? eval even? exact->inexact "\ + "exact? exp expt floor for-each force gcd imag-part inexact->exact "\ + "inexact? integer->char integer? interaction-environment lcm "\ + "length list list->string list->vector list-ref list-tail load log "\ + "magnitude make-polar make-rectangular make-string make-vector "\ + "map max member memq memv min modulo negative? newline not "\ + "null-environment number->string numerator odd? open-input-file "\ + "open-output-file or peek-char positive? quasiquote quote quotient "\ + "rational? rationalize read read-char real-part real? remainder "\ + "reverse round scheme-report-environment set-car! set-cdr! sin "\ + "sqrt string->list string->number string->symbol string-append "\ + "string-ci<=? string-ci=? "\ + "string-ci>? string-copy string-fill! string-length string-ref "\ + "string-set! string<=? string=? string>? "\ + "substring symbol->string tan truncate values vector "\ + "vector->list vector-fill! vector-length vector-ref vector-set! "\ + "with-input-from-file with-output-to-file write write-char zero?", + builtins); + + non_word_chars="[\\s\\(\\)\\[\\]\\{\\};\\|]"; + + normal_identifiers="-!$%&\\*\\+\\./:<=>\\?\\^_~a-zA-Z0-9"; + identifier_chars="[" normal_identifiers "][" normal_identifiers ",#]*"; + } + function add_highlighter(regex, highlight) { + printf("add-highlighter shared/scheme/code/ regex \"%s\" %s\n", regex, highlight); + } + function quoted_join(words, quoted, first) { + first=1 + for (i in words) { + if (!first) { quoted=quoted "|"; } + quoted=quoted "\\Q" words[i] "\\E"; + first=0; + } + return quoted; + } + function add_word_highlighter(words, face, regex) { + regex = non_word_chars "+(" quoted_join(words) ")" non_word_chars + add_highlighter(regex, "1:" face) + } + function print_words(words) { + for (i in words) { printf(" %s", words[i]); } + } + + BEGIN { + printf("hook global WinSetOption filetype=scheme %%{ set-option window static_words "); + print_words(keywords); print_words(meta); print_words(operators); print_words(builtins); + printf(" }\n") + + add_word_highlighter(keywords, "keyword"); + add_word_highlighter(meta, "meta"); + add_word_highlighter(operators, "operator"); + add_word_highlighter(builtins, "builtin"); + add_word_highlighter(types, "type"); + add_highlighter(non_word_chars "+('" identifier_chars ")", "1:attribute"); + add_highlighter("\\(define\\W+\\((" identifier_chars ")", "1:function"); + add_highlighter("\\(define\\W+(" identifier_chars ")\\W+\\(lambda", "1:function"); + } +EOF +} + +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook -group scheme-highlight global WinSetOption filetype=scheme %{ + add-highlighter window/scheme ref scheme + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/scheme } +} + + +hook global WinSetOption filetype=scheme %{ + set-option buffer extra_word_chars '_' '-' '!' '%' '?' '<' '>' '=' + hook window InsertEnd .* -group scheme-trim-indent lisp-trim-indent + hook window InsertChar \n -group scheme-indent lisp-indent-on-new-line + + hook -once -always window WinSetOption filetype=.* %{ remove-hooks window scheme-.+ } +} diff --git a/rc/filetype/scss.kak b/rc/filetype/scss.kak new file mode 100644 index 00000000..bb720db5 --- /dev/null +++ b/rc/filetype/scss.kak @@ -0,0 +1,45 @@ +# http://sass-lang.com +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +# require css.kak + +# Detection +# ‾‾‾‾‾‾‾‾‾ + +hook global BufCreate .*[.](scss) %{ + set-option buffer filetype scss +} + +# Highlighters +# ‾‾‾‾‾‾‾‾‾‾‾‾ + +add-highlighter shared/scss regions +add-highlighter shared/scss/core default-region group +add-highlighter shared/scss/comment region // $ fill comment + +add-highlighter shared/scss/core/ ref css +add-highlighter shared/scss/core/ regex @[A-Za-z][A-Za-z0-9_-]* 0:meta + +# Commands +# ‾‾‾‾‾‾‾‾ + +define-command -hidden scss-trim-indent css-trim-indent +define-command -hidden scss-indent-on-new-line css-indent-on-new-line +define-command -hidden scss-indent-on-closing-curly-brace css-indent-on-closing-curly-brace + +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook -group scss-highlight global WinSetOption filetype=scss %{ + add-highlighter window/scss ref scss + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/scss } +} + +hook global WinSetOption filetype=scss %[ + hook window ModeChange insert:.* -group scss-trim-indent scss-trim-indent + hook window InsertChar \n -group scss-indent scss-indent-on-new-line + hook window InsertChar \} -group scss-indent scss-indent-on-closing-curly-brace + set-option buffer extra_word_chars '_' '-' + + hook -once -always window WinSetOption filetype=.* %{ remove-hooks window scss-.+ } +] diff --git a/rc/filetype/sh.kak b/rc/filetype/sh.kak new file mode 100644 index 00000000..517f6a18 --- /dev/null +++ b/rc/filetype/sh.kak @@ -0,0 +1,43 @@ +hook global BufCreate .*\.(z|ba|c|k|mk)?sh(rc|_profile)? %{ + set-option buffer filetype sh +} + +add-highlighter shared/sh regions +add-highlighter shared/sh/code default-region group +add-highlighter shared/sh/double_string region %{(?|<|>=|<=|<>|\+=|-=|\*=|/=|%=|&=|^-=|\|\*=' 0:operator +add-highlighter shared/sql/code/ regex \bNULL\b 0:value +add-highlighter shared/sql/code/ regex \b\d+(?:\.\d+)?\b 0:value + +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook -group sql-highlight global WinSetOption filetype=sql %{ + add-highlighter window/sql ref sql + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/sql } +} diff --git a/rc/filetype/swift.kak b/rc/filetype/swift.kak new file mode 100644 index 00000000..1526cadb --- /dev/null +++ b/rc/filetype/swift.kak @@ -0,0 +1,28 @@ +hook global BufCreate .*\.(swift) %{ + set-option buffer filetype swift +} + +add-highlighter shared/swift regions +add-highlighter shared/swift/code default-region group +add-highlighter shared/swift/string region %{(? } + ## If the line above is a project indent with a tab + try %{ execute-keys -draft Z k ^\h*([^:\n]+): z i } + # cleanup trailing white spaces on previous line + try %{ execute-keys -draft k s \h+$ d } + } +} + +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook -group taskpaper-highlight global WinSetOption filetype=taskpaper %{ + add-highlighter window/taskpaper ref taskpaper + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/taskpaper } +} + +hook global WinSetOption filetype=taskpaper %{ + hook window InsertChar \n -group taskpaper-indent taskpaper-indent-on-new-line + hook -once -always window WinSetOption filetype=.* %{ remove-hooks window taskpaper-.+ } +} diff --git a/rc/filetype/toml.kak b/rc/filetype/toml.kak new file mode 100644 index 00000000..f95fbb9d --- /dev/null +++ b/rc/filetype/toml.kak @@ -0,0 +1,63 @@ +# https://github.com/toml-lang/toml/tree/v0.4.0 +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +# Detection +# ‾‾‾‾‾‾‾‾‾ + +hook global BufCreate .*\.(toml) %{ + set-option buffer filetype toml +} + +# Highlighters +# ‾‾‾‾‾‾‾‾‾‾‾‾ + +add-highlighter shared/toml regions +add-highlighter shared/toml/code default-region group +add-highlighter shared/toml/comment region '#' $ fill comment +add-highlighter shared/toml/string1 region '"""' (? s \h+$ d } +} + +define-command -hidden toml-indent-on-new-line %{ + evaluate-commands -draft -itersel %{ + # copy comment prefix and following white spaces + try %{ execute-keys -draft k s ^\h*\K#\h* y gh j P } + # preserve previous line indent + try %{ execute-keys -draft \; K } + # filter previous line + try %{ execute-keys -draft k : toml-trim-indent } + } +} + +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook -group toml-highlight global WinSetOption filetype=toml %{ + add-highlighter window/toml ref toml + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/toml } +} + +hook global WinSetOption filetype=toml %{ + hook window ModeChange insert:.* -group toml-trim-indent toml-trim-indent + hook window InsertChar \n -group toml-indent toml-indent-on-new-line + + hook -once -always window WinSetOption filetype=.* %{ remove-hooks window toml-.+ } +} diff --git a/rc/filetype/troff.kak b/rc/filetype/troff.kak new file mode 100644 index 00000000..072cc3d1 --- /dev/null +++ b/rc/filetype/troff.kak @@ -0,0 +1,30 @@ +# Detection +# ‾‾‾‾‾‾‾‾‾ + +hook global BufCreate .*\.\d+ %{ + set-option buffer filetype troff +} + +# Highlighters +# ‾‾‾‾‾‾‾‾‾‾‾‾ + +add-highlighter shared/troff group +add-highlighter shared/troff/ regex '\\f[A-Z]' 0:attribute +add-highlighter shared/troff/ regex '\\fB(.+?)\\f[A-Z]' 1:+b +add-highlighter shared/troff/ regex '\\fI(.+?)\\f[A-Z]' 1:+i + +add-highlighter shared/troff/ regex '^\.[a-zA-Z]{1,2}\b' 0:meta +add-highlighter shared/troff/ regex '^\.TH\s+[^\n]+' 0:title +add-highlighter shared/troff/ regex '^\.SH\s+[^\n]+' 0:header +add-highlighter shared/troff/ regex '^\.IR\s+(\S+)' 1:+i +add-highlighter shared/troff/ regex '^\.BR\s+(\S+)' 1:+b +add-highlighter shared/troff/ regex '^\.I\s+([^\n]+)' 1:+i +add-highlighter shared/troff/ regex '^\.B\s+([^\n]+)' 1:+b + +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook -group troff-highlight global WinSetOption filetype=troff %{ + add-highlighter window/troff ref troff + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/troff } +} diff --git a/rc/filetype/tupfile.kak b/rc/filetype/tupfile.kak new file mode 100644 index 00000000..e7ba0d52 --- /dev/null +++ b/rc/filetype/tupfile.kak @@ -0,0 +1,33 @@ +# http://gittup.org/tup/ +# + +# Detection +# ‾‾‾‾‾‾‾‾‾ + +hook global BufCreate .*/?Tup(file|rules)(\.\w+)?$ %{ + set-option buffer filetype tupfile +} + +# Highlighters +# ‾‾‾‾‾‾‾‾‾‾‾‾ + +add-highlighter shared/tupfile regions +add-highlighter shared/tupfile/code default-region group +add-highlighter shared/tupfile/string region '"' (? s \h+$ d } +} + +define-command -hidden yaml-indent-on-new-line %{ + evaluate-commands -draft -itersel %{ + # copy '#' comment prefix and following white spaces + try %{ execute-keys -draft k s ^\h*\K#\h* y gh j P } + # preserve previous line indent + try %{ execute-keys -draft \; K } + # filter previous line + try %{ execute-keys -draft k : yaml-trim-indent } + # indent after : + try %{ execute-keys -draft k x :$ j } + } +} + +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook -group yaml-highlight global WinSetOption filetype=yaml %{ + add-highlighter window/yaml ref yaml + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/yaml } +} + +hook global WinSetOption filetype=yaml %{ + hook window ModeChange insert:.* -group yaml-trim-indent yaml-trim-indent + hook window InsertChar \n -group yaml-indent yaml-indent-on-new-line + hook -once -always window WinSetOption filetype=.* %{ remove-hooks window yaml-.+ } +} diff --git a/rc/tools/autorestore.kak b/rc/tools/autorestore.kak new file mode 100644 index 00000000..f8e3e14d --- /dev/null +++ b/rc/tools/autorestore.kak @@ -0,0 +1,71 @@ +declare-option -docstring "remove backups once they've been restored" \ + bool autorestore_purge_restored true + +## Insert the content of the backup file into the current buffer, if a suitable one is found +define-command autorestore-restore-buffer -docstring "Restore the backup for the current file if it exists" %{ + evaluate-commands %sh{ + buffer_basename="${kak_buffile##*/}" + buffer_dirname=$(dirname "${kak_buffile}") + + if [ -f "${kak_buffile}" ]; then + newer=$(find "${buffer_dirname}"/".${buffer_basename}.kak."* -newer "${kak_buffile}" -exec ls -1t {} + 2>/dev/null | head -n 1) + + older=$(find "${buffer_dirname}"/".${buffer_basename}.kak."* \! -newer "${kak_buffile}" -exec ls -1t {} + 2>/dev/null | head -n 1) + else + # New buffers that were never written to disk. + newer=$(ls -1t "${buffer_dirname}"/".${buffer_basename}.kak."* 2>/dev/null | head -n 1) + fi + + if [ -z "${newer}" ]; then + if [ -n "${older}" ]; then + printf %s\\n " + echo -debug Old backup file(s) found: will not restore ${older} . + " + fi + exit + fi + + printf %s\\n " + ## Replace the content of the buffer with the content of the backup file + echo -debug Restoring file: ${newer} + + execute-keys -draft %{ %d!cat\"${newer}\"d } + + ## If the backup file has to be removed, issue the command once + ## the current buffer has been saved + ## If the autorestore_purge_restored option has been unset right after the + ## buffer was restored, do not remove the backup + hook -group autorestore buffer BufWritePost '${kak_buffile}' %{ + nop %sh{ + if [ \"\${kak_opt_autorestore_purge_restored}\" = true ]; + then + rm -f \"${buffer_dirname}/.${buffer_basename}.kak.\"* + fi + } + } + " + } +} + +## Remove all the backups that have been created for the current buffer +define-command autorestore-purge-backups -docstring "Remove all the backups of the current buffer" %{ + evaluate-commands %sh{ + [ ! -f "${kak_buffile}" ] && exit + + buffer_basename="${kak_bufname##*/}" + buffer_dirname=$(dirname "${kak_bufname}") + + rm -f "${buffer_dirname}/.${buffer_basename}.kak."* + + printf %s\\n " + echo -markup {Information}Backup files removed. + " + } +} + +## If for some reason, backup files need to be ignored +define-command autorestore-disable -docstring "Disable automatic backup recovering" %{ + remove-hooks global autorestore +} + +hook -group autorestore global BufCreate .* %{ autorestore-restore-buffer } diff --git a/rc/tools/autowrap.kak b/rc/tools/autowrap.kak new file mode 100644 index 00000000..0fb12123 --- /dev/null +++ b/rc/tools/autowrap.kak @@ -0,0 +1,48 @@ +declare-option -docstring "maximum amount of characters per line, after which a newline character will be inserted" \ + int autowrap_column 80 + +declare-option -docstring %{when enabled, paragraph formatting will reformat the whole paragraph in which characters are being inserted +This can potentially break formatting of documents containing markup (e.g. markdown)} \ + bool autowrap_format_paragraph no +declare-option -docstring %{command to which the paragraphs to wrap will be passed +all occurences of '%c' are replaced with `autowrap_column`} \ + str autowrap_fmtcmd 'fold -s -w %c' + +define-command -hidden autowrap-cursor %{ evaluate-commands -save-regs '/"|^@m' %{ + try %{ + ## if the line isn't too long, do nothing + execute-keys -draft "^[^\n]{%opt{autowrap_column},}[^\n]" + + try %{ + reg m "%val{selections_desc}" + + ## if we're adding characters past the limit, just wrap them around + execute-keys -draft ".{%opt{autowrap_column}}\h*[^\s]*1s(\h+)[^\h]*\zc" + } catch %{ + ## if we're adding characters in the middle of a sentence, use + ## the `fmtcmd` command to wrap the entire paragraph + evaluate-commands %sh{ + if [ "${kak_opt_autowrap_format_paragraph}" = true ] \ + && [ -n "${kak_opt_autowrap_fmtcmd}" ]; then + format_cmd=$(printf %s "${kak_opt_autowrap_fmtcmd}" \ + | sed "s/%c/${kak_opt_autowrap_column}/g") + printf %s " + evaluate-commands -draft %{ + execute-keys 'p|${format_cmd}' + try %{ execute-keys s\h+$ d } + } + select '${kak_main_reg_m}' + " + fi + } + } + } +} } + +define-command autowrap-enable -docstring "Automatically wrap the lines in which characters are inserted" %{ + hook -group autowrap window InsertChar [^\n] autowrap-cursor +} + +define-command autowrap-disable -docstring "Disable automatic line wrapping" %{ + remove-hooks window autowrap +} diff --git a/rc/tools/clang.kak b/rc/tools/clang.kak new file mode 100644 index 00000000..3386073b --- /dev/null +++ b/rc/tools/clang.kak @@ -0,0 +1,180 @@ +declare-option -docstring "options to pass to the `clang` shell command" \ + str clang_options + +declare-option -hidden str clang_tmp_dir +declare-option -hidden completions clang_completions +declare-option -hidden line-specs clang_flags +declare-option -hidden line-specs clang_errors + +define-command -params ..1 \ + -docstring %{Parse the contents of the current buffer +The syntaxic errors detected during parsing are shown when auto-diagnostics are enabled} \ + clang-parse %{ + evaluate-commands %sh{ + dir=$(mktemp -d "${TMPDIR:-/tmp}"/kak-clang.XXXXXXXX) + mkfifo ${dir}/fifo + printf %s\\n "set-option buffer clang_tmp_dir ${dir}" + printf %s\\n "evaluate-commands -no-hooks write -sync ${dir}/buf" + } + # end the previous %sh{} so that its output gets interpreted by kakoune + # before launching the following as a background task. + evaluate-commands %sh{ + dir=${kak_opt_clang_tmp_dir} + printf %s\\n "evaluate-commands -draft %{ + edit! -fifo ${dir}/fifo -debug *clang-output* + set-option buffer filetype make + set-option buffer make_current_error_line 0 + hook -once -always buffer BufCloseFifo .* %{ nop %sh{ rm -r ${dir} } } + }" + # this runs in a detached shell, asynchronously, so that kakoune does + # not hang while clang is running. As completions references a cursor + # position and a buffer timestamp, only valid completions should be + # displayed. + ( + case ${kak_opt_filetype} in + c) ft=c ;; + cpp) ft=c++ ;; + obj-c) ft=objective-c ;; + *) ft=c++ ;; + esac + + if [ "$1" = "-complete" ]; then + pos=-:${kak_cursor_line}:${kak_cursor_column} + header="${kak_cursor_line}.${kak_cursor_column}@${kak_timestamp}" + compl=$(clang++ -x ${ft} -fsyntax-only ${kak_opt_clang_options} \ + -Xclang -code-completion-brief-comments -Xclang -code-completion-at=${pos} - < ${dir}/buf 2> ${dir}/stderr | + awk -F ': ' ' + /^COMPLETION:/ && ! /\(Hidden\)/ { + id=$2 + gsub(/ +$/, "", id) + gsub(/~/, "~~", id) + gsub(/\|/, "\\|", id) + + gsub(/[[{<]#|#[}>]/, "", $3) + gsub(/#]/, " ", $3) + gsub(/:: /, "::", $3) + gsub(/ +$/, "", $3) + desc=$4 ? $3 "\n" $4 : $3 + + gsub(/~/, "~~", desc) + gsub(/\|/, "\\|", desc) + if (id in docstrings) + docstrings[id]=docstrings[id] "\n" desc + else + docstrings[id]=desc + } + END { + for (id in docstrings) { + menu=id + gsub(/(^|[^[:alnum:]_])(operator|new|delete)($|[^{}_[:alnum:]]+)/, "{keyword}&{}", menu) + gsub(/(^|[[:space:]])(int|size_t|bool|char|unsigned|signed|long)($|[[:space:]])/, "{type}&{}", menu) + gsub(/[^{}_[:alnum:]]+/, "{operator}&{}", menu) + printf "%%~%s|%s|%s~ ", id, docstrings[id], menu + } + }') + printf %s\\n "evaluate-commands -client ${kak_client} echo 'clang completion done' + set-option 'buffer=${kak_buffile}' clang_completions ${header} ${compl}" | kak -p ${kak_session} + else + clang++ -x ${ft} -fsyntax-only ${kak_opt_clang_options} - < ${dir}/buf 2> ${dir}/stderr + printf %s\\n "evaluate-commands -client ${kak_client} echo 'clang parsing done'" | kak -p ${kak_session} + fi + + flags=$(cat ${dir}/stderr | sed -rne " + /^:[0-9]+:([0-9]+:)? (fatal )?error/ { s/^:([0-9]+):.*/'\1|{red}█'/; p } + /^:[0-9]+:([0-9]+:)? warning/ { s/^:([0-9]+):.*/'\1|{yellow}█'/; p } + " | paste -s -d ' ' -) + + errors=$(cat ${dir}/stderr | sed -rne " + /^:[0-9]+:([0-9]+:)? ((fatal )?error|warning)/ { + s/'/''/g; s/^:([0-9]+):([0-9]+:)? (.*)/'\1|\3'/; p + }" | sort -n | paste -s -d ' ' -) + + sed -e "s||${kak_bufname}|g" < ${dir}/stderr > ${dir}/fifo + + printf %s\\n "set-option 'buffer=${kak_buffile}' clang_flags ${kak_timestamp} ${flags} + set-option 'buffer=${kak_buffile}' clang_errors ${kak_timestamp} ${errors}" | kak -p ${kak_session} + ) > /dev/null 2>&1 < /dev/null & + } +} + +define-command clang-complete -docstring "Complete the current selection" %{ clang-parse -complete } + +define-command -hidden clang-show-completion-info %[ try %[ + evaluate-commands -draft %[ + execute-keys {( ^\( b \A\w+\z + evaluate-commands %sh[ + desc=$(printf %s\\n "${kak_opt_clang_completions}" | sed -e "{ s/\([^\\]\):/\1\n/g }" | sed -ne "/^${kak_selection}|/ { s/^[^|]\+|//; s/|.*$//; s/\\\:/:/g; p }") + if [ -n "$desc" ]; then + printf %s\\n "evaluate-commands -client $kak_client %{info -anchor ${kak_cursor_line}.${kak_cursor_column} -placement above %{${desc}}}" + fi + ] ] +] ] + +define-command clang-enable-autocomplete -docstring "Enable automatic clang completion" %{ + set-option window completers "option=clang_completions" %opt{completers} + hook window -group clang-autocomplete InsertIdle .* %{ + try %{ + execute-keys -draft (\.|->|::).\z + echo 'completing...' + clang-complete + } + clang-show-completion-info + } + alias window complete clang-complete +} + +define-command clang-disable-autocomplete -docstring "Disable automatic clang completion" %{ + evaluate-commands %sh{ printf "set-option window completers %s\n" $(printf %s "${kak_opt_completers}" | sed -e "s/'option=clang_completions'//g") } + remove-hooks window clang-autocomplete + unalias window complete clang-complete +} + +define-command -hidden clang-show-error-info %{ + update-option buffer clang_errors # Ensure we are up to date with buffer changes + evaluate-commands %sh{ + eval "set -- ${kak_opt_clang_errors}" + shift # skip timestamp + desc=$(for error in "$@"; do + if [ "${error%%|*}" = "$kak_cursor_line" ]; then + printf '%s\n' "${error##*|}" + fi + done) + if [ -n "$desc" ]; then + desc=$(printf %s "${desc}" | sed "s/'/''/g") + printf "info -anchor %d.%d '%s'\n" "${kak_cursor_line}" "${kak_cursor_column}" "${desc}" + fi + } } + +define-command clang-enable-diagnostics -docstring %{Activate automatic error reporting and diagnostics +Information about the analysis are showned after the buffer has been parsed with the clang-parse function} \ +%{ + add-highlighter window/clang_flags flag-lines default clang_flags + hook window -group clang-diagnostics NormalIdle .* %{ clang-show-error-info } + hook window -group clang-diagnostics WinSetOption ^clang_errors=.* %{ info; clang-show-error-info } +} + +define-command clang-disable-diagnostics -docstring "Disable automatic error reporting and diagnostics" %{ + remove-highlighter window/clang_flags + remove-hooks window clang-diagnostics +} + +define-command clang-diagnostics-next -docstring "Jump to the next line that contains an error" %{ + update-option buffer clang_errors # Ensure we are up to date with buffer changes + evaluate-commands %sh{ + eval "set -- ${kak_opt_clang_errors}" + shift # skip timestamp + for error in "$@"; do + candidate=${error%%|*} + first_line=${first_line-$candidate} + if [ "$candidate" -gt $kak_cursor_line ]; then + line=$candidate + break + fi + done + line=${line-$first_line} + if [ -n "$line" ]; then + printf %s\\n "execute-keys ${line} g" + else + echo "echo -markup '{Error}no next clang diagnostic'" + fi + } } diff --git a/rc/tools/comment.kak b/rc/tools/comment.kak new file mode 100644 index 00000000..fbfb8267 --- /dev/null +++ b/rc/tools/comment.kak @@ -0,0 +1,180 @@ +# Line comments +declare-option -docstring "characters inserted at the beginning of a commented line" \ + str comment_line '#' + +# Block comments +declare-option -docstring "characters inserted before a commented block" \ + str comment_block_begin +declare-option -docstring "characters inserted after a commented block" \ + str comment_block_end + +# Default comments for all languages +hook global BufSetOption filetype=asciidoc %{ + set-option buffer comment_block_begin '///' + set-option buffer comment_block_end '///' +} + +hook global BufSetOption filetype=(c|cpp|dart|go|java|javascript|objc|php|rust|sass|scala|scss|swift|typescript) %{ + set-option buffer comment_line '//' + set-option buffer comment_block_begin '/*' + set-option buffer comment_block_end '*/' +} + +hook global BufSetOption filetype=(cabal|haskell|moon|idris|elm) %{ + set-option buffer comment_line '--' + set-option buffer comment_block_begin '{-' + set-option buffer comment_block_end '-}' +} + +hook global BufSetOption filetype=clojure %{ + set-option buffer comment_line '#_' + set-option buffer comment_block_begin '(comment ' + set-option buffer comment_block_end ')' +} + +hook global BufSetOption filetype=coffee %{ + set-option buffer comment_block_begin '###' + set-option buffer comment_block_end '###' +} + +hook global BufSetOption filetype=css %{ + set-option buffer comment_line '' + set-option buffer comment_block_begin '/*' + set-option buffer comment_block_end '*/' +} + +hook global BufSetOption filetype=d %{ + set-option buffer comment_line '//' + set-option buffer comment_block_begin '/+' + set-option buffer comment_block_end '+/' +} + +hook global BufSetOption filetype=(gas|ini) %{ + set-option buffer comment_line ';' +} + +hook global BufSetOption filetype=haml %{ + set-option buffer comment_line '-#' +} + +hook global BufSetOption filetype=(html|xml) %{ + set-option buffer comment_line '' + set-option buffer comment_block_begin '' +} + +hook global BufSetOption filetype=latex %{ + set-option buffer comment_line '%' +} + +hook global BufSetOption filetype=lisp %{ + set-option buffer comment_line ';' + set-option buffer comment_block_begin '#|' + set-option buffer comment_block_end '|#' +} + +hook global BufSetOption filetype=lua %{ + set-option buffer comment_line '--' + set-option buffer comment_block_begin '--[[' + set-option buffer comment_block_end ']]' +} + +hook global BufSetOption filetype=markdown %{ + set-option buffer comment_line '' + set-option buffer comment_block_begin '[//]' + set-option buffer comment_block_end '# (:)' +} + +hook global BufSetOption filetype=perl %{ + set-option buffer comment_block_begin '#[' + set-option buffer comment_block_end ']' +} + +hook global BufSetOption filetype=pug %{ + set-option buffer comment_line '//' +} + +hook global BufSetOption filetype=python %{ + set-option buffer comment_block_begin "'''" + set-option buffer comment_block_end "'''" +} + +hook global BufSetOption filetype=ragel %{ + set-option buffer comment_line '%%' + set-option buffer comment_block_begin '%%{' + set-option buffer comment_block_end '}%%' +} + +hook global BufSetOption filetype=ruby %{ + set-option buffer comment_block_begin '^begin=' + set-option buffer comment_block_end '^=end' +} + +define-command comment-block -docstring '(un)comment selections using block comments' %{ + evaluate-commands %sh{ + if [ -z "${kak_opt_comment_block_begin}" ] || [ -z "${kak_opt_comment_block_end}" ]; then + echo "fail \"The 'comment_block' options are empty, could not comment the selection\"" + fi + } + evaluate-commands -save-regs '"/' -draft %{ + # Keep non-empty selections + execute-keys \A\s*\z + + try %{ + # Assert that the selection has been commented + set-register / "\A\Q%opt{comment_block_begin}\E.*\Q%opt{comment_block_end}\E\n*\z" + execute-keys "s" + # Uncomment it + set-register / "\A\Q%opt{comment_block_begin}\E|\Q%opt{comment_block_end}\E\n*\z" + execute-keys sd + } catch %{ + # Comment the selection + set-register '"' "%opt{comment_block_begin}" + execute-keys P + set-register '"' "%opt{comment_block_end}" + execute-keys p + } + } +} + +define-command comment-line -docstring '(un)comment selected lines using line comments' %{ + evaluate-commands %sh{ + if [ -z "${kak_opt_comment_line}" ]; then + echo "fail \"The 'comment_line' option is empty, could not comment the line\"" + fi + } + evaluate-commands -save-regs '"/' -draft %{ + # Select the content of the lines, without indentation + execute-keys gi + + try %{ + # Keep non-empty lines + execute-keys \A\s*\z + } + + try %{ + set-register / "\A\Q%opt{comment_line}\E\h?" + + try %{ + # See if there are any uncommented lines in the selection + execute-keys -draft + + # There are uncommented lines, so comment everything + set-register '"' "%opt{comment_line} " + align-selections-left + execute-keys P + } catch %{ + # All lines were commented, so uncomment everything + execute-keys sd + } + } + } +} + +define-command align-selections-left -docstring 'extend selections to the left to align with the leftmost selected column' %{ + evaluate-commands %sh{ + leftmost_column=$(echo "$kak_selections_desc" | tr ' ' '\n' | cut -d',' -f1 | cut -d'.' -f2 | sort -n | head -n1) + aligned_selections=$(echo "$kak_selections_desc" | sed -E "s/\.[0-9]+,/.$leftmost_column,/g") + echo "select $aligned_selections" + } +} diff --git a/rc/tools/ctags.kak b/rc/tools/ctags.kak new file mode 100644 index 00000000..20eabac0 --- /dev/null +++ b/rc/tools/ctags.kak @@ -0,0 +1,123 @@ +# Kakoune Exuberant CTags support script +# +# This script requires the readtags command available in ctags source but +# not installed by default + +declare-option -docstring "list of paths to tag files to parse when looking up a symbol" \ + str-list ctagsfiles 'tags' + +define-command -params ..1 \ + -shell-script-candidates %{ + realpath() { ( cd "$(dirname "$1")"; printf "%s/%s\n" "$(pwd -P)" "$(basename "$1")" ) } + eval "set -- $kak_opt_ctagsfiles" + for candidate in "$@"; do + [ -f "$candidate" ] && realpath "$candidate" + done | awk '!x[$0]++' | # remove duplicates + while read -r tags; do + namecache="${tags%/*}/.kak.${tags##*/}.namecache" + if [ -z "$(find "$namecache" -prune -newer "$tags")" ]; then + cut -f 1 "$tags" | grep -v '^!' | uniq > "$namecache" + fi + cat "$namecache" + done} \ + -docstring %{ctags-search []: jump to a symbol's definition +If no symbol is passed then the current selection is used as symbol name} \ + ctags-search \ + %{ evaluate-commands %sh{ + realpath() { ( cd "$(dirname "$1")"; printf "%s/%s\n" "$(pwd -P)" "$(basename "$1")" ) } + export tagname=${1:-${kak_selection}} + eval "set -- $kak_opt_ctagsfiles" + for candidate in "$@"; do + [ -f "$candidate" ] && realpath "$candidate" + done | awk '!x[$0]++' | # remove duplicates + while read -r tags; do + printf '!TAGROOT\t%s\n' "$(realpath "${tags%/*}")/" + readtags -t "$tags" $tagname + done | awk -F '\t|\n' ' + /^!TAGROOT\t/ { tagroot=$2 } + /[^\t]+\t[^\t]+\t\/\^.*\$?\// { + re=$0; + sub(".*\t/\\^", "", re); sub("\\$?/$", "", re); gsub("(\\{|\\}|\\\\E).*$", "", re); + keys=re; gsub(/", keys); gsub(/\t/, "", keys); + out = out " %{" $2 " {MenuInfo}" re "} %{evaluate-commands %{ try %{ edit %{" path($2) "}; execute-keys %{/\\Q" keys "vc} } catch %{ echo %{unable to find tag} } } }" + } + /[^\t]+\t[^\t]+\t[0-9]+/ { out = out " %{" $2 ":" $3 "} %{evaluate-commands %{ edit %{" path($2) "} %{" $3 "}}}" } + END { print ( length(out) == 0 ? "echo -markup %{{Error}no such tag " ENVIRON["tagname"] "}" : "menu -markup -auto-single " out ) } + + # Ensure x is an absolute file path, by prepending with tagroot + function path(x) { return x ~/^\// ? x : tagroot x }' + }} + +define-command ctags-complete -docstring "Insert completion candidates for the current selection into the buffer's local variables" %{ evaluate-commands -draft %{ + execute-keys hb^\w+$ + nop %sh{ { + compl=$(readtags -p "$kak_selection" | cut -f 1 | sort | uniq | sed -e 's/:/\\:/g' | sed -e 's/\n/:/g' ) + compl="${kak_cursor_line}.${kak_cursor_column}+${#kak_selection}@${kak_timestamp}:${compl}" + printf %s\\n "set-option buffer=$kak_bufname ctags_completions '${compl}'" | kak -p ${kak_session} + } > /dev/null 2>&1 < /dev/null & } +}} + +define-command ctags-funcinfo -docstring "Display ctags information about a selected function" %{ + evaluate-commands -draft %{ + try %{ + execute-keys '[(;B[a-zA-Z_]+\(' + evaluate-commands %sh{ + f=${kak_selection%?} + sig='\tsignature:(.*)' + csn='\t(class|struct|namespace):(\S+)' + sigs=$(readtags -e -Q '(eq? $kind "f")' "${f}" | sed -re "s/^.*${csn}.*${sig}$/\3 [\2::${f}]/ ;t ;s/^.*${sig}$/\1 [${f}]/") + if [ -n "$sigs" ]; then + printf %s\\n "evaluate-commands -client ${kak_client} %{info -anchor $kak_cursor_line.$kak_cursor_column -placement above '$sigs'}" + fi + } + } + } +} + +define-command ctags-enable-autoinfo -docstring "Automatically display ctags information about function" %{ + hook window -group ctags-autoinfo NormalIdle .* ctags-funcinfo + hook window -group ctags-autoinfo InsertIdle .* ctags-funcinfo +} + +define-command ctags-disable-autoinfo -docstring "Disable automatic ctags information displaying" %{ remove-hooks window ctags-autoinfo } + +declare-option -docstring "shell command to run" \ + str ctagscmd "ctags -R --fields=+S" +declare-option -docstring "path to the directory in which the tags file will be generated" str ctagspaths "." + +define-command ctags-generate -docstring 'Generate tag file asynchronously' %{ + echo -markup "{Information}launching tag generation in the background" + nop %sh{ ( + while ! mkdir .tags.kaklock 2>/dev/null; do sleep 1; done + trap 'rmdir .tags.kaklock' EXIT + + if ${kak_opt_ctagscmd} -f .tags.kaktmp ${kak_opt_ctagspaths}; then + mv .tags.kaktmp tags + msg="tags generation complete" + else + msg="tags generation failed" + fi + + printf %s\\n "evaluate-commands -client $kak_client echo -markup '{Information}${msg}'" | kak -p ${kak_session} + ) > /dev/null 2>&1 < /dev/null & } +} + +define-command ctags-update-tags -docstring 'Update tags for the given file' %{ + nop %sh{ ( + while ! mkdir .tags.kaklock 2>/dev/null; do sleep 1; done + trap 'rmdir .tags.kaklock' EXIT + + if ${kak_opt_ctagscmd} -f .file_tags.kaktmp $kak_bufname; then + export LC_COLLATE=C LC_ALL=C # ensure ASCII sorting order + # merge the updated tags tags with the general tags (filtering out out of date tags from it) into the target file + grep -Fv "$(printf '\t%s\t' "$kak_bufname")" tags | grep -v '^!' | sort --merge - .file_tags.kaktmp >> .tags.kaktmp + rm .file_tags.kaktmp + mv .tags.kaktmp tags + msg="tags updated for $kak_bufname" + else + msg="tags update failed for $kak_bufname" + fi + + printf %s\\n "evaluate-commands -client $kak_client echo -markup '{Information}${msg}'" | kak -p ${kak_session} + ) > /dev/null 2>&1 < /dev/null & } +} diff --git a/rc/tools/doc.kak b/rc/tools/doc.kak new file mode 100644 index 00000000..f1dbc850 --- /dev/null +++ b/rc/tools/doc.kak @@ -0,0 +1,165 @@ +declare-option -docstring "name of the client in which documentation is to be displayed" \ + str docsclient + +declare-option -hidden range-specs doc_render_ranges +declare-option -hidden range-specs doc_render_links +declare-option -hidden range-specs doc_links +declare-option -hidden range-specs doc_anchors + +define-command -hidden -params 4 doc-render-regex %{ + evaluate-commands -draft %{ try %{ + execute-keys \%s %arg{1} + execute-keys -draft s %arg{2} d + execute-keys "%arg{3}" + evaluate-commands %sh{ + face="$4" + eval "set -- $kak_selections_desc" + for desc in "$@"; do ranges="$ranges '$desc|$face'"; done + echo "update-option buffer doc_render_ranges" + echo "set-option -add buffer doc_render_ranges $ranges" + } + } } +} + +define-command -hidden doc-parse-links %{ + evaluate-commands -draft %{ try %{ + execute-keys \%s (.*?),.*? + execute-keys -draft s .*,| d + execute-keys H + set-option buffer doc_links %val{timestamp} + set-option buffer doc_render_links %val{timestamp} + evaluate-commands -itersel %{ + set-option -add buffer doc_links "%val{selection_desc}|%reg{1}" + set-option -add buffer doc_render_links "%val{selection_desc}|default+u" + } + } } +} + +define-command -hidden doc-parse-anchors %{ + evaluate-commands -draft %{ try %{ + set-option buffer doc_anchors %val{timestamp} + # Find sections as add them as imlicit anchors + execute-keys \%s ^={2,}\h+([^\n]+)$ + evaluate-commands -itersel %{ + set-option -add buffer doc_anchors "%val{selection_desc}|%sh{printf '%s' ""$kak_main_reg_1"" | tr '[A-Z ]' '[a-z-]'}" + } + + # Parse explicit anchors and remove their text + execute-keys \%s \[\[(.*?)\]\]\s* + evaluate-commands -itersel %{ + set-option -add buffer doc_anchors "%val{selection_desc}|%reg{1}" + } + execute-keys d + update-option buffer doc_anchors + } } +} + +define-command doc-jump-to-anchor -params 1 %{ + update-option buffer doc_anchors + evaluate-commands %sh{ + anchor="$1" + eval "set -- $kak_opt_doc_anchors" + + shift + for range in "$@"; do + if [ "${range#*|}" = "$anchor" ]; then + printf '%s\n' "select '${range%|*}'; execute-keys vv" + exit + fi + done + printf "echo -markup {Error}No such anchor '%s'" "${anchor}" + } +} + +define-command doc-follow-link %{ + update-option buffer doc_links + evaluate-commands %sh{ + eval "set -- $kak_opt_doc_links" + for link in "$@"; do + printf '%s\n' "$link" + done | awk -v FS='[.,|#]' ' + BEGIN { + l=ENVIRON["kak_cursor_line"]; + c=ENVIRON["kak_cursor_column"]; + } + l >= $1 && c >= $2 && l <= $3 && c <= $4 { + if (NF == 6) { + print "doc " $5 + if ($6 != "") { + print "doc-jump-to-anchor %{" $6 "}" + } + } else { + print "doc-jump-to-anchor %{" $5 "}" + } + exit + } + ' + } +} + +define-command -params 1 -hidden doc-render %{ + edit! -scratch "*doc-%sh{basename $1 .asciidoc}*" + execute-keys "!cat %arg{1}gg" + + doc-parse-anchors + + # Join paragraphs together + try %{ + execute-keys -draft '%S\n{2,}|(?<=\+)\n|^[^\n]+::\n|^\h*[*-]\h+' \ + ^\h*-{2,}(\n|\z) S\n\z \n + } + + # Remove some line end markers + try %{ execute-keys -draft \%s \h*(\+|:{2,})$ d } + + # Setup the doc_render_ranges option + set-option buffer doc_render_ranges %val{timestamp} + doc-render-regex \B(? d } + + set-option buffer readonly true + add-highlighter buffer/ ranges doc_render_ranges + add-highlighter buffer/ ranges doc_render_links + add-highlighter buffer/ wrap -word -indent + map buffer normal ': doc-follow-link' +} + +define-command -params 1..2 \ + -shell-script-candidates %{ + if [ "$kak_token_to_complete" -eq 0 ]; then + find "${kak_runtime}/doc/" -type f -name "*.asciidoc" | sed 's,.*/,,; s/\.[^/]*$//' + elif [ "$kak_token_to_complete" -eq 1 ]; then + readonly page="${kak_runtime}/doc/${1}.asciidoc" + if [ -f "${page}" ]; then + awk ' + /^==+ +/ { sub(/^==+ +/, ""); print } + /^\[\[[^\]]+\]\]/ { sub(/^\[\[/, ""); sub(/\]\].*/, ""); print } + ' < $page | tr '[A-Z ]' '[a-z-]' + fi + fi + } \ + doc -docstring %{doc []: open a buffer containing documentation about a given topic +An optional keyword argument can be passed to the function, which will be automatically selected in the documentation} %{ + evaluate-commands %sh{ + readonly page="${kak_runtime}/doc/${1}.asciidoc" + if [ -f "${page}" ]; then + if [ $# -eq 2 ]; then + jump_cmd="doc-jump-to-anchor '$2'" + fi + printf %s\\n "evaluate-commands -try-client %opt{docsclient} %{ doc-render ${page}; ${jump_cmd} }" + else + printf %s\\n "echo -markup '{Error}No such doc file: ${page}'" + fi + } +} + +alias global help doc diff --git a/rc/tools/formatter.kak b/rc/tools/formatter.kak new file mode 100644 index 00000000..40c38444 --- /dev/null +++ b/rc/tools/formatter.kak @@ -0,0 +1,31 @@ +declare-option -docstring "shell command to which the contents of the current buffer is piped" \ + str formatcmd + +define-command format -docstring "Format the contents of the current buffer" %{ evaluate-commands -draft -no-hooks %{ + evaluate-commands %sh{ + if [ -n "${kak_opt_formatcmd}" ]; then + path_file_tmp=$(mktemp "${TMPDIR:-/tmp}"/kak-formatter-XXXXXX) + printf %s\\n " + write -sync \"${path_file_tmp}\" + + evaluate-commands %sh{ + readonly path_file_out=\$(mktemp \"${TMPDIR:-/tmp}\"/kak-formatter-XXXXXX) + + if cat \"${path_file_tmp}\" | eval \"${kak_opt_formatcmd}\" > \"\${path_file_out}\"; then + printf '%s\\n' \"execute-keys \\%|cat'\${path_file_out}'\" + printf '%s\\n' \"nop %sh{ rm -f '\${path_file_out}' }\" + else + printf '%s\\n' \" + evaluate-commands -client '${kak_client}' echo -markup '{Error}formatter returned an error (\$?)' + \" + rm -f \"\${path_file_out}\" + fi + + rm -f \"${path_file_tmp}\" + } + " + else + printf '%s\n' "evaluate-commands -client '${kak_client}' echo -markup '{Error}formatcmd option not specified'" + fi + } +} } diff --git a/rc/tools/git.kak b/rc/tools/git.kak new file mode 100644 index 00000000..21b5627b --- /dev/null +++ b/rc/tools/git.kak @@ -0,0 +1,214 @@ +declare-option -docstring "name of the client in which documentation is to be displayed" \ + str docsclient + +hook -group git-log-highlight global WinSetOption filetype=git-log %{ + add-highlighter window/git-log group + add-highlighter window/git-log/ regex '^(commit) ([0-9a-f]+)$' 1:keyword 2:meta + add-highlighter window/git-log/ regex '^([a-zA-Z_-]+:) (.*?)$' 1:variable 2:value + add-highlighter window/git-log/ ref diff # highlight potential diffs from the -p option + + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/git-log } +} + + +hook -group git-status-highlight global WinSetOption filetype=git-status %{ + add-highlighter window/git-status group + add-highlighter window/git-status/ regex '^\h+(?:((?:both )?modified:)|(added:|new file:)|(deleted(?: by \w+)?:)|(renamed:)|(copied:))(?:.*?)$' 1:yellow 2:green 3:red 4:cyan 5:blue 6:magenta + + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/git-status } +} + + +declare-option -hidden line-specs git_blame_flags +declare-option -hidden line-specs git_diff_flags + +define-command -params 1.. \ + -docstring %sh{printf 'git []: git wrapping helper +All the optional arguments are forwarded to the git utility +Available commands:\n add\n rm\n blame\n commit\n checkout\n diff\n hide-blame\n hide-diff\n log\n show\n show-diff\n status\n update-diff'} \ + -shell-script-candidates %{ + if [ $kak_token_to_complete -eq 0 ]; then + printf "add\nrm\nblame\ncommit\ncheckout\ndiff\nhide-blame\nhide-diff\nlog\nshow\nshow-diff\nstatus\nupdate-diff\n" + else + case "$1" in + commit) printf -- "--amend\n--no-edit\n--all\n--reset-author\n--fixup\n--squash\n"; git ls-files -m ;; + add) git ls-files -dmo --exclude-standard ;; + rm) git ls-files -c ;; + esac + fi + } \ + git %{ evaluate-commands %sh{ + show_git_cmd_output() { + local filetype + case "$1" in + show|diff) filetype=diff ;; + log) filetype=git-log ;; + status) filetype=git-status ;; + esac + output=$(mktemp -d "${TMPDIR:-/tmp}"/kak-git.XXXXXXXX)/fifo + mkfifo ${output} + ( git "$@" > ${output} 2>&1 ) > /dev/null 2>&1 < /dev/null & + + printf %s "evaluate-commands -try-client '$kak_opt_docsclient' %{ + edit! -fifo ${output} *git* + set-option buffer filetype '${filetype}' + hook -always -once buffer BufCloseFifo .* %{ nop %sh{ rm -r $(dirname ${output}) } } + }" + } + + run_git_blame() { + ( + printf %s "evaluate-commands -client '$kak_client' %{ + try %{ add-highlighter window/git-blame flag-lines Information git_blame_flags } + set-option buffer=$kak_bufname git_blame_flags '$kak_timestamp' + }" | kak -p ${kak_session} + git blame "$@" --incremental ${kak_buffile} | awk ' + function send_flags(text, flag, i) { + if (line == "") { return; } + text=substr(sha,1,8) " " dates[sha] " " authors[sha] + # gsub("|", "\\|", text) + gsub("~", "~~", text) + flag="%~" line "|" text "~" + for ( i=1; i < count; i++ ) { + flag=flag " %~" line+i "|" text "~" + } + cmd = "kak -p " ENVIRON["kak_session"] + print "set-option -add buffer=" ENVIRON["kak_bufname"] " git_blame_flags " flag | cmd + close(cmd) + } + /^([0-9a-f]{40}) ([0-9]+) ([0-9]+) ([0-9]+)/ { + send_flags() + sha=$1 + line=$3 + count=$4 + } + /^author / { authors[sha]=substr($0,8) } + /^author-time ([0-9]*)/ { + cmd = "date -d @" $2 " +\"%F %T\"" + cmd | getline dates[sha] + close(cmd) + } + END { send_flags(); }' + ) > /dev/null 2>&1 < /dev/null & + } + + update_diff() { + git --no-pager diff -U0 "$kak_buffile" | perl -e ' + $flags = $ENV{"kak_timestamp"}; + foreach $line () { + if ($line =~ /@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))?/) { + $from_line = $1; + $from_count = ($2 eq "" ? 1 : $2); + $to_line = $3; + $to_count = ($4 eq "" ? 1 : $4); + + if ($from_count == 0 and $to_count > 0) { + for $i (0..$to_count - 1) { + $line = $to_line + $i; + $flags .= " $line|\{green\}+"; + } + } + elsif ($from_count > 0 and $to_count == 0) { + if ($to_line == 0) { + $flags .= " 1|\{red\}‾"; + } else { + $flags .= " $to_line|\{red\}_"; + } + } + elsif ($from_count > 0 and $from_count == $to_count) { + for $i (0..$to_count - 1) { + $line = $to_line + $i; + $flags .= " $line|\{blue\}~"; + } + } + elsif ($from_count > 0 and $from_count < $to_count) { + for $i (0..$from_count - 1) { + $line = $to_line + $i; + $flags .= " $line|\{blue\}~"; + } + for $i ($from_count..$to_count - 1) { + $line = $to_line + $i; + $flags .= " $line|\{green\}+"; + } + } + elsif ($to_count > 0 and $from_count > $to_count) { + for $i (0..$to_count - 2) { + $line = $to_line + $i; + $flags .= " $line|\{blue\}~"; + } + $last = $to_line + $to_count - 1; + $flags .= " $last|\{blue+u\}~"; + } + } + } + print "set-option buffer git_diff_flags $flags" + ' + } + + commit() { + # Handle case where message needs not to be edited + if grep -E -q -e "-m|-F|-C|--message=.*|--file=.*|--reuse-message=.*|--no-edit|--fixup.*|--squash.*"; then + if git commit "$@" > /dev/null 2>&1; then + echo 'echo -markup "{Information}Commit succeeded"' + else + echo 'echo -markup "{Error}Commit failed"' + fi + exit + fi <<-EOF + $@ + EOF + + # fails, and generate COMMIT_EDITMSG + GIT_EDITOR='' EDITOR='' git commit "$@" > /dev/null 2>&1 + msgfile="$(git rev-parse --git-dir)/COMMIT_EDITMSG" + printf %s "edit '$msgfile' + hook buffer BufWritePost '.*\Q$msgfile\E' %{ evaluate-commands %sh{ + if git commit -F '$msgfile' --cleanup=strip $* > /dev/null; then + printf %s 'evaluate-commands -client $kak_client echo -markup %{{Information}Commit succeeded}; delete-buffer' + else + printf %s 'evaluate-commands -client $kak_client echo -markup %{{Error}Commit failed}' + fi + } }" + } + + case "$1" in + show|log|diff|status) show_git_cmd_output "$@" ;; + blame) shift; run_git_blame "$@" ;; + hide-blame) + printf %s "try %{ + set-option buffer=$kak_bufname git_blame_flags $kak_timestamp + remove-highlighter window/git-blame + }" + ;; + show-diff) + echo 'try %{ add-highlighter window/git-diff flag-lines Default git_diff_flags }' + update_diff + ;; + hide-diff) + echo 'try %{ remove-highlighter window/git-diff }' + ;; + update-diff) update_diff ;; + commit) shift; commit "$@" ;; + checkout) + name="${2:-${kak_buffile}}" + git checkout "${name}" > /dev/null 2>&1 + ;; + add) + name="${2:-${kak_buffile}}" + if git add -- "${name}" > /dev/null 2>&1; then + printf %s "echo -markup '{Information}git: added ${name}'" + else + printf %s "echo -markup '{Error}git: unable to add ${name}'" + fi + ;; + rm) + name="${2:-${kak_buffile}}" + if git rm -- "${name}" > /dev/null 2>&1; then + printf %s "echo -markup '{Information}git: removed ${name}'" + else + printf %s "echo -markup '{Error}git: unable to remove ${name}'" + fi + ;; + *) printf %s "echo -markup %{{Error}unknown git command '$1'}"; exit ;; + esac +}} diff --git a/rc/tools/go/go-tools.kak b/rc/tools/go/go-tools.kak new file mode 100644 index 00000000..ee26698e --- /dev/null +++ b/rc/tools/go/go-tools.kak @@ -0,0 +1,182 @@ +# Provides integration of the following tools: +# - gocode for code completion (github.com/nsf/gocode) +# - goimports for code formatting on save +# - gogetdoc for documentation display and source jump (needs jq) (github.com/zmb3/gogetdoc) +# Needs the following tools in the path: +# - jq for json deserializaton + +evaluate-commands %sh{ + for dep in gocode goimports gogetdoc jq; do + if ! command -v $dep > /dev/null 2>&1; then + echo "echo -debug %{Dependency unmet: $dep, please install it to use go-tools}" + fi + done +} + +# Auto-completion +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +declare-option -hidden str go_complete_tmp_dir +declare-option -hidden completions gocode_completions + +define-command go-complete -docstring "Complete the current selection with gocode" %{ + evaluate-commands %sh{ + dir=$(mktemp -d "${TMPDIR:-/tmp}"/kak-go.XXXXXXXX) + printf %s\\n "set-option buffer go_complete_tmp_dir ${dir}" + printf %s\\n "evaluate-commands -no-hooks write ${dir}/buf" + } + nop %sh{ + dir=${kak_opt_go_complete_tmp_dir} + ( + gocode_data=$(gocode -f=godit --in=${dir}/buf autocomplete ${kak_cursor_byte_offset}) + rm -r ${dir} + column_offset=$(printf %s "${gocode_data}" | head -n1 | cut -d, -f1) + + header="${kak_cursor_line}.$((${kak_cursor_column} - $column_offset))@${kak_timestamp}" + compl=$(echo "${gocode_data}" | sed 1d | awk -F ",," '{ + gsub(/~/, "~~", $1) + gsub(/~/, "~~", $2) + print "%~" $2 "||" $1 "~" + }' | paste -s -) + printf %s\\n "evaluate-commands -client '${kak_client}' %{ + set-option 'buffer=${kak_bufname}' gocode_completions ${header} ${compl} + }" | kak -p ${kak_session} + ) > /dev/null 2>&1 < /dev/null & + } +} + +define-command go-enable-autocomplete -docstring "Add gocode completion candidates to the completer" %{ + set-option window completers "option=gocode_completions" %opt{completers} + hook window -group go-autocomplete InsertIdle .* %{ try %{ + execute-keys -draft [\w\.].\z + go-complete + } } + alias window complete go-complete +} + +define-command go-disable-autocomplete -docstring "Disable gocode completion" %{ + set-option window completers %sh{ printf %s\\n "${kak_opt_completers}" | sed "s/'option=gocode_completions'//g" } + remove-hooks window go-autocomplete + unalias window complete go-complete +} + +# Auto-format +# ‾‾‾‾‾‾‾‾‾‾‾ + +declare-option -hidden str go_format_tmp_dir + +define-command -params ..1 go-format \ + -docstring "go-format [-use-goimports]: custom formatter for go files" %{ + evaluate-commands %sh{ + dir=$(mktemp -d "${TMPDIR:-/tmp}"/kak-go.XXXXXXXX) + printf %s\\n "set-option buffer go_format_tmp_dir ${dir}" + printf %s\\n "evaluate-commands -no-hooks write ${dir}/buf" + } + evaluate-commands %sh{ + dir=${kak_opt_go_format_tmp_dir} + if [ "$1" = "-use-goimports" ]; then + fmt_cmd="goimports -srcdir '${kak_buffile}'" + else + fmt_cmd="gofmt -s" + fi + eval "${fmt_cmd} -e -w ${dir}/buf 2> ${dir}/stderr" + if [ $? ]; then + cp ${dir}/buf "${kak_buffile}" + else + # we should report error if linting isn't active + printf %s\\n "echo -debug '$(cat ${dir}/stderr)'" + fi + rm -r ${dir} + } + edit! +} + +# Documentation +# ‾‾‾‾‾‾‾‾‾‾‾‾‾ + +declare-option -hidden str go_doc_tmp_dir + +# FIXME text escaping +define-command -hidden -params 1..2 gogetdoc-cmd %{ + evaluate-commands %sh{ + dir=$(mktemp -d "${TMPDIR:-/tmp}"/kak-go.XXXXXXXX) + printf %s\\n "set-option buffer go_doc_tmp_dir ${dir}" + printf %s\\n "evaluate-commands -no-hooks write ${dir}/buf" + } + evaluate-commands %sh{ + dir=${kak_opt_go_doc_tmp_dir} + ( + printf %s\\n "${kak_buffile}" > ${dir}/modified + cat ${dir}/buf | wc -c >> ${dir}/modified + cat ${dir}/buf >> ${dir}/modified + + if [ "$2" = "1" ]; then + args="-json" + fi + output=$(cat ${dir}/modified \ + | gogetdoc $args -pos "${kak_buffile}:#${kak_cursor_byte_offset}" -modified \ + | sed 's/%/%%/g') + rm -r ${dir} + printf %s "${output}" | grep -v -q "^gogetdoc: " + status=$? + + case "$1" in + "info") + if [ ${status} -eq 0 ]; then + printf %s\\n "evaluate-commands -client '${kak_client}' %{ + info -anchor ${kak_cursor_line}.${kak_cursor_column} %@${output}@ + }" | kak -p ${kak_session} + else + msg=$(printf %s "${output}" | cut -d' ' -f2-) + printf %s\\n "evaluate-commands -client '${kak_client}' %{ + echo '${msg}' + }" | kak -p ${kak_session} + fi + ;; + "echo") + if [ ${status} -eq 0 ]; then + signature=$(printf %s "${output}" | sed -n 3p) + printf %s\\n "evaluate-commands -client '${kak_client}' %{ + echo '${signature}' + }" | kak -p ${kak_session} + fi + ;; + "jump") + if [ ${status} -eq 0 ]; then + pos=$(printf %s "${output}" | jq -r .pos) + file=$(printf %s "${pos}" | cut -d: -f1) + line=$(printf %s "${pos}" | cut -d: -f2) + col=$(printf %s "${pos}" | cut -d: -f3) + printf %s\\n "evaluate-commands -client '${kak_client}' %{ + evaluate-commands -try-client '${kak_opt_jumpclient}' edit -existing ${file} ${line} ${col} + try %{ focus '${kak_opt_jumpclient}' } + }" | kak -p ${kak_session} + fi + ;; + *) + printf %s\\n "evaluate-commands -client '${kak_client}' %{ + echo -error %{unkown command '$1'} + }" | kak -p ${kak_session} + ;; + + esac + ) > /dev/null 2>&1 < /dev/null & + } +} + +define-command go-doc-info -docstring "Show the documention of the symbol under the cursor" %{ + gogetdoc-cmd "info" +} + +define-command go-print-signature -docstring "Print the signature of the symbol under the cursor" %{ + gogetdoc-cmd "echo" +} + +define-command go-jump -docstring "Jump to the symbol definition" %{ + gogetdoc-cmd "jump" 1 +} + +define-command go-share-selection -docstring "Share the selection using the Go Playground" %{ evaluate-commands %sh{ + snippet_id=$(printf %s\\n "${kak_selection}" | curl -s https://play.golang.org/share --data-binary @-) + printf "echo https://play.golang.org/p/%s" ${snippet_id} +} } diff --git a/rc/tools/grep.kak b/rc/tools/grep.kak new file mode 100644 index 00000000..9e6ed5ab --- /dev/null +++ b/rc/tools/grep.kak @@ -0,0 +1,73 @@ +declare-option -docstring "shell command run to search for subtext in a file/directory" \ + str grepcmd 'grep -RHn' +declare-option -docstring "name of the client in which utilities display information" \ + str toolsclient +declare-option -hidden int grep_current_line 0 + +define-command -params .. -file-completion \ + -docstring %{grep []: grep utility wrapper +All the optional arguments are forwarded to the grep utility} \ + grep %{ evaluate-commands %sh{ + output=$(mktemp -d "${TMPDIR:-/tmp}"/kak-grep.XXXXXXXX)/fifo + mkfifo ${output} + if [ $# -gt 0 ]; then + ( ${kak_opt_grepcmd} "$@" | tr -d '\r' > ${output} 2>&1 ) > /dev/null 2>&1 < /dev/null & + else + ( ${kak_opt_grepcmd} "${kak_selection}" | tr -d '\r' > ${output} 2>&1 ) > /dev/null 2>&1 < /dev/null & + fi + + printf %s\\n "evaluate-commands -try-client '$kak_opt_toolsclient' %{ + edit! -fifo ${output} -scroll *grep* + set-option buffer filetype grep + set-option buffer grep_current_line 0 + hook -always -once buffer BufCloseFifo .* %{ nop %sh{ rm -r $(dirname ${output}) } } + }" +}} + +hook -group grep-highlight global WinSetOption filetype=grep %{ + add-highlighter window/grep group + add-highlighter window/grep/ regex "^((?:\w:)?[^:\n]+):(\d+):(\d+)?" 1:cyan 2:green 3:green + add-highlighter window/grep/ line %{%opt{grep_current_line}} default+b + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/grep } +} + +hook global WinSetOption filetype=grep %{ + hook buffer -group grep-hooks NormalKey grep-jump + hook -once -always window WinSetOption filetype=.* %{ remove-hooks buffer grep-hooks } +} + +declare-option -docstring "name of the client in which all source code jumps will be executed" \ + str jumpclient + +define-command -hidden grep-jump %{ + evaluate-commands %{ # use evaluate-commands to ensure jumps are collapsed + try %{ + execute-keys 's^((?:\w:)?[^:]+):(\d+):(\d+)?' + set-option buffer grep_current_line %val{cursor_line} + evaluate-commands -try-client %opt{jumpclient} edit -existing %reg{1} %reg{2} %reg{3} + try %{ focus %opt{jumpclient} } + } + } +} + +define-command grep-next-match -docstring 'Jump to the next grep match' %{ + evaluate-commands -try-client %opt{jumpclient} %{ + buffer '*grep*' + # First jump to enf of buffer so that if grep_current_line == 0 + # 0g will be a no-op and we'll jump to the first result. + # Yeah, thats ugly... + execute-keys "ge %opt{grep_current_line}g /^[^:]+:\d+:" + grep-jump + } + try %{ evaluate-commands -client %opt{toolsclient} %{ execute-keys gg %opt{grep_current_line}g } } +} + +define-command grep-previous-match -docstring 'Jump to the previous grep match' %{ + evaluate-commands -try-client %opt{jumpclient} %{ + buffer '*grep*' + # See comment in grep-next-match + execute-keys "ge %opt{grep_current_line}g ^[^:]+:\d+:" + grep-jump + } + try %{ evaluate-commands -client %opt{toolsclient} %{ execute-keys gg %opt{grep_current_line}g } } +} diff --git a/rc/tools/lint.kak b/rc/tools/lint.kak new file mode 100644 index 00000000..11189315 --- /dev/null +++ b/rc/tools/lint.kak @@ -0,0 +1,176 @@ +declare-option -docstring %{shell command to which the path of a copy of the current buffer will be passed +The output returned by this command is expected to comply with the following format: + {filename}:{line}:{column}: {kind}: {message}} \ + str lintcmd + +declare-option -hidden line-specs lint_flags +declare-option -hidden range-specs lint_errors +declare-option -hidden int lint_error_count +declare-option -hidden int lint_warning_count + +define-command lint -docstring 'Parse the current buffer with a linter' %{ + evaluate-commands %sh{ + if [ -z "${kak_opt_lintcmd}" ]; then + printf %s\\n 'echo -markup {Error}The `lintcmd` option is not set' + exit 1 + fi + + extension="" + if printf %s "${kak_buffile}" | grep -qE '[^/.]\.[[:alnum:]]+$'; then + extension=".${kak_buffile##*.}" + fi + + dir=$(mktemp -d "${TMPDIR:-/tmp}"/kak-lint.XXXXXXXX) + mkfifo "$dir"/fifo + printf '%s\n' "evaluate-commands -no-hooks write -sync $dir/buf${extension}" + + printf '%s\n' "evaluate-commands -draft %{ + edit! -fifo $dir/fifo -debug *lint-output* + set-option buffer filetype make + set-option buffer make_current_error_line 0 + hook -always -once buffer BufCloseFifo .* %{ nop %sh{ rm -r '$dir' } } + }" + + { # do the parsing in the background and when ready send to the session + + eval "$kak_opt_lintcmd '$dir'/buf${extension}" | sort -t: -k2,2 -n > "$dir"/stderr + + # Flags for the gutter: + # stamp l3|{red}█ l11|{yellow}█ + # Contextual error messages: + # stamp 'l1.c1,l1.c1|kind:message' 'l2.c2,l2.c2|kind:message' + awk -F: -v file="$kak_buffile" -v stamp="$kak_timestamp" -v client="$kak_client" ' + BEGIN { + error_count = 0 + warning_count = 0 + } + /:[1-9][0-9]*:[1-9][0-9]*: ([Ff]atal )?[Ee]rror/ { + flags = flags " " $2 "|{red}█" + error_count++ + } + /:[1-9][0-9]*:[1-9][0-9]*:/ { + if ($4 !~ /[Ee]rror/) { + flags = flags " " $2 "|{yellow}█" + warning_count++ + } + } + /:[1-9][0-9]*:[1-9][0-9]*:/ { + kind = substr($4, 2) + error = $2 "." $3 "," $2 "." $3 "|" kind + msg = "" + # fix case where $5 is not the last field because of extra colons in the message + for (i=5; i<=NF; i++) msg = msg ":" $i + gsub(/\|/, "\\|", msg) + gsub("'\''", "'"''"'", msg) + error = error msg " (col " $3 ")" + errors = errors " '\''" error "'\''" + } + END { + print "set-option \"buffer=" file "\" lint_flags " stamp flags + gsub("~", "\\~", errors) + print "set-option \"buffer=" file "\" lint_errors " stamp errors + print "set-option \"buffer=" file "\" lint_error_count " error_count + print "set-option \"buffer=" file "\" lint_warning_count " warning_count + print "evaluate-commands -client " client " lint-show-counters" + } + ' "$dir"/stderr | kak -p "$kak_session" + + cut -d: -f2- "$dir"/stderr | awk -v bufname="${kak_bufname}" ' + /^[1-9][0-9]*:[1-9][0-9]*:/ { + print bufname ":" $0 + } + ' > "$dir"/fifo + + } >/dev/null 2>&1 ]: make utility wrapper +All the optional arguments are forwarded to the make utility} \ + make %{ evaluate-commands %sh{ + output=$(mktemp -d "${TMPDIR:-/tmp}"/kak-make.XXXXXXXX)/fifo + mkfifo ${output} + ( eval ${kak_opt_makecmd} "$@" > ${output} 2>&1 ) > /dev/null 2>&1 < /dev/null & + + printf %s\\n "evaluate-commands -try-client '$kak_opt_toolsclient' %{ + edit! -fifo ${output} -scroll *make* + set-option buffer filetype make + set-option buffer make_current_error_line 0 + hook -always -once buffer BufCloseFifo .* %{ nop %sh{ rm -r $(dirname ${output}) } } + }" +}} + +add-highlighter shared/make group +add-highlighter shared/make/ regex "^((?:\w:)?[^:\n]+):(\d+):(?:(\d+):)?\h+(?:((?:fatal )?error)|(warning)|(note)|(required from(?: here)?))?.*?$" 1:cyan 2:green 3:green 4:red 5:yellow 6:blue 7:yellow +add-highlighter shared/make/ regex "^\h*(~*(?:(\^)~*)?)$" 1:green 2:cyan+b +add-highlighter shared/make/ line '%opt{make_current_error_line}' default+b + +hook -group make-highlight global WinSetOption filetype=make %{ + add-highlighter window/make ref make + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/make } +} + +hook global WinSetOption filetype=make %{ + hook buffer -group make-hooks NormalKey make-jump + hook -once -always window WinSetOption filetype=.* %{ remove-hooks buffer make-hooks } +} + +declare-option -docstring "name of the client in which all source code jumps will be executed" \ + str jumpclient + +define-command -hidden make-open-error -params 4 %{ + evaluate-commands -try-client %opt{jumpclient} %{ + edit -existing "%arg{1}" %arg{2} %arg{3} + echo -markup "{Information}%arg{4}" + try %{ focus } + } +} + +define-command -hidden make-jump %{ + evaluate-commands %{ + try %{ + execute-keys gl "Entering directory" + # Try to parse the error into capture groups, failing on absolute paths + execute-keys s "Entering directory [`']([^']+)'.*\n([^:/][^:]*):(\d+):(?:(\d+):)?([^\n]+)\z" l + set-option buffer make_current_error_line %val{cursor_line} + make-open-error "%reg{1}/%reg{2}" "%reg{3}" "%reg{4}" "%reg{5}" + } catch %{ + execute-keys s "((?:\w:)?[^:]+):(\d+):(?:(\d+):)?([^\n]+)\z" l + set-option buffer make_current_error_line %val{cursor_line} + make-open-error "%reg{1}" "%reg{2}" "%reg{3}" "%reg{4}" + } + } +} + +define-command make-next-error -docstring 'Jump to the next make error' %{ + evaluate-commands -try-client %opt{jumpclient} %{ + buffer '*make*' + execute-keys "%opt{make_current_error_line}ggl" "/^(?:\w:)?[^:\n]+:\d+:(?:\d+:)?%opt{make_error_pattern}" + make-jump + } + try %{ evaluate-commands -client %opt{toolsclient} %{ execute-keys %opt{make_current_error_line}g } } +} + +define-command make-previous-error -docstring 'Jump to the previous make error' %{ + evaluate-commands -try-client %opt{jumpclient} %{ + buffer '*make*' + execute-keys "%opt{make_current_error_line}g" "^(?:\w:)?[^:\n]+:\d+:(?:\d+:)?%opt{make_error_pattern}" + make-jump + } + try %{ evaluate-commands -client %opt{toolsclient} %{ execute-keys %opt{make_current_error_line}g } } +} diff --git a/rc/tools/man.kak b/rc/tools/man.kak new file mode 100644 index 00000000..41d91104 --- /dev/null +++ b/rc/tools/man.kak @@ -0,0 +1,68 @@ +declare-option -docstring "name of the client in which documentation is to be displayed" \ + str docsclient + +declare-option -hidden str manpage + +hook -group man-highlight global WinSetOption filetype=man %{ + add-highlighter window/man-highlight group + # Sections + add-highlighter window/man-highlight/ regex ^\S.*?$ 0:title + # Subsections + add-highlighter window/man-highlight/ regex '^ {3}\S.*?$' 0:default+b + # Command line options + add-highlighter window/man-highlight/ regex '^ {7}-[^\s,]+(,\s+-[^\s,]+)*' 0:list + # References to other manpages + add-highlighter window/man-highlight/ regex [-a-zA-Z0-9_.]+\([a-z0-9]+\) 0:header + + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/man-highlight } +} + +hook global WinSetOption filetype=man %{ + hook -group man-hooks window WinResize .* %{ man-impl %val{bufname} %opt{manpage} } + hook -once -always window WinSetOption filetype=.* %{ remove-hooks window man-hooks } +} + +define-command -hidden -params 2..3 man-impl %{ evaluate-commands %sh{ + buffer_name="$1" + shift + manout=$(mktemp "${TMPDIR:-/tmp}"/kak-man-XXXXXX) + colout=$(mktemp "${TMPDIR:-/tmp}"/kak-man-XXXXXX) + MANWIDTH=${kak_window_width} man "$@" > $manout 2>/dev/null + retval=$? + col -b -x > ${colout} < ${manout} + rm ${manout} + if [ "${retval}" -eq 0 ]; then + printf %s\\n " + edit -scratch '$buffer_name' + execute-keys '%|cat${colout}gk' + nop %sh{rm ${colout}} + set-option buffer filetype man + set-option window manpage '$@' + " + else + printf %s\\n "echo -markup %{{Error}man '$@' failed: see *debug* buffer for details}" + rm ${colout} + fi +} } + +define-command -params ..1 \ + -shell-script-candidates %{ + find /usr/share/man/ -name '*.[1-8]*' | sed 's,^.*/\(.*\)\.\([1-8][a-zA-Z]*\).*$,\1(\2),' + } \ + -docstring %{man []: manpage viewer wrapper +If no argument is passed to the command, the selection will be used as page +The page can be a word, or a word directly followed by a section number between parenthesis, e.g. kak(1)} \ + man %{ evaluate-commands %sh{ + subject=${1-$kak_selection} + + ## The completion suggestions display the page number, strip them if present + case "${subject}" in + *\([1-8]*\)) + pagenum="${subject##*(}" + pagenum="${pagenum%)}" + subject="${subject%%(*}" + ;; + esac + + printf %s\\n "evaluate-commands -try-client %opt{docsclient} man-impl *man* $pagenum $subject" +} } diff --git a/rc/tools/python/jedi.kak b/rc/tools/python/jedi.kak new file mode 100644 index 00000000..a0fe9449 --- /dev/null +++ b/rc/tools/python/jedi.kak @@ -0,0 +1,47 @@ +declare-option -hidden str jedi_tmp_dir +declare-option -hidden completions jedi_completions +declare-option -docstring "colon separated list of path added to `python`'s $PYTHONPATH environment variable" \ + str jedi_python_path + +define-command jedi-complete -docstring "Complete the current selection" %{ + evaluate-commands %sh{ + dir=$(mktemp -d "${TMPDIR:-/tmp}"/kak-jedi.XXXXXXXX) + mkfifo ${dir}/fifo + printf %s\\n "set-option buffer jedi_tmp_dir ${dir}" + printf %s\\n "evaluate-commands -no-hooks write -sync ${dir}/buf" + } + evaluate-commands %sh{ + dir=${kak_opt_jedi_tmp_dir} + printf %s\\n "evaluate-commands -draft %{ edit! -fifo ${dir}/fifo *jedi-output* }" + ( + cd $(dirname ${kak_buffile}) + header="${kak_cursor_line}.${kak_cursor_column}@${kak_timestamp}" + + export PYTHONPATH="$kak_opt_jedi_python_path:$PYTHONPATH" + compl=$(python 2> "${dir}/fifo" <<-END + import jedi + script=jedi.Script(open('$dir/buf', 'r').read(), $kak_cursor_line, $kak_cursor_column - 1, '$kak_buffile') + print(' '.join(["'" + (str(c.name).replace("|", "\\|") + "|" + str(c.docstring()).replace("|", "\\|") + "|" + str(c.name).replace("|", "\\|")).replace("~", "~~").replace("'", "''") + "'" for c in script.completions()])) + END + ) + printf %s\\n "evaluate-commands -client ${kak_client} %~echo completed; set-option %{buffer=${kak_buffile}} jedi_completions ${header} ${compl}~" | kak -p ${kak_session} + rm -r ${dir} + ) > /dev/null 2>&1 < /dev/null & + } +} + +define-command jedi-enable-autocomplete -docstring "Add jedi completion candidates to the completer" %{ + set-option window completers option=jedi_completions %opt{completers} + hook window -group jedi-autocomplete InsertIdle .* %{ try %{ + execute-keys -draft \..\z + echo 'completing...' + jedi-complete + } } + alias window complete jedi-complete +} + +define-command jedi-disable-autocomplete -docstring "Disable jedi completion" %{ + set-option window completers %sh{ printf %s\\n "'${kak_opt_completers}'" | sed -e 's/option=jedi_completions://g' } + remove-hooks window jedi-autocomplete + unalias window complete jedi-complete +} diff --git a/rc/tools/ranger.kak b/rc/tools/ranger.kak new file mode 100644 index 00000000..4bb49a7b --- /dev/null +++ b/rc/tools/ranger.kak @@ -0,0 +1,59 @@ +# http://ranger.nongnu.org +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +define-command ranger-open-on-edit-directory \ + -docstring 'Start the ranger file system explorer when trying to edit a directory' %{ + hook global RuntimeError "\d+:\d+: '\w+' (.*): is a directory" %{ evaluate-commands %sh{ + directory=$kak_hook_param_capture_1 + echo ranger $directory + }} +} + +define-command \ + -params .. -file-completion \ + -docstring %{ranger []: open the file system explorer to select buffers to open + All the optional arguments are forwarded to the ranger utility} \ + ranger %{ evaluate-commands %sh{ + if [ -n "${TMUX}" ]; then + tmux split-window -h \ + ranger $@ --cmd " \ + map eval \ + fm.execute_console('shell \ + echo evaluate-commands -client ' + ranger.ext.shell_escape.shell_escape('$kak_client') + ' edit {file} | \ + kak -p '.format(file=fm.thisfile.path) + ranger.ext.shell_escape.shell_escape('$kak_session') + '; \ + tmux select-pane -t $kak_client_env_TMUX_PANE') \ + if fm.thisfile.is_file else fm.execute_console('move right=1')" + + elif [ -n "${STY}" ]; then + + script="/tmp/kak-ranger-${kak_client}-${kak_session}.sh" + selections="/tmp/kak-ranger-${kak_client}-${kak_session}.txt" + cat > "$script" << EOF +#! /usr/bin/env sh +cd "$PWD" +ranger --choosefiles="$selections" $@ +while read -r f; do + printf %s "evaluate-commands -client '${kak_client}' edit '\"\$f\"'" | kak -p '${kak_session}' +done < "$selections" +screen -X remove +rm -f "$selections" "$script" +EOF + + tty="$(ps -o tty ${kak_client_pid} | tail -n 1)" + screen -X eval \ + 'split -h' \ + 'focus down' \ + "screen sh '$script'" \ + < "/dev/$tty" + + elif [ -n "$WINDOWID" ]; then + setsid $kak_opt_termcmd " \ + ranger $@ --cmd "'"'" \ + map eval \ + fm.execute_console('shell \ + echo evaluate-commands -client ' + ranger.ext.shell_escape.shell_escape('$kak_client') + ' edit {file} | \ + kak -p '.format(file=fm.thisfile.path) + ranger.ext.shell_escape.shell_escape('$kak_session') + '; \ + xdotool windowactivate $kak_client_env_WINDOWID') \ + if fm.thisfile.is_file else fm.execute_console('move right=1')"'"' < /dev/null > /dev/null 2>&1 & + fi +}} diff --git a/rc/tools/rust/racer.kak b/rc/tools/rust/racer.kak new file mode 100644 index 00000000..2371c597 --- /dev/null +++ b/rc/tools/rust/racer.kak @@ -0,0 +1,153 @@ +declare-option -hidden str racer_tmp_dir +declare-option -hidden completions racer_completions + +define-command racer-complete -docstring "Complete the current selection with racer" %{ + evaluate-commands %sh{ + dir=$(mktemp -d "${TMPDIR:-/tmp}"/kak-racer.XXXXXXXX) + printf %s\\n "set-option buffer racer_tmp_dir ${dir}" + printf %s\\n "evaluate-commands -no-hooks %{ write ${dir}/buf }" + } + evaluate-commands %sh{ + dir=${kak_opt_racer_tmp_dir} + ( + cursor="${kak_cursor_line} $((${kak_cursor_column} - 1))" + racer_data=$(racer --interface tab-text complete-with-snippet ${cursor} ${kak_buffile} ${dir}/buf) + compl=$(printf %s\\n "${racer_data}" | awk ' + BEGIN { FS = "\t"; ORS = ":" } + /^PREFIX/ { + column = ENVIRON["kak_cursor_column"] + $2 - $3 + print ENVIRON["kak_cursor_line"] "." column "@@" ENVIRON["kak_timestamp"] + } + /^MATCH/ { + word = $2 + type = $7 + desc = substr($9, 2, length($9) - 2) + gsub(/\|/, "\\|", desc) + gsub(/\\n/, "\n", desc) + menu = $8 + sub(/^pub /, "", menu) + gsub(/\|/, "\\|", menu) + if (type == "Function") { + sub(word, "{default+F}" word "{default+d}", menu) + gsub(/^fn /, " fn ", menu) # The extra spaces are there to vertically align + # the type of element on the menu to make it easy + # to read + menu = "{default+d}" menu + } else if (type == "Enum") { + menu = substr(menu, 0, length(menu) - 2) + sub(word, "{default+F}" word "{default+d}", menu) + gsub(/^enum /, " enum ", menu) # The extra spaces are there to vertically align + # the type of element on the menu to make it easy + # to read + } else if (type == "Module") { + if (length(menu) > 30) { # The "menu" bit (as returned by racer), + # contains the path to the source file + # containing the module... + + menu = substr(menu, length(menu) - 29, 30) # ... trimming it, so the completion menu + # doesn''t get distorted if it''s too long + } + menu = " mod {default+F}" word "{default+d} .." menu # The extra spaces are there to vertically align + # the type of element on the menu to make it easy + # to read + } else if (type == "Trait") { + sub(word, "{default+F}" word "{default+d}", menu) + gsub(/^trait /, " trait ", menu) # The extra spaces are there to vertically align + # the type of element on the menu to make it easy + # to read + } else if (type == "Type") { + sub(word, "{default+F}" word "{default+d}", menu) + gsub(/^type /, " type ", menu) # The extra spaces are there to vertically align + # the type of element on the menu to make it easy + # to read + } else if (type == "Struct") { + sub(word, "{default+F}" word "{default+d}", menu) # Struct doesn''t have extra spaces because it''s + # the longest keyword + } else { + menu = "{default+F}" word "{default+d} " menu + } + candidate = word "|" desc "|" menu + gsub(/:/, "\\:", candidate) + print candidate + }' + ) + printf %s\\n "evaluate-commands -client '${kak_client}' %{ + set-option buffer=${kak_bufname} racer_completions %@${compl%?}@ + }" | kak -p ${kak_session} + rm -r ${dir} + ) > /dev/null 2>&1 < /dev/null & + } +} + +define-command racer-enable-autocomplete -docstring "Add racer completion candidates to the completer" %{ + set-option window completers option=racer_completions %opt{completers} + hook window -group racer-autocomplete InsertIdle .* %{ try %{ + execute-keys -draft ([\w\.]|::).\z + racer-complete + } } + alias window complete racer-complete +} + +define-command racer-disable-autocomplete -docstring "Disable racer completion" %{ + evaluate-commands %sh{ printf "set-option window completers %s\n" $(printf %s "${kak_opt_completers}" | sed -e "s/'option=racer_completions'//g") } + remove-hooks window racer-autocomplete + unalias window complete racer-complete +} + +define-command racer-go-definition -docstring "Jump to where the rust identifier below the cursor is defined" %{ + evaluate-commands %sh{ + dir=$(mktemp -d "${TMPDIR:-/tmp}"/kak-racer.XXXXXXXX) + printf %s\\n "set-option buffer racer_tmp_dir ${dir}" + printf %s\\n "evaluate-commands -no-hooks %{ write ${dir}/buf }" + } + evaluate-commands %sh{ + dir=${kak_opt_racer_tmp_dir} + cursor="${kak_cursor_line} $((${kak_cursor_column} - 1))" + racer_data=$(racer --interface tab-text find-definition ${cursor} "${kak_buffile}" "${dir}/buf" | head -n 1) + + racer_match=$(printf %s\\n "$racer_data" | cut -f1 ) + if [ "$racer_match" = "MATCH" ]; then + racer_line=$(printf %s\\n "$racer_data" | cut -f3 ) + racer_column=$(printf %s\\n "$racer_data" | cut -f4 ) + racer_file=$(printf %s\\n "$racer_data" | cut -f5 ) + printf %s\\n "edit -existing '$racer_file' $racer_line $racer_column" + case ${racer_file} in + "${RUST_SRC_PATH}"* | "${CARGO_HOME:-$HOME/.cargo}"/registry/src/*) + printf %s\\n "set-option buffer readonly true";; + esac + else + printf %s\\n "echo -debug 'racer could not find a definition'" + fi + } +} + +define-command racer-show-doc -docstring "Show the documentation about the rust identifier below the cursor" %{ + evaluate-commands %sh{ + dir=$(mktemp -d "${TMPDIR:-/tmp}"/kak-racer.XXXXXXXX) + printf %s\\n "set-option buffer racer_tmp_dir ${dir}" + printf %s\\n "evaluate-commands -no-hooks %{ write ${dir}/buf }" + } + evaluate-commands %sh{ + dir=${kak_opt_racer_tmp_dir} + cursor="${kak_cursor_line} ${kak_cursor_column}" + racer_data=$(racer --interface tab-text complete-with-snippet ${cursor} "${kak_buffile}" "${dir}/buf" | sed -n 2p ) + racer_match=$(printf %s\\n "$racer_data" | cut -f1) + if [ "$racer_match" = "MATCH" ]; then + racer_doc=$( + printf %s\\n "$racer_data" | + cut -f9 | + sed -e ' + + # Remove leading and trailing quotes + s/^"\(.*\)"$/\1/g + + # Escape all @ so that it can be properly used in the string expansion + s/@/\\@/g + + ') + printf "info %%@$racer_doc@" + else + printf %s\\n "echo -debug 'racer could not find a definition'" + fi + } +} diff --git a/rc/tools/spell.kak b/rc/tools/spell.kak new file mode 100644 index 00000000..10c0f915 --- /dev/null +++ b/rc/tools/spell.kak @@ -0,0 +1,121 @@ +declare-option -hidden range-specs spell_regions +declare-option -hidden str spell_lang +declare-option -hidden str spell_tmp_file + +define-command -params ..1 \ + -docstring %{spell []: spell check the current buffer +The first optional argument is the language against which the check will be performed +Formats of language supported: + - ISO language code, e.g. 'en' + - language code above followed by a dash or underscore with an ISO country code, e.g. 'en-US'} \ + spell %{ + try %{ add-highlighter window/ ranges 'spell_regions' } + evaluate-commands %sh{ + file=$(mktemp -d "${TMPDIR:-/tmp}"/kak-spell.XXXXXXXX)/buffer + printf 'eval -no-hooks write -sync %s\n' "${file}" + printf 'set-option buffer spell_tmp_file %s\n' "${file}" + } + evaluate-commands %sh{ + if [ $# -ge 1 ]; then + if [ ${#1} -ne 2 ] && [ ${#1} -ne 5 ]; then + echo "echo -markup '{Error}Invalid language code (examples of expected format: en, en_US, en-US)'" + rm -rf "$(dirname "$kak_opt_spell_tmp_file")" + exit 1 + else + options="-l '$1'" + printf 'set-option buffer spell_lang %s\n' "$1" + fi + fi + + { + sed 's/^/^/' "$kak_opt_spell_tmp_file" | eval "aspell --byte-offsets -a $options" 2>&1 | { + line_num=1 + regions=$kak_timestamp + read line # drop the identification message + while read -r line; do + case "$line" in + [\#\&]*) + if expr "$line" : '^&' >/dev/null; then + pos=$(printf %s\\n "$line" | cut -d ' ' -f 4 | sed 's/:$//') + else + pos=$(printf %s\\n "$line" | cut -d ' ' -f 3) + fi + word=$(printf %s\\n "$line" | cut -d ' ' -f 2) + len=$(printf %s "$word" | wc -c) + regions="$regions $line_num.$pos+${len}|Error" + ;; + '') line_num=$((line_num + 1));; + \*) ;; + *) printf 'echo -markup %%{{Error}%s}\n' "${line}" | kak -p "${kak_session}";; + esac + done + printf 'set-option "buffer=%s" spell_regions %s' "${kak_bufname}" "${regions}" \ + | kak -p "${kak_session}" + } + rm -rf $(dirname "$kak_opt_spell_tmp_file") + } /dev/null 2>&1 & + } +} + +define-command spell-clear %{ + unset-option buffer spell_regions +} + +define-command spell-next %{ evaluate-commands %sh{ + anchor_line="${kak_selection_desc%%.*}" + anchor_col="${kak_selection_desc%%,*}" + anchor_col="${anchor_col##*.}" + + start_first="${kak_opt_spell_regions#* }" + start_first="${start_first%%|*}" + start_first="${start_first#\'}" + + find_next_word_desc() { + ## XXX: the `spell` command adds sorted selection descriptions to the range + printf %s\\n "${1}" \ + | sed -e "s/'//g" -e 's/^[0-9]* //' -e 's/|[^ ]*//g' \ + | tr ' ' '\n' \ + | while IFS=, read -r start end; do + start_line="${start%.*}" + start_col="${start#*.}" + end_line="${end%.*}" + end_col="${end#*.}" + + if [ "${start_line}" -lt "${anchor_line}" ]; then + continue + elif [ "${start_line}" -eq "${anchor_line}" ] \ + && [ "${start_col}" -le "${anchor_col}" ]; then + continue + fi + + printf 'select %s,%s\n' "${start}" "${end}" + break + done + } + + # no selection descriptions are in `spell_regions` + if ! expr "${start_first}" : '[0-9][0-9]*\.[0-9][0-9]*,[0-9][0-9]*\.[0-9]' >/dev/null; then + exit + fi + + next_word_desc=$(find_next_word_desc "${kak_opt_spell_regions}") + if [ -n "${next_word_desc}" ]; then + printf %s\\n "${next_word_desc}" + else + printf 'select %s\n' "${start_first}" + fi +} } + +define-command spell-replace %{ evaluate-commands %sh{ + if [ -n "$kak_opt_spell_lang" ]; then + options="-l '$kak_opt_spell_lang'" + fi + suggestions=$(printf %s "$kak_selection" | eval "aspell -a $options" | grep '^&' | cut -d: -f2) + menu=$(printf %s "${suggestions#?}" | awk -F', ' ' + { + for (i=1; i<=NF; i++) + printf "%s", "%{"$i"}" "%{execute-keys -itersel %{c"$i"be}}" + } + ') + printf 'try %%{ menu -auto-single %s }' "${menu}" +} } diff --git a/rc/windowing/iterm.kak b/rc/windowing/iterm.kak new file mode 100644 index 00000000..7518d2d0 --- /dev/null +++ b/rc/windowing/iterm.kak @@ -0,0 +1,131 @@ +# https://www.iterm2.com +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +## The default behaviour for the `terminal` command is to open a vertical pane in +## an iTerm session if not in a tmux session. +hook global KakBegin .* %sh{ + if [ "$TERM_PROGRAM" = "iTerm.app" ] && [ -z "$TMUX" ]; then + echo " + alias global focus iterm-focus + alias global terminal iterm-terminal-vertical + " + fi +} + +define-command -hidden -params 2.. iterm-terminal-split-impl %{ + nop %sh{ + direction="$1" + shift + # join the arguments as one string for the shell execution (see x11.kak) + args=$( + for i in "$@"; do + if [ "$i" = '' ]; then + printf "'' " + else + printf %s "$i" | sed -e "s|'|'\\\\''|g; s|^|'|; s|$|' |" + fi + done + ) + # go through another round of escaping for osascript + # \ -> \\ + # " -> \" + escaped=$(printf %s "$args" | sed -e 's|\\|\\\\|g; s|"|\\"|g') + cmd="env PATH='${PATH}' TMPDIR='${TMPDIR}' $escaped" + osascript \ + -e "tell application \"iTerm\"" \ + -e " tell current session of current window" \ + -e " tell (split ${direction} with same profile command \"${cmd}\") to select" \ + -e " end tell" \ + -e "end tell" >/dev/null + } +} + +define-command iterm-terminal-vertical -params 1.. -shell-completion -docstring ' +iterm-terminal-vertical []: create a new terminal as an iterm pane +The current pane is split into two, left and right +The program passed as argument will be executed in the new terminal'\ +%{ + iterm-terminal-split-impl 'vertically' %arg{@} +} +define-command iterm-terminal-horizontal -params 1.. -shell-completion -docstring ' +iterm-terminal-horizontal []: create a new terminal as an iterm pane +The current pane is split into two, top and bottom +The program passed as argument will be executed in the new terminal'\ +%{ + iterm-terminal-split-impl 'horizontally' %arg{@} +} + +define-command iterm-terminal-tab -params 1.. -shell-completion -docstring ' +iterm-terminal-tab []: create a new terminal as an iterm tab +The program passed as argument will be executed in the new terminal'\ +%{ + nop %sh{ + # see above + args=$( + for i in "$@"; do + if [ "$i" = '' ]; then + printf "'' " + else + printf %s "$i" | sed -e "s|'|'\\\\''|g; s|^|'|; s|$|' |" + fi + done + ) + escaped=$(printf %s "$args" | sed -e 's|\\|\\\\|g; s|"|\\"|g') + cmd="env PATH='${PATH}' TMPDIR='${TMPDIR}' $escaped" + osascript \ + -e "tell application \"iTerm\"" \ + -e " tell current window" \ + -e " create tab with default profile command \"${cmd}\"" \ + -e " end tell" \ + -e "end tell" >/dev/null + } +} + +define-command iterm-terminal-window -params 1.. -shell-completion -docstring ' +iterm-terminal-window []: create a new terminal as an iterm window +The program passed as argument will be executed in the new terminal'\ +%{ + nop %sh{ + # see above + args=$( + for i in "$@"; do + if [ "$i" = '' ]; then + printf "'' " + else + printf %s "$i" | sed -e "s|'|'\\\\''|g; s|^|'|; s|$|' |" + fi + done + ) + escaped=$(printf %s "$args" | sed -e 's|\\|\\\\|g; s|"|\\"|g') + cmd="env PATH='${PATH}' TMPDIR='${TMPDIR}' $escaped" + osascript \ + -e "tell application \"iTerm\"" \ + -e " create window with default profile command \"${cmd}\"" \ + -e "end tell" >/dev/null + } +} + +define-command iterm-focus -params ..1 -client-completion -docstring ' +iterm-focus []: focus the given client +If no client is passed then the current one is used' \ +%{ + evaluate-commands %sh{ + if [ $# -eq 1 ]; then + printf %s\\n "evaluate-commands -client '$1' focus" + else + session="${kak_client_env_ITERM_SESSION_ID#*:}" + osascript \ + -e "tell application \"iTerm\" to repeat with aWin in windows" \ + -e " tell aWin to repeat with aTab in tabs" \ + -e " tell aTab to repeat with aSession in sessions" \ + -e " tell aSession" \ + -e " if (unique id = \"${session}\") then" \ + -e " select" \ + -e " end if" \ + -e " end tell" \ + -e " end repeat" \ + -e " end repeat" \ + -e "end repeat" + fi + } +} diff --git a/rc/windowing/kitty.kak b/rc/windowing/kitty.kak new file mode 100644 index 00000000..79583945 --- /dev/null +++ b/rc/windowing/kitty.kak @@ -0,0 +1,65 @@ +declare-option -docstring %{window type that kitty creates on new and repl calls (kitty|os)} str kitty_window_type kitty + +hook -group kitty-hooks global KakBegin .* %sh{ + if [ "$TERM" = "xterm-kitty" ] && [ -z "$TMUX" ]; then + echo " + alias global terminal kitty-terminal + alias global terminal-tab kitty-terminal-tab + alias global focus kitty-focus + alias global repl kitty-repl + alias global send-text kitty-send-text + " + fi +} + +define-command kitty-terminal -params 1.. -shell-completion -docstring ' +kitty-terminal []: create a new terminal as a kitty window +The program passed as argument will be executed in the new terminal' \ +%{ + nop %sh{ + kitty @ new-window --no-response --window-type $kak_opt_kitty_window_type "$@" + } +} + +define-command kitty-terminal-tab -params 1.. -shell-completion -docstring ' +kitty-terminal-tab []: create a new terminal as kitty tab +The program passed as argument will be executed in the new terminal' \ +%{ + nop %sh{ + kitty @ new-window --no-response --new-tab "$@" + } +} + +define-command kitty-focus -params ..1 -client-completion -docstring ' +kitty-focus []: focus the given client +If no client is passed then the current one is used' \ +%{ + evaluate-commands %sh{ + if [ $# -eq 1 ]; then + printf "evaluate-commands -client '%s' focus" "$1" + else + kitty @ focus-tab --no-response -m=id:$kak_client_env_KITTY_WINDOW_ID + kitty @ focus-window --no-response -m=id:$kak_client_env_KITTY_WINDOW_ID + fi + } +} + +define-command kitty-repl -params .. -shell-completion -docstring ' +kitty-repl []: create a new window for repl interaction +All optional parameters are forwarded to the new window' \ +%{ + nop %sh{ + if [ $# -eq 0 ]; then + cmd="${SHELL:-/bin/sh}" + else + cmd="$*" + fi + kitty @ new-window --no-response --window-type $kak_opt_kitty_window_type --title kak_repl_window --cwd "$PWD" $cmd < /dev/null > /dev/null 2>&1 & + } +} + +define-command kitty-send-text -docstring "send the selected text to the repl window" %{ + nop %sh{ + kitty @ send-text -m=title:kak_repl_window "${kak_selection}" + } +} diff --git a/rc/windowing/new-client.kak b/rc/windowing/new-client.kak new file mode 100644 index 00000000..6ec538a9 --- /dev/null +++ b/rc/windowing/new-client.kak @@ -0,0 +1,12 @@ +define-command new -params .. -command-completion -docstring ' +new []: create a new kakoune client +The ''terminal'' alias is being used to determine the user''s preferred terminal emulator +The optional arguments are passed as commands to the new client' \ +%{ + try %{ + terminal kak -c %val{session} -e "%arg{@}" + } catch %{ + fail "The 'terminal' alias must be defined to use this command" + } +} + diff --git a/rc/windowing/screen.kak b/rc/windowing/screen.kak new file mode 100644 index 00000000..e4ddd2e9 --- /dev/null +++ b/rc/windowing/screen.kak @@ -0,0 +1,69 @@ +# http://gnu.org/software/screen/ +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook -group GNUscreen global KakBegin .* %sh{ + [ -z "${STY}" ] && exit + echo " + alias global focus screen-focus + alias global terminal screen-terminal-vertical + " +} + +define-command screen-terminal-impl -hidden -params 3.. %{ + nop %sh{ + tty="$(ps -o tty ${kak_client_pid} | tail -n 1)" + screen -X eval "$1" "$2" + shift 2 + # see x11.kak for what this achieves + args=$( + for i in "$@"; do + if [ "$i" = '' ]; then + printf "'' " + else + printf %s "$i" | sed -e "s|'|'\\\\''|g; s|^|'|; s|$|' |" + fi + done + ) + screen -X screen sh -c "${args} ; screen -X remove" < "/dev/$tty" + } +} + +define-command screen-terminal-vertical -params 1.. -shell-completion -docstring ' +screen-terminal-vertical [] []: create a new terminal as a screen pane +The current pane is split into two, left and right +The program passed as argument will be executed in the new terminal' \ +%{ + screen-terminal-impl 'split -v' 'focus right' %arg{@} +} +define-command screen-terminal-horizontal -params 1.. -shell-completion -docstring ' +screen-terminal-horizontal []: create a new terminal as a screen pane +The current pane is split into two, top and bottom +The program passed as argument will be executed in the new terminal' \ +%{ + screen-terminal-impl 'split -h' 'focus down' %arg{@} +} +define-command screen-terminal-window -params 1.. -shell-completion -docstring ' +screen-terminal-window []: create a new terminal as a screen window +The program passed as argument will be executed in the new terminal' \ +%{ + nop %sh{ + tty="$(ps -o tty ${kak_client_pid} | tail -n 1)" + screen -X screen "$@" < "/dev/$tty" + } +} + +define-command screen-focus -params ..1 -client-completion -docstring ' +screen-focus []: focus the given client +If no client is passed then the current one is used' \ +%{ + evaluate-commands %sh{ + if [ $# -eq 1 ]; then + printf %s\\n " + evaluate-commands -client '$1' focus + " + elif [ -n "${kak_client_env_STY}" ]; then + tty="$(ps -o tty ${kak_client_pid} | tail -n 1)" + screen -X select "${kak_client_env_WINDOW}" < "/dev/$tty" + fi + } +} diff --git a/rc/windowing/tmux.kak b/rc/windowing/tmux.kak new file mode 100644 index 00000000..acc5c097 --- /dev/null +++ b/rc/windowing/tmux.kak @@ -0,0 +1,61 @@ +# http://tmux.github.io/ +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +## The default behaviour for the `new` command is to open an horizontal pane in a tmux session +hook global KakBegin .* %sh{ + if [ -n "$TMUX" ]; then + echo " + alias global focus tmux-focus + alias global terminal tmux-terminal-horizontal + " + fi +} + +define-command -hidden -params 2.. tmux-terminal-impl %{ + evaluate-commands %sh{ + tmux=${kak_client_env_TMUX:-$TMUX} + if [ -z "$tmux" ]; then + echo "fail 'This command is only available in a tmux session'" + exit + fi + tmux_args="$1" + shift + # ideally we should escape single ';' to stop tmux from interpreting it as a new command + # but that's probably too rare to care + TMUX=$tmux tmux $tmux_args env TMPDIR="$TMPDIR" "$@" < /dev/null > /dev/null 2>&1 & + } +} + +define-command tmux-terminal-vertical -params 1.. -shell-completion -docstring ' +tmux-terminal-vertical []: create a new terminal as a tmux pane +The current pane is split into two, top and bottom +The program passed as argument will be executed in the new terminal' \ +%{ + tmux-terminal-impl 'split-window -v' %arg{@} +} +define-command tmux-terminal-horizontal -params 1.. -shell-completion -docstring ' +tmux-terminal-horizontal []: create a new terminal as a tmux pane +The current pane is split into two, left and right +The program passed as argument will be executed in the new terminal' \ +%{ + tmux-terminal-impl 'split-window -h' %arg{@} +} +define-command tmux-terminal-window -params 1.. -shell-completion -docstring ' +tmux-terminal-window [] []: create a new terminal as a tmux window +The program passed as argument will be executed in the new terminal' \ +%{ + tmux-terminal-impl 'new-window' %arg{@} +} + +define-command tmux-focus -params ..1 -client-completion -docstring ' +tmux-focus []: focus the given client +If no client is passed then the current one is used' \ +%{ + evaluate-commands %sh{ + if [ $# -eq 1 ]; then + printf "evaluate-commands -client '%s' focus" "$1" + elif [ -n "${kak_client_env_TMUX}" ]; then + TMUX="${kak_client_env_TMUX}" tmux select-pane -t "${kak_client_env_TMUX_PANE}" > /dev/null + fi + } +} diff --git a/rc/windowing/tmux/repl.kak b/rc/windowing/tmux/repl.kak new file mode 100644 index 00000000..a176f5f5 --- /dev/null +++ b/rc/windowing/tmux/repl.kak @@ -0,0 +1,67 @@ +# http://tmux.github.io/ +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +declare-option -docstring "tmux pane id in which the REPL is running" str tmux_repl_id + +hook global KakBegin .* %sh{ + if [ -n "$TMUX" ]; then + VERSION_TMUX=$(tmux -V | cut -d' ' -f2) + VERSION_TMUX=${VERSION_TMUX%%.*} + + if [ "${VERSION_TMUX}" = "master" ] \ + || [ "${VERSION_TMUX}" -ge 2 ]; then + echo " + alias global repl tmux-repl-horizontal + alias global send-text tmux-send-text + " + else + echo " + alias global repl tmux-repl-disabled + alias global send-text tmux-repl-disabled + " + fi + fi +} + +define-command -hidden -params 1..2 tmux-repl-impl %{ + evaluate-commands %sh{ + if [ -z "$TMUX" ]; then + echo "echo -markup '{Error}This command is only available in a tmux session'" + exit + fi + tmux_args="$1" + shift + tmux_cmd="$@" + tmux $tmux_args $tmux_cmd + printf "set-option global tmux_repl_id '%s'" $(tmux display-message -p '#{session_id}:#{window_id}.#{pane_id}') + } +} + +define-command tmux-repl-vertical -params 0..1 -command-completion -docstring "Create a new vertical pane for repl interaction" %{ + tmux-repl-impl 'split-window -v' %arg{@} +} + +define-command tmux-repl-horizontal -params 0..1 -command-completion -docstring "Create a new horizontal pane for repl interaction" %{ + tmux-repl-impl 'split-window -h' %arg{@} +} + +define-command tmux-repl-window -params 0..1 -command-completion -docstring "Create a new window for repl interaction" %{ + tmux-repl-impl 'new-window' %arg{@} +} + +define-command -hidden tmux-send-text -params 0..1 -docstring "tmux-send-text [text]: Send text(append new line) to the REPL pane. + If no text is passed, then the selection is used" %{ + nop %sh{ + if [ $# -eq 0 ]; then + tmux set-buffer -b kak_selection "${kak_selection}" + else + tmux set-buffer -b kak_selection "$1" + fi + tmux paste-buffer -b kak_selection -t "$kak_opt_tmux_repl_id" + } +} + +define-command -hidden tmux-repl-disabled %{ evaluate-commands %sh{ + VERSION_TMUX=$(tmux -V) + printf %s "echo -markup %{{Error}The version of tmux is too old: got ${VERSION_TMUX}, expected >= 2.x}" +} } diff --git a/rc/windowing/x11.kak b/rc/windowing/x11.kak new file mode 100644 index 00000000..27b637ae --- /dev/null +++ b/rc/windowing/x11.kak @@ -0,0 +1,73 @@ +# termcmd should be set such as the next argument is the whole +# command line to execute +declare-option -docstring %{shell command run to spawn a new terminal +A shell command is appended to the one set in this option at runtime} \ + str termcmd %sh{ + for termcmd in 'alacritty -e sh -c' \ + 'kitty sh -c' \ + 'termite -e ' \ + 'urxvt -e sh -c' \ + 'rxvt -e sh -c' \ + 'xterm -e sh -c' \ + 'roxterm -e sh -c' \ + 'mintty -e sh -c' \ + 'sakura -x ' \ + 'gnome-terminal -e ' \ + 'xfce4-terminal -e ' \ + 'konsole -e '; do + terminal=${termcmd%% *} + if command -v $terminal >/dev/null 2>&1; then + printf %s\\n "$termcmd" + exit + fi + done +} + +define-command x11-terminal -params 1.. -shell-completion -docstring ' +x11-terminal []: create a new terminal as an x11 window +The program passed as argument will be executed in the new terminal' \ +%{ + evaluate-commands %sh{ + if [ -z "${kak_opt_termcmd}" ]; then + echo "fail 'termcmd option is not set'" + exit + fi + # join arguments into a single string, in which they're delimited + # by single quotes, and with single quotes inside transformed to '\'' + # so that sh -c "$args" will re-split the arguments properly + # example: + # $1 = ab + # $2 = foo bar + # $3 = + # $4 = foo'bar + # $args = 'ab' 'foo bar' '' 'foo'\''bar' + # would be nicer to do in a single sed/awk call but that's difficult + args=$( + for i in "$@"; do + # special case to preserve empty variables as sed won't touch these + if [ "$i" = '' ]; then + printf "'' " + else + printf %s "$i" | sed -e "s|'|'\\\\''|g; s|^|'|; s|$|' |" + fi + done + ) + setsid ${kak_opt_termcmd} "$args" < /dev/null > /dev/null 2>&1 & + } +} + +define-command x11-focus -params ..1 -client-completion -docstring ' +x11-focus []: focus a given client''s window +If no client is passed, then the current client is used' \ +%{ + evaluate-commands %sh{ + if [ $# -eq 1 ]; then + printf "evaluate-commands -client '%s' focus" "$1" + else + xdotool windowactivate $kak_client_env_WINDOWID > /dev/null + fi + } +} + +alias global focus x11-focus +alias global terminal x11-terminal diff --git a/rc/windowing/x11/repl.kak b/rc/windowing/x11/repl.kak new file mode 100644 index 00000000..865e2748 --- /dev/null +++ b/rc/windowing/x11/repl.kak @@ -0,0 +1,26 @@ +# termcmd should already be set in x11.kak +define-command -docstring %{x11-repl []: create a new window for repl interaction +All optional parameters are forwarded to the new window} \ + -params .. \ + -shell-completion \ + x11-repl %{ evaluate-commands %sh{ + if [ -z "${kak_opt_termcmd}" ]; then + echo "echo -markup '{Error}termcmd option is not set'" + exit + fi + if [ $# -eq 0 ]; then cmd="${SHELL:-sh}"; else cmd="$@"; fi + setsid ${kak_opt_termcmd} ${cmd} -t kak_repl_window < /dev/null > /dev/null 2>&1 & +}} + +define-command x11-send-text -docstring "send the selected text to the repl window" %{ + nop %sh{ + printf %s\\n "${kak_selection}" | xsel -i + wid=$(xdotool getactivewindow) + xdotool search --name kak_repl_window windowactivate + xdotool key --clearmodifiers "Shift+Insert" + xdotool windowactivate $wid + } +} + +alias global repl x11-repl +alias global send-text x11-send-text diff --git a/test/indent/c-family/align-while-expr/rc b/test/indent/c-family/align-while-expr/rc index 53c40654..2c2a7247 100644 --- a/test/indent/c-family/align-while-expr/rc +++ b/test/indent/c-family/align-while-expr/rc @@ -1,3 +1,3 @@ source "%val{runtime}/colors/default.kak" -source "%val{runtime}/rc/core/c-family.kak" +source "%val{runtime}/rc/filetype/c-family.kak" set buffer filetype cpp diff --git a/test/indent/c-family/close-namespace/rc b/test/indent/c-family/close-namespace/rc index 53c40654..2c2a7247 100644 --- a/test/indent/c-family/close-namespace/rc +++ b/test/indent/c-family/close-namespace/rc @@ -1,3 +1,3 @@ source "%val{runtime}/colors/default.kak" -source "%val{runtime}/rc/core/c-family.kak" +source "%val{runtime}/rc/filetype/c-family.kak" set buffer filetype cpp diff --git a/test/indent/c-family/close-struct/rc b/test/indent/c-family/close-struct/rc index 53c40654..2c2a7247 100644 --- a/test/indent/c-family/close-struct/rc +++ b/test/indent/c-family/close-struct/rc @@ -1,3 +1,3 @@ source "%val{runtime}/colors/default.kak" -source "%val{runtime}/rc/core/c-family.kak" +source "%val{runtime}/rc/filetype/c-family.kak" set buffer filetype cpp diff --git a/test/indent/c-family/comment-line-continuation/rc b/test/indent/c-family/comment-line-continuation/rc index 53c40654..2c2a7247 100644 --- a/test/indent/c-family/comment-line-continuation/rc +++ b/test/indent/c-family/comment-line-continuation/rc @@ -1,3 +1,3 @@ source "%val{runtime}/colors/default.kak" -source "%val{runtime}/rc/core/c-family.kak" +source "%val{runtime}/rc/filetype/c-family.kak" set buffer filetype cpp diff --git a/test/indent/c-family/construct-align/rc b/test/indent/c-family/construct-align/rc index 53c40654..2c2a7247 100644 --- a/test/indent/c-family/construct-align/rc +++ b/test/indent/c-family/construct-align/rc @@ -1,3 +1,3 @@ source "%val{runtime}/colors/default.kak" -source "%val{runtime}/rc/core/c-family.kak" +source "%val{runtime}/rc/filetype/c-family.kak" set buffer filetype cpp diff --git a/test/indent/c-family/deindent-if-body/rc b/test/indent/c-family/deindent-if-body/rc index 53c40654..2c2a7247 100644 --- a/test/indent/c-family/deindent-if-body/rc +++ b/test/indent/c-family/deindent-if-body/rc @@ -1,3 +1,3 @@ source "%val{runtime}/colors/default.kak" -source "%val{runtime}/rc/core/c-family.kak" +source "%val{runtime}/rc/filetype/c-family.kak" set buffer filetype cpp diff --git a/test/indent/c-family/indent-after-parenthesis/rc b/test/indent/c-family/indent-after-parenthesis/rc index 53c40654..2c2a7247 100644 --- a/test/indent/c-family/indent-after-parenthesis/rc +++ b/test/indent/c-family/indent-after-parenthesis/rc @@ -1,3 +1,3 @@ source "%val{runtime}/colors/default.kak" -source "%val{runtime}/rc/core/c-family.kak" +source "%val{runtime}/rc/filetype/c-family.kak" set buffer filetype cpp diff --git a/test/indent/c-family/indent-if-body/rc b/test/indent/c-family/indent-if-body/rc index 53c40654..2c2a7247 100644 --- a/test/indent/c-family/indent-if-body/rc +++ b/test/indent/c-family/indent-if-body/rc @@ -1,3 +1,3 @@ source "%val{runtime}/colors/default.kak" -source "%val{runtime}/rc/core/c-family.kak" +source "%val{runtime}/rc/filetype/c-family.kak" set buffer filetype cpp diff --git a/test/indent/c-family/indent-if-brace/rc b/test/indent/c-family/indent-if-brace/rc index 53c40654..2c2a7247 100644 --- a/test/indent/c-family/indent-if-brace/rc +++ b/test/indent/c-family/indent-if-brace/rc @@ -1,3 +1,3 @@ source "%val{runtime}/colors/default.kak" -source "%val{runtime}/rc/core/c-family.kak" +source "%val{runtime}/rc/filetype/c-family.kak" set buffer filetype cpp diff --git a/test/indent/c-family/move-brace/rc b/test/indent/c-family/move-brace/rc index 53c40654..2c2a7247 100644 --- a/test/indent/c-family/move-brace/rc +++ b/test/indent/c-family/move-brace/rc @@ -1,3 +1,3 @@ source "%val{runtime}/colors/default.kak" -source "%val{runtime}/rc/core/c-family.kak" +source "%val{runtime}/rc/filetype/c-family.kak" set buffer filetype cpp diff --git a/test/indent/c-family/multiline-nested-align/rc b/test/indent/c-family/multiline-nested-align/rc index 53c40654..2c2a7247 100644 --- a/test/indent/c-family/multiline-nested-align/rc +++ b/test/indent/c-family/multiline-nested-align/rc @@ -1,3 +1,3 @@ source "%val{runtime}/colors/default.kak" -source "%val{runtime}/rc/core/c-family.kak" +source "%val{runtime}/rc/filetype/c-family.kak" set buffer filetype cpp diff --git a/test/indent/c-family/nested-align/rc b/test/indent/c-family/nested-align/rc index 53c40654..2c2a7247 100644 --- a/test/indent/c-family/nested-align/rc +++ b/test/indent/c-family/nested-align/rc @@ -1,3 +1,3 @@ source "%val{runtime}/colors/default.kak" -source "%val{runtime}/rc/core/c-family.kak" +source "%val{runtime}/rc/filetype/c-family.kak" set buffer filetype cpp diff --git a/test/indent/c-family/open-function/rc b/test/indent/c-family/open-function/rc index 53c40654..2c2a7247 100644 --- a/test/indent/c-family/open-function/rc +++ b/test/indent/c-family/open-function/rc @@ -1,3 +1,3 @@ source "%val{runtime}/colors/default.kak" -source "%val{runtime}/rc/core/c-family.kak" +source "%val{runtime}/rc/filetype/c-family.kak" set buffer filetype cpp diff --git a/test/indent/comment/comment-multiple-lines-indented/rc b/test/indent/comment/comment-multiple-lines-indented/rc index 4808655d..f9dc592b 100644 --- a/test/indent/comment/comment-multiple-lines-indented/rc +++ b/test/indent/comment/comment-multiple-lines-indented/rc @@ -1,4 +1,4 @@ source "%val{runtime}/colors/default.kak" -source "%val{runtime}/rc/base/yaml.kak" -source "%val{runtime}/rc/core/comment.kak" +source "%val{runtime}/rc/filetype/yaml.kak" +source "%val{runtime}/rc/tools/comment.kak" set buffer filetype yaml diff --git a/test/indent/comment/comment-multiple-lines-unindented/rc b/test/indent/comment/comment-multiple-lines-unindented/rc index 4808655d..f9dc592b 100644 --- a/test/indent/comment/comment-multiple-lines-unindented/rc +++ b/test/indent/comment/comment-multiple-lines-unindented/rc @@ -1,4 +1,4 @@ source "%val{runtime}/colors/default.kak" -source "%val{runtime}/rc/base/yaml.kak" -source "%val{runtime}/rc/core/comment.kak" +source "%val{runtime}/rc/filetype/yaml.kak" +source "%val{runtime}/rc/tools/comment.kak" set buffer filetype yaml diff --git a/test/indent/comment/comment-multiple-lines-when-partially-commented/rc b/test/indent/comment/comment-multiple-lines-when-partially-commented/rc index 4808655d..f9dc592b 100644 --- a/test/indent/comment/comment-multiple-lines-when-partially-commented/rc +++ b/test/indent/comment/comment-multiple-lines-when-partially-commented/rc @@ -1,4 +1,4 @@ source "%val{runtime}/colors/default.kak" -source "%val{runtime}/rc/base/yaml.kak" -source "%val{runtime}/rc/core/comment.kak" +source "%val{runtime}/rc/filetype/yaml.kak" +source "%val{runtime}/rc/tools/comment.kak" set buffer filetype yaml diff --git a/test/indent/comment/uncomment-multiple-indented-lines/rc b/test/indent/comment/uncomment-multiple-indented-lines/rc index 4808655d..f9dc592b 100644 --- a/test/indent/comment/uncomment-multiple-indented-lines/rc +++ b/test/indent/comment/uncomment-multiple-indented-lines/rc @@ -1,4 +1,4 @@ source "%val{runtime}/colors/default.kak" -source "%val{runtime}/rc/base/yaml.kak" -source "%val{runtime}/rc/core/comment.kak" +source "%val{runtime}/rc/filetype/yaml.kak" +source "%val{runtime}/rc/tools/comment.kak" set buffer filetype yaml diff --git a/test/indent/haskell/before-comment/rc b/test/indent/haskell/before-comment/rc index 7e506fc4..3f756817 100644 --- a/test/indent/haskell/before-comment/rc +++ b/test/indent/haskell/before-comment/rc @@ -1,3 +1,3 @@ source "%val{runtime}/colors/default.kak" -source "%val{runtime}/rc/base/haskell.kak" +source "%val{runtime}/rc/filetype/haskell.kak" set buffer filetype haskell diff --git a/test/indent/haskell/indented-comment/rc b/test/indent/haskell/indented-comment/rc index 7e506fc4..3f756817 100644 --- a/test/indent/haskell/indented-comment/rc +++ b/test/indent/haskell/indented-comment/rc @@ -1,3 +1,3 @@ source "%val{runtime}/colors/default.kak" -source "%val{runtime}/rc/base/haskell.kak" +source "%val{runtime}/rc/filetype/haskell.kak" set buffer filetype haskell diff --git a/test/indent/haskell/inside-comment/rc b/test/indent/haskell/inside-comment/rc index 7e506fc4..3f756817 100644 --- a/test/indent/haskell/inside-comment/rc +++ b/test/indent/haskell/inside-comment/rc @@ -1,3 +1,3 @@ source "%val{runtime}/colors/default.kak" -source "%val{runtime}/rc/base/haskell.kak" +source "%val{runtime}/rc/filetype/haskell.kak" set buffer filetype haskell diff --git a/test/indent/html/indent-closing-tag/rc b/test/indent/html/indent-closing-tag/rc index 5756ea1a..ef3301f7 100644 --- a/test/indent/html/indent-closing-tag/rc +++ b/test/indent/html/indent-closing-tag/rc @@ -1,3 +1,3 @@ source "%val{runtime}/colors/default.kak" -source "%val{runtime}/rc/base/html.kak" +source "%val{runtime}/rc/filetype/html.kak" set buffer filetype html diff --git a/test/indent/lua/insert-end-only-when-needed/rc b/test/indent/lua/insert-end-only-when-needed/rc index 7550d15c..b5cf999d 100644 --- a/test/indent/lua/insert-end-only-when-needed/rc +++ b/test/indent/lua/insert-end-only-when-needed/rc @@ -1,3 +1,3 @@ source "%val{runtime}/colors/default.kak" -source "%val{runtime}/rc/base/lua.kak" +source "%val{runtime}/rc/filetype/lua.kak" set buffer filetype lua diff --git a/test/indent/markdown/inside-complex-blockquote/rc b/test/indent/markdown/inside-complex-blockquote/rc index 7b9ff85e..59ce7862 100644 --- a/test/indent/markdown/inside-complex-blockquote/rc +++ b/test/indent/markdown/inside-complex-blockquote/rc @@ -1,3 +1,3 @@ source "%val{runtime}/colors/default.kak" -source "%val{runtime}/rc/base/markdown.kak" +source "%val{runtime}/rc/filetype/markdown.kak" set buffer filetype markdown diff --git a/test/indent/markdown/inside-list-item/rc b/test/indent/markdown/inside-list-item/rc index 7b9ff85e..59ce7862 100644 --- a/test/indent/markdown/inside-list-item/rc +++ b/test/indent/markdown/inside-list-item/rc @@ -1,3 +1,3 @@ source "%val{runtime}/colors/default.kak" -source "%val{runtime}/rc/base/markdown.kak" +source "%val{runtime}/rc/filetype/markdown.kak" set buffer filetype markdown diff --git a/test/indent/markdown/inside-nested-list-item/rc b/test/indent/markdown/inside-nested-list-item/rc index 7b9ff85e..59ce7862 100644 --- a/test/indent/markdown/inside-nested-list-item/rc +++ b/test/indent/markdown/inside-nested-list-item/rc @@ -1,3 +1,3 @@ source "%val{runtime}/colors/default.kak" -source "%val{runtime}/rc/base/markdown.kak" +source "%val{runtime}/rc/filetype/markdown.kak" set buffer filetype markdown diff --git a/test/indent/markdown/inside-simple-blockquote/rc b/test/indent/markdown/inside-simple-blockquote/rc index 7b9ff85e..59ce7862 100644 --- a/test/indent/markdown/inside-simple-blockquote/rc +++ b/test/indent/markdown/inside-simple-blockquote/rc @@ -1,3 +1,3 @@ source "%val{runtime}/colors/default.kak" -source "%val{runtime}/rc/base/markdown.kak" +source "%val{runtime}/rc/filetype/markdown.kak" set buffer filetype markdown diff --git a/test/indent/markdown/inside-strong-emphasis/rc b/test/indent/markdown/inside-strong-emphasis/rc index 7b9ff85e..59ce7862 100644 --- a/test/indent/markdown/inside-strong-emphasis/rc +++ b/test/indent/markdown/inside-strong-emphasis/rc @@ -1,3 +1,3 @@ source "%val{runtime}/colors/default.kak" -source "%val{runtime}/rc/base/markdown.kak" +source "%val{runtime}/rc/filetype/markdown.kak" set buffer filetype markdown diff --git a/test/indent/markdown/list-item/rc b/test/indent/markdown/list-item/rc index 7b9ff85e..59ce7862 100644 --- a/test/indent/markdown/list-item/rc +++ b/test/indent/markdown/list-item/rc @@ -1,3 +1,3 @@ source "%val{runtime}/colors/default.kak" -source "%val{runtime}/rc/base/markdown.kak" +source "%val{runtime}/rc/filetype/markdown.kak" set buffer filetype markdown diff --git a/test/indent/markdown/open-after-setext-heading-1/rc b/test/indent/markdown/open-after-setext-heading-1/rc index 7b9ff85e..59ce7862 100644 --- a/test/indent/markdown/open-after-setext-heading-1/rc +++ b/test/indent/markdown/open-after-setext-heading-1/rc @@ -1,3 +1,3 @@ source "%val{runtime}/colors/default.kak" -source "%val{runtime}/rc/base/markdown.kak" +source "%val{runtime}/rc/filetype/markdown.kak" set buffer filetype markdown diff --git a/test/indent/markdown/open-after-setext-heading-2/rc b/test/indent/markdown/open-after-setext-heading-2/rc index 7b9ff85e..59ce7862 100644 --- a/test/indent/markdown/open-after-setext-heading-2/rc +++ b/test/indent/markdown/open-after-setext-heading-2/rc @@ -1,3 +1,3 @@ source "%val{runtime}/colors/default.kak" -source "%val{runtime}/rc/base/markdown.kak" +source "%val{runtime}/rc/filetype/markdown.kak" set buffer filetype markdown diff --git a/test/indent/ruby/following-blocks-should-not-prevent-end/rc b/test/indent/ruby/following-blocks-should-not-prevent-end/rc index d4fadeea..934f7e83 100644 --- a/test/indent/ruby/following-blocks-should-not-prevent-end/rc +++ b/test/indent/ruby/following-blocks-should-not-prevent-end/rc @@ -1,3 +1,3 @@ source "%val{runtime}/colors/default.kak" -source "%val{runtime}/rc/base/ruby.kak" +source "%val{runtime}/rc/filetype/ruby.kak" set buffer filetype ruby diff --git a/test/indent/ruby/indent-after-class/rc b/test/indent/ruby/indent-after-class/rc index d4fadeea..934f7e83 100644 --- a/test/indent/ruby/indent-after-class/rc +++ b/test/indent/ruby/indent-after-class/rc @@ -1,3 +1,3 @@ source "%val{runtime}/colors/default.kak" -source "%val{runtime}/rc/base/ruby.kak" +source "%val{runtime}/rc/filetype/ruby.kak" set buffer filetype ruby diff --git a/test/indent/ruby/method-definition-shouldnt-duplicate/rc b/test/indent/ruby/method-definition-shouldnt-duplicate/rc index d4fadeea..934f7e83 100644 --- a/test/indent/ruby/method-definition-shouldnt-duplicate/rc +++ b/test/indent/ruby/method-definition-shouldnt-duplicate/rc @@ -1,3 +1,3 @@ source "%val{runtime}/colors/default.kak" -source "%val{runtime}/rc/base/ruby.kak" +source "%val{runtime}/rc/filetype/ruby.kak" set buffer filetype ruby diff --git a/test/regression/1074-comment-leader-autoinsert-error/rc b/test/regression/1074-comment-leader-autoinsert-error/rc index 53c40654..2c2a7247 100644 --- a/test/regression/1074-comment-leader-autoinsert-error/rc +++ b/test/regression/1074-comment-leader-autoinsert-error/rc @@ -1,3 +1,3 @@ source "%val{runtime}/colors/default.kak" -source "%val{runtime}/rc/core/c-family.kak" +source "%val{runtime}/rc/filetype/c-family.kak" set buffer filetype cpp diff --git a/test/regression/1111-unexpected-behaviour-on-new-line-in-comment/rc b/test/regression/1111-unexpected-behaviour-on-new-line-in-comment/rc index 53c40654..2c2a7247 100644 --- a/test/regression/1111-unexpected-behaviour-on-new-line-in-comment/rc +++ b/test/regression/1111-unexpected-behaviour-on-new-line-in-comment/rc @@ -1,3 +1,3 @@ source "%val{runtime}/colors/default.kak" -source "%val{runtime}/rc/core/c-family.kak" +source "%val{runtime}/rc/filetype/c-family.kak" set buffer filetype cpp diff --git a/test/regression/1118-misaligned-comment-start/rc b/test/regression/1118-misaligned-comment-start/rc index 53c40654..2c2a7247 100644 --- a/test/regression/1118-misaligned-comment-start/rc +++ b/test/regression/1118-misaligned-comment-start/rc @@ -1,3 +1,3 @@ source "%val{runtime}/colors/default.kak" -source "%val{runtime}/rc/core/c-family.kak" +source "%val{runtime}/rc/filetype/c-family.kak" set buffer filetype cpp diff --git a/test/regression/1308-wrong-behaviour-of-kak-indent-on-newline/rc b/test/regression/1308-wrong-behaviour-of-kak-indent-on-newline/rc index 3daaec2e..367014a1 100644 --- a/test/regression/1308-wrong-behaviour-of-kak-indent-on-newline/rc +++ b/test/regression/1308-wrong-behaviour-of-kak-indent-on-newline/rc @@ -1,3 +1,3 @@ source "%val{runtime}/colors/default.kak" -source "%val{runtime}/rc/core/kakrc.kak" +source "%val{runtime}/rc/filetype/kakrc.kak" set buffer filetype kak diff --git a/test/regression/1525-lua-indent-error/rc b/test/regression/1525-lua-indent-error/rc index 7550d15c..b5cf999d 100644 --- a/test/regression/1525-lua-indent-error/rc +++ b/test/regression/1525-lua-indent-error/rc @@ -1,3 +1,3 @@ source "%val{runtime}/colors/default.kak" -source "%val{runtime}/rc/base/lua.kak" +source "%val{runtime}/rc/filetype/lua.kak" set buffer filetype lua diff --git a/test/regression/1920-crash-on-python-in-docstring/rc b/test/regression/1920-crash-on-python-in-docstring/rc index 909f53ff..a098fc21 100644 --- a/test/regression/1920-crash-on-python-in-docstring/rc +++ b/test/regression/1920-crash-on-python-in-docstring/rc @@ -1,3 +1,3 @@ source "%val{runtime}/colors/default.kak" -source "%val{runtime}/rc/core/python.kak" +source "%val{runtime}/rc/filetype/python.kak" set buffer filetype python diff --git a/test/regression/2499-html-regions-assert/rc b/test/regression/2499-html-regions-assert/rc index 5756ea1a..ef3301f7 100644 --- a/test/regression/2499-html-regions-assert/rc +++ b/test/regression/2499-html-regions-assert/rc @@ -1,3 +1,3 @@ source "%val{runtime}/colors/default.kak" -source "%val{runtime}/rc/base/html.kak" +source "%val{runtime}/rc/filetype/html.kak" set buffer filetype html diff --git a/test/regression/860-python-incorrect-commenting/rc b/test/regression/860-python-incorrect-commenting/rc index 909f53ff..a098fc21 100644 --- a/test/regression/860-python-incorrect-commenting/rc +++ b/test/regression/860-python-incorrect-commenting/rc @@ -1,3 +1,3 @@ source "%val{runtime}/colors/default.kak" -source "%val{runtime}/rc/core/python.kak" +source "%val{runtime}/rc/filetype/python.kak" set buffer filetype python diff --git a/test/regression/872-indentation-misbeahviour-c++/rc b/test/regression/872-indentation-misbeahviour-c++/rc index 53c40654..2c2a7247 100644 --- a/test/regression/872-indentation-misbeahviour-c++/rc +++ b/test/regression/872-indentation-misbeahviour-c++/rc @@ -1,3 +1,3 @@ source "%val{runtime}/colors/default.kak" -source "%val{runtime}/rc/core/c-family.kak" +source "%val{runtime}/rc/filetype/c-family.kak" set buffer filetype cpp diff --git a/test/regression/918-wrong-asterisk-inserted/rc b/test/regression/918-wrong-asterisk-inserted/rc index 53c40654..2c2a7247 100644 --- a/test/regression/918-wrong-asterisk-inserted/rc +++ b/test/regression/918-wrong-asterisk-inserted/rc @@ -1,3 +1,3 @@ source "%val{runtime}/colors/default.kak" -source "%val{runtime}/rc/core/c-family.kak" +source "%val{runtime}/rc/filetype/c-family.kak" set buffer filetype cpp -- cgit v1.2.3