Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provides requires #2782

Merged
merged 18 commits into from
Apr 25, 2019
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion doc/pages/changelog.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,20 @@ released versions.
* `edit -scratch` with no buffer name will create a new
scratch buffer with a unique autogenerated name.

* 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
Expand Down
15 changes: 15 additions & 0 deletions doc/pages/commands.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,21 @@ 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* [<switches>] <name> <commands>::
declares a module *name* that is defined by *commands*. *commands* will be
evaluated as if by source the first time *require-module <name>* is run.

*-override*:::
allow the module to replace and existing one with the same name

*require-module* <name>::
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
Expand Down
3 changes: 3 additions & 0 deletions doc/pages/hooks.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,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.
Expand Down
2 changes: 1 addition & 1 deletion rc/detection/editorconfig.kak
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 12 additions & 6 deletions rc/filetype/asciidoc.kak
Original file line number Diff line number Diff line change
Expand Up @@ -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
# ‾‾‾‾‾‾‾‾‾‾‾‾

Expand All @@ -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 }
}
83 changes: 43 additions & 40 deletions rc/filetype/c-family.kak
Original file line number Diff line number Diff line change
Expand Up @@ -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 <a-x> 1s^(\h+)$<ret> d }
Expand Down Expand Up @@ -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 "
Expand Down Expand Up @@ -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 "
Expand Down Expand Up @@ -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 "
Expand All @@ -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
Expand Down Expand Up @@ -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
}

🦀
38 changes: 22 additions & 16 deletions rc/filetype/cabal.kak
Original file line number Diff line number Diff line change
Expand Up @@ -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
# ‾‾‾‾‾‾‾‾‾‾‾‾

Expand Down Expand Up @@ -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-.+ }
]
41 changes: 24 additions & 17 deletions rc/filetype/clojure.kak
Original file line number Diff line number Diff line change
@@ -1,15 +1,35 @@
# http://clojure.org
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾

# require lisp.kak

# Detection
# ‾‾‾‾‾‾‾‾‾

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
# ‾‾‾‾‾‾‾‾‾‾‾‾

Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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-.+ }
]
14 changes: 11 additions & 3 deletions rc/filetype/cmake.kak
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 }
}
Loading