Skip to content
New issue

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

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

Already on GitHub? # to your account

Only insert completions if cursor is at EOL #20

Merged
merged 2 commits into from
Jul 1, 2020
Merged
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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ Here `|` denotes the current cursor position. No manual cursor motion involved :
`...|`
- the set of pairs is configurable

To disable completing pairs unless the cursor is at the end of the line, set
the `$pisces_only_insert_at_eol` variable:

```fish
set -U pisces_only_insert_at_eol 1
```

### Installation

Expand Down
6 changes: 3 additions & 3 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 $r "_pisces_insert_identical $right"
else

bind -M $mode $l "commandline -i -- $left; and _pisces_append $right"
bind -M $mode $r "_pisces_skip $right"
bind -M $mode $l "_pisces_insert_left $left $right"
bind -M $mode $r "_pisces_insert_right $right"
end
end
8 changes: 8 additions & 0 deletions functions/_pisces_insert_identical.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
function _pisces_insert_identical -a text -d "The binding command for a pair where the left and right delimiters are identical"
if _pisces_should_insert $text
_pisces_skip $text
or _pisces_append $text
else
commandline -i -- $text
end
end
5 changes: 5 additions & 0 deletions functions/_pisces_insert_left.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
function _pisces_insert_left -a left right -d "The binding command to insert the left delimiter"
commandline -i -- $left
and _pisces_should_insert $right
and _pisces_append $right
end
7 changes: 7 additions & 0 deletions functions/_pisces_insert_right.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
function _pisces_insert_right -a right -d "The binding command to insert the right delimiter"
if _pisces_should_insert $right
_pisces_skip $right
else
commandline -i -- $right
end
end
2 changes: 1 addition & 1 deletion functions/_pisces_lookup.fish
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ function _pisces_lookup -a pos len -d "Returns the text at the given position re
set input (commandline -b)

# NOTE: it's important to quote $input, because it may have newlines
string sub --start (math "$cur + $pos + 1") --length $len -- "$input" ^/dev/null
string sub --start (math "$cur + $pos + 1") --length $len -- "$input" 2>/dev/null
or echo '' # if it's out of bounds (probably better to return cut part)
end
11 changes: 11 additions & 0 deletions functions/_pisces_should_insert.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
function _pisces_should_insert -a insert -d "Determines if we should insert text"
# If $pisces_only_insert_at_eol is unset, return true
# Otherwise, return true if the cursor is at the end of the line OR
# if the cursor is before a copy of $insert (i.e. a delimiter) at the end
# of the line.
set cmd_to_cursor (commandline -c)
set cmd (commandline)
test -z "$pisces_only_insert_at_eol" \
-o "$cmd_to_cursor" = "$cmd" \
-o "$cmd_to_cursor$insert" = "$cmd"
end
2 changes: 1 addition & 1 deletion functions/_pisces_skip.fish
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ function _pisces_skip -a text -d "Skips given text if it's already under the cur

set length (string length -- $text)

if [ (_pisces_lookup 0 $length) = $text ]
if test (_pisces_lookup 0 $length) = "$text"
_pisces_jump $length
return 0
else
Expand Down