From e233e7f028366ce8f5d58fe1cc8a88210664ddb3 Mon Sep 17 00:00:00 2001 From: Marc Coquand Date: Thu, 5 Sep 2024 12:27:17 -0500 Subject: add kak --- config/kak/phantom-selection.kak | 84 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 config/kak/phantom-selection.kak (limited to 'config/kak/phantom-selection.kak') diff --git a/config/kak/phantom-selection.kak b/config/kak/phantom-selection.kak new file mode 100644 index 0000000..e64c468 --- /dev/null +++ b/config/kak/phantom-selection.kak @@ -0,0 +1,84 @@ +provide-module phantom-selection %{ + +set-face global PhantomSelection black,green+F + +declare-option -hidden str-list phantom_selections +declare-option -hidden range-specs phantom_selections_ranges + +add-highlighter global/ ranges phantom_selections_ranges + +define-command -hidden phantom-selection-store-and-highlight %{ + set window phantom_selections %reg{^} + set window phantom_selections_ranges %val{timestamp} + eval -no-hooks -draft -itersel %{ + set -add window phantom_selections_ranges "%val{selection_desc}|PhantomSelection" + } +} + +define-command -hidden phantom-selection-iterate-impl -params 1 %{ + eval -save-regs ^ %{ + reg ^ %opt{phantom_selections} + try %{ + exec z + exec %arg{1} + # keep the main selection and put all the other in the mark + # a recent change to Kakoune swaps with "," (and + # with ). Try both to make sure we clear selections + # both with and without this breaking change. Pad them with + # to cancel out the key with the other behavior. + exec -save-regs '' 'Z' + phantom-selection-store-and-highlight + exec '<,>' + } catch %{ + fail 'No phantom selections' + } + } +} + +define-command phantom-selection-iterate-next -docstring " +Turn secondary selections into phantoms and select the next phantom +" %{ + phantom-selection-iterate-impl ')' +} + +define-command phantom-selection-iterate-prev -docstring " +Turn secondary selections into phantoms and select the previous phantom +" %{ + phantom-selection-iterate-impl '(' +} + +define-command phantom-selection-clear -docstring " +Remove all phantom selections +" %{ + unset window phantom_selections + unset window phantom_selections_ranges +} + +define-command phantom-selection-select-all -docstring " +Select all phantom selections +" %{ + eval -save-regs ^ %{ + reg ^ %opt{phantom_selections} + try %{ + exec z + echo "" + } catch %{ + fail 'No phantom selections' + } + } +} + +define-command phantom-selection-add-selection -docstring " +Create phantoms out of the current selections +" %{ + eval -draft -save-regs ^ %{ + reg ^ %opt{phantom_selections} + try %{ exec "a" } + exec -save-regs '' "Z" + phantom-selection-store-and-highlight + } +} + +} + +require-module phantom-selection -- cgit v1.2.3