diff --git a/doc/pages/changelog.asciidoc b/doc/pages/changelog.asciidoc index 707dac55..156e6472 100644 --- a/doc/pages/changelog.asciidoc +++ b/doc/pages/changelog.asciidoc @@ -24,13 +24,20 @@ released versions. * `InsertCompletionSelect` hook has been removed as `completions` commands now provides a similar feature. +* Introduced a module system using the `provide-module` and + `require-module` commands that allows for lazily loading language + support files with dependency resolution. + +* Added a new hook `ModuleLoad` which is run when a module is loaded, + allowing for module specific configuration. + == Kakoune 2019.01.20 * `auto_complete` has been renamed to `autocomplete` for more consistency. * Start of a builtin key parser in the ncurses ui bypassing - the ncurses one. Can be favored by setting the ui option + the ncurses one. Can be favored by setting the ui option `ncurses_builtin_key_parser` to `true`. * Right clicks extend the current selection, the control modifier allows diff --git a/doc/pages/commands.asciidoc b/doc/pages/commands.asciidoc index cc1b06af..ebaafaea 100644 --- a/doc/pages/commands.asciidoc +++ b/doc/pages/commands.asciidoc @@ -328,6 +328,22 @@ but not really useful in that context. *debug* {info,buffers,options,memory,shared-strings,profile-hash-maps,faces,mappings}:: print some debug information in the *\*debug** buffer +== Module commands + +*provide-module* [] :: + declares a module *name* that is defined by *commands*. *commands* will be + evaluated as if by source the first time *require-module * is run. + +*-override*::: + allow the module to replace an existing one with the same name. Fails if + the module has already been evaluated. + +*require-module* :: + guarantees the commands associated with *name* have been evaluated before + continuing command execution. Fails if *name* has not been defined by a + *provide-module* command. Does nothing if the associated commands have + already been evaluated. + == Multiple commands Commands (c.f. previous sections) can be chained, by being separated either diff --git a/doc/pages/hooks.asciidoc b/doc/pages/hooks.asciidoc index 163b2fdd..ec45fe63 100644 --- a/doc/pages/hooks.asciidoc +++ b/doc/pages/hooks.asciidoc @@ -176,6 +176,9 @@ name. Hooks with no description will always use an empty string. *RawKey* `key`:: Triggered whenever a key is pressed by the user +*ModuleLoad* `module`:: + Triggered when a module is evaluated by the first `require-module` call + Note that some hooks will not consider underlying scopes depending on what context they are bound to be run into, e.g. the `BufWritePost` hook is a buffer hook, and will not consider the `window` scope. diff --git a/rc/detection/editorconfig.kak b/rc/detection/editorconfig.kak index 9421e033..388e0540 100644 --- a/rc/detection/editorconfig.kak +++ b/rc/detection/editorconfig.kak @@ -8,7 +8,7 @@ hook global BufCreate .*[.](editorconfig) %{ set-option buffer filetype ini set-option buffer static_words indent_style indent_size tab_width \ end_of_line charset insert_final_newline trim_trailing_whitespace root \ - latin1 utf-8 utf-8-bom utf-16be utf-16le lf cr crlf unset space tab + latin1 utf-8 utf-8-bom utf-16be utf-16le lf cr crlf unset space tab } declare-option -hidden bool editorconfig_trim_trailing_whitespace false diff --git a/rc/filetype/asciidoc.kak b/rc/filetype/asciidoc.kak index 8bdcce07..b6e79002 100644 --- a/rc/filetype/asciidoc.kak +++ b/rc/filetype/asciidoc.kak @@ -8,6 +8,18 @@ hook global BufCreate .+\.(a(scii)?doc|asc) %{ set-option buffer filetype asciidoc } +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook -group asciidoc-highlight global WinSetOption filetype=asciidoc %{ + require-module asciidoc + + add-highlighter window/asciidoc ref asciidoc + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/asciidoc } +} + +provide-module asciidoc %{ + # Highlighters # ‾‾‾‾‾‾‾‾‾‾‾‾ @@ -34,10 +46,4 @@ 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 index fbfa702a..e4217a0b 100644 --- a/rc/filetype/c-family.kak +++ b/rc/filetype/c-family.kak @@ -23,6 +23,44 @@ hook global BufCreate .*\.m %{ set-option buffer filetype objc } +hook global WinSetOption filetype=(c|cpp|objc) %[ + require-module c-family + + evaluate-commands "set-option window static_words %%opt{%val{hook_param_capture_1}_static_words}" + + hook -group "%val{hook_param_capture_1}-trim-indent" window ModeChange insert:.* c-family-trim-indent + hook -group "%val{hook_param_capture_1}-insert" window InsertChar \n c-family-insert-on-newline + hook -group "%val{hook_param_capture_1}-indent" window InsertChar \n c-family-indent-on-newline + hook -group "%val{hook_param_capture_1}-indent" window InsertChar \{ c-family-indent-on-opening-curly-brace + hook -group "%val{hook_param_capture_1}-indent" window InsertChar \} c-family-indent-on-closing-curly-brace + hook -group "%val{hook_param_capture_1}-insert" window InsertChar \} c-family-insert-on-closing-curly-brace + + alias window alt "%val{hook_param_capture_1}-alternative-file" + + hook -once -always window WinSetOption filetype=.* " + remove-hooks window %val{hook_param_capture_1}-.+ + unalias window alt %val{hook_param_capture_1}-alternative-file + " +] + +hook -group c-highlight global WinSetOption filetype=c %{ + add-highlighter window/c ref c + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/c } +} + +hook -group cpp-highlight global WinSetOption filetype=cpp %{ + add-highlighter window/cpp ref cpp + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/cpp } +} + +hook -group objc-highlight global WinSetOption filetype=objc %{ + add-highlighter window/objc ref objc + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/objc } +} + + +provide-module c-family %§ + 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 } @@ -227,9 +265,7 @@ evaluate-commands %sh{ 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=c %{ - set-option window static_words $(join "${keywords} ${attributes} ${types} ${macros}" ' ') - }" + printf %s\\n "declare-option str-list c_static_words $(join "${keywords} ${attributes} ${types} ${macros}" ' ')" # Highlight keywords printf %s " @@ -279,9 +315,7 @@ evaluate-commands %sh{ 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=cpp %{ - set-option window static_words $(join "${keywords} ${attributes} ${entities} ${types} ${values}" ' ') - }" + printf %s\\n "declare-option str-list cpp_static_words $(join "${keywords} ${attributes} ${entities} ${types} ${values}" ' ')" # Highlight keywords printf %s " @@ -321,9 +355,7 @@ evaluate-commands %sh{ 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=objc %{ - set-option window static_words $(join "${keywords} ${attributes} ${types} ${values} ${decorators}" ' ') - }" + printf %s\\n "declare-option str-list objc_static_words $(join "${keywords} ${attributes} ${types} ${values} ${decorators}" ' ')" # Highlight keywords printf %s " @@ -335,37 +367,6 @@ evaluate-commands %sh{ " } -hook global WinSetOption filetype=(c|cpp|objc) %[ - hook -group "%val{hook_param_capture_1}-trim-indent" window ModeChange insert:.* c-family-trim-indent - hook -group "%val{hook_param_capture_1}-insert" window InsertChar \n c-family-insert-on-newline - hook -group "%val{hook_param_capture_1}-indent" window InsertChar \n c-family-indent-on-newline - hook -group "%val{hook_param_capture_1}-indent" window InsertChar \{ c-family-indent-on-opening-curly-brace - hook -group "%val{hook_param_capture_1}-indent" window InsertChar \} c-family-indent-on-closing-curly-brace - hook -group "%val{hook_param_capture_1}-insert" window InsertChar \} c-family-insert-on-closing-curly-brace - - alias window alt "%val{hook_param_capture_1}-alternative-file" - - hook -once -always window WinSetOption filetype=.* " - remove-hooks window %val{hook_param_capture_1}-.+ - unalias window alt %val{hook_param_capture_1}-alternative-file - " -] - -hook -group c-highlight global WinSetOption filetype=c %{ - add-highlighter window/c ref c - hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/c } -} - -hook -group cpp-highlight global WinSetOption filetype=cpp %{ - add-highlighter window/cpp ref cpp - hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/cpp } -} - -hook -group objc-highlight global WinSetOption filetype=objc %{ - add-highlighter window/objc ref objc - hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/objc } -} - declare-option -docstring %{control the type of include guard to be inserted in empty headers Can be one of the following: ifdef: old style ifndef/define guard @@ -441,3 +442,5 @@ define-command cpp-alternative-file -docstring "Jump to the alternate cpp 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 index b3e7e58c..a376a2f7 100644 --- a/rc/filetype/cabal.kak +++ b/rc/filetype/cabal.kak @@ -8,6 +8,28 @@ hook global BufCreate .*[.](cabal) %{ set-option buffer filetype cabal } +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook global WinSetOption filetype=cabal %[ + require-module 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-.+ } +] + +hook -group cabal-highlight global WinSetOption filetype=cabal %{ + add-highlighter window/cabal ref cabal + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/cabal } +} + + +provide-module cabal %[ + # Highlighters # ‾‾‾‾‾‾‾‾‾‾‾‾ @@ -55,20 +77,4 @@ define-command -hidden cabal-indent-on-closing-curly-brace %[ ] ] -# 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 index da6134a6..e7852227 100644 --- a/rc/filetype/clojure.kak +++ b/rc/filetype/clojure.kak @@ -1,8 +1,6 @@ # http://clojure.org # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ -# require lisp.kak - # Detection # ‾‾‾‾‾‾‾‾‾ @@ -10,6 +8,28 @@ hook global BufCreate .*[.](clj|cljc|cljs|cljx|edn) %{ set-option buffer filetype clojure } +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ +hook global WinSetOption filetype=clojure %[ + require-module clojure + + set-option window static_words %opt{clojure_static_words} + + 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-.+ } +] + +hook -group clojure-highlight global WinSetOption filetype=clojure %{ + add-highlighter window/clojure ref clojure + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/clojure } +} + +provide-module clojure %{ + +require-module lisp + # Highlighters # ‾‾‾‾‾‾‾‾‾‾‾‾ @@ -151,12 +171,11 @@ evaluate-commands %sh{ print_word_highlighter(core_fns, "function"); print_word_highlighter(core_vars, "variable"); - printf(" hook global WinSetOption filetype=clojure %%{\n"\ - " set-option window static_words "); + printf("declare-option str-list clojure_static_words ") print_static_words(keywords); print_static_words(core_fns); print_static_words(core_vars); - printf("\n }\n"); + printf("\n"); } EOF } @@ -193,16 +212,4 @@ define-command -hidden clojure-indent-on-new-line %{ } } -# 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 index 77ec18c5..cb5c65db 100644 --- a/rc/filetype/cmake.kak +++ b/rc/filetype/cmake.kak @@ -6,6 +6,17 @@ hook global BufCreate .*/CMakeCache.txt %{ set-option buffer filetype ini } +hook global WinSetOption filetype=cmake %{ + require-module cmake +} + +hook -group cmake-highlight global WinSetOption filetype=cmake %{ + add-highlighter window/cmake ref cmake + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/cmake } +} + +provide-module cmake %{ + add-highlighter shared/cmake regions add-highlighter shared/cmake/code default-region group add-highlighter shared/cmake/comment region '#' '$' fill comment @@ -21,7 +32,4 @@ add-highlighter shared/cmake/argument/quoted/ fill string add-highlighter shared/cmake/argument/quoted/ regex '\$\{\w+\}' 0:variable add-highlighter shared/cmake/argument/quoted/ regex '\w+\h*(?=\()' 0:function -hook -group cmake-highlight global WinSetOption filetype=cmake %{ - add-highlighter window/cmake ref cmake - hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/cmake } } diff --git a/rc/filetype/coffee.kak b/rc/filetype/coffee.kak index c8e7384e..a4b2fab6 100644 --- a/rc/filetype/coffee.kak +++ b/rc/filetype/coffee.kak @@ -8,6 +8,26 @@ hook global BufCreate .*[.](coffee) %{ set-option buffer filetype coffee } +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook global WinSetOption filetype=coffee %{ + require-module 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-.+ } +} + +hook -group coffee-highlight global WinSetOption filetype=coffee %{ + add-highlighter window/coffee ref coffee + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/coffee } +} + + +provide-module coffee %[ + # Highlighters # ‾‾‾‾‾‾‾‾‾‾‾‾ @@ -63,17 +83,4 @@ define-command -hidden coffee-indent-on-new-line %{ } } -# 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 index ecc456ed..f8a0d26e 100644 --- a/rc/filetype/css.kak +++ b/rc/filetype/css.kak @@ -8,6 +8,28 @@ hook global BufCreate .*[.](css) %{ set-option buffer filetype css } +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook global WinSetOption filetype=css %[ + require-module 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-.+ } +] + +hook -group css-highlight global WinSetOption filetype=css %{ + add-highlighter window/css ref css + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/css } +} + + +provide-module css %[ + # Highlighters # ‾‾‾‾‾‾‾‾‾‾‾‾ @@ -58,19 +80,4 @@ define-command -hidden css-indent-on-closing-curly-brace %[ ] ] -# 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 index 180da7d0..aa24423c 100644 --- a/rc/filetype/cucumber.kak +++ b/rc/filetype/cucumber.kak @@ -8,6 +8,26 @@ hook global BufCreate .*[.](feature|story) %{ set-option buffer filetype cucumber } +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook global WinSetOption filetype=cucumber %{ + require-module 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-.+ } +} + +hook -group cucumber-highlight global WinSetOption filetype=cucumber %{ + add-highlighter window/cucumber ref cucumber + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/cucumber } +} + + +provide-module cucumber %{ + # Highlighters # ‾‾‾‾‾‾‾‾‾‾‾‾ @@ -73,17 +93,4 @@ define-command -hidden cucumber-indent-on-new-line %{ } } -# 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 index f0f08248..16c6d8d1 100644 --- a/rc/filetype/d.kak +++ b/rc/filetype/d.kak @@ -8,6 +8,30 @@ hook global BufCreate .*\.di? %{ set-option buffer filetype d } +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook global WinSetOption filetype=d %{ + require-module d + + set-option window static_words %opt{d_static_words} + + # 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-.+ } +} + +hook -group d-highlight global WinSetOption filetype=d %{ + add-highlighter window/d ref d + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/d } +} + +provide-module d %§ + # Highlighters # ‾‾‾‾‾‾‾‾‾‾‾‾ @@ -62,9 +86,7 @@ evaluate-commands %sh{ decorators="disable|property|nogc|safe|trusted|system" # Add the language's grammar to the static completion list - printf %s\\n "hook global WinSetOption filetype=d %{ - set-option window static_words ${keywords} ${attributes} ${types} ${values} ${decorators} ${properties} - }" | tr '|' ' ' + printf %s\\n "declare-option str-list d_static_words ${keywords} ${attributes} ${types} ${values} ${decorators} ${properties}" | tr '|' ' ' # Highlight keywords printf %s " @@ -113,20 +135,4 @@ define-command -hidden d-indent-on-closing-curly-brace %[ 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 index 5b5600cb..f61dd365 100644 --- a/rc/filetype/dart.kak +++ b/rc/filetype/dart.kak @@ -8,6 +8,31 @@ hook global BufCreate .*\.dart %{ set-option buffer filetype dart } +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook global WinSetOption filetype=dart %{ + require-module dart + + set-option window static_words %opt{dart_static_words} + + # 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-.+ } +} + +hook -group dart-highlight global WinSetOption filetype=dart %{ + add-highlighter window/dart ref dart + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/dart } +} + + +provide-module dart %§ + # Highlighters # ‾‾‾‾‾‾‾‾‾‾‾‾ @@ -38,9 +63,7 @@ evaluate-commands %sh{ 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 '|' ' ' + printf %s\\n "declare-option str-list dart_static_words ${keywords} ${attributes} ${types} ${values}" | tr '|' ' ' # Highlight keywords printf %s " @@ -87,20 +110,4 @@ define-command -hidden dart-indent-on-closing-curly-brace %[ 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/dockerfile.kak b/rc/filetype/dockerfile.kak index 07da2347..f308ec92 100644 --- a/rc/filetype/dockerfile.kak +++ b/rc/filetype/dockerfile.kak @@ -10,6 +10,21 @@ hook global BufCreate .*/?Dockerfile(\.\w+)?$ %{ set-option buffer filetype dockerfile } +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook global WinSetOption filetype=dockerfile %{ + require-module dockerfile + set-option window static_words %opt{dockerfile_static_words} +} + +hook -group dockerfile-highlight global WinSetOption filetype=dockerfile %{ + add-highlighter window/dockerfile ref dockerfile + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/dockerfile } +} + +provide-module dockerfile %{ + # Highlighters # ‾‾‾‾‾‾‾‾‾‾‾‾ @@ -25,9 +40,7 @@ evaluate-commands %sh{ keywords="${keywords}|MAINTAINER|RUN|SHELL|STOPSIGNAL|USER|VOLUME|WORKDIR" # Add the language's grammar to the static completion list - printf %s\\n "hook global WinSetOption filetype=dockerfile %{ - set window static_words ONBUILD|${keywords} - }" | tr '|' ' ' + printf %s\\n "declare-option str-list dockerfile_static_words ONBUILD|${keywords}" | tr '|' ' ' # Highlight keywords printf %s " @@ -39,10 +52,4 @@ evaluate-commands %sh{ add-highlighter shared/dockerfile/code/ regex '\$\{[\w_]+\}' 0:value add-highlighter shared/dockerfile/code/ regex '\$[\w_]+' 0:value -# Initialization -# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ - -hook -group dockerfile-highlight global WinSetOption filetype=dockerfile %{ - add-highlighter window/dockerfile ref dockerfile - hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/dockerfile } } diff --git a/rc/filetype/elixir.kak b/rc/filetype/elixir.kak index a2587d1e..56c3681e 100644 --- a/rc/filetype/elixir.kak +++ b/rc/filetype/elixir.kak @@ -8,6 +8,25 @@ hook global BufCreate .*[.](ex|exs) %{ set-option buffer filetype elixir } +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook global WinSetOption filetype=elixir %{ + require-module 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-.+ } +} + +hook -group elixir-highlight global WinSetOption filetype=elixir %{ + add-highlighter window/elixir ref elixir + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/elixir } +} + + +provide-module elixir %[ # Highlighters # ‾‾‾‾‾‾‾‾‾‾‾‾ @@ -48,11 +67,11 @@ define-command -hidden elixir-trim-indent %{ define-command -hidden elixir-indent-on-new-line %{ evaluate-commands -draft -itersel %{ - # copy -- comments prefix and following white spaces + # 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: + # indent after line ending with: # try %{ execute-keys -draft k x (do|else|->)$ & } # filter previous line try %{ execute-keys -draft k : elixir-trim-indent } @@ -61,17 +80,4 @@ define-command -hidden elixir-indent-on-new-line %{ } } -# 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 index 05d1248b..88057428 100644 --- a/rc/filetype/elm.kak +++ b/rc/filetype/elm.kak @@ -8,6 +8,25 @@ hook global BufCreate .*[.](elm) %{ set-option buffer filetype elm } +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook global WinSetOption filetype=elm %{ + require-module 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-.+ } +} + +hook -group elm-highlight global WinSetOption filetype=elm %{ + add-highlighter window/elm ref elm + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/elm } +} + +provide-module elm %[ + # Highlighters # ‾‾‾‾‾‾‾‾‾‾‾‾ @@ -51,17 +70,4 @@ define-command -hidden elm-indent-on-new-line %{ } } -# 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 index 1e2067fe..b04b7b47 100644 --- a/rc/filetype/etc.kak +++ b/rc/filetype/etc.kak @@ -11,69 +11,85 @@ hook global BufCreate .*/etc/env.d/.* %{ set-option buffer fil 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 global WinSetOption filetype=etc-(hosts|resolv-conf|shadow|passwd|gshadow|group|fstab) %{ + require-module "etc-%val{hook_param_capture_1}" +} + 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 } } + + +# Highlighters + +provide-module etc-resolv-conf %{ +## /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 +} + +provide-module etc-hosts %{ +## /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 +} + +provide-module etc-fstab %{ +## /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 +} + +provide-module etc-group %{ +## /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 +} + +provide-module etc-gshadow %{ +## /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 +} + +provide-module etc-shadow %{ +## /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 +} + +provide-module etc-passwd %{ +## /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 +} diff --git a/rc/filetype/exherbo.kak b/rc/filetype/exherbo.kak index 42cc618c..72714255 100644 --- a/rc/filetype/exherbo.kak +++ b/rc/filetype/exherbo.kak @@ -25,6 +25,26 @@ hook global BufCreate .*/etc/paludis(-.*)?/repository_defaults\.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 } +hook global WinSetOption filetype=exheres-0-(metadata|options-descriptions|licence-groups) %{ + require-module exheres +} + +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 } +} + +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 } +} + +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 } +} + +provide-module exheres %{ # Highlighters ## exheres-0 Repository metadata files add-highlighter shared/exheres-0-metadata group @@ -34,11 +54,6 @@ add-highlighter shared/exheres-0-metadata/ regex ^(?:[\s\t]+)?[\S]+[\s\t]+=[\s\t 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 @@ -46,22 +61,37 @@ add-highlighter shared/exheres-0-options-descriptions/ regex ^(?:[\s\t]+)?[\S]+[ 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 } } +hook global WinSetOption filetype=paludis-(key-value|options|mirrors|specs)-conf %{ + require-module paludis +} + +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 } +} + +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 } +} + +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 } +} + +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 } +} +provide-module paludis %{ ## Paludis configurations ### options.conf add-highlighter shared/paludis-options-conf group @@ -73,49 +103,36 @@ 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 global WinSetOption filetype=glep42 %{ + require-module glep42 +} hook -group glep42-highlight global WinSetOption filetype=glep42 %{ add-highlighter window/glep42 ref glep42 hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/glep42 } } + +provide-module glep42 %{ +## 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 +} diff --git a/rc/filetype/fish.kak b/rc/filetype/fish.kak index 24da9d20..49d0c9f8 100644 --- a/rc/filetype/fish.kak +++ b/rc/filetype/fish.kak @@ -8,6 +8,26 @@ hook global BufCreate .*[.](fish) %{ set-option buffer filetype fish } +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook global WinSetOption filetype=fish %{ + require-module fish + + hook window InsertChar .* -group fish-indent fish-indent-on-char + hook window InsertChar \n -group fish-indent fish-indent-on-new-line + + hook -once -always window WinSetOption filetype=.* %{ remove-hooks window fish-.+ } +} + +hook -group fish-highlight global WinSetOption filetype=fish %{ + add-highlighter window/fish ref fish + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/fish } +} + + +provide-module fish %{ + # Highlighters # ‾‾‾‾‾‾‾‾‾‾‾‾ @@ -57,17 +77,4 @@ define-command -hidden fish-indent-on-new-line %{ } } -# 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-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 index 0c1f79f8..67c25a85 100644 --- a/rc/filetype/gas.kak +++ b/rc/filetype/gas.kak @@ -4,6 +4,21 @@ hook global BufCreate .*\.(s|S|asm)$ %{ set-option buffer filetype gas } +hook global WinSetOption filetype=gas %{ + require-module gas + + hook window InsertChar \n -group gas-indent gas-indent-on-new-line + hook -once -always window WinSetOption filetype=.* %{ remove-hooks window gas-.+ } +} + +hook -group gas-highlight global WinSetOption filetype=gas %{ + add-highlighter window/gas ref gas + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/gas } +} + + +provide-module gas %{ + add-highlighter shared/gas regions add-highlighter shared/gas/code default-region group add-highlighter shared/gas/string region '"' (? ~ -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 index 13d58f0a..3a39ab37 100644 --- a/rc/filetype/git.kak +++ b/rc/filetype/git.kak @@ -10,31 +10,44 @@ 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 } +hook global WinSetOption filetype=git-(commit|notes|rebase) %{ + require-module "git-%val{hook_param_capture_1}" +} + +hook -group git-commit-highlight global WinSetOption filetype=git-commit %{ + add-highlighter window/git-commit ref git-commit + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/git-commit } +} + +hook -group git-notes-highlight global WinSetOption filetype=git-notes %{ + add-highlighter window/git-notes ref git-notes + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/git-notes } +} + +hook -group git-rebase-highlight global WinSetOption filetype=git-rebase %{ + add-highlighter window/git-rebase ref git-rebase + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/git-rebase } +} + + +provide-module git-commit %{ +add-highlighter shared/git-commit regions +add-highlighter shared/git-commit/diff region '^diff --git' '^(?=diff --git)' ref diff # highlight potential diffs from the -v option +add-highlighter shared/git-commit/comments region '^\h*#' '$' group +add-highlighter shared/git-commit/comments/ fill comment +add-highlighter shared/git-commit/comments/ regex "\b(?:(modified)|(deleted)|(new file)|(renamed|copied)):([^\n]*)$" 1:yellow 2:red 3:green 4:blue 5:magenta +} + +provide-module git-notes %{ +add-highlighter shared/git-notes regex '^\h*#[^\n]*$' 0:comment +} + +provide-module git-rebase %{ +add-highlighter shared/git-rebase group +add-highlighter shared/git-rebase/ regex "#[^\n]*\n" 0:comment +add-highlighter shared/git-rebase/ regex "^(pick|edit|reword|squash|fixup|exec|break|drop|label|reset|merge|[persfxbdltm]) (\w+)" 1:keyword 2:meta } diff --git a/rc/filetype/go.kak b/rc/filetype/go.kak index 8aebe657..fccb563b 100644 --- a/rc/filetype/go.kak +++ b/rc/filetype/go.kak @@ -8,6 +8,30 @@ hook global BufCreate .*\.go %{ set-option buffer filetype go } +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook global WinSetOption filetype=go %{ + require-module go + + set-option window static_words %opt{go_static_words} + + # 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-.+ } +} + +hook -group go-highlight global WinSetOption filetype=go %{ + add-highlighter window/go ref go + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/go } +} + +provide-module go %§ + # Highlighters # ‾‾‾‾‾‾‾‾‾‾‾‾ @@ -23,26 +47,26 @@ add-highlighter shared/go/code/ regex %{-?([0-9]*\.(?!0[xX]))?\b([0-9]+|0[xX][0- evaluate-commands %sh{ # Grammar - keywords="break|default|func|interface|select|case|defer|go|map|struct" - keywords="${keywords}|chan|else|goto|package|switch|const|fallthrough|if|range|type" - keywords="${keywords}|continue|for|import|return|var" - types="bool|byte|chan|complex128|complex64|error|float32|float64|int|int16|int32" - types="${types}|int64|int8|interface|intptr|map|rune|string|struct|uint|uint16|uint32|uint64|uint8" - values="false|true|nil|iota" - functions="append|cap|close|complex|copy|delete|imag|len|make|new|panic|print|println|real|recover" + keywords='break default func interface select case defer go map struct + chan else goto package switch const fallthrough if range type + continue for import return var' + types='bool byte chan complex128 complex64 error float32 float64 int int16 int32 + int64 int8 interface intptr map rune string struct uint uint16 uint32 uint64 uint8' + values='false true nil iota' + functions='append cap close complex copy delete imag len make new panic print println real recover' + + 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=go %{ - set-option window static_words ${keywords} ${attributes} ${types} ${values} ${functions} - }" | tr '|' ' ' + printf %s\\n "declare-option str-list go_static_words $(join "${keywords} ${attributes} ${types} ${values} ${functions}" ' ')" # Highlight keywords printf %s " - add-highlighter shared/go/code/ regex \b(${keywords})\b 0:keyword - add-highlighter shared/go/code/ regex \b(${attributes})\b 0:attribute - add-highlighter shared/go/code/ regex \b(${types})\b 0:type - add-highlighter shared/go/code/ regex \b(${values})\b 0:value - add-highlighter shared/go/code/ regex \b(${functions})\b 0:builtin + add-highlighter shared/go/code/ regex \b($(join "${keywords}" '|'))\b 0:keyword + add-highlighter shared/go/code/ regex \b($(join "${attributes}" '|'))\b 0:attribute + add-highlighter shared/go/code/ regex \b($(join "${types}" '|'))\b 0:type + add-highlighter shared/go/code/ regex \b($(join "${values}" '|'))\b 0:value + add-highlighter shared/go/code/ regex \b($(join "${functions}" '|'))\b 0:builtin " } @@ -78,20 +102,4 @@ define-command -hidden go-indent-on-closing-curly-brace %[ 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 index e3e7f593..f13c8764 100644 --- a/rc/filetype/haml.kak +++ b/rc/filetype/haml.kak @@ -8,6 +8,29 @@ hook global BufCreate .*[.](haml) %{ set-option buffer filetype haml } +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook global WinSetOption filetype=haml %{ + require-module 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-.+ } +} + +hook -group haml-highlight global WinSetOption filetype=haml %{ + add-highlighter window/haml ref haml + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/haml } +} + + +provide-module haml %[ +require-module ruby +require-module coffee +require-module sass + # Highlighters # ‾‾‾‾‾‾‾‾‾‾‾‾ @@ -46,17 +69,4 @@ define-command -hidden haml-indent-on-new-line %{ } } -# 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 index c51bcaf4..88b3ed29 100644 --- a/rc/filetype/haskell.kak +++ b/rc/filetype/haskell.kak @@ -8,6 +8,27 @@ hook global BufCreate .*[.](hs) %{ set-option buffer filetype haskell } +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook global WinSetOption filetype=haskell %{ + require-module 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-.+ } +} + +hook -group haskell-highlight global WinSetOption filetype=haskell %{ + add-highlighter window/haskell ref haskell + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/haskell } +} + + +provide-module haskell %[ + # Highlighters # ‾‾‾‾‾‾‾‾‾‾‾‾ @@ -88,18 +109,4 @@ define-command -hidden haskell-indent-on-new-line %{ } } -# 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 index a0948e6f..2474baf3 100644 --- a/rc/filetype/hbs.kak +++ b/rc/filetype/hbs.kak @@ -8,6 +8,27 @@ hook global BufCreate .*[.](hbs) %{ set-option buffer filetype hbs } +hook global WinSetOption filetype=hbs %{ + require-module 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-.+ } +} + +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 } +} + + +provide-module hbs %[ + # Highlighters # ‾‾‾‾‾‾‾‾‾‾‾‾ @@ -80,18 +101,4 @@ define-command -hidden maybe-add-hbs-to-html %{ evaluate-commands %sh{ 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 index 5f76721d..57d1ee6e 100644 --- a/rc/filetype/html.kak +++ b/rc/filetype/html.kak @@ -12,6 +12,36 @@ hook global BufCreate .*\.xml %{ set-option buffer filetype xml } +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook global WinSetOption filetype=(html|xml) %{ + require-module html + + 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}-.+"" + " +} + +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}"" + " +} + + +provide-module html %[ + +try %{ + require-module css + require-module javascript +} + # Highlighters # ‾‾‾‾‾‾‾‾‾‾‾‾ @@ -54,22 +84,4 @@ define-command -hidden html-indent-on-new-line %{ 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 index e661fcd7..b46a2388 100644 --- a/rc/filetype/i3.kak +++ b/rc/filetype/i3.kak @@ -2,6 +2,28 @@ hook global BufCreate .*(sway|i3)/config %{ set buffer filetype i3 } +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook global WinSetOption filetype=i3 %[ + require-module 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-.+ } +] + +hook -group i3-highlight global WinSetOption filetype=i3 %{ + add-highlighter window/i3 ref i3 + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/i3 } +} + + +provide-module i3 %[ + add-highlighter shared/i3 regions add-highlighter shared/i3/code default-region group add-highlighter shared/i3/double_string region %{"} %{"} group @@ -63,19 +85,4 @@ define-command -hidden i3-indent-on-closing-curly-brace %[ 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 index c03cae4e..7e070176 100644 --- a/rc/filetype/ini.kak +++ b/rc/filetype/ini.kak @@ -2,6 +2,18 @@ hook global BufCreate .+\.(repo|ini|cfg|properties) %{ set-option buffer filetype ini } +hook global WinSetOption filetype=ini %{ + require-module ini +} + +hook -group ini-highlight global WinSetOption filetype=ini %{ + add-highlighter window/ini ref ini + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/ini } +} + + +provide-module ini %{ + add-highlighter shared/ini regions add-highlighter shared/ini/code default-region group add-highlighter shared/ini/comment region '(^|\h)\K[#;]' $ fill comment @@ -9,7 +21,4 @@ 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 index 7caa5aee..0fd2bec9 100644 --- a/rc/filetype/java.kak +++ b/rc/filetype/java.kak @@ -2,6 +2,29 @@ hook global BufCreate .*\.java %{ set-option buffer filetype java } +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook global WinSetOption filetype=java %{ + require-module 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-.+ } +} + +hook -group java-highlight global WinSetOption filetype=java %{ + add-highlighter window/java ref java + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/java } +} + + +provide-module java %§ + add-highlighter shared/java regions add-highlighter shared/java/code default-region group add-highlighter shared/java/string region %{(?^\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 index c02c6aab..6f60a4ec 100644 --- a/rc/filetype/javascript.kak +++ b/rc/filetype/javascript.kak @@ -9,6 +9,34 @@ hook global BufCreate .*[.](ts)x? %{ set-option buffer filetype typescript } +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook global WinSetOption filetype=(javascript|typescript) %{ + require-module javascript + + hook window ModeChange insert:.* -group "%val{hook_param_capture_1}-trim-indent" javascript-trim-indent + hook window InsertChar .* -group "%val{hook_param_capture_1}-indent" javascript-indent-on-char + hook window InsertChar \n -group "%val{hook_param_capture_1}-indent" javascript-indent-on-new-line + + hook -once -always window WinSetOption filetype=.* " + remove-hooks window %val{hook_param_capture_1}-.+ + " +} + +hook -group javascript-highlight global WinSetOption filetype=javascript %{ + add-highlighter window/javascript ref javascript + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/javascript } +} + +hook -group typescript-highlight global WinSetOption filetype=typescript %{ + add-highlighter window/typescript ref typescript + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/typescript } +} + + +provide-module javascript %§ + # Commands # ‾‾‾‾‾‾‾‾ @@ -89,23 +117,6 @@ define-command -hidden init-javascript-filetype -params 1 %~ # https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get # https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/set 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|get|if|import|in|instanceof|let|new|of|return|set|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 @@ -117,3 +128,5 @@ add-highlighter shared/typescript/code/ regex \b(array|boolean|date|number|objec # 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 index ae04c55a..094c3652 100644 --- a/rc/filetype/json.kak +++ b/rc/filetype/json.kak @@ -8,6 +8,27 @@ hook global BufCreate .*[.](json) %{ set-option buffer filetype json } +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook global WinSetOption filetype=json %{ + require-module 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-.+ } +} + +hook -group json-highlight global WinSetOption filetype=json %{ + add-highlighter window/json ref json + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/json } +} + + +provide-module json %( + # Highlighters # ‾‾‾‾‾‾‾‾‾‾‾‾ @@ -43,18 +64,4 @@ define-command -hidden json-indent-on-new-line %< > > -# 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 index abdf547a..10edb743 100644 --- a/rc/filetype/julia.kak +++ b/rc/filetype/julia.kak @@ -8,6 +8,21 @@ hook global BufCreate .*\.(jl) %{ set-option buffer filetype julia } +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook global WinSetOption filetype=julia %{ + require-module julia +} + +hook -group julia-highlight global WinSetOption filetype=julia %{ + add-highlighter window/julia ref julia + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/julia } +} + + +provide-module julia %{ + # Highlighters # ‾‾‾‾‾‾‾‾‾‾‾‾ @@ -21,10 +36,4 @@ add-highlighter shared/julia/code/ regex %{\b(true|false|C_NULL|Inf|NaN|Inf32|Na add-highlighter shared/julia/code/ regex \b(if|else|elseif|while|for|begin|end|quote|try|catch|return|local|abstract|function|macro|ccall|finally|typealias|break|continue|type|global|module|using|import|export|const|let|bitstype|do|in|baremodule|importall|immutable)\b 0:keyword add-highlighter shared/julia/code/ regex \b(Number|Real|BigInt|Integer|UInt|UInt8|UInt16|UInt32|UInt64|UInt128|Int|Int8|Int16|Int32|Int64|Int128|BigFloat|FloatingPoint|Float16|Float32|Float64|Complex128|Complex64|Bool|Cuchar|Cshort|Cushort|Cint|Cuint|Clonglong|Culonglong|Cintmax_t|Cuintmax_t|Cfloat|Cdouble|Cptrdiff_t|Cssize_t|Csize_t|Cchar|Clong|Culong|Cwchar_t|Char|ASCIIString|UTF8String|ByteString|SubString|AbstractString|Array|DArray|AbstractArray|AbstractVector|AbstractMatrix|AbstractSparseMatrix|SubArray|StridedArray|StridedVector|StridedMatrix|VecOrMat|StridedVecOrMat|DenseArray|SparseMatrixCSC|BitArray|Range|OrdinalRange|StepRange|UnitRange|FloatRange|Tuple|NTuple|Vararg|DataType|Symbol|Function|Vector|Matrix|Union|Type|Any|Complex|String|Ptr|Void|Exception|Task|Signed|Unsigned|Associative|Dict|IO|IOStream|Rational|Regex|RegexMatch|Set|IntSet|Expr|WeakRef|ObjectIdDict|AbstractRNG|MersenneTwister)\b 0:type -# Initialization -# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ - -hook -group julia-highlight global WinSetOption filetype=julia %{ - add-highlighter window/julia ref julia - hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/julia } } diff --git a/rc/filetype/just.kak b/rc/filetype/just.kak index 201bfc3d..f81f0b58 100644 --- a/rc/filetype/just.kak +++ b/rc/filetype/just.kak @@ -5,6 +5,21 @@ hook global BufCreate .*/?[jJ]ustfile %{ set-option buffer filetype justfile } +hook global WinSetOption filetype=justfile %{ + require-module justfile + + hook window InsertChar \n -group justfile-indent just-indent-on-new-line + hook -once -always window WinSetOption filetype=.* %{ remove-hooks window justfile-.+ } +} + +hook -group justfile-highlight global WinSetOption filetype=justfile %{ + add-highlighter window/justfile ref justfile + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/justfile } +} + + +provide-module justfile %{ + # Indentation # ‾‾‾‾‾‾‾‾‾‾‾ @@ -37,12 +52,4 @@ add-highlighter shared/justfile/content/ regex '^(@)?([\w-]+)(?:\s(.+))?\s?(:)(. add-highlighter shared/justfile/content/ regex '([=+])' 1:operator add-highlighter shared/justfile/content/ regex '^([\w-]+)\s=' 1:value -hook -group justfile-highlight global WinSetOption filetype=justfile %{ - add-highlighter window/justfile ref justfile - hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/justfile } -} - -hook global WinSetOption filetype=justfile %{ - hook window InsertChar \n -group justfile-indent just-indent-on-new-line - hook -once -always window WinSetOption filetype=.* %{ remove-hooks window justfile-.+ } } diff --git a/rc/filetype/kakrc.kak b/rc/filetype/kakrc.kak index 07deda7d..4e473fcc 100644 --- a/rc/filetype/kakrc.kak +++ b/rc/filetype/kakrc.kak @@ -8,6 +8,33 @@ hook global BufCreate (.*/)?(kakrc|.*\.kak) %{ set-option buffer filetype kak } +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook global WinSetOption filetype=kak %~ + require-module kak + + set-option window static_words %opt{kak_static_words} + + 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-.+ } +~ + +hook -group kak-highlight global WinSetOption filetype=kak %{ + add-highlighter window/kakrc ref kakrc + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/kakrc } +} + +provide-module kak %§ + +require-module sh + # Highlighters & Completion # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ @@ -33,7 +60,7 @@ evaluate-commands %sh{ 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!" + edit! write! kill! quit! write-quit! delete-buffer! provide-module require-module" 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 @@ -44,10 +71,7 @@ evaluate-commands %sh{ 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 '_' '-' - }" + printf %s\\n "declare-option str-list kak_static_words $(join "${keywords} ${attributes} ${types} ${values}" ' ')'" # 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 @@ -90,21 +114,4 @@ define-command -hidden kak-indent-on-closing-char %{ 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 index 6f30b4b8..0e7441b1 100644 --- a/rc/filetype/kickstart.kak +++ b/rc/filetype/kickstart.kak @@ -2,6 +2,18 @@ hook global BufCreate .*\.ks %{ set-option buffer filetype kickstart } +hook global WinSetOption filetype=kickstart %{ + require-module kickstart +} + +hook -group kickstart-highlight global WinSetOption filetype=kickstart %{ + add-highlighter window/kickstart ref kickstart + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/kickstart } +} + + +provide-module kickstart %{ + add-highlighter shared/kickstart regions add-highlighter shared/kickstart/code default-region group add-highlighter shared/kickstart/comment region '(^|\h)\K#' $ fill comment @@ -23,8 +35,4 @@ add-highlighter shared/kickstart/shell/ regex '\A\h*\K%(pre-install|pre|post)\b' add-highlighter shared/kickstart/shell/ regex '^\h*%end\b' 0:type add-highlighter shared/kickstart/shell/ ref sh - -hook -group kickstart-highlight global WinSetOption filetype=kickstart %{ - add-highlighter window/kickstart ref kickstart - hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/kickstart } } diff --git a/rc/filetype/latex.kak b/rc/filetype/latex.kak index acb5c1fc..ebdeb97c 100644 --- a/rc/filetype/latex.kak +++ b/rc/filetype/latex.kak @@ -8,6 +8,20 @@ hook global BufCreate .*\.tex %{ set-option buffer filetype latex } +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook global WinSetOption filetype=latex %{ + require-module latex +} + +hook -group latex-highlight global WinSetOption filetype=latex %{ + add-highlighter window/latex ref latex + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/latex } +} + +provide-module latex %( + # Highlighters # ‾‾‾‾‾‾‾‾‾‾‾‾ @@ -26,10 +40,4 @@ add-highlighter shared/latex/content/ regex '\\(emph|textit)\{([^}]+)\}' 2:defau # Bold text add-highlighter shared/latex/content/ regex '\\textbf\{([^}]+)\}' 1:default+b -# Initialization -# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ - -hook -group latex-highlight global WinSetOption filetype=latex %{ - add-highlighter window/latex ref latex - hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/latex } -} +) diff --git a/rc/filetype/lisp.kak b/rc/filetype/lisp.kak index 378bb3c5..1efed1eb 100644 --- a/rc/filetype/lisp.kak +++ b/rc/filetype/lisp.kak @@ -8,6 +8,25 @@ hook global BufCreate .*[.](lisp) %{ set-option buffer filetype lisp } +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook global WinSetOption filetype=lisp %{ + require-module 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-.+ } +} + +hook -group lisp-highlight global WinSetOption filetype=lisp %{ + add-highlighter window/lisp ref lisp + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/lisp } +} + +provide-module lisp %{ + # Highlighters # ‾‾‾‾‾‾‾‾‾‾‾‾ @@ -58,17 +77,4 @@ define-command -hidden lisp-indent-on-new-line %{ } } -# 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 index 605148e0..ed97cbb8 100644 --- a/rc/filetype/lua.kak +++ b/rc/filetype/lua.kak @@ -8,6 +8,32 @@ hook global BufCreate .*[.](lua) %{ set-option buffer filetype lua } +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook global WinSetOption filetype=lua %{ + require-module 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 + } +} + +hook -group lua-highlight global WinSetOption filetype=lua %{ + add-highlighter window/lua ref lua + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/lua } +} + + +provide-module lua %[ + # Highlighters # ‾‾‾‾‾‾‾‾‾‾‾‾ @@ -81,23 +107,4 @@ define-command -hidden lua-insert-on-new-line %[ ] ] -# 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 index 4323d28c..95b7d88a 100644 --- a/rc/filetype/mail.kak +++ b/rc/filetype/mail.kak @@ -2,12 +2,21 @@ hook global BufCreate .+\.eml %{ set-option buffer filetype mail } +hook global WinSetOption filetype=mail %{ + require-module mail +} + +hook -group mail-highlight global WinSetOption filetype=mail %{ + add-highlighter window/mail ref mail + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/mail } +} + + +provide-module 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 index 569d51f9..7f7ebbe5 100644 --- a/rc/filetype/makefile.kak +++ b/rc/filetype/makefile.kak @@ -5,6 +5,25 @@ hook global BufCreate .*(/?[mM]akefile|\.mk) %{ set-option buffer filetype makefile } +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook global WinSetOption filetype=makefile %{ + require-module makefile + + set-option window static_words %opt{makefile_static_words} + + hook window InsertChar \n -group makefile-indent makefile-indent-on-new-line + hook -once -always window WinSetOption filetype=.* %{ remove-hooks window makefile-.+ } +} + +hook -group makefile-highlight global WinSetOption filetype=makefile %{ + add-highlighter window/makefile ref makefile + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/makefile } +} + +provide-module makefile %{ + # Highlighters # ‾‾‾‾‾‾‾‾‾‾‾‾ @@ -22,9 +41,7 @@ evaluate-commands %sh{ 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 '|' ' ' + printf %s\\n "declare-option str-list makefile_static_words ${keywords}" | tr '|' ' ' # Highlight keywords printf %s "add-highlighter shared/makefile/content/ regex \b(${keywords})\b 0:keyword" @@ -46,15 +63,4 @@ define-command -hidden makefile-indent-on-new-line %{ } } -# 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 index 18f3ccf6..ab380b7f 100644 --- a/rc/filetype/markdown.kak +++ b/rc/filetype/markdown.kak @@ -8,6 +8,24 @@ hook global BufCreate .*[.](markdown|md|mkd) %{ set-option buffer filetype markdown } +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook global WinSetOption filetype=markdown %{ + require-module markdown + + hook window InsertChar \n -group markdown-indent markdown-indent-on-new-line + hook -once -always window WinSetOption filetype=.* %{ remove-hooks window markdown-.+ } +} + +hook -group markdown-highlight global WinSetOption filetype=markdown %{ + add-highlighter window/markdown ref markdown + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/markdown } +} + + +provide-module markdown %{ + # Highlighters # ‾‾‾‾‾‾‾‾‾‾‾‾ @@ -71,15 +89,4 @@ define-command -hidden markdown-indent-on-new-line %{ } } -# 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 index 3f84eea2..f21cd202 100644 --- a/rc/filetype/mercurial.kak +++ b/rc/filetype/mercurial.kak @@ -8,11 +8,26 @@ hook global BufCreate .*hg-editor-\w+\.txt$ %{ set-option buffer filetype hg-commit } +hook global WinSetOption filetype=hg-commit %{ + require-module hg-commit +} + +hook -group hg-commit-highlight global WinSetOption filetype=hg-commit %{ + add-highlighter window/hg-commit ref hg-commit + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/hg-commit-highlight } +} + +provide-module hg-commit %{ + +# Faces +# ‾‾‾‾‾ + +set-face global MercurialCommitComment cyan + # 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 } +add-highlighter shared/hg-commit group +add-highlighter shared/hg-commit/ regex '^HG:[^\n]*' 0:comment + } diff --git a/rc/filetype/moon.kak b/rc/filetype/moon.kak index a1d2ecb8..1ff48f38 100644 --- a/rc/filetype/moon.kak +++ b/rc/filetype/moon.kak @@ -8,6 +8,32 @@ hook global BufCreate .*[.](moon) %{ set-option buffer filetype moon } +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook global WinSetOption filetype=moon %{ + require-module 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 + } +} + +hook -group moon-highlight global WinSetOption filetype=moon %{ + add-highlighter window/moon ref moon + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/moon } +} + + +provide-module moon %[ + # Highlighters # ‾‾‾‾‾‾‾‾‾‾‾‾ @@ -85,23 +111,4 @@ define-command -hidden moon-indent-on-new-line %{ } } -# 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 index 901ce68a..1b9283cb 100644 --- a/rc/filetype/nim.kak +++ b/rc/filetype/nim.kak @@ -8,6 +8,28 @@ hook global BufCreate .*\.nim(s|ble)? %{ set-option buffer filetype nim } +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook global WinSetOption filetype=nim %{ + require-module nim + + set-option window static_words %opt{nim_static_words} + + 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-.+ } +} + +hook -group nim-highlight global WinSetOption filetype=nim %{ + add-highlighter window/nim ref nim + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/nim } +} + +provide-module nim %{ + # Highlighters # ‾‾‾‾‾‾‾‾‾‾‾‾ @@ -51,9 +73,7 @@ evaluate-commands %sh{ 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} - }" + printf %s\\n "declare-option str-list nim_static_words ${static_words}" keywords="$(join "${keywords}" '|')" operators="$(join "${operators}" '|')" @@ -95,18 +115,4 @@ def -hidden nim-indent-on-new-line %{ } } -# 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 index 0a3d49bf..33a4dbd4 100644 --- a/rc/filetype/ocaml.kak +++ b/rc/filetype/ocaml.kak @@ -5,9 +5,24 @@ # ‾‾‾‾‾‾‾‾‾ hook global BufCreate .*\.mli? %{ - set-option buffer filetype ocaml + set-option buffer filetype ocaml } +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook global WinSetOption filetype=ocaml %{ + require-module ocaml + set-option window static_words %opt{ocaml_static_words} +} + +hook -group ocaml-highlight global WinSetOption filetype=ocaml %{ + add-highlighter window/ocaml ref ocaml + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/ocaml } +} + +provide-module ocaml %{ + # Highlighters # ‾‾‾‾‾‾‾‾‾‾‾‾ @@ -16,23 +31,20 @@ add-highlighter shared/ocaml/code default-region group add-highlighter shared/ocaml/string region '"' (?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-.+ } +} + +hook -group perl-highlight global WinSetOption filetype=perl %{ + add-highlighter window/perl ref perl + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/perl } +} + +provide-module perl %§ + # Highlighters # ‾‾‾‾‾‾‾‾‾‾‾‾ @@ -20,31 +44,31 @@ add-highlighter shared/perl/comment region (?^\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 index 4acfde85..8ee1d8ce 100644 --- a/rc/filetype/php.kak +++ b/rc/filetype/php.kak @@ -5,6 +5,27 @@ hook global BufCreate .*[.](php) %{ set-option buffer filetype php } +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook global WinSetOption filetype=php %{ + require-module 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-.+ } +} + +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 } +} + +provide-module php %( +require-module html + # Highlighters # ‾‾‾‾‾‾‾‾‾‾‾‾ @@ -73,18 +94,4 @@ define-command -hidden php-indent-on-new-line %< > > -# 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 index 713cc295..762f7c1a 100644 --- a/rc/filetype/pony.kak +++ b/rc/filetype/pony.kak @@ -8,6 +8,28 @@ hook global BufCreate .*[.](pony) %{ set-option buffer filetype pony } +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook global WinSetOption filetype=pony %{ + require-module pony + + set-option window static_words %opt{pony_static_words} + + 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-.+ } +} + +hook -group pony-highlight global WinSetOption filetype=pony %{ + add-highlighter window/pony ref pony + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter pony } +} + +provide-module pony %{ + # Highlighters & Completion # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ @@ -33,9 +55,7 @@ evaluate-commands %sh{ # Add the language's grammar to the static completion list static_words="${values} ${meta} ${keywords} ${types_decl} ${capabilities}" static_words="${static_words} ${struct}" - printf %s\\n "hook global WinSetOption filetype=pony %{ - set-option window static_words ${static_words} - }" | tr '|' ' ' + printf %s\\n "declare-option str-list pony_static_words ${static_words}" | tr '|' ' ' # Highlight keywords printf %s " @@ -75,18 +95,4 @@ define-command -hidden pony-indent-on-new-line %{ } } -# 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 index 2ef10480..4e568704 100644 --- a/rc/filetype/protobuf.kak +++ b/rc/filetype/protobuf.kak @@ -7,6 +7,28 @@ hook global BufCreate .*\.proto$ %{ set-option buffer filetype protobuf } +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook global WinSetOption filetype=protobuf %[ + require-module protobuf + + set-option window static_words %opt{protobuf_static_words} + + 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-.+ } +] + +hook -group protobuf-highlight global WinSetOption filetype=protobuf %{ + add-highlighter window/protobuf ref protobuf + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/protobuf } +} + +provide-module protobuf %[ + # Highlighters # ‾‾‾‾‾‾‾‾‾‾‾‾ @@ -20,31 +42,30 @@ add-highlighter shared/protobuf/code/ regex %{(0x)?[0-9]+\b} 0:value evaluate-commands %sh{ # Grammer - keywords="default|deprecated|enum|extend|import|message|oneof|option" - keywords="${keywords}|package|service|syntax" - attributes="optional|repeated|required" - types="double|float|int32|int64|uint32|uint64|sint32|sint64|fixed32|fixed64" - types="${types}|sfixed32|sfixed64|bool|string|bytes|rpc" - values="false|true" + keywords='default deprecated enum extend import message oneof option + package service syntax' + attributes='optional repeated required' + types='double float int32 int64 uint32 uint64 sint32 sint64 fixed32 fixed64 + sfixed32 sfixed64 bool string bytes rpc' + values='false true' + + join() { sep=$2; eval set -- $1; IFS="$sep"; echo "$*"; } # Add the language's grammer to the static completion list - printf '%s\n' "hook global WinSetOption filetype=protobuf %{ - set-option window static_words ${keywords} ${attributes} ${types} ${values} - }" | tr '|' ' ' + printf %s\\n "declare-option str-list protobuf_static_words $(join "${keywords} ${attributes} ${types} ${values}" ' ')" # Highlight keywords printf %s " - add-highlighter shared/protobuf/code/keywords regex \b(${keywords})\b 0:keyword - add-highlighter shared/protobuf/code/attributes regex \b(${attributes})\b 0:attribute - add-highlighter shared/protobuf/code/types regex \b(${types})\b 0:type - add-highlighter shared/protobuf/code/values regex \b(${values})\b 0:value + add-highlighter shared/protobuf/code/keywords regex \b($(join "${keywords}" '|'))\b 0:keyword + add-highlighter shared/protobuf/code/attributes regex \b($(join "${attributes}" '|'))\b 0:attribute + add-highlighter shared/protobuf/code/types regex \b($(join "${types}" '|'))\b 0:type + add-highlighter shared/protobuf/code/values regex \b($(join "${values}" '|'))\b 0:value " } # Commands # ‾‾‾‾‾‾‾‾ - define-command -hidden protobuf-indent-on-newline %~ evaluate-commands -draft -itersel %[ # preserve previous line indent @@ -68,18 +89,4 @@ define-command -hidden protobuf-indent-on-closing-curly-brace %[ 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 index 13aa839f..c4a30511 100644 --- a/rc/filetype/pug.kak +++ b/rc/filetype/pug.kak @@ -12,6 +12,26 @@ hook global BufCreate .*[.](pug|jade) %{ set-option buffer filetype pug } +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook global WinSetOption filetype=pug %{ + require-module 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-.+ } +} + +hook -group pug-highlight global WinSetOption filetype=pug %{ + add-highlighter window/pug ref pug + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/pug } +} + + +provide-module pug %{ + # Highlighters # ‾‾‾‾‾‾‾‾‾‾‾‾ @@ -58,17 +78,4 @@ define-command -hidden pug-indent-on-new-line %{ } } -# 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 index 9084dd1c..7c4472a3 100644 --- a/rc/filetype/python.kak +++ b/rc/filetype/python.kak @@ -8,6 +8,27 @@ hook global BufCreate .*[.](py) %{ set-option buffer filetype python } +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook global WinSetOption filetype=python %{ + require-module python + + set-option window static_words %opt{python_static_words} + + 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-.+ } +} + +hook -group python-highlight global WinSetOption filetype=python %{ + add-highlighter window/python ref python + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/python } +} + +provide-module python %{ + # Highlighters & Completion # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ @@ -36,79 +57,79 @@ add-highlighter shared/python/docstring/ region '\.\.\. \K' '\z' ref python evaluate-commands %sh{ # Grammar - values="True|False|None|self|inf" - meta="import|from" + 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__" + attributes="__annotations__ __closure__ __code__ __defaults__ __dict__ __doc__ + __globals__ __kwdefaults__ __module__ __name__ __qualname__" + methods="__abs__ __add__ __aenter__ __aexit__ __aiter__ __and__ __anext__ + __await__ __bool__ __bytes__ __call__ __complex__ __contains__ + __del__ __delattr__ __delete__ __delitem__ __dir__ __divmod__ + __enter__ __eq__ __exit__ __float__ __floordiv__ __format__ + __ge__ __get__ __getattr__ __getattribute__ __getitem__ + __gt__ __hash__ __iadd__ __iand__ __ifloordiv__ __ilshift__ + __imatmul__ __imod__ __imul__ __index__ __init__ + __init_subclass__ __int__ __invert__ __ior__ __ipow__ + __irshift__ __isub__ __iter__ __itruediv__ __ixor__ __le__ + __len__ __length_hint__ __lshift__ __lt__ __matmul__ + __missing__ __mod__ __mul__ __ne__ __neg__ __new__ __or__ + __pos__ __pow__ __radd__ __rand__ __rdivmod__ __repr__ + __reversed__ __rfloordiv__ __rlshift__ __rmatmul__ __rmod__ + __rmul__ __ror__ __round__ __rpow__ __rrshift__ __rshift__ + __rsub__ __rtruediv__ __rxor__ __set__ __setattr__ + __setitem__ __set_name__ __slots__ __str__ __sub__ + __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" + exceptions="ArithmeticError AssertionError AttributeError BaseException BlockingIOError + BrokenPipeError BufferError BytesWarning ChildProcessError + ConnectionAbortedError ConnectionError ConnectionRefusedError + ConnectionResetError DeprecationWarning EOFError Exception + FileExistsError FileNotFoundError FloatingPointError FutureWarning + GeneratorExit ImportError ImportWarning IndentationError + IndexError InterruptedError IsADirectoryError KeyboardInterrupt + KeyError LookupError MemoryError ModuleNotFoundError NameError + NotADirectoryError NotImplementedError OSError OverflowError + PendingDeprecationWarning PermissionError ProcessLookupError + RecursionError ReferenceError ResourceWarning RuntimeError + RuntimeWarning StopAsyncIteration StopIteration SyntaxError + SyntaxWarning SystemError SystemExit TabError TimeoutError TypeError + UnboundLocalError UnicodeDecodeError UnicodeEncodeError UnicodeError + UnicodeTranslateError UnicodeWarning UserWarning ValueError Warning + 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" + keywords="and as assert async await break class continue def del elif else except exec + finally for global if in is lambda nonlocal not or pass print + 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" + types="bool buffer bytearray bytes complex dict file float frozenset int + list long memoryview object set str tuple unicode xrange" - functions="abs|all|any|ascii|bin|breakpoint|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" + functions="abs all any ascii bin breakpoint callable chr classmethod compile complex + delattr dict dir divmod enumerate eval exec filter + format frozenset getattr globals hasattr hash help + hex id __import__ input isinstance issubclass iter + len locals map max memoryview min next oct open ord + pow print property range repr reversed round + setattr slice sorted staticmethod sum super type vars zip" + + 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=python %{ - set-option window static_words ${values} ${meta} ${attributes} ${methods} ${exceptions} ${keywords} ${types} ${functions} - }" | tr '|' ' ' + printf %s\\n "declare-option str-list python_static_words $(join "${values} ${meta} ${attributes} ${methods} ${exceptions} ${keywords} ${types} ${functions}" ' ')" # 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 '\b($(join "${values}" '|'))\b' 0:value + add-highlighter shared/python/code/ regex '\b($(join "${meta}" '|'))\b' 0:meta + add-highlighter shared/python/code/ regex '\b($(join "${attribute}" '|'))\b' 0:attribute + add-highlighter shared/python/code/ regex '\bdef\s+($(join "${methods}" '|'))\b' 1:function + add-highlighter shared/python/code/ regex '\b($(join "${exceptions}" '|'))\b' 0:function + add-highlighter shared/python/code/ regex '\b($(join "${keywords}" '|'))\b' 0:keyword + add-highlighter shared/python/code/ regex '\b($(join "${functions}" '|'))\b\(' 1:builtin + add-highlighter shared/python/code/ regex '\b($(join "${types}" '|'))\b' 0:type add-highlighter shared/python/code/ regex '@[\w_]+\b' 0:attribute " } @@ -132,17 +153,4 @@ define-command -hidden python-indent-on-new-line %{ } } -# 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 index b6e8dd4c..8f3d448f 100644 --- a/rc/filetype/ragel.kak +++ b/rc/filetype/ragel.kak @@ -10,6 +10,26 @@ hook global BufCreate .*[.](ragel|rl) %{ set-option buffer filetype ragel } +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook global WinSetOption filetype=ragel %{ + require-module 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-.+ } +} + +hook -group ragel-highlight global WinSetOption filetype=ragel %{ + add-highlighter window/ragel ref ragel + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/ragel } +} + +provide-module ragel %§ + # Highlighters # ‾‾‾‾‾‾‾‾‾‾‾‾ @@ -53,18 +73,4 @@ define-command -hidden ragel-indent-on-new-line %< > > -# 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 index 1eaf4bfc..29fc32a9 100644 --- a/rc/filetype/restructuredtext.kak +++ b/rc/filetype/restructuredtext.kak @@ -5,6 +5,20 @@ hook global BufCreate .*[.](rst) %{ set-option buffer filetype restructuredtext } +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook global WinSetOption filetype=restructuredtext %{ + require-module restructuredtext +} + +hook -group restructuredtext-highlight global WinSetOption filetype=restructuredtext %{ + add-highlighter window/restructuredtext ref restructuredtext + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/restructuredtext } +} + +provide-module restructuredtext %{ + # Highlighters # ‾‾‾‾‾‾‾‾‾‾‾‾ @@ -65,10 +79,4 @@ add-highlighter shared/restructuredtext/content/ regex [^*](\*\*([^\s*]|([^\s*][ 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 index 3e5cfcfa..7996b089 100644 --- a/rc/filetype/ruby.kak +++ b/rc/filetype/ruby.kak @@ -8,6 +8,33 @@ hook global BufCreate .*(([.](rb))|(irbrc)|(pryrc)|(Brewfile)|(Capfile|[.]cap)|( set-option buffer filetype ruby } +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook global WinSetOption filetype=ruby %{ + require-module ruby + + set-option window static_words %opt{ruby_static_words} + + 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 + } +} + +hook -group ruby-highlight global WinSetOption filetype=ruby %{ + add-highlighter window/ruby ref ruby + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/ruby } +} + +provide-module ruby %[ + # Highlighters # ‾‾‾‾‾‾‾‾‾‾‾‾ @@ -55,9 +82,7 @@ evaluate-commands %sh{ 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 '|' ' ' + printf %s\\n "declare-option str-list ruby_static_words ${keywords} ${attributes} ${values} ${meta}" | tr '|' ' ' # Highlight keywords printf %s " @@ -146,23 +171,4 @@ define-command -hidden ruby-insert-on-new-line %[ ] ] -# 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 index 28cb98c3..e83caf4f 100644 --- a/rc/filetype/rust.kak +++ b/rc/filetype/rust.kak @@ -8,6 +8,34 @@ hook global BufCreate .*[.](rust|rs) %{ set-option buffer filetype rust } +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook global WinSetOption filetype=rust %[ + require-module 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 + hook -once -always window WinSetOption filetype=.* %{ remove-hooks window rust-.+ } +] + +hook -group rust-highlight global WinSetOption filetype=rust %{ + add-highlighter window/rust ref rust + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/rust } +} + +# Configuration +# ‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook global WinSetOption filetype=rust %[ + set window formatcmd 'rustfmt' +] + + +provide-module rust %§ + # Highlighters # ‾‾‾‾‾‾‾‾‾‾‾‾ @@ -71,25 +99,4 @@ define-command -hidden rust-indent-on-closing %[ _ ] -# 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 - hook -once -always window WinSetOption filetype=.* %{ remove-hooks window rust-.+ } -] - -# Configuration -# ‾‾‾‾‾‾‾‾‾‾‾‾‾ - -hook global WinSetOption filetype=rust %[ - set window formatcmd 'rustfmt' -] +§ diff --git a/rc/filetype/sass.kak b/rc/filetype/sass.kak index d23a7b81..c5872253 100644 --- a/rc/filetype/sass.kak +++ b/rc/filetype/sass.kak @@ -8,6 +8,27 @@ hook global BufCreate .*[.](sass) %{ set-option buffer filetype sass } +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook global WinSetOption filetype=sass %{ + require-module 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-.+ } +} + +hook -group sass-highlight global WinSetOption filetype=sass %{ + add-highlighter window/sass ref sass + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/sass } +} + + +provide-module sass %{ + # Highlighters # ‾‾‾‾‾‾‾‾‾‾‾‾ @@ -45,18 +66,4 @@ define-command -hidden sass-indent-on-new-line %{ } } -# 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 index 1e62e2ad..73f086b5 100644 --- a/rc/filetype/scala.kak +++ b/rc/filetype/scala.kak @@ -8,6 +8,27 @@ hook global BufCreate .*[.](scala) %{ set-option buffer filetype scala } +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook global WinSetOption filetype=scala %[ + require-module 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-.+ } +] + +hook -group scala-highlight global WinSetOption filetype=scala %{ + add-highlighter window/scala ref scala + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/scala } +} + + +provide-module scala %[ + # Highlighters # ‾‾‾‾‾‾‾‾‾‾‾‾ @@ -58,18 +79,4 @@ define-command -hidden scala-indent-on-closing-curly-brace %[ ] ] -# 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 index ec86638b..b130127b 100644 --- a/rc/filetype/scheme.kak +++ b/rc/filetype/scheme.kak @@ -1,8 +1,6 @@ # http://www.scheme-reports.org # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ -# require lisp.kak - # Detection # ‾‾‾‾‾‾‾‾‾ @@ -10,6 +8,30 @@ hook global BufCreate (.*/)?(.*\.(scm|ss|sld)) %{ set-option buffer filetype scheme } +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook global WinSetOption filetype=scheme %{ + require-module scheme + + set-option window static_words %opt{scheme_static_words} + + 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-.+ } +} + +hook -group scheme-highlight global WinSetOption filetype=scheme %{ + add-highlighter window/scheme ref scheme + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/scheme } +} + +provide-module scheme %{ + +require-module lisp + # Highlighters # ‾‾‾‾‾‾‾‾‾‾‾‾ @@ -99,9 +121,9 @@ evaluate-commands %sh{ exec awk -f - <<'EOF' } 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") + printf("declare-option str-list scheme_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"); @@ -115,19 +137,4 @@ evaluate-commands %sh{ exec awk -f - <<'EOF' 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 index bb720db5..7cb15e52 100644 --- a/rc/filetype/scss.kak +++ b/rc/filetype/scss.kak @@ -1,8 +1,6 @@ # http://sass-lang.com # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ -# require css.kak - # Detection # ‾‾‾‾‾‾‾‾‾ @@ -10,6 +8,30 @@ hook global BufCreate .*[.](scss) %{ set-option buffer filetype scss } +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook global WinSetOption filetype=scss %[ + require-module 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-.+ } +] + +hook -group scss-highlight global WinSetOption filetype=scss %{ + add-highlighter window/scss ref scss + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/scss } +} + + +provide-module scss %[ + +require-module css + # Highlighters # ‾‾‾‾‾‾‾‾‾‾‾‾ @@ -27,19 +49,4 @@ 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 index acd62993..ae09183f 100644 --- a/rc/filetype/sh.kak +++ b/rc/filetype/sh.kak @@ -2,6 +2,18 @@ hook global BufCreate .*\.(z|ba|c|k|mk)?sh(rc|_profile)? %{ set-option buffer filetype sh } +hook global WinSetOption filetype=sh %{ + require-module sh + set-option window static_words %opt{sh_static_words} +} + +hook -group sh-highlight global WinSetOption filetype=sh %{ + add-highlighter window/sh ref sh + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/sh } +} + +provide-module sh %[ + add-highlighter shared/sh regions add-highlighter shared/sh/code default-region group add-highlighter shared/sh/double_string region %{(?|<|>=|<=|<>|\+=|-= 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 index 1526cadb..e1f6d9af 100644 --- a/rc/filetype/swift.kak +++ b/rc/filetype/swift.kak @@ -2,6 +2,18 @@ hook global BufCreate .*\.(swift) %{ set-option buffer filetype swift } +hook global WinSetOption filetype=swift %{ + require-module swift +} + +hook -group swift-highlight global WinSetOption filetype=swift %{ + add-highlighter window/swift ref swift + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/swift } +} + + +provide-module swift %{ + add-highlighter shared/swift regions add-highlighter shared/swift/code default-region group add-highlighter shared/swift/string region %{(? /dev/null 2>&1; then @@ -180,3 +186,5 @@ define-command go-share-selection -docstring "Share the selection using the Go P 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/python/jedi.kak b/rc/tools/python/jedi.kak index f86a20f2..5f28ba64 100644 --- a/rc/tools/python/jedi.kak +++ b/rc/tools/python/jedi.kak @@ -1,3 +1,9 @@ +hook -once global BufSetOption filetype=python %{ + require-module jedi +} + +provide-module jedi %{ + 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" \ @@ -17,7 +23,7 @@ define-command jedi-complete -docstring "Complete the current selection" %{ cd $(dirname ${kak_buffile}) header="${kak_cursor_line}.${kak_cursor_column}@${kak_timestamp}" - export PYTHONPATH="$kak_opt_jedi_python_path:$PYTHONPATH" + 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') @@ -45,3 +51,5 @@ define-command jedi-disable-autocomplete -docstring "Disable jedi completion" %{ remove-hooks window jedi-autocomplete unalias window complete jedi-complete } + +} diff --git a/rc/tools/rust/racer.kak b/rc/tools/rust/racer.kak index 28890431..e3a61c29 100644 --- a/rc/tools/rust/racer.kak +++ b/rc/tools/rust/racer.kak @@ -1,3 +1,9 @@ +hook -once global BufSetOption filetype=rust %{ + require-module racer +} + +provide-module racer %{ + declare-option -hidden str racer_tmp_dir declare-option -hidden completions racer_completions @@ -152,3 +158,5 @@ define-command racer-show-doc -docstring "Show the documentation about the rust fi } } + +} diff --git a/rc/windowing/iterm.kak b/rc/windowing/iterm.kak index 7518d2d0..c48aebc8 100644 --- a/rc/windowing/iterm.kak +++ b/rc/windowing/iterm.kak @@ -5,13 +5,12 @@ ## 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 - " + echo "require-module iterm" fi } +provide-module iterm %{ + define-command -hidden -params 2.. iterm-terminal-split-impl %{ nop %sh{ direction="$1" @@ -129,3 +128,8 @@ If no client is passed then the current one is used' \ fi } } + +alias global focus iterm-focus +alias global terminal iterm-terminal-vertical + +} diff --git a/rc/windowing/kitty.kak b/rc/windowing/kitty.kak index 1d2155f7..954af045 100644 --- a/rc/windowing/kitty.kak +++ b/rc/windowing/kitty.kak @@ -1,17 +1,14 @@ -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 - " + echo "require-module kitty" fi } +provide-module kitty %{ + +declare-option -docstring %{window type that kitty creates on new and repl calls (kitty|os)} str kitty_window_type kitty + 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' \ @@ -63,3 +60,11 @@ define-command kitty-send-text -docstring "send the selected text to the repl wi kitty @ send-text -m=title:kak_repl_window "${kak_selection}" } } + +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 + +} diff --git a/rc/windowing/repl/tmux.kak b/rc/windowing/repl/tmux.kak index a176f5f5..291717db 100644 --- a/rc/windowing/repl/tmux.kak +++ b/rc/windowing/repl/tmux.kak @@ -1,28 +1,14 @@ # 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 +hook global ModuleLoad tmux %{ + require-module tmux-repl } +provide-module tmux-repl %{ + +declare-option -docstring "tmux pane id in which the REPL is running" str tmux_repl_id + define-command -hidden -params 1..2 tmux-repl-impl %{ evaluate-commands %sh{ if [ -z "$TMUX" ]; then @@ -52,7 +38,7 @@ define-command tmux-repl-window -params 0..1 -command-completion -docstring "Cre 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 + if [ $# -eq 0 ]; then tmux set-buffer -b kak_selection "${kak_selection}" else tmux set-buffer -b kak_selection "$1" @@ -65,3 +51,23 @@ 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}" } } + +evaluate-commands %sh{ + 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 +} + +} diff --git a/rc/windowing/repl/x11.kak b/rc/windowing/repl/x11.kak index 865e2748..54966c2a 100644 --- a/rc/windowing/repl/x11.kak +++ b/rc/windowing/repl/x11.kak @@ -1,3 +1,9 @@ +hook global ModuleLoad x11 %{ + require-module x11-repl +} + +provide-module x11-repl %{ + # 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} \ @@ -24,3 +30,5 @@ define-command x11-send-text -docstring "send the selected text to the repl wind alias global repl x11-repl alias global send-text x11-send-text + +} diff --git a/rc/windowing/screen.kak b/rc/windowing/screen.kak index e4ddd2e9..8c77e1e9 100644 --- a/rc/windowing/screen.kak +++ b/rc/windowing/screen.kak @@ -3,12 +3,11 @@ hook -group GNUscreen global KakBegin .* %sh{ [ -z "${STY}" ] && exit - echo " - alias global focus screen-focus - alias global terminal screen-terminal-vertical - " + echo "require-module screen" } +provide-module screen %{ + define-command screen-terminal-impl -hidden -params 3.. %{ nop %sh{ tty="$(ps -o tty ${kak_client_pid} | tail -n 1)" @@ -67,3 +66,8 @@ If no client is passed then the current one is used' \ fi } } + +alias global focus screen-focus +alias global terminal screen-terminal-vertical + +} diff --git a/rc/windowing/tmux.kak b/rc/windowing/tmux.kak index acc5c097..b3c3dbdc 100644 --- a/rc/windowing/tmux.kak +++ b/rc/windowing/tmux.kak @@ -1,16 +1,14 @@ # 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 - " + echo "require-module tmux" fi } +provide-module tmux %{ + define-command -hidden -params 2.. tmux-terminal-impl %{ evaluate-commands %sh{ tmux=${kak_client_env_TMUX:-$TMUX} @@ -59,3 +57,9 @@ If no client is passed then the current one is used' \ fi } } + +## The default behaviour for the `new` command is to open an horizontal pane in a tmux session +alias global focus tmux-focus +alias global terminal tmux-terminal-horizontal + +} diff --git a/rc/windowing/x11.kak b/rc/windowing/x11.kak index 27b637ae..004b0b0a 100644 --- a/rc/windowing/x11.kak +++ b/rc/windowing/x11.kak @@ -1,3 +1,13 @@ +# x11 + +hook global KakBegin .* %sh{ + if [ -n "$DISPLAY" ] && [ -z "$TMUX" ]; then + echo "require-module x11" + fi +} + +provide-module x11 %{ + # 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 @@ -71,3 +81,5 @@ If no client is passed, then the current client is used' \ alias global focus x11-focus alias global terminal x11-terminal + +} diff --git a/src/command_manager.cc b/src/command_manager.cc index 5e8c8196..1fdfa34d 100644 --- a/src/command_manager.cc +++ b/src/command_manager.cc @@ -40,6 +40,36 @@ void CommandManager::register_command(String command_name, std::move(completer) }; } +bool CommandManager::module_defined(StringView module_name) const +{ + return m_modules.find(module_name) != m_modules.end(); +} + +void CommandManager::register_module(String module_name, String commands) +{ + auto module = m_modules.find(module_name); + if (module != m_modules.end() and module->value.loaded) + throw runtime_error{format("module already loaded: '{}'", module_name)}; + + m_modules[module_name] = { false, std::move(commands) }; +} + +void CommandManager::load_module(StringView module_name, Context& context) +{ + auto module = m_modules.find(module_name); + if (module == m_modules.end()) + throw runtime_error{format("no such module: '{}'", module_name)}; + if (module->value.loaded) + return; + + module->value.loaded = true; + Context empty_context{Context::EmptyContextFlag{}}; + execute(module->value.commands, empty_context); + module->value.commands.clear(); + + context.hooks().run_hook(Hook::ModuleLoad, module_name, context); +} + struct parse_error : runtime_error { parse_error(StringView error) diff --git a/src/command_manager.hh b/src/command_manager.hh index 0468a1fc..329c24f2 100644 --- a/src/command_manager.hh +++ b/src/command_manager.hh @@ -123,6 +123,12 @@ public: void clear_last_complete_command() { m_last_complete_command = String{}; } + bool module_defined(StringView module_name) const; + + void register_module(String module_name, String commands); + + void load_module(StringView module_name, Context& context); + private: void execute_single_command(CommandParameters params, Context& context, @@ -143,6 +149,14 @@ private: String m_last_complete_command; int m_command_depth = 0; + struct Module + { + bool loaded; + String commands; + }; + using ModuleMap = HashMap; + ModuleMap m_modules; + CommandMap::const_iterator find_command(const Context& context, StringView name) const; }; diff --git a/src/commands.cc b/src/commands.cc index 559fe90b..51adb80c 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -2403,6 +2403,46 @@ const CommandDesc enter_user_mode_cmd = { } }; +const CommandDesc provide_module_cmd = { + "provide-module", + nullptr, + "provide-module [] : declares a module provided by ", + ParameterDesc{ + { { "override", { false, "allow overriding an existing module" } } }, + ParameterDesc::Flags::None, + 2, 2 + }, + CommandFlags::None, + CommandHelper{}, + CommandCompleter{}, + [](const ParametersParser& parser, Context& context, const ShellContext&) + { + const String& module_name = parser[0]; + auto& cm = CommandManager::instance(); + + if (not all_of(module_name, is_identifier)) + throw runtime_error(format("invalid module name: '{}'", module_name)); + + if (cm.module_defined(module_name) and not parser.get_switch("override")) + throw runtime_error(format("module '{}' already defined", module_name)); + cm.register_module(module_name, parser[1]); + } +}; + +const CommandDesc require_module_cmd = { + "require-module", + nullptr, + "require-module : ensures that module has been loaded", + ParameterDesc{ {}, ParameterDesc::Flags::None, 1, 1 }, + CommandFlags::None, + CommandHelper{}, + CommandCompleter{}, + [](const ParametersParser& parser, Context& context, const ShellContext&) + { + CommandManager::instance().load_module(parser[0], context); + } +}; + } void register_commands() @@ -2468,6 +2508,8 @@ void register_commands() register_command(fail_cmd); register_command(declare_user_mode_cmd); register_command(enter_user_mode_cmd); + register_command(provide_module_cmd); + register_command(require_module_cmd); } } diff --git a/src/hook_manager.hh b/src/hook_manager.hh index 909d24bc..f1e6667b 100644 --- a/src/hook_manager.hh +++ b/src/hook_manager.hh @@ -56,12 +56,13 @@ enum class Hook WinCreate, WinDisplay, WinResize, - WinSetOption + WinSetOption, + ModuleLoad }; constexpr auto enum_desc(Meta::Type) { - return make_array, 40>({ + return make_array, 41>({ {Hook::BufCreate, "BufCreate"}, {Hook::BufNewFile, "BufNewFile"}, {Hook::BufOpenFile, "BufOpenFile"}, @@ -102,6 +103,7 @@ constexpr auto enum_desc(Meta::Type) {Hook::WinDisplay, "WinDisplay"}, {Hook::WinResize, "WinResize"}, {Hook::WinSetOption, "WinSetOption"}, + {Hook::ModuleLoad, "ModuleLoad"} }); }