1
1
mirror of https://github.com/mawww/kakoune.git synced 2024-11-23 15:23:29 +03:00

Change cleanup of core/ languages to use a simpler hook -once

This commit is contained in:
Olivier Perret 2018-11-28 10:39:07 +01:00
parent c6f98f8483
commit 6765723c68
10 changed files with 66 additions and 70 deletions

View File

@ -36,6 +36,8 @@ add-highlighter shared/asciidoc/ regex ^:[-\w]+: 0:meta
# Initialization
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾
#
hook -group asciidoc-highlight global WinSetOption filetype=asciidoc %{ add-highlighter window/asciidoc ref asciidoc }
hook -group asciidoc-highlight global WinSetOption filetype=(?!asciidoc).* %{ remove-highlighter window/asciidoc }
hook -group asciidoc-highlight global WinSetOption filetype=asciidoc %{
add-highlighter window/asciidoc ref asciidoc
hook -once -always window WinSetOption filetype=(?!asciidoc).* %{ remove-highlighter window/asciidoc }
}

View File

@ -3,7 +3,7 @@ hook global BufCreate .*\.(cc|cpp|cxx|C|hh|hpp|hxx|H)$ %{
}
hook global BufSetOption filetype=c\+\+ %{
set-option buffer filetype cpp
hook -once buffer NormalIdle '' "set-option buffer filetype cpp"
}
hook global BufCreate .*\.c$ %{
@ -318,34 +318,37 @@ evaluate-commands %sh{
}
hook global WinSetOption filetype=(c|cpp|objc) %[
try %{ # we might be switching from one c-family language to another
remove-hooks window c-family-.+
}
hook -group c-family-indent window ModeChange insert:.* c-family-trim-autoindent
hook -group c-family-insert window InsertChar \n c-family-insert-on-newline
hook -group c-family-indent window InsertChar \n c-family-indent-on-newline
hook -group c-family-indent window InsertChar \{ c-family-indent-on-opening-curly-brace
hook -group c-family-indent window InsertChar \} c-family-indent-on-closing-curly-brace
hook -group c-family-insert window InsertChar \} c-family-insert-on-closing-curly-brace
hook -group "%val{hook_param_capture_1}-family-indent" window ModeChange insert:.* c-family-trim-autoindent
hook -group "%val{hook_param_capture_1}-family-insert" window InsertChar \n c-family-insert-on-newline
hook -group "%val{hook_param_capture_1}-family-indent" window InsertChar \n c-family-indent-on-newline
hook -group "%val{hook_param_capture_1}-family-indent" window InsertChar \{ c-family-indent-on-opening-curly-brace
hook -group "%val{hook_param_capture_1}-family-indent" window InsertChar \} c-family-indent-on-closing-curly-brace
hook -group "%val{hook_param_capture_1}-family-insert" window InsertChar \} c-family-insert-on-closing-curly-brace
alias window alt c-family-alternative-file
hook -once -always window WinSetOption "filetype=(?!%val{hook_param_capture_1}).*" "
remove-hooks window c-family-.+
"
hook -once -always window WinSetOption filetype=(?!c)(?!cpp)(?!objc).* %{
unalias window alt c-family-alternative-file
}
]
hook global WinSetOption filetype=(?!c)(?!cpp)(?!objc).* %[
remove-hooks window c-family-.+
hook -group c-highlight global WinSetOption filetype=c %{
add-highlighter window/c ref c
hook -once -always window WinSetOption filetype=(?!c).* %{ remove-highlighter window/c }
}
unalias window alt c-family-alternative-file
]
hook -group cpp-highlight global WinSetOption filetype=cpp %{
add-highlighter window/cpp ref cpp
hook -once -always window WinSetOption filetype=(?!cpp).* %{ remove-highlighter window/cpp }
}
hook -group c-highlight global WinSetOption filetype=c %[ add-highlighter window/c ref c ]
hook -group c-highlight global WinSetOption filetype=(?!c).* %[ remove-highlighter window/c ]
hook -group cpp-highlight global WinSetOption filetype=cpp %[ add-highlighter window/cpp ref cpp ]
hook -group cpp-highlight global WinSetOption filetype=(?!cpp).* %[ remove-highlighter window/cpp ]
hook -group objc-highlight global WinSetOption filetype=objc %[ add-highlighter window/objc ref objc ]
hook -group objc-highlight global WinSetOption filetype=(?!objc).* %[ remove-highlighter window/objc ]
hook -group objc-highlight global WinSetOption filetype=objc %{
add-highlighter window/objc ref objc
hook -once -always window WinSetOption filetype=(?!objc).* %{ 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:

View File

@ -7,5 +7,7 @@ add-highlighter shared/diff/ regex "^\+[^\n]*\n" 0:green,default
add-highlighter shared/diff/ regex "^-[^\n]*\n" 0:red,default
add-highlighter shared/diff/ regex "^@@[^\n]*@@" 0:cyan,default
hook -group diff-highlight global WinSetOption filetype=diff %{ add-highlighter window/diff ref diff }
hook -group diff-highlight global WinSetOption filetype=(?!diff).* %{ remove-highlighter window/diff }
hook -group diff-highlight global WinSetOption filetype=diff %{
add-highlighter window/diff ref diff
hook -once -always window WinSetOption filetype=(?!diff).* %{ remove-highlighter window/diff }
}

View File

@ -28,16 +28,12 @@ hook -group grep-highlight global WinSetOption filetype=grep %{
add-highlighter window/grep group
add-highlighter window/grep/ regex "^((?:\w:)?[^:\n]+):(\d+):(\d+)?" 1:cyan 2:green 3:green
add-highlighter window/grep/ line %{%opt{grep_current_line}} default+b
hook -once -always window WinSetOption filetype=(?!grep).* %{ remove-highlighter window/grep }
}
hook global WinSetOption filetype=grep %{
hook buffer -group grep-hooks NormalKey <ret> grep-jump
}
hook -group grep-highlight global WinSetOption filetype=(?!grep).* %{ remove-highlighter window/grep }
hook global WinSetOption filetype=(?!grep).* %{
remove-hooks buffer grep-hooks
hook -once -always window WinSetOption filetype=(?!grep).* %{ remove-hooks buffer grep-hooks }
}
declare-option -docstring "name of the client in which all source code jumps will be executed" \

View File

@ -92,7 +92,10 @@ define-command -hidden kak-indent-on-closing-char %{
# Initialization
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾
hook -group kak-highlight global WinSetOption filetype=kak %{ add-highlighter window/kakrc ref kakrc }
hook -group kak-highlight global WinSetOption filetype=kak %{
add-highlighter window/kakrc ref kakrc
hook -once -always window WinSetOption filetype=(?!kak).* %{ remove-highlighter window/kakrc }
}
hook global WinSetOption filetype=kak %~
hook window InsertChar \n -group kak-indent kak-indent-on-new-line
@ -101,7 +104,6 @@ hook global WinSetOption filetype=kak %~
# cleanup trailing whitespaces on current line insert end
hook window ModeChange insert:.* -group kak-indent %{ try %{ execute-keys -draft \; <a-x> s ^\h+$ <ret> d } }
set-option buffer extra_word_chars '_' '-'
~
hook -group kak-highlight global WinSetOption filetype=(?!kak).* %{ remove-highlighter window/kakrc }
hook global WinSetOption filetype=(?!kak).* %{ remove-hooks window kak-indent }
hook -once -always window WinSetOption filetype=(?!kak).* %{ remove-hooks window kak-.+ }
~

View File

@ -28,16 +28,14 @@ add-highlighter shared/make/ regex "^((?:\w:)?[^:\n]+):(\d+):(?:(\d+):)?\h+(?:((
add-highlighter shared/make/ regex "^\h*(~*(?:(\^)~*)?)$" 1:green 2:cyan+b
add-highlighter shared/make/ line '%opt{make_current_error_line}' default+b
hook -group make-highlight global WinSetOption filetype=make %{ add-highlighter window/make ref make }
hook -group make-highlight global WinSetOption filetype=make %{
add-highlighter window/make ref make
hook -once -always window WinSetOption filetype=(?!make).* %{ remove-highlighter window/make }
}
hook global WinSetOption filetype=make %{
hook buffer -group make-hooks NormalKey <ret> make-jump
}
hook -group make-highlight global WinSetOption filetype=(?!make).* %{ remove-highlighter window/make }
hook global WinSetOption filetype=(?!make).* %{
remove-hooks buffer make-hooks
hook -once -always window WinSetOption filetype=(?!make).* %{ remove-hooks buffer make-hooks }
}
declare-option -docstring "name of the client in which all source code jumps will be executed" \

View File

@ -49,14 +49,12 @@ define-command -hidden makefile-indent-on-new-line %{
# Initialization
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾
hook -group makefile-highlight global WinSetOption filetype=makefile %{ add-highlighter window/makefile ref makefile }
hook -group makefile-highlight global WinSetOption filetype=makefile %{
add-highlighter window/makefile ref makefile
hook -once -always window WinSetOption filetype=(?!makefile).* %{ remove-highlighter window/makefile }
}
hook global WinSetOption filetype=makefile %{
hook window InsertChar \n -group makefile-indent makefile-indent-on-new-line
}
hook -group makefile-highlight global WinSetOption filetype=(?!makefile).* %{ remove-highlighter window/makefile }
hook global WinSetOption filetype=(?!makefile).* %{
remove-hooks window makefile-indent
hook -once -always window WinSetOption filetype=(?!makefile).* %{ remove-hooks window makefile-.+ }
}

View File

@ -13,18 +13,13 @@ hook -group man-highlight global WinSetOption filetype=man %{
add-highlighter window/man-highlight/ regex '^ {7}-[^\s,]+(,\s+-[^\s,]+)*' 0:yellow
# References to other manpages
add-highlighter window/man-highlight/ regex [-a-zA-Z0-9_.]+\([a-z0-9]+\) 0:green
hook -once -always window WinSetOption filetype=(?!man).* %{ remove-highlighter window/man-highlight }
}
hook global WinSetOption filetype=man %{
hook -group man-hooks window WinResize .* %{
man-impl %val{bufname} %opt{manpage}
}
}
hook -group man-highlight global WinSetOption filetype=(?!man).* %{ remove-highlighter window/man-highlight }
hook global WinSetOption filetype=(?!man).* %{
remove-hooks window man-hooks
hook -group man-hooks window WinResize .* %{ man-impl %val{bufname} %opt{manpage} }
hook -once -always window WinSetOption filetype=(?!man).* %{ remove-hooks window man-hooks }
}
define-command -hidden -params 2..3 man-impl %{ evaluate-commands %sh{

View File

@ -135,16 +135,14 @@ define-command -hidden python-indent-on-new-line %{
# Initialization
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾
hook -group python-highlight global WinSetOption filetype=python %{ add-highlighter window/python ref python }
hook -group python-highlight global WinSetOption filetype=python %{
add-highlighter window/python ref python
hook -once -always window WinSetOption filetype=(?!python).* %{ 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-indent %{ try %{ execute-keys -draft \; <a-x> s ^\h+$ <ret> d } }
}
hook -group python-highlight global WinSetOption filetype=(?!python).* %{ remove-highlighter window/python }
hook global WinSetOption filetype=(?!python).* %{
remove-hooks window python-indent
hook -once -always window WinSetOption filetype=(?!python).* %{ remove-hooks window python-.+ }
}

View File

@ -37,5 +37,7 @@ add-highlighter shared/sh/code/function regex ^\h*(\w+)\h*\(\) 1:function
add-highlighter shared/sh/code/expansion regex \$(\w+|\{.+?\}|#|@|\?|\$|!|-|\*) 0:value
add-highlighter shared/sh/double_string/expansion regex \$(\w+|\{.+?\}) 0:value
hook -group sh-highlight global WinSetOption filetype=sh %{ add-highlighter window/sh ref sh }
hook -group sh-highlight global WinSetOption filetype=(?!sh).* %{ remove-highlighter window/sh }
hook -group sh-highlight global WinSetOption filetype=sh %{
add-highlighter window/sh ref sh
hook -once -always window WinSetOption filetype=(?!sh).* %{ remove-highlighter window/sh }
}