zsh-users
 help / color / mirror / code / Atom feed
* copy-prev-word doesn't respect universal argument
@ 2005-11-02  3:44 Vin Shelton
  2005-11-02 11:06 ` Peter Stephenson
  0 siblings, 1 reply; 3+ messages in thread
From: Vin Shelton @ 2005-11-02  3:44 UTC (permalink / raw)
  To: zsh-users

Why don't copy-prev-word and copy-prev-shell-word respect the
universal argument?

Given the following:

  bindkey '^XA' copy-prev-word
  echo abc def ghi <ESC>2^XA

I would expect the result to be

  echo abc def ghi def

but zle seems always to copy the most recent word, ('ghi' in this
case), yielding:

  echo abc def ghi ghi

no matter what the prefix arg is.  I'm surprised I'm the first person
to request this.  Is there an alternate way to copy an arbitrary word
from earlier in the same command, or is the !#:<n> syntax sufficient
for most people?

Thanks,
  Vin


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: copy-prev-word doesn't respect universal argument
  2005-11-02  3:44 copy-prev-word doesn't respect universal argument Vin Shelton
@ 2005-11-02 11:06 ` Peter Stephenson
  2005-11-03  3:26   ` Vin Shelton
  0 siblings, 1 reply; 3+ messages in thread
From: Peter Stephenson @ 2005-11-02 11:06 UTC (permalink / raw)
  To: zsh-users

Vin Shelton <acs@alumni.princeton.edu> wrote:
> Why don't copy-prev-word and copy-prev-shell-word respect the
> universal argument?
> 
> Given the following:
> 
>   bindkey '^XA' copy-prev-word
>   echo abc def ghi <ESC>2^XA
> 
> I would expect the result to be
> 
>   echo abc def ghi def
> 
> but zle seems always to copy the most recent word, ('ghi' in this
> case), yielding:
> 
>   echo abc def ghi ghi
> 
> no matter what the prefix arg is.  I'm surprised I'm the first person
> to request this.

I think it's just a question of "when are you going to get around to
putting up those shelves".

I didn't bother handling negative prefix arguments.  Once, I would have
been more zealous.

> Is there an alternate way to copy an arbitrary word
> from earlier in the same command, or is the !#:<n> syntax sufficient
> for most people?

Actually, there is: see the supplied function copy-earlier-word which can
cycle through earlier words in the same way as insert-last-word cycles back
through the history.  In fact, copy-earlier-word works in combination with
insert-last-word so that you can copy earlier words on previous command
lines, too.  Note, however, that the sense of the digit argument is
different; N copies the Nth word from the start of the line.  I'm not sure
why I did it that way (and althought it's correctly documented it disagrees
with a comment in the function).

Index: Src/Zle/zle_misc.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/zle_misc.c,v
retrieving revision 1.32
diff -u -r1.32 zle_misc.c
--- Src/Zle/zle_misc.c	2 Nov 2005 10:11:33 -0000	1.32
+++ Src/Zle/zle_misc.c	2 Nov 2005 10:51:51 -0000
@@ -616,17 +616,28 @@
 int
 copyprevword(UNUSED(char **args))
 {
-    int len, t0;
+    int len, t0 = zlecs, t1;
 
-    for (t0 = zlecs - 1; t0 >= 0; t0--)
-	if (ZC_iword(zleline[t0]))
-	    break;
-    for (; t0 >= 0; t0--)
-	if (!ZC_iword(zleline[t0]))
-	    break;
-    if (t0)
-	t0++;
-    len = zlecs - t0;
+    if (zmult > 0) {
+	int count = zmult;
+
+	for (;;) {
+	    t1 = t0;
+
+	    while (t0 && !ZC_iword(zleline[t0-1]))
+		t0--;
+	    while (t0 && ZC_iword(zleline[t0-1]))
+		t0--;
+
+	    if (!--count)
+		break;
+	    if (t0 == 0)
+		return 1;
+	}
+    }
+    else
+	return 1;
+    len = t1 - t0;
     spaceinline(len);
     ZS_memcpy(zleline + zlecs, zleline + t0, len);
     zlecs += len;
@@ -642,12 +653,19 @@
     int i;
     unsigned char *p = NULL;
 
-    if ((l = bufferwords(NULL, NULL, &i)))
+    if (zmult <= 0)
+	return 1;
+
+    if ((l = bufferwords(NULL, NULL, &i))) {
+	i -= (zmult-1);
+	if (i < 0)
+	    return 1;
         for (n = firstnode(l); n; incnode(n))
             if (!i--) {
                 p = (unsigned char *)getdata(n);
                 break;
             }
+    }
 
     if (p) {
 	int len;
-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070


This message has been scanned for viruses by BlackSpider MailControl - www.blackspider.com


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: copy-prev-word doesn't respect universal argument
  2005-11-02 11:06 ` Peter Stephenson
@ 2005-11-03  3:26   ` Vin Shelton
  0 siblings, 0 replies; 3+ messages in thread
From: Vin Shelton @ 2005-11-03  3:26 UTC (permalink / raw)
  To: Peter Stephenson; +Cc: zsh-users

Peter Stephenson <pws@csr.com> writes:

> Vin Shelton <acs@alumni.princeton.edu> wrote:
>> Why don't copy-prev-word and copy-prev-shell-word respect the
>> universal argument?
>> 
>> Given the following:
>> 
>>   bindkey '^XA' copy-prev-word
>>   echo abc def ghi <ESC>2^XA
>> 
>> I would expect the result to be
>> 
>>   echo abc def ghi def
>> 
>> but zle seems always to copy the most recent word, ('ghi' in this
>> case), yielding:
>> 
>>   echo abc def ghi ghi
>> 
>> no matter what the prefix arg is.  I'm surprised I'm the first person
>> to request this.
>
> I think it's just a question of "when are you going to get around to
> putting up those shelves".

Looks like you did a pretty good job on this set of shelves.  :-)

Thank you, Peter.

  - vin


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2005-11-03  3:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-11-02  3:44 copy-prev-word doesn't respect universal argument Vin Shelton
2005-11-02 11:06 ` Peter Stephenson
2005-11-03  3:26   ` Vin Shelton

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).