zsh-workers
 help / color / mirror / code / Atom feed
From: "Ingo Wilken" <Ingo.Wilken@Informatik.Uni-Oldenburg.DE>
To: zsh-workers@math.gatech.edu
Cc: ingo@pyrit.Informatik.Uni-Oldenburg.DE (Ingo Wilken)
Subject: two new key commands for 3.0.4
Date: Fri, 4 Jul 1997 03:23:34 +0200 (MET DST)	[thread overview]
Message-ID: <m0wjx5z-000AgCC@pyrit.Informatik.Uni-Oldenburg.DE> (raw)

Hello,

I once used a PD shell on a non-Unix system that had two key commands
that I missed ever since.  zsh has something the comes close, but not
quite.

The first is almost the same as the copy-prev-word command, except that
it should ignore the word the cursor is in or adjacent to:
    Case 1:  ~> echo foo bar []
    Case 2:  ~> echo foo bar[]
    Case 3:  ~> echo foo b[a]r
[] ist the cursor.  copy-prev-word copies "bar" in case 1 and 2, and a "b"
in case 3.  I wanted a command that copies "bar" in case 1, and "foo" in
case 2 and 3.  I could not think of a better name, so I called it
copy-prev-word-skip for now.

The second copies all arguments from the previous command, similar to
insert-last-word, but it should always copy _all_ words except the first.
I called it insert-last-args.  As with insert-last-word, using this
command repeatedly cycles through the history.

The patch below implements both commands for zsh 3.0.4.  I am not sub-
scribed to any of the zsh mailing lists, so please Cc: all replies to me.

Regards,
Ingo

--- cut here ---
diff -cr zsh-3.0.4/Src/zle.h zsh-3.0.4b/Src/zle.h
*** zsh-3.0.4/Src/zle.h	Tue Jun  3 07:11:24 1997
--- zsh-3.0.4b/Src/zle.h	Thu Jul  3 21:46:38 1997
***************
*** 293,298 ****
--- 293,299 ----
      z_clearscreen,
      z_completeword,
      z_copyprevword,
+     z_copyprevwordskip,
      z_copyregionaskill,
      z_deletechar,
      z_deletecharorlist,
***************
*** 328,333 ****
--- 329,335 ----
      z_historysearchbackward,
      z_historysearchforward,
      z_infernexthistory,
+     z_insertlastargs,
      z_insertlastword,
      z_killbuffer,
      z_killline,
diff -cr zsh-3.0.4/Src/zle_bindings.c zsh-3.0.4b/Src/zle_bindings.c
*** zsh-3.0.4/Src/zle_bindings.c	Fri Jun 28 15:43:51 1996
--- zsh-3.0.4b/Src/zle_bindings.c	Thu Jul  3 21:46:30 1997
***************
*** 53,58 ****
--- 53,59 ----
      {"clear-screen", clearscreen, ZLE_MENUCMP},
      {"complete-word", completeword, ZLE_MENUCMP},
      {"copy-prev-word", copyprevword, 0},
+     {"copy-prev-word-skip", copyprevwordskip, 0},
      {"copy-region-as-kill", copyregionaskill, ZLE_KILL},
      {"delete-char", deletechar, ZLE_DELETE},
      {"delete-char-or-list", deletecharorlist, ZLE_MENUCMP},
***************
*** 88,93 ****
--- 89,95 ----
      {"history-search-backward", historysearchbackward, ZLE_HISTSEARCH},
      {"history-search-forward", historysearchforward, ZLE_HISTSEARCH},
      {"infer-next-history", infernexthistory, 0},
+     {"insert-last-args", insertlastargs, 0},
      {"insert-last-word", insertlastword, ZLE_INSERT},
      {"kill-buffer", killbuffer, ZLE_KILL},
      {"kill-line", killline, ZLE_KILL},
diff -cr zsh-3.0.4/Src/zle_hist.c zsh-3.0.4b/Src/zle_hist.c
*** zsh-3.0.4/Src/zle_hist.c	Tue Dec 17 21:14:11 1996
--- zsh-3.0.4b/Src/zle_hist.c	Thu Jul  3 22:41:22 1997
***************
*** 504,509 ****
--- 504,566 ----
      while (len--) {
  	line[cs++] = *s == Meta ? *++s ^ 32 : *s;
  	s++;
+     }
+ 
+     *t = save;
+ }
+ 
+ /**/
+ void
+ insertlastargs(void)
+ {
+     Histent he;
+     char *s, *t;
+     int len;
+ 
+     static char *lastinsert;
+     static int lasthist, lastpos;
+     int evhist, save;
+ 
+     if (!zmult)
+         zmult = 1;
+     evhist = curhist - zmult;
+ 
+     if (lastinsert) {
+         int lastlen = strlen(lastinsert);
+         int pos = cs;
+ 
+         if (lastpos <= pos &&
+             lastlen == pos - lastpos &&
+             memcmp(lastinsert, (char *)&line[lastpos], lastlen) == 0) {
+             evhist = lasthist - zmult;
+             cs = lastpos;
+             foredel(pos - cs);
+         }
+         zsfree(lastinsert);
+         lastinsert = NULL;
+     }
+     if (!(he = quietgethist(evhist))) {
+         feep();
+         return;
+     }
+ 
+     s = t = he->text;
+     if (he->nwords >= 2) {
+         t += he->words[2*he->nwords-1];
+         s += he->words[2];
+     }
+     save = *t;
+     *t = '\0';  /* ignore trailing whitespace */
+ 
+     lasthist = evhist;
+     lastpos = cs;
+     lastinsert = ztrdup(s);
+ 
+     len = ztrlen(s);
+     spaceinline(len);
+     while (len--) {
+         line[cs++] = *s == Meta ? *++s ^ 32 : *s;
+         s++;
      }
  
      *t = save;
diff -cr zsh-3.0.4/Src/zle_misc.c zsh-3.0.4b/Src/zle_misc.c
*** zsh-3.0.4/Src/zle_misc.c	Tue Jun  3 07:11:25 1997
--- zsh-3.0.4b/Src/zle_misc.c	Thu Jul  3 19:34:29 1997
***************
*** 447,452 ****
--- 447,486 ----
      len = cs - t0;
      spaceinline(len);
      memcpy((char *)&line[cs], (char *)&line[t0], len);
+     cs += len;
+ }
+ 
+ /**/
+ void
+ copyprevwordskip(void)
+ {
+     int len, t0, t1, t2;
+ 
+     t2 = t1 = 0;
+     t0 = cs - 1;
+     /* if adjacent to a word, skip it */
+     if (iword(line[t0])) {
+         t2 = cs;
+         for (; t0 >= 0; t0--)
+             if (!iword(line[t0]))
+                 break;
+         t1 = t0 + 1;
+     }
+     /* now skip whitespace */
+     for (; t0 >= 0; t0--)
+         if (iword(line[t0]))
+             break;
+     if (t0 >= 0) {
+         t2 = t0 + 1;
+         /* skip over the word */
+         for (; t0 >= 0; t0--)
+             if (!iword(line[t0]))
+                 break;
+         t1 = t0 + 1;
+     }
+     len = t2 - t1;
+     spaceinline(len);
+     memcpy((char *)&line[cs], (char *)&line[t1], len);
      cs += len;
  }
  
--- cut here ---


             reply	other threads:[~1997-07-04  1:40 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-07-04  1:23 Ingo Wilken [this message]
1997-07-04  3:47 ` Geoff Wing
1997-07-04 13:29 ` Peter Stephenson

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=m0wjx5z-000AgCC@pyrit.Informatik.Uni-Oldenburg.DE \
    --to=ingo.wilken@informatik.uni-oldenburg.de \
    --cc=ingo@pyrit.Informatik.Uni-Oldenburg.DE \
    --cc=zsh-workers@math.gatech.edu \
    /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).