Skip to content

Commit

Permalink
fix(cursor): do not treat markers as patterns... [#140]
Browse files Browse the repository at this point in the history
Previously, setting one or both markers to '+'
resulted in an error:

> zsh: failed to compile regex: repetition-operator operand invalid

And when one or both markers was '^', expansions without the cursor
marker were doubled, with the cursor between them.
  • Loading branch information
olets committed Nov 8, 2024
1 parent cacd344 commit 4449f42
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions zsh-abbr.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -1508,7 +1508,7 @@ abbr-expand() {
# BEGIN DUPE abbr-expand 2x with differences
# if it expanded and this widget can push to history
(( ABBR_EXPAND_PUSH_ABBREVIATION_TO_HISTORY )) && print -s $abbreviation
if (( ABBR_SET_EXPANSION_CURSOR )) && [[ $expansion =~ $ABBR_EXPANSION_CURSOR_MARKER ]]; then
if (( ABBR_SET_EXPANSION_CURSOR )) && [[ $expansion != ${expansion/$ABBR_EXPANSION_CURSOR_MARKER} ]]; then
LBUFFER=${expansion%%$ABBR_EXPANSION_CURSOR_MARKER*} # DUPE difference
RBUFFER=${expansion#*$ABBR_EXPANSION_CURSOR_MARKER}$RBUFFER
ret=2 # DUPE difference
Expand Down Expand Up @@ -1552,7 +1552,7 @@ abbr-expand() {
# BEGIN DUPE abbr-expand 2x with differences
# if it expanded and this widget can push to history
(( ABBR_EXPAND_PUSH_ABBREVIATION_TO_HISTORY )) && print -s $abbreviation
if (( ABBR_SET_EXPANSION_CURSOR )) && [[ $expansion =~ $ABBR_EXPANSION_CURSOR_MARKER ]]; then
if (( ABBR_SET_EXPANSION_CURSOR )) && [[ $expansion != ${expansion/$ABBR_EXPANSION_CURSOR_MARKER} ]]; then
LBUFFER=${LBUFFER%%$abbreviation}${expansion%%$ABBR_EXPANSION_CURSOR_MARKER*} # DUPE difference
RBUFFER=${expansion#*$ABBR_EXPANSION_CURSOR_MARKER}$RBUFFER
ret=3
Expand Down Expand Up @@ -1608,7 +1608,7 @@ abbr-expand-and-insert() {
(( $? == 2 || $? == 3 )) && cursor_was_placed=1
(( cursor_was_placed )) && return

if (( ABBR_SET_LINE_CURSOR )) && [[ $BUFFER =~ $ABBR_LINE_CURSOR_MARKER ]]; then
if (( ABBR_SET_LINE_CURSOR )) && [[ $BUFFER != ${BUFFER/$ABBR_LINE_CURSOR_MARKER} ]]; then
buffer=$BUFFER

LBUFFER=${buffer%%$ABBR_LINE_CURSOR_MARKER*}
Expand Down

0 comments on commit 4449f42

Please sign in to comment.