zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: list bindings with given prefix.
@ 2001-03-28 15:17 Peter Stephenson
  2001-04-01 15:11 ` Oliver Kiddle
  0 siblings, 1 reply; 3+ messages in thread
From: Peter Stephenson @ 2001-03-28 15:17 UTC (permalink / raw)
  To: Zsh hackers list

This allows `bindkey -p <seq>' to list bindings which have <seq> as a
prefix (not counting bindings for <seq> itself).  The previous unposted zle
change is necessary to apply the documentation hunk, unfortunately (or just
apply it to mod_zle.yo).  This is the simplest change rather than the most
efficient, but I don't think that's a problem here.

I can't absolutely guarantee this doesn't have some odd effect in
combination with the code that handles ranges, but it doesn't look like
it.  I'm pretty confident it doesn't mess up any functionality there
already.

If it seems to work I'll attempt to write a routine to delete bindings
using the same logic.

Index: Src/Zle/zle_keymap.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/zle_keymap.c,v
retrieving revision 1.5
diff -u -r1.5 zle_keymap.c
--- Src/Zle/zle_keymap.c	2001/03/14 12:20:18	1.5
+++ Src/Zle/zle_keymap.c	2001/03/28 15:08:11
@@ -86,6 +86,8 @@
     char *lastseq;
     Thingy bind;
     char *str;
+    char *prefix;
+    int prefixlen;
 };
 
 #define BS_LIST (1<<0)
@@ -890,7 +892,7 @@
 
     bs.flags = ops['L'] ? BS_LIST : 0;
     bs.kmname = kmname;
-    if(argv[0]) {
+    if(argv[0] && !ops['p']) {
 	int len;
 	char *seq;
 
@@ -899,8 +901,22 @@
 	bs.flags |= BS_ALL;
 	bs.firstseq = bs.lastseq = seq;
 	bs.bind = keybind(km, seq, &bs.str);
+	bs.prefix = NULL;
+	bs.prefixlen = 0;
 	bindlistout(&bs);
     } else {
+	/* empty prefix is equivalent to no prefix */
+	if (ops['p'] && (!argv[0] || argv[0][0])) {
+	    if (!argv[0]) {
+		zwarnnam(name, "option -p requires a prefix string", NULL, 0);
+		return 1;
+	    }
+	    bs.prefix = getkeystring(argv[0], &bs.prefixlen, 2, NULL);
+	    bs.prefix = metafy(bs.prefix, bs.prefixlen, META_HREALLOC);
+	} else {
+	    bs.prefix = NULL;
+	    bs.prefixlen = 0;
+	}
 	bs.firstseq = ztrdup("");
 	bs.lastseq = ztrdup("");
 	bs.bind = t_undefinedkey;
@@ -918,6 +934,10 @@
 scanbindlist(char *seq, Thingy bind, char *str, void *magic)
 {
     struct bindstate *bs = magic;
+
+    if (bs->prefixlen &&
+	(strncmp(seq, bs->prefix, bs->prefixlen) || !seq[bs->prefixlen]))
+	return;
 
     if(bind == bs->bind && (bind || !strcmp(str, bs->str)) &&
        ztrlen(seq) == 1 && ztrlen(bs->lastseq) == 1) {
Index: Doc/Zsh/zle.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/zle.yo,v
retrieving revision 1.11
diff -u -r1.11 zle.yo
--- Doc/Zsh/zle.yo	2001/03/28 14:39:58	1.11
+++ Doc/Zsh/zle.yo	2001/03/28 15:08:11
@@ -195,6 +195,10 @@
 displayed - the implicit linking of keymaps is the only thing that
 happens.)
 
+When the option tt(-p) is used, the var(in-string) must be present.
+The listing shows all bindings which have the given key sequence as a
+prefix, not including any bindings for the key sequence itself.
+
 When the tt(-L) option is used, the list is in the form of tt(bindkey)
 commands to create the key bindings.
 )

-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR Ltd., Unit 300, Science Park, Milton Road,
Cambridge, CB4 0XL, UK                          Tel: +44 (0)1223 392070


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

* Re: PATCH: list bindings with given prefix.
  2001-03-28 15:17 PATCH: list bindings with given prefix Peter Stephenson
@ 2001-04-01 15:11 ` Oliver Kiddle
  2001-04-03 19:00   ` Bart Schaefer
  0 siblings, 1 reply; 3+ messages in thread
From: Oliver Kiddle @ 2001-04-01 15:11 UTC (permalink / raw)
  To: Peter Stephenson; +Cc: Zsh hackers list

Peter Stephenson wrote:
> 
> This allows `bindkey -p <seq>' to list bindings which have <seq> as a
> prefix (not counting bindings for <seq> itself).  The previous unposted zle

How do I use this to list all key bindings which are Meta something:
  bindkey -p \\M
doesn't work.

Also, I've just noticed that the output of bindkey includes these:

"^\^" up-case-word
"^\^[OA" up-history
"^\^[OB" down-history
"^\^[OC" forward-char
"^\^[OD" backward-char
"^\^[[A" up-history
"^\^[[B" down-history
"^\^[[C" forward-char
"^\^[[D" backward-char

The first one is set from this command in my .zshrc:
    bindkey '^^' up-case-word
but I don't see where the back-slash came from. It is also there in
3.1.9-dev-8 so this isn't recent. I also don't see why the others should
start with ^\. I don't know where they come from - after zsh -f followed
by . ./.zshrc, they aren't there but I expect they have something to do
with the recent changes for binding cursor keys (they don't appear in
3.1.9-dev-8).

Oliver


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

* Re: PATCH: list bindings with given prefix.
  2001-04-01 15:11 ` Oliver Kiddle
@ 2001-04-03 19:00   ` Bart Schaefer
  0 siblings, 0 replies; 3+ messages in thread
From: Bart Schaefer @ 2001-04-03 19:00 UTC (permalink / raw)
  To: zsh-workers

On Apr 1,  4:11pm, Oliver Kiddle wrote:
} Subject: Re: PATCH: list bindings with given prefix.
}
} Peter Stephenson wrote:
} > 
} > This allows `bindkey -p <seq>' to list bindings which have <seq> as a
} > prefix (not counting bindings for <seq> itself).
} 
} How do I use this to list all key bindings which are Meta something:

You don't; Meta isn't a prefix.  Stick with `bindkey | fgrep \"\\M` ...

}   bindkey -p \\M
} doesn't work.

The -p option is using getkeystring(), which returns an empty string when
parsing a \M by itself.  It might be possible to special-case it, but \M
is not a real character any more than \C is, and the current implemention
needs at least one character of prefix to compare with.  (Do you expect to
be able to list all control-character bindings with `bindkey -p ^' ?

} Also, I've just noticed that the output of bindkey includes these:
} 
} "^\^" up-case-word
} "^\^[OA" up-history
} "^\^[OB" down-history
} "^\^[OC" forward-char
} "^\^[OD" backward-char
} "^\^[[A" up-history
} "^\^[[B" down-history
} "^\^[[C" forward-char
} "^\^[[D" backward-char
} 
} The first one is set from this command in my .zshrc:
}     bindkey '^^' up-case-word
} but I don't see where the back-slash came from.

In double quotes, a backslash quotes the following character and then is
removed, so "^\^" is the same as "^^", and not the same as "^\\" (which
to bindkey is control-backslash).  I don't know why bindkey decided it
needs to backslash the second carat.

} I also don't see why the others should start with ^\. I don't know where
} they come from - after zsh -f followed by . ./.zshrc, they aren't there

That part has me stumped.

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

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   


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

end of thread, other threads:[~2001-04-03 19:02 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-03-28 15:17 PATCH: list bindings with given prefix Peter Stephenson
2001-04-01 15:11 ` Oliver Kiddle
2001-04-03 19:00   ` Bart Schaefer

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