diff --git a/.config/kak/autoload/byline.kak b/.config/kak/autoload/byline.kak index 495ae12b..7797c116 100644 --- a/.config/kak/autoload/byline.kak +++ b/.config/kak/autoload/byline.kak @@ -1,7 +1,9 @@ provide-module byline %{ + # helpers for shell-less boolean checks try %{ define-command -hidden true nop } try %{ define-command -hidden false fail } + # used to store origina readonly status declare-option -hidden bool base_readonly false # Mappings @@ -11,7 +13,7 @@ provide-module byline %{ # High-level selection expanding and contracting, based on selection direction - define-command -hidden byline-drag-down %{ + define-command byline-drag-down %{ evaluate-commands -itersel -no-hooks %{ try %{ byline-assert-selection-forwards @@ -22,7 +24,7 @@ provide-module byline %{ } } - define-command -hidden byline-drag-up %{ + define-command byline-drag-up %{ evaluate-commands -itersel -no-hooks %{ try %{ byline-assert-selection-forwards @@ -50,21 +52,40 @@ provide-module byline %{ byline-assert-selection-reduced } catch %{ evaluate-commands -no-hooks -draft -save-regs 'ab' %{ + # this "check" requires readonly to be false, + # so we store its original value before changing it + set-option buffer base_readonly %opt{readonly} # store current cursor pos set-register a %val{cursor_byte_offset} # force cursor forward execute-keys # store second cursor pos set-register b %val{cursor_byte_offset} + # check whether readonly is enabled + try %{ + %opt{base_readonly} + # disable temporarily + set-option buffer readonly false + } # if the sel faces forward, the cursor hasn't moved # So we paste reg a. the pasted content is now selected. # We can use to check whether it matches register b. try %{ execute-keys %exp{"aP%reg{b}u} + # only re-enable readme if it was originally on + try %{ + %opt{base_readonly} + set-option buffer readonly true + } } catch %{ # clean up the pasted content if the above # assertion failed execute-keys 'u' + # only re-enable readme if it was originally on + try %{ + %opt{base_readonly} + set-option buffer readonly true + } # propogate failure to caller fail }