about summary refs log tree commit diff
path: root/Functions
diff options
context:
space:
mode:
authorPeter Stephenson <pws@zsh.org>2014-07-24 10:49:50 +0100
committerPeter Stephenson <pws@zsh.org>2014-07-24 10:49:50 +0100
commit6076c474f2427ec9a75cecab1fc95f7cd9f066f6 (patch)
tree4566847be9d1225eefc9ad150df95f1d76c01efb /Functions
parent341d4434146d2216d4cdf4f0fffd060670d4c5c6 (diff)
downloadzsh-6076c474f2427ec9a75cecab1fc95f7cd9f066f6.tar.gz
zsh-6076c474f2427ec9a75cecab1fc95f7cd9f066f6.tar.xz
zsh-6076c474f2427ec9a75cecab1fc95f7cd9f066f6.zip
unposted: replace-argument can take negative prefix to count from end
Diffstat (limited to 'Functions')
-rw-r--r--Functions/Zle/replace-argument16
1 files changed, 9 insertions, 7 deletions
diff --git a/Functions/Zle/replace-argument b/Functions/Zle/replace-argument
index b43fc39bb..0ef3de7b5 100644
--- a/Functions/Zle/replace-argument
+++ b/Functions/Zle/replace-argument
@@ -12,21 +12,23 @@ if (( ${#BUFFER} == 0 )); then
   CURSOR=${#BUFFER}
 fi
 
-local widget=$WIDGET
-integer numeric cursor=CURSOR
+local widget=$WIDGET numeric
+integer cursor=CURSOR
 if (( ${+NUMERIC} )); then
   numeric=$NUMERIC
-else
-  numeric=-1
 fi
 local reply REPLY REPLY2
 integer index
 split-shell-arguments
 
-if (( numeric >= 0 )); then
-  index=$(( 2 + 2*numeric ))
+if [[ -n $numeric ]]; then
+  if (( numeric < 0 )); then
+    (( index = ${#reply} - 1 + 2*(numeric+1) ))
+  else
+    (( index = 2 + 2*numeric ))
+  fi
 else
-  index=$((REPLY & ~1 ))
+  (( index = REPLY & ~1 ))
 fi
 
 local edit