zsh-users
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@csr.com>
To: zsh-users@sunsite.dk
Subject: Re: copy-prev-word doesn't respect universal argument
Date: Wed, 2 Nov 2005 11:06:59 +0000	[thread overview]
Message-ID: <20051102110659.0ce2c2b0.pws@csr.com> (raw)
In-Reply-To: <m38xw73e8x.fsf@zion.rcn.com>

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


  reply	other threads:[~2005-11-02 11:07 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-11-02  3:44 Vin Shelton
2005-11-02 11:06 ` Peter Stephenson [this message]
2005-11-03  3:26   ` Vin Shelton

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20051102110659.0ce2c2b0.pws@csr.com \
    --to=pws@csr.com \
    --cc=zsh-users@sunsite.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).