summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog4
-rw-r--r--Doc/Zsh/zle.yo4
-rw-r--r--Src/Zle/zle_keymap.c22
-rw-r--r--Src/Zle/zle_main.c2
4 files changed, 30 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 46042f222..c99b1caa9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
2001-03-28 Peter Stephenson <pws@csr.com>
+ * 13818: Doc/Zsh/zle.yo, Src/Zle/zle_keymap,c. Src/Zle/zle_main.c
+ [zle_main hunk got omitted from posted patch, oops]: Add
+ `bindkey -p' to list bindings with a given prefix.
+
* unposted: Doc/Zsh/zle.yo, Doc/Zsh/mod_zle.yo: move ZLE builtin
documentation from mod_zle.yo to zle.yo.
diff --git a/Doc/Zsh/zle.yo b/Doc/Zsh/zle.yo
index 7c30b6802..87e5182b3 100644
--- a/Doc/Zsh/zle.yo
+++ b/Doc/Zsh/zle.yo
@@ -195,6 +195,10 @@ if the tt(-e) or tt(-v) option is used alone, the keymap is em(not)
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.
)
diff --git a/Src/Zle/zle_keymap.c b/Src/Zle/zle_keymap.c
index c6646450d..9a485a506 100644
--- a/Src/Zle/zle_keymap.c
+++ b/Src/Zle/zle_keymap.c
@@ -86,6 +86,8 @@ struct bindstate {
char *lastseq;
Thingy bind;
char *str;
+ char *prefix;
+ int prefixlen;
};
#define BS_LIST (1<<0)
@@ -890,7 +892,7 @@ bin_bindkey_list(char *name, char *kmname, Keymap km, char **argv, char *ops, ch
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 @@ bin_bindkey_list(char *name, char *kmname, Keymap km, char **argv, char *ops, ch
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;
@@ -919,6 +935,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) {
int l = bs->lastseq[1] ?
diff --git a/Src/Zle/zle_main.c b/Src/Zle/zle_main.c
index d867a0fb2..967cb61b9 100644
--- a/Src/Zle/zle_main.c
+++ b/Src/Zle/zle_main.c
@@ -1091,7 +1091,7 @@ zleaftertrap(Hookdef dummy, void *dat)
}
static struct builtin bintab[] = {
- BUILTIN("bindkey", 0, bin_bindkey, 0, -1, 0, "evaMldDANmrsLR", NULL),
+ BUILTIN("bindkey", 0, bin_bindkey, 0, -1, 0, "evaMldDANmrsLRp", NULL),
BUILTIN("vared", 0, bin_vared, 1, 7, 0, NULL, NULL),
BUILTIN("zle", 0, bin_zle, 0, -1, 0, "lDANCLmMgGcRaUI", NULL),
};