about summary refs log tree commit diff
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
parent341d4434146d2216d4cdf4f0fffd060670d4c5c6 (diff)
downloadzsh-6076c474f2427ec9a75cecab1fc95f7cd9f066f6.tar.gz
zsh-6076c474f2427ec9a75cecab1fc95f7cd9f066f6.tar.xz
zsh-6076c474f2427ec9a75cecab1fc95f7cd9f066f6.zip
unposted: replace-argument can take negative prefix to count from end
-rw-r--r--ChangeLog6
-rw-r--r--Doc/Zsh/contrib.yo1
-rw-r--r--Functions/Zle/replace-argument16
3 files changed, 16 insertions, 7 deletions
diff --git a/ChangeLog b/ChangeLog
index e9deb6e55..563708769 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2014-07-24  Peter Stephenson  <p.stephenson@samsung.com>
+
+	* unposted: Functions/Zle/replace-argument, Doc/Zsh/contrib.yo:
+	allow negative numeric prefix to count backwards from last
+	argument.
+
 2014-07-23  Peter Stephenson  <p.w.stephenson@ntlworld.com>
 
 	* Jai Keerthan: users/18981: Completion/Unix/Command/_tmux:
diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo
index 4ee404c1b..1c1a66a3b 100644
--- a/Doc/Zsh/contrib.yo
+++ b/Doc/Zsh/contrib.yo
@@ -2339,6 +2339,7 @@ is not executed).  Arguments are as delimited by standard shell syntax,
 
 If a numeric argument is given, that specifies the argument to be
 replaced.  0 means the command name, as in history expansion.
+A negative numeric argument counts backward from the last word.
 
 If no numeric argument is given, the current argument is replaced;
 this is the last argument if the previous history line is being used.
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