Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

PATCH: 3.1.4: alternative universal-argument upgrade



I wrote:
> Is it OK to assume 0..9 and - are bound to self-insert?  It's a little
> messier to test for them earlier

One day I'm going to be able to fix things in a single patch, but
until then...

Zsh has a perfectly workable key-ungetting mechanism, so here's a
different, self contained patch to make universal-argument take
(positive or negative) integers after it, which doesn't rely on any
special behaviour bound to the digit keys or minus.  I'm not aware of
any problems with this approach; it should work fine in any
key-binding mode.

As this version is self-contained, it does not include the
neg-argument fix in 4420 this time, so that has to be applied as well
(again, sorry).

*** Doc/Zsh/zle.yo.mult2	Mon Oct 12 10:22:19 1998
--- Doc/Zsh/zle.yo	Mon Oct 12 10:23:23 1998
***************
*** 779,785 ****
  )
  tindex(universal-argument)
  item(tt(universal-argument))(
! Multiply the argument of the next command by 4.
  )
  enditem()
  texinode(Completion)(Miscellaneous)(Arguments)(Zsh Line Editor)
--- 779,791 ----
  )
  tindex(universal-argument)
  item(tt(universal-argument))(
! Multiply the argument of the next command by 4.  Alternatively, if
! this command is followed by an integer (positive or negative), use
! that as the argument for the next command.  Thus digits cannot be
! repeated using this command.  For example, if this command occurs
! twice, followed immediately by tt(forward-char), move forward sixteen
! spaces; if instead it is followed by tt(-2), then tt(forward-char),
! move backward two spaces.
  )
  enditem()
  texinode(Completion)(Miscellaneous)(Arguments)(Zsh Line Editor)
*** Src/Zle/zle_misc.c.mult2	Mon Oct 12 10:20:27 1998
--- Src/Zle/zle_misc.c	Mon Oct 12 10:32:03 1998
***************
*** 470,476 ****
  void
  universalargument(void)
  {
!     zmod.tmult *= 4;
      zmod.flags |= MOD_TMULT;
      prefixflag = 1;
  }
--- 470,494 ----
  void
  universalargument(void)
  {
!     int digcnt = 0, pref = 0, minus = 1, gotk;
!     while ((gotk = getkey(0)) != EOF) {
! 	if (gotk == '-' && !digcnt) {
! 	    minus = -1;
! 	    digcnt++;
! 	} else if (gotk >= '0' && gotk <= '9') {
! 	    pref = pref * 10 + (gotk & 0xf);
! 	    digcnt++;
! 	} else {
! 	    /* why is ungetkey() static? */
! 	    char kgot = gotk;
! 	    ungetkeys(&kgot, 1);
! 	    break;
! 	}
!     }
!     if (digcnt)
! 	zmod.tmult = minus * (pref ? pref : 1);
!     else
! 	zmod.tmult *= 4;
      zmod.flags |= MOD_TMULT;
      prefixflag = 1;
  }

-- 
Peter Stephenson <pws@xxxxxxxxxxxxxxxxx>       Tel: +39 050 844536
WWW:  http://www.ifh.de/~pws/
Dipartimento di Fisica, Via Buonarotti 2, 56100 Pisa, Italy



Messages sorted by: Reverse Date, Date, Thread, Author