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

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