zsh-workers
 help / color / mirror / code / Atom feed
* delete-to-char
@ 1999-09-21  2:52 Vin Shelton
  1999-09-23  2:47 ` delete-to-char Vin Shelton
  0 siblings, 1 reply; 6+ messages in thread
From: Vin Shelton @ 1999-09-21  2:52 UTC (permalink / raw)
  To: zsh-workers

OK, I'm waking up to the new world of modules and I came across the
deltochar module and the delete-to-char function.  I hope I'm not
rehashing an old discussion, but both XEmacs (as of 21.0) and FSF
Emacs (as of at least 20.4) now define zap-to-char as deleting up to
but not including the specified character.  It would be good, IMHO, to
have delete-to-char model that functionality.  Currently
delete-to-char deletes up to and including the specified character.

I can submit a patch if people were amenable to this change.
Whaddaya think?

  - vin


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

* Re: delete-to-char
  1999-09-21  2:52 delete-to-char Vin Shelton
@ 1999-09-23  2:47 ` Vin Shelton
  1999-09-23  9:00   ` delete-to-char Peter Stephenson
  0 siblings, 1 reply; 6+ messages in thread
From: Vin Shelton @ 1999-09-23  2:47 UTC (permalink / raw)
  To: zsh-workers

Not waiting for the bits to dry, I generated this patch.  In the
course of testing this, I found that M-digit did not work for me with
bindkey -me, even though bindkey thinks they are bound to
digit-argument.  M-anydigit just beeps.  "od -x" tells me that M-0
sends 0xb0, M-1 sends 0xb1, etc.  Do I have my xterm/stty settings
wrong, or is this a bug in zsh.

ESC-digit does work, so I did manage to test this.

  - vin

--- Src/Zle/deltochar.c.orig	Wed Jun 23 08:12:25 1999
+++ Src/Zle/deltochar.c	Wed Sep 22 22:24:16 1999
@@ -43,7 +43,8 @@
 	    while (dest != ll && line[dest] != c)
 		dest++;
 	    if (dest != ll) {
-		dest++;
+		if (n > 0)
+		    dest++;
 		if (!n) {
 		    forekill(dest - cs, 0);
 		    ok++;
@@ -59,7 +60,7 @@
 		dest--;
 	    if (line[dest] == c) {
 		if (!n) {
-		    backkill(cs - dest, 1);
+		    backkill(cs - dest - 1, 1);
 		    ok++;
 		}
 		if (dest)
--- Doc/Zsh/mod_deltochar.yo.orig	Tue Jun 22 04:02:49 1999
+++ Doc/Zsh/mod_deltochar.yo	Wed Sep 22 22:28:37 1999
@@ -6,7 +6,7 @@
 tindex(delete-to-char)
 item(tt(delete-to-char))(
 Read a character from the keyboard, and
-delete from the cursor position up to and including the next
+delete from the cursor position up to but not including the next
 (or, with repeat count var(n), the var(n)th) instance of that character.
 )
 enditem()


>>>>> On 20 Sep 1999, I wrote:

Vin> OK, I'm waking up to the new world of modules and I came across the
Vin> deltochar module and the delete-to-char function.  I hope I'm not
Vin> rehashing an old discussion, but both XEmacs (as of 21.0) and FSF
Vin> Emacs (as of at least 20.4) now define zap-to-char as deleting up to
Vin> but not including the specified character.  It would be good, IMHO, to
Vin> have delete-to-char model that functionality.  Currently
Vin> delete-to-char deletes up to and including the specified character.

Vin> I can submit a patch if people were amenable to this change.
Vin> Whaddaya think?

Vin>   - vin



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

* Re: delete-to-char
  1999-09-23  2:47 ` delete-to-char Vin Shelton
@ 1999-09-23  9:00   ` Peter Stephenson
  1999-09-23  9:11     ` delete-to-char Peter Stephenson
  0 siblings, 1 reply; 6+ messages in thread
From: Peter Stephenson @ 1999-09-23  9:00 UTC (permalink / raw)
  To: zsh-workers

Vin Shelton wrote:
> >>>>> On 20 Sep 1999, I wrote:
> 
> Vin> OK, I'm waking up to the new world of modules and I came across the
> Vin> deltochar module and the delete-to-char function.  I hope I'm not
> Vin> rehashing an old discussion, but both XEmacs (as of 21.0) and FSF
> Vin> Emacs (as of at least 20.4) now define zap-to-char as deleting up to
> Vin> but not including the specified character.  It would be good, IMHO, to
> Vin> have delete-to-char model that functionality.  Currently
> Vin> delete-to-char deletes up to and including the specified character.

Sorry, I meant to reply to this before.  I hadn't changed it before,
firstly because I never understood why they changed the behaviour and don't
like the new one, and secondly because since I wrote delete-to-char it's
become easy to do the same thing as a shell function, which I've included
below.  (Actually, until Sven adapted read -k quite recently, it
wasn't that easy.)  But Sven's right that it should really be in a different
widget.  The patch at the end, after the function, uses your code
to adapt the deltochar() function, but only when called from a different
widget zap-to-char; this makes the change very economical.

> Not waiting for the bits to dry, I generated this patch.  In the
> course of testing this, I found that M-digit did not work for me with
> bindkey -me, even though bindkey thinks they are bound to
> digit-argument.  M-anydigit just beeps.  "od -x" tells me that M-0
> sends 0xb0, M-1 sends 0xb1, etc.  Do I have my xterm/stty settings
> wrong, or is this a bug in zsh.

The other meta things, like M-x, work, right?  I'm having the same problem.
I thought it was just my terminal, but maybe it's zsh.  If I type M-1 it
just beeps, but if I type `bindkey "', then a quoted M-1, then `"<RETURN>',
it says
"\M-1" digit-argument
so something a little weird is happening.


emulate -L zsh
setopt extendedglob

integer num=${NUMERIC:-1} ret
local key match mbegin mend oldrbuf="$RBUFFER" oldlbuf="$LBUFFER"

read -k key
while (( num )); do
  if (( num > 0 )); then
    if [[ $RBUFFER = (#b)[^$key]#$key(*) ]]; then
      if (( num == 1 )); then
	RBUFFER=$key${match[1]}
      else
	RBUFFER=${match[1]}
      fi
      (( num-- ))
    else
      ret=1
      RBUFFER="$oldrbuf"
      break
    fi
  else
    if [[ $LBUFFER = (#b)(*)${key}[^$key]# ]]; then
      if (( num == -1 )); then
	LBUFFER=${match[1]}$key
      else
	LBUFFER=${match[1]}
      fi
      (( num++ ))
    else
      ret=1
      LBUFFER="$oldlbuf"
      break
    fi
  fi
done

return $ret


--- Doc/Zsh/mod_deltochar.yo.dc2	Thu Sep 23 10:31:21 1999
+++ Doc/Zsh/mod_deltochar.yo	Thu Sep 23 10:51:15 1999
@@ -1,6 +1,6 @@
 texinode(The deltochar Module)(The example Module)(The complist Module)(Zsh Modules)
 sect(The deltochar Module)
-The tt(deltochar) module makes available one ZLE function:
+The tt(deltochar) module makes available two ZLE functions:
 
 startitem()
 tindex(delete-to-char)
@@ -8,5 +8,11 @@
 Read a character from the keyboard, and
 delete from the cursor position up to and including the next
 (or, with repeat count var(n), the var(n)th) instance of that character.
+Negative repeat counts mean delete backwards.
+)
+tindex(zap-to-char)
+item(tt(zap-to-char))(
+This behaves like tt(delete-to-char), except that the final occurence of
+the character itself is not deleted.
 )
 enditem()
--- Src/Zle/deltochar.c.dc2	Thu Sep 23 10:31:21 1999
+++ Src/Zle/deltochar.c	Thu Sep 23 10:52:27 1999
@@ -31,19 +31,22 @@
 #include "deltochar.pro"
 
 static Widget w_deletetochar;
+static Widget w_zaptochar;
 
 /**/
 static int
 deltochar(char **args)
 {
     int c = getkey(0), dest = cs, ok = 0, n = zmult;
+    int zap = (bindk->widget == w_zaptochar);
 
     if (n > 0) {
 	while (n-- && dest != ll) {
 	    while (dest != ll && line[dest] != c)
 		dest++;
 	    if (dest != ll) {
-		dest++;
+		if (!zap || n > 0)
+		    dest++;
 		if (!n) {
 		    forekill(dest - cs, 0);
 		    ok++;
@@ -59,7 +62,7 @@
 		dest--;
 	    if (line[dest] == c) {
 		if (!n) {
-		    backkill(cs - dest, 1);
+		    backkill(cs - dest - zap, 1);
 		    ok++;
 		}
 		if (dest)
@@ -83,9 +86,14 @@
 {
     w_deletetochar = addzlefunction("delete-to-char", deltochar,
                                     ZLE_KILL | ZLE_KEEPSUFFIX);
-    if (w_deletetochar)
-	return 0;
-    zwarnnam(m->nam, "name clash when adding ZLE function `delete-to-char'",
+    if (w_deletetochar) {
+	w_zaptochar = addzlefunction("zap-to-char", deltochar,
+				     ZLE_KILL | ZLE_KEEPSUFFIX);
+	if (w_zaptochar)
+	    return 0;
+	deletezlefunction(w_deletetochar);
+    }
+    zwarnnam(m->nam, "deltochar: name clash when adding ZLE functions",
 	     NULL, 0);
     return -1;
 }
@@ -97,6 +105,7 @@
 cleanup_deltochar(Module m)
 {
     deletezlefunction(w_deletetochar);
+    deletezlefunction(w_zaptochar);
     return 0;
 }
 
-- 
Peter Stephenson <pws@ibmth.df.unipi.it>       Tel: +39 050 844536
WWW:  http://www.ifh.de/~pws/
Dipartimento di Fisica, Via Buonarroti 2, 56127 Pisa, Italy


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

* Re: delete-to-char
  1999-09-23  9:00   ` delete-to-char Peter Stephenson
@ 1999-09-23  9:11     ` Peter Stephenson
  0 siblings, 0 replies; 6+ messages in thread
From: Peter Stephenson @ 1999-09-23  9:11 UTC (permalink / raw)
  To: zsh-workers

Peter Stephenson wrote:
> Vin Shelton wrote:
> > In the
> > course of testing this, I found that M-digit did not work for me with
> > bindkey -me, even though bindkey thinks they are bound to
> > digit-argument.  M-anydigit just beeps.  "od -x" tells me that M-0
> > sends 0xb0, M-1 sends 0xb1, etc.  Do I have my xterm/stty settings
> > wrong, or is this a bug in zsh.
> 
> The other meta things, like M-x, work, right?  I'm having the same problem.
> I thought it was just my terminal, but maybe it's zsh.  If I type M-1 it
> just beeps, but if I type `bindkey "', then a quoted M-1, then `"<RETURN>',
> it says
> "\M-1" digit-argument
> so something a little weird is happening.

Guess who generated this bug?  Bart complained that non-digits were doing
weird things when attached to digit-argument, so I `fixed' it.  This
restores handling of metafied as well as normal digits.

--- Src/Zle/zle_misc.c.dig	Wed Jul  7 09:32:06 1999
+++ Src/Zle/zle_misc.c	Thu Sep 23 11:08:46 1999
@@ -458,7 +458,8 @@
 {
     int sign = (zmult < 0) ? -1 : 1;
 
-    if (c < '0' || c > '9')
+    /* allow metafied as well as ordinary digits */
+    if ((c & 0x7f) < '0' || (c & 0x7f) > '9')
 	return 1;
 
     if (!(zmod.flags & MOD_TMULT))

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


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

* Re: delete-to-char
  1999-09-23  9:01 delete-to-char Sven Wischnowsky
@ 1999-09-23 12:05 ` Vin Shelton
  0 siblings, 0 replies; 6+ messages in thread
From: Vin Shelton @ 1999-09-23 12:05 UTC (permalink / raw)
  To: zsh-workers


Vin Shelton wrote:
>> Not waiting for the bits to dry, I generated this patch.

>>>>> On Thu, 23 Sep 1999, Sven Wischnowsky <wischnow@informatik.hu-berlin.de> said:

Sven> Hm, I don't use this, but I had expacted that you would just add
Sven> a second widget `zap-to-char' to the module giving the behaviour
Sven> you wanted. Maaybe there are people using deltochar and you have
Sven> just stepped on their toes.

Of course you're right.  Thanks Peter, for turning my work into
something more useful.

  - vin


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

* Re: delete-to-char
@ 1999-09-23  9:01 Sven Wischnowsky
  1999-09-23 12:05 ` delete-to-char Vin Shelton
  0 siblings, 1 reply; 6+ messages in thread
From: Sven Wischnowsky @ 1999-09-23  9:01 UTC (permalink / raw)
  To: zsh-workers


Vin Shelton wrote:

> Not waiting for the bits to dry, I generated this patch.

Hm, I don't use this, but I had expacted that you would just add a
second widget `zap-to-char' to the module giving the behaviour you
wanted. Maaybe there are people using deltochar and you have just
stepped on their toes.


Bye
 Sven


--
Sven Wischnowsky                         wischnow@informatik.hu-berlin.de


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

end of thread, other threads:[~1999-09-23 12:01 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-09-21  2:52 delete-to-char Vin Shelton
1999-09-23  2:47 ` delete-to-char Vin Shelton
1999-09-23  9:00   ` delete-to-char Peter Stephenson
1999-09-23  9:11     ` delete-to-char Peter Stephenson
1999-09-23  9:01 delete-to-char Sven Wischnowsky
1999-09-23 12:05 ` delete-to-char Vin Shelton

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