From 6765723c689467edfa407b95ff86be529ce2983c Mon Sep 17 00:00:00 2001 From: Olivier Perret Date: Wed, 28 Nov 2018 10:39:07 +0100 Subject: [PATCH] Change cleanup of core/ languages to use a simpler hook -once --- rc/core/asciidoc.kak | 8 +++++--- rc/core/c-family.kak | 49 +++++++++++++++++++++++--------------------- rc/core/diff.kak | 6 ++++-- rc/core/grep.kak | 8 ++------ rc/core/kakrc.kak | 10 +++++---- rc/core/make.kak | 12 +++++------ rc/core/makefile.kak | 12 +++++------ rc/core/man.kak | 13 ++++-------- rc/core/python.kak | 12 +++++------ rc/core/sh.kak | 6 ++++-- 10 files changed, 66 insertions(+), 70 deletions(-) diff --git a/rc/core/asciidoc.kak b/rc/core/asciidoc.kak index ffc7471c..6855e7fc 100644 --- a/rc/core/asciidoc.kak +++ b/rc/core/asciidoc.kak @@ -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 } +} diff --git a/rc/core/c-family.kak b/rc/core/c-family.kak index e485568e..c80dc230 100644 --- a/rc/core/c-family.kak +++ b/rc/core/c-family.kak @@ -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: diff --git a/rc/core/diff.kak b/rc/core/diff.kak index e8b7c25a..51612c74 100644 --- a/rc/core/diff.kak +++ b/rc/core/diff.kak @@ -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 } +} diff --git a/rc/core/grep.kak b/rc/core/grep.kak index b36ca618..6e0dcb56 100644 --- a/rc/core/grep.kak +++ b/rc/core/grep.kak @@ -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 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" \ diff --git a/rc/core/kakrc.kak b/rc/core/kakrc.kak index 5115a9e9..caab485a 100644 --- a/rc/core/kakrc.kak +++ b/rc/core/kakrc.kak @@ -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 \; s ^\h+$ 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-.+ } +~ diff --git a/rc/core/make.kak b/rc/core/make.kak index d47083bb..f9ed68cc 100644 --- a/rc/core/make.kak +++ b/rc/core/make.kak @@ -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 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" \ diff --git a/rc/core/makefile.kak b/rc/core/makefile.kak index 564231ff..ff1fa26c 100644 --- a/rc/core/makefile.kak +++ b/rc/core/makefile.kak @@ -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-.+ } } diff --git a/rc/core/man.kak b/rc/core/man.kak index 660f184c..8ce66b95 100644 --- a/rc/core/man.kak +++ b/rc/core/man.kak @@ -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{ diff --git a/rc/core/python.kak b/rc/core/python.kak index a91f0364..8563423d 100644 --- a/rc/core/python.kak +++ b/rc/core/python.kak @@ -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 \; s ^\h+$ 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-.+ } } diff --git a/rc/core/sh.kak b/rc/core/sh.kak index 0840c4f0..47085cf8 100644 --- a/rc/core/sh.kak +++ b/rc/core/sh.kak @@ -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 } +}