Skip to content

Commit

Permalink
use new memo feature of zsh to find item in region_highlight
Browse files Browse the repository at this point in the history
  • Loading branch information
Oliver Kiddle committed Jun 23, 2020
1 parent 339dc2d commit 56fcfb6
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions exchange
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,23 @@

setopt localoptions noksharrays

local colour
local colour memo="memo=zsh-viexchange"
local pos1 pos2 swap nl1 nl2
local _save_cur _save_cut="$CUTBUFFER"
local REPLY

zstyle -s zle:$WIDGET highlight colour || colour='fg=26,bg=195'

# retrieve first exchange selection
pos2=( ${(M)region_highlight:#* $colour} )
pos2=( ${(M)region_highlight:#*$memo*} ) # try memo feature
if (( ! $#pos2 )); then
region_highlight+=( " 0 0 fg=red, $memo" )
if [[ ${region_highlight[-1]} = "0 0 fg=red" ]]; then
# zsh 5.8 or earlier, search for entry by colour
pos2=( ${(M)region_highlight:#* $colour} )
fi
region_highlight[-1]=()
fi

# check if we should clear the selection or select a line
if [[ $WIDGET = *-line ]]; then
Expand Down Expand Up @@ -61,6 +69,6 @@ if (( $#pos2 )); then
BUFFER[1+pos1[1],pos1[2]]="$swap$nl1"
fi
elif (( $#pos1 )); then
region_highlight+=( "$pos1[1] $pos1[2] $colour")
region_highlight+=( "$pos1[1] $pos1[2] $colour, $memo")
fi
CUTBUFFER="$_save_cut" CURSOR="$_save_cur"

0 comments on commit 56fcfb6

Please sign in to comment.