diff --git a/.config/kak/autoload/search-highlight.kak b/.config/kak/autoload/search-highlight.kak index b118c5b5..087e4db7 100644 --- a/.config/kak/autoload/search-highlight.kak +++ b/.config/kak/autoload/search-highlight.kak @@ -38,48 +38,54 @@ provide-module search-highlight %— # 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 %{ + # we only watch the search register in / and reverse / searches + hook -group search-highlight window NormalKey (/|) %{ + # register hook to show highlighting during search + hook -group search-highlight-impl window RegisterModified '/' %{ + # check whether already enabled try %{ - # if the user escapes search, we should immediately clear the highlight - # in normal mode so we set the flag before escaping - # but only if the option is set - %opt{search_highlight_prompt_escape} - map window prompt ': set-option window search_highlight_quit true' - } - # if not already enabled, 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' - - # register hook to clear highlighter after leaving search - hook -once -group search-highlight window NormalIdle .* %{ - # check if auto clear is set + %opt{search_highlight_status} + } catch %{ try %{ - %opt{search_highlight_auto_clear} - search-highlight-clear - } catch %{ - # check if user escaped search + # if the user escapes search, we should immediately clear the highlight + # in normal mode so we set the flag before escaping + # but only if the option is set + %opt{search_highlight_prompt_escape} + map window prompt ': set-option window search_highlight_quit true' + } + # if not already enabled, 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' + + # register hook to clear highlighter after leaving search + hook -once -group search-highlight window NormalIdle .* %{ + # stop watching the search register + # (we've left search now) + remove-hooks window search-highlight-impl + # check if auto clear is set try %{ - %opt{search_highlight_quit} - # if so, clear immediately + %opt{search_highlight_auto_clear} search-highlight-clear } catch %{ - # otherwise, we clear on escape - hook -once -group search-highlight window NormalKey %{ + # check if user escaped search + try %{ + %opt{search_highlight_quit} + # if so, clear immediately search-highlight-clear + } catch %{ + # otherwise, we clear on escape + hook -once -group search-highlight window NormalKey %{ + search-highlight-clear + } } } + # clear the prompt mapping so it doesn't conflict with + # other prompt types + unmap window prompt + # reset the quit-early flag + set-option window search_highlight_quit false } - # clear the prompt mapping so it doesn't conflict with - # other prompt types - unmap window prompt - # reset the quit-early flag - set-option window search_highlight_quit false } } } @@ -87,7 +93,7 @@ provide-module search-highlight %— # remove the plugin's hooks define-command -hidden search-highlight-disable-impl %{ - remove-hooks window search-highlight + remove-hooks window search-highlight(-impl)? } ## begin public commands