Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Natural Selection integration #18

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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