zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: 3.1.4: (alternative) neg-argument fix
@ 1998-10-09 11:25 Peter Stephenson
  1998-10-09 15:44 ` Bart Schaefer
  0 siblings, 1 reply; 4+ messages in thread
From: Peter Stephenson @ 1998-10-09 11:25 UTC (permalink / raw)
  To: Zsh hackers list

There was a patch from Bart back in zsh-workers/4268 to fix a problem
with neg-argument (\e- in emacs mode), namely \e-\e1 gave you 11
instead of 1 and so on.  Now I come to look at this, I can't get it to
work, i.e. neg-argument won't function at all.  I can't think of
anything that might be clashing with the patch, thought it's not
impossible.

However, even if I've done something silly there is the following
point: \e- on its own should act as an argument -1 even if no further
digit is typed.  It's only when you get back to digitargument() for a
new digit, if any, that you need to know whether an existing -1 should
be treated as a real -1 (e.g you already typed \e-\e1) or not (you've
only just typed \e-).  I couldn't see a way of doing this without
adding a new flag, though that doesn't mean there isn't one.  This
therefore is my alternative version of 4268.

Is there any enthusiasm for upgrading universal-argument to do what
emacs does, that is to take any following digits as part of the
argument?

*** Src/Zle/zle.h.mult	Thu Jul  9 13:27:28 1998
--- Src/Zle/zle.h	Fri Oct  9 11:28:26 1998
***************
*** 90,95 ****
--- 90,96 ----
  #define MOD_TMULT (1<<1)   /* a repeat count is being entered */
  #define MOD_VIBUF (1<<2)   /* a vi cut buffer has been selected */
  #define MOD_VIAPP (1<<3)   /* appending to the vi cut buffer */
+ #define MOD_NEG   (1<<4)   /* last command was negate argument */
  
  /* current modifier status */
  
*** Src/Zle/zle_misc.c.mult	Thu Jul  9 12:04:41 1998
--- Src/Zle/zle_misc.c	Fri Oct  9 11:28:38 1998
***************
*** 442,448 ****
  
      if (!(zmod.flags & MOD_TMULT))
  	zmod.tmult = 0;
!     zmod.tmult = zmod.tmult * 10 + sign * (c & 0xf);
      zmod.flags |= MOD_TMULT;
      prefixflag = 1;
  }
--- 442,454 ----
  
      if (!(zmod.flags & MOD_TMULT))
  	zmod.tmult = 0;
!     if (zmod.flags & MOD_NEG) {
! 	/* If we just had a negative argument, this is the digit, *
! 	 * rather than the -1 assumed by negargument()            */
! 	zmod.tmult = sign * (c & 0xf);
! 	zmod.flags &= ~MOD_NEG;
!     } else
! 	zmod.tmult = zmod.tmult * 10 + sign * (c & 0xf);
      zmod.flags |= MOD_TMULT;
      prefixflag = 1;
  }
***************
*** 456,462 ****
  	return;
      }
      zmod.tmult = -1;
!     zmod.flags |= MOD_TMULT;
      prefixflag = 1;
  }
  
--- 462,468 ----
  	return;
      }
      zmod.tmult = -1;
!     zmod.flags |= MOD_TMULT|MOD_NEG;
      prefixflag = 1;
  }
  

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


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

* Re: PATCH: 3.1.4: (alternative) neg-argument fix
  1998-10-09 11:25 PATCH: 3.1.4: (alternative) neg-argument fix Peter Stephenson
@ 1998-10-09 15:44 ` Bart Schaefer
  1998-10-10 16:33   ` PATCH: 3.1.4: universal-argument upgrade Peter Stephenson
  0 siblings, 1 reply; 4+ messages in thread
From: Bart Schaefer @ 1998-10-09 15:44 UTC (permalink / raw)
  To: Zsh hackers list

On Oct 9,  1:25pm, Peter Stephenson wrote:
} Subject: PATCH: 3.1.4: (alternative) neg-argument fix
}
} There was a patch from Bart back in zsh-workers/4268 to fix a problem
} with neg-argument (\e- in emacs mode), namely \e-\e1 gave you 11
} instead of 1 and so on.  Now I come to look at this, I can't get it to
} work, i.e. neg-argument won't function at all.

Hmm.  I believe you're right.  I changed the 3.1.4 code to match the
equivalent code in 3.0.5, but I missed that digitargument() zeros
zmod.tmult when MOD_TMULT isn't flagged.  (3.0.5 never zeroes zmult,
and always multiplies by it.)

} I couldn't see a way of doing this without
} adding a new flag, though that doesn't mean there isn't one.

Has the whole multiplier thing become more complicated than necessary in
3.1.4?  MOD_TMULT obviously does more than the `gotmult' global in 3.0.5
did.

In any case, Peter's patch is preferable to mine.

} Is there any enthusiasm for upgrading universal-argument to do what
} emacs does, that is to take any following digits as part of the
} argument?

YES!  That would be so much easier than having to clamp down Alt or hit
ESC repeatedly to enter the digits.  Just remember that it also needs
to take a following `-' as part of the argument.

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com


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

* PATCH: 3.1.4: universal-argument upgrade
  1998-10-09 15:44 ` Bart Schaefer
@ 1998-10-10 16:33   ` Peter Stephenson
  1998-10-12  8:37     ` PATCH: 3.1.4: alternative " Peter Stephenson
  0 siblings, 1 reply; 4+ messages in thread
From: Peter Stephenson @ 1998-10-10 16:33 UTC (permalink / raw)
  To: Zsh hackers list

"Bart Schaefer" wrote:
> } I couldn't see a way of doing this without
> } adding a new flag, though that doesn't mean there isn't one.
> 
> Has the whole multiplier thing become more complicated than necessary in
> 3.1.4?  MOD_TMULT obviously does more than the `gotmult' global in 3.0.5
> did.

Looks like it, I have to admit I was confused to begin with.

> } Is there any enthusiasm for upgrading universal-argument to do what
> } emacs does, that is to take any following digits as part of the
> } argument?
> 
> YES!  That would be so much easier than having to clamp down Alt or hit
> ESC repeatedly to enter the digits.  Just remember that it also needs
> to take a following `-' as part of the argument.

OK, here it is.  This replaces the previous patch, since instead of
MOD_NEG I use MOD_REPL:  a 4 from universal-argument becomes
replaceable in the same way as a -1 from neg-argument.  It remains
unbound by default.  It's annoying that ^U for backward-kill-line is
so engrained in the shell-user psyche.

The only compatibility issue is that you can't repeat digits with
universal-argument, i.e (after rebinding universal-argument to ^U)
^U2 doesn't give you four twos any more, for obvious reasons.  I take
it this is entirely minor.

Is it OK to assume 0..9 and - are bound to self-insert?  It's a little
messier to test for them earlier: the problem is that you can't tell
after you've retrieved the binding whether it was a real `0' etc. or a
multi-key sequence ending in `0' such as `^X0', since that information
is buried inside getkeymapcmd() --- which I don't want to hack about
--- and on the latter occasion you certainly don't want digit-argument
behaviour.  It means it won't work in vi command mode, although the
digit handling is in any case different there.  (Actually, that's a
partial lie: unless you attempt to enter a -, it looks like it works
OK because the normal vi digit behaviour comes into play after you
enter universal-argument, i.e. the latter is then ignored.)

*** Doc/Zsh/zle.yo.mult	Sun May 11 13:24:01 1997
--- Doc/Zsh/zle.yo	Sat Oct 10 18:06:25 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,792 ----
  )
  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.  Note that this assumes the digits and dash
! are bound to tt(self-insert), as is usually the case.
  )
  enditem()
  texinode(Completion)(Miscellaneous)(Arguments)(Zsh Line Editor)
*** Src/Zle/zle.h.mult	Thu Jul  9 13:27:28 1998
--- Src/Zle/zle.h	Sat Oct 10 18:04:44 1998
***************
*** 90,95 ****
--- 90,97 ----
  #define MOD_TMULT (1<<1)   /* a repeat count is being entered */
  #define MOD_VIBUF (1<<2)   /* a vi cut buffer has been selected */
  #define MOD_VIAPP (1<<3)   /* appending to the vi cut buffer */
+ #define MOD_REPL  (1<<4)   /* current tmult is replaceable */
+ #define MOD_UNIV  (1<<5)   /* universal argument in progress */
  
  /* current modifier status */
  
*** Src/Zle/zle_misc.c.mult	Thu Jul  9 12:04:41 1998
--- Src/Zle/zle_misc.c	Sat Oct 10 17:48:56 1998
***************
*** 62,67 ****
--- 62,76 ----
  {
      char s[3], *p = s;
  
+     if (zmod.flags & MOD_UNIV) {
+ 	if (c >= '0' && c <= '9') {
+ 	    digitargument();
+ 	    return;
+ 	} else if (c == '-' && (zmod.flags & MOD_REPL)) {
+ 	    negargument();
+ 	    return;
+ 	}
+     }
      if(imeta(c)) {
  	*p++ = Meta;
  	c ^= 32;
***************
*** 442,448 ****
  
      if (!(zmod.flags & MOD_TMULT))
  	zmod.tmult = 0;
!     zmod.tmult = zmod.tmult * 10 + sign * (c & 0xf);
      zmod.flags |= MOD_TMULT;
      prefixflag = 1;
  }
--- 451,463 ----
  
      if (!(zmod.flags & MOD_TMULT))
  	zmod.tmult = 0;
!     if (zmod.flags & MOD_REPL) {
! 	/* If we just had a negative or universal argument, this is *
! 	 * the digit, rather than the -1 or 4 at first assumed.     */
! 	zmod.tmult = sign * (c & 0xf);
! 	zmod.flags &= ~MOD_REPL;
!     } else
! 	zmod.tmult = zmod.tmult * 10 + sign * (c & 0xf);
      zmod.flags |= MOD_TMULT;
      prefixflag = 1;
  }
***************
*** 451,462 ****
  void
  negargument(void)
  {
!     if(zmod.flags & MOD_TMULT) {
  	feep();
  	return;
      }
      zmod.tmult = -1;
!     zmod.flags |= MOD_TMULT;
      prefixflag = 1;
  }
  
--- 466,478 ----
  void
  negargument(void)
  {
!     if((zmod.flags & MOD_TMULT) && 
!        (zmod.flags & (MOD_REPL|MOD_UNIV)) != (MOD_REPL|MOD_UNIV)) {
  	feep();
  	return;
      }
      zmod.tmult = -1;
!     zmod.flags |= MOD_TMULT|MOD_REPL;
      prefixflag = 1;
  }
  
***************
*** 465,471 ****
  universalargument(void)
  {
      zmod.tmult *= 4;
!     zmod.flags |= MOD_TMULT;
      prefixflag = 1;
  }
  
--- 481,487 ----
  universalargument(void)
  {
      zmod.tmult *= 4;
!     zmod.flags |= MOD_TMULT|MOD_UNIV|MOD_REPL;
      prefixflag = 1;
  }
  
  
-- 
Peter Stephenson <pws@ibmth.df.unipi.it>       Tel: +39 050 844536
WWW:  http://www.ifh.de/~pws/
Dipartimento di Fisica, Via Buonarotti 2, 56100 Pisa, Italy


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

* PATCH: 3.1.4: alternative universal-argument upgrade
  1998-10-10 16:33   ` PATCH: 3.1.4: universal-argument upgrade Peter Stephenson
@ 1998-10-12  8:37     ` Peter Stephenson
  0 siblings, 0 replies; 4+ messages in thread
From: Peter Stephenson @ 1998-10-12  8:37 UTC (permalink / raw)
  To: Zsh hackers list

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@ibmth.df.unipi.it>       Tel: +39 050 844536
WWW:  http://www.ifh.de/~pws/
Dipartimento di Fisica, Via Buonarotti 2, 56100 Pisa, Italy


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

end of thread, other threads:[~1998-10-12  8:56 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-10-09 11:25 PATCH: 3.1.4: (alternative) neg-argument fix Peter Stephenson
1998-10-09 15:44 ` Bart Schaefer
1998-10-10 16:33   ` PATCH: 3.1.4: universal-argument upgrade Peter Stephenson
1998-10-12  8:37     ` PATCH: 3.1.4: alternative " 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).