diff --git a/.config/kak/autoload/search-highlight.kak b/.config/kak/autoload/search-highlight.kak index 7b0a27c7..926d1f72 100644 --- a/.config/kak/autoload/search-highlight.kak +++ b/.config/kak/autoload/search-highlight.kak @@ -10,23 +10,33 @@ provide-module search-highlight %— def -hidden -override search-highlight-on nop def -hidden -override search-highlight-off fail + # enable the plugin define-command -hidden search-highlight-enable-impl %{ + # register hook to show highlighting during search hook -group search-highlight window RegisterModified '/' %{ + # check whether already enabled try %{ %opt{search_highlight_status} } catch %{ + # if not, add the highlighter add-highlighter window/search-highlight dynregex '%reg{/}' %exp{0:%opt{search_highlight_face}} + # update status tracker set-option window search_highlight_status 'search-highlight-on' - } - } - hook -group search-highlight window NormalKey '' %{ - try %{ - %opt{search_highlight_status} - remove-highlighter window/search-highlight - set-option window search_highlight_status 'search-highlight-off' + # register hook to clear highlighter after leaving search + hook -once -group search-highlight window NormalIdle .* %{ + try %{ + # for safety; only run if highlighting is on + %opt{search_highlight_status} + # remove highlighter + remove-highlighter window/search-highlight + # update status + set-option window search_highlight_status 'search-highlight-off' + } + } } } } + # remove the plugin's hooks define-command -hidden search-highlight-disable-impl %{ remove-hooks window search-highlight } diff --git a/.config/kak/kakrc b/.config/kak/kakrc index 9f0a61a9..f49ee0da 100644 --- a/.config/kak/kakrc +++ b/.config/kak/kakrc @@ -124,7 +124,7 @@ set-option -add global ui_options terminal_assistant=none set-option global tabstop 4 set-option global indentwidth 4 -hook global WinSetOption filetype=kak %{ +hook -once global WinSetOption filetype=kak %{ declare-option str-list extra_kak_keywords addhl decl def compl eval exec rmhl rmhooks face set unset eval %sh{ @@ -133,6 +133,9 @@ hook global WinSetOption filetype=kak %{ printf '%s' "add-highlighter shared/kakrc/code/extra_keywords regex (?:\s|\A)\K($(join "${kak_opt_extra_kak_keywords}" '|'))(?:(?=\s)|\z) 0:keyword" fi } +} + +hook global WinSetOption filetype=kak %{ # make brackets gray a-la Ashen add-highlighter window/bracket regex [\[\]\(\)\{\}]{1} 0:rgb:737373