Skip to content

Commit

Permalink
Add Natural Selection integration
Browse files Browse the repository at this point in the history
  • Loading branch information
daleeidd committed Apr 19, 2019
1 parent 43cfa9d commit 0cac4a0
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
6 changes: 6 additions & 0 deletions functions/_pisces_backspace.fish
Original file line number Diff line number Diff line change
@@ -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 ]
Expand Down
4 changes: 2 additions & 2 deletions functions/_pisces_bind_pair.fish
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 6 additions & 0 deletions functions/_pisces_skip.fish
Original file line number Diff line number Diff line change
@@ -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 ]
Expand Down
19 changes: 19 additions & 0 deletions functions/_pisces_wrap.fish
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 0cac4a0

Please sign in to comment.