From 0cac4a0a43d6a8db8b2adcce209692b1de9f33fd Mon Sep 17 00:00:00 2001 From: Dale Eidd Date: Sun, 14 Apr 2019 20:35:09 +1000 Subject: [PATCH] Add Natural Selection integration --- functions/_pisces_backspace.fish | 6 ++++++ functions/_pisces_bind_pair.fish | 4 ++-- functions/_pisces_skip.fish | 6 ++++++ functions/_pisces_wrap.fish | 19 +++++++++++++++++++ 4 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 functions/_pisces_wrap.fish diff --git a/functions/_pisces_backspace.fish b/functions/_pisces_backspace.fish index a675af1..dc5e3df 100644 --- a/functions/_pisces_backspace.fish +++ b/functions/_pisces_backspace.fish @@ -1,5 +1,11 @@ function _pisces_backspace -d "Overrides backspace to handle empty pairs removal" + # Natural Selection integration: + if functions -q _natural_selection_is_selecting; and _natural_selection_is_selecting + _natural_selection_kill_selection + return 0 + end + set -l line (commandline | string join \n) set -l index (commandline -C) if [ $index -ge 1 ] diff --git a/functions/_pisces_bind_pair.fish b/functions/_pisces_bind_pair.fish index 44c5b8a..7423b7b 100644 --- a/functions/_pisces_bind_pair.fish +++ b/functions/_pisces_bind_pair.fish @@ -11,10 +11,10 @@ function _pisces_bind_pair -a mode left right -d "Creates bindings for the given if [ $left = $right ] - bind -M $mode $r "_pisces_skip $right; or _pisces_append $right" + bind -M $mode $l "_pisces_wrap $left $right" else - bind -M $mode $l "commandline -i -- $left; and _pisces_append $right" + bind -M $mode $l "_pisces_wrap $left $right" bind -M $mode $r "_pisces_skip $right" end end diff --git a/functions/_pisces_skip.fish b/functions/_pisces_skip.fish index 2ed8902..097044e 100644 --- a/functions/_pisces_skip.fish +++ b/functions/_pisces_skip.fish @@ -1,5 +1,11 @@ function _pisces_skip -a text -d "Skips given text if it's already under the cursor" + # Natural Selection integration: + if functions -q _natural_selection_is_selecting; and _natural_selection_is_selecting + _natural_selection_replace_selection "$text" + return 0 + end + set length (string length -- $text) if [ (_pisces_lookup 0 $length) = $text ] diff --git a/functions/_pisces_wrap.fish b/functions/_pisces_wrap.fish new file mode 100644 index 0000000..7cc813f --- /dev/null +++ b/functions/_pisces_wrap.fish @@ -0,0 +1,19 @@ +function _pisces_wrap -a left right -d "Wraps text with string pairs" + + # Natural Selection integration: + if functions -q _natural_selection_is_selecting; and _natural_selection_is_selecting + _natural_selection_wrap_selection "$left" "$right" + return 0 + end + + set length (string length -- $left) + + if [ $left = $right ]; and [ (_pisces_lookup -1 $length) = $left ] + _pisces_append $right + return 1 + else + commandline -i -- $left + and _pisces_append $right + return 1 + end +end