zsh-workers
 help / color / mirror / code / Atom feed
* two new key commands for 3.0.4
@ 1997-07-04  1:23 Ingo Wilken
  1997-07-04  3:47 ` Geoff Wing
  1997-07-04 13:29 ` Peter Stephenson
  0 siblings, 2 replies; 3+ messages in thread
From: Ingo Wilken @ 1997-07-04  1:23 UTC (permalink / raw)
  To: zsh-workers; +Cc: Ingo Wilken

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 ---


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

* Re: two new key commands for 3.0.4
  1997-07-04  1:23 two new key commands for 3.0.4 Ingo Wilken
@ 1997-07-04  3:47 ` Geoff Wing
  1997-07-04 13:29 ` Peter Stephenson
  1 sibling, 0 replies; 3+ messages in thread
From: Geoff Wing @ 1997-07-04  3:47 UTC (permalink / raw)
  To: zsh-workers

Ingo Wilken <Ingo.Wilken@Informatik.Uni-Oldenburg.DE> typed:
: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.

I don't think we really need to `bloat' zsh with almost-the-same functions,
especially with 3.0.* being the `stable branch' with only bug-fixes now.
I'm sure you could do both with  zle  and  bindkey  in 3.1.2-beta
-- 
Geoff Wing [mason@primenet.com.au]   Technical Manager
  Phone    : +61-3-9818 2977         PrimeNet - Internet Consultancy
  Facsimile: +61-3-9819 3788         Web : <URL:http://www.primenet.com.au/>
  Mobile   : 0412 162 441


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

* Re: two new key commands for 3.0.4
  1997-07-04  1:23 two new key commands for 3.0.4 Ingo Wilken
  1997-07-04  3:47 ` Geoff Wing
@ 1997-07-04 13:29 ` Peter Stephenson
  1 sibling, 0 replies; 3+ messages in thread
From: Peter Stephenson @ 1997-07-04 13:29 UTC (permalink / raw)
  To: Ingo Wilken, Zsh hackers list

"Ingo Wilken" wrote:
> copy-prev-word-skip
>
> insert-last-args

Unless you have turned off !-history (setopt nobanghist),
insert-last-args can be done by typing !*<TAB>.  (One day it will be
possible to do this within a shell function and turn on ! for the
duration of the function.)

As far as copy-prev-word-skip is concerned, I think the following is
preferable: it alters copy-prev-word to use its prefix argument to
copy words before the last, so that putting <ESC>2 in front will have
the effect you want.  (Arguably, it should have done this all along.)
This patch is against 3.1; the code has migrated a bit and may need a
little massaging for 3.0 but won't have to change fundamentally.

*** Doc/Zsh/zle.yo.cpw	Mon Apr 28 06:21:52 1997
--- Doc/Zsh/zle.yo	Fri Jul  4 15:01:33 1997
***************
*** 550,556 ****
  )
  tindex(copy-prev-word)
  item(tt(copy-prev-word) (ESC-^_) (unbound) (unbound))(
! Duplicate the word behind the cursor.
  )
  tindex(vi-delete)
  item(tt(vi-delete) (unbound) (d) (unbound))(
--- 550,557 ----
  )
  tindex(copy-prev-word)
  item(tt(copy-prev-word) (ESC-^_) (unbound) (unbound))(
! Duplicate the whitespace-delimited word behind the cursor.  With a
! prefix argument greater than one, copy the word so many back instead.
  )
  tindex(vi-delete)
  item(tt(vi-delete) (unbound) (d) (unbound))(
*** Src/Zle/zle_misc.c.cpw	Sun Jun  1 07:50:37 1997
--- Src/Zle/zle_misc.c	Fri Jul  4 14:55:07 1997
***************
*** 508,524 ****
  void
  copyprevword(void)
  {
!     int len, t0;
  
!     for (t0 = cs - 1; t0 >= 0; t0--)
! 	if (iword(line[t0]))
! 	    break;
!     for (; t0 >= 0; t0--)
! 	if (!iword(line[t0]))
! 	    break;
      if (t0)
  	t0++;
!     len = cs - t0;
      spaceinline(len);
      memcpy((char *)&line[cs], (char *)&line[t0], len);
      cs += len;
--- 508,528 ----
  void
  copyprevword(void)
  {
!     int len, t0 = cs - 1, start = cs, m = zmult;
  
!     do {
! 	for (; t0 >= 0; t0--)
! 	    if (iword(line[t0]))
! 		break;
! 	if (zmult > 1 && m)
! 	    start = t0 + 1;
! 	for (; t0 >= 0; t0--)
! 	    if (!iword(line[t0]))
! 		break;
!     } while (--m > 0 && t0);
      if (t0)
  	t0++;
!     len = start - t0;
      spaceinline(len);
      memcpy((char *)&line[cs], (char *)&line[t0], len);
      cs += len;

-- 
Peter Stephenson <pws@ifh.de>       Tel: +49 33762 77366
WWW:  http://www.ifh.de/~pws/       Fax: +49 33762 77413
Deutsches Elektronen-Synchrotron --- Institut fuer Hochenergiephysik Zeuthen
DESY-IfH, 15735 Zeuthen, Germany.


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

end of thread, other threads:[~1997-07-04 13:38 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-07-04  1:23 two new key commands for 3.0.4 Ingo Wilken
1997-07-04  3:47 ` Geoff Wing
1997-07-04 13:29 ` Peter Stephenson

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).