From fe8a55b640256711e81b94f9488ec7bdd8d1e956 Mon Sep 17 00:00:00 2001 From: Clint Adams Date: Sat, 16 Dec 2000 16:25:41 +0000 Subject: 13285: use vi-up and -down in vicmd mode --- ChangeLog | 6 ++++ Src/Zle/zle_bindings.c | 14 ++++---- Src/Zle/zle_keymap.c | 96 +++++++++++++++++++++++++++++--------------------- 3 files changed, 69 insertions(+), 47 deletions(-) diff --git a/ChangeLog b/ChangeLog index 68a79acf9..655c050da 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2000-12-16 Clint Adams + + * 13285: Src/Zle/zle_bindings.c, Src/Zle/zle_keymap.c: + use vi-up-line-or-history and vi-down-line-or-history in + the vicmd keymap (rather than their emacsy counterparts). + 2000-12-15 Tanaka Akira * 13281: Functions/Misc/mere: new implementation. diff --git a/Src/Zle/zle_bindings.c b/Src/Zle/zle_bindings.c index 40e555ad1..67acc15f9 100644 --- a/Src/Zle/zle_bindings.c +++ b/Src/Zle/zle_bindings.c @@ -69,7 +69,7 @@ widgets[] = { */ /**/ -struct thingy thingies[] = { +mod_export struct thingy thingies[] = { #define T(name, th_flags, w_idget, t_next) \ { NULL, name, th_flags, 2, w_idget, t_next }, #include "thingies.list" @@ -200,9 +200,9 @@ int metabind[128] = { /* M-K */ z_undefinedkey, /* M-L */ z_downcaseword, /* M-M */ z_undefinedkey, - /* M-N */ z_historybeginningsearchforward, + /* M-N */ z_historysearchforward, /* M-O */ z_undefinedkey, - /* M-P */ z_historybeginningsearchbackward, + /* M-P */ z_historysearchbackward, /* M-Q */ z_pushline, /* M-R */ z_undefinedkey, /* M-S */ z_spellword, @@ -232,9 +232,9 @@ int metabind[128] = { /* M-k */ z_undefinedkey, /* M-l */ z_downcaseword, /* M-m */ z_undefinedkey, - /* M-n */ z_historybeginningsearchforward, + /* M-n */ z_historysearchforward, /* M-o */ z_undefinedkey, - /* M-p */ z_historybeginningsearchbackward, + /* M-p */ z_historysearchbackward, /* M-q */ z_pushline, /* M-r */ z_undefinedkey, /* M-s */ z_spellword, @@ -396,8 +396,8 @@ int vicmdbind[128] = { /* g */ z_undefinedkey, /* h */ z_vibackwardchar, /* i */ z_viinsert, - /* j */ z_downlineorhistory, - /* k */ z_uplineorhistory, + /* j */ z_vidownlineorhistory, + /* k */ z_viuplineorhistory, /* l */ z_viforwardchar, /* m */ z_visetmark, /* n */ z_virepeatsearch, diff --git a/Src/Zle/zle_keymap.c b/Src/Zle/zle_keymap.c index 7de96bd03..09601eb6d 100644 --- a/Src/Zle/zle_keymap.c +++ b/Src/Zle/zle_keymap.c @@ -98,17 +98,20 @@ struct bindstate { /* currently selected keymap, and its name */ /**/ -Keymap curkeymap; +Keymap curkeymap, localkeymap; /**/ char *curkeymapname; /* the hash table of keymap names */ -static HashTable keymapnamtab; +/**/ +mod_export HashTable keymapnamtab; /* key sequence reading data */ -static char *keybuf; +/**/ +char *keybuf; + static int keybuflen, keybufsz = 20; /* last command executed with execute-named-command */ @@ -128,6 +131,7 @@ createkeymapnamtab(void) keymapnamtab->hash = hasher; keymapnamtab->emptytable = emptyhashtable; keymapnamtab->filltable = NULL; + keymapnamtab->cmpnodes = strcmp; keymapnamtab->addnode = addhashnode; keymapnamtab->getnode = gethashnode2; keymapnamtab->getnode2 = gethashnode2; @@ -170,6 +174,7 @@ newkeytab(char *kmname) ht->hash = hasher; ht->emptytable = emptyhashtable; ht->filltable = NULL; + ht->cmpnodes = strcmp; ht->addnode = addhashnode; ht->getnode = gethashnode2; ht->getnode2 = gethashnode2; @@ -212,7 +217,7 @@ freekeynode(HashNode hn) static HashTable copyto; /**/ -static Keymap +mod_export Keymap newkeymap(Keymap tocopy, char *kmname) { Keymap km = zcalloc(sizeof(*km)); @@ -246,7 +251,7 @@ scancopykeys(HashNode hn, int flags) } /**/ -static void +void deletekeymap(Keymap km) { int i; @@ -318,21 +323,21 @@ openkeymap(char *name) } /**/ -static int -unlinkkeymap(char *name) +mod_export int +unlinkkeymap(char *name, int ignm) { KeymapName n = (KeymapName) keymapnamtab->getnode(keymapnamtab, name); if(!n) return 2; - if(n->flags & KMN_IMMORTAL) + if(!ignm && (n->flags & KMN_IMMORTAL)) return 1; keymapnamtab->freenode(keymapnamtab->removenode(keymapnamtab, name)); return 0; } /**/ -static int -linkkeymap(Keymap km, char *name) +mod_export int +linkkeymap(Keymap km, char *name, int imm) { KeymapName n = (KeymapName) keymapnamtab->getnode(keymapnamtab, name); if(n) { @@ -343,9 +348,12 @@ linkkeymap(Keymap km, char *name) if(!--n->keymap->rc) deletekeymap(n->keymap); n->keymap = km; - } else - keymapnamtab->addnode(keymapnamtab, ztrdup(name), - makekeymapnamnode(km)); + } else { + n = makekeymapnamnode(km); + if (imm) + n->flags |= KMN_IMMORTAL; + keymapnamtab->addnode(keymapnamtab, ztrdup(name), n); + } km->rc++; return 0; } @@ -375,6 +383,15 @@ selectkeymap(char *name, int fb) return 0; } +/* Select a local key map. */ + +/**/ +mod_export void +selectlocalmap(Keymap m) +{ + localkeymap = m; +} + /* Reopen the currently selected keymap, in case it got deleted. This * * should be called after doing anything that might have run an * * arbitrary user-specified command. */ @@ -397,7 +414,7 @@ reselectkeymap(void) * back onto the input. */ /**/ -int +mod_export int bindkey(Keymap km, char *seq, Thingy bind, char *str) { Key k; @@ -598,10 +615,10 @@ bin_bindkey(char *name, char **argv, char *ops, int func) int n; /* select operation and ensure no clashing arguments */ - for(op = opns; op->o && !ops[op->o]; op++) ; + for(op = opns; op->o && !ops[STOUC(op->o)]; op++) ; if(op->o) for(opp = op; (++opp)->o; ) - if(ops[opp->o]) { + if(ops[STOUC(opp->o)]) { zwarnnam(name, "incompatible operation selection options", NULL, 0); return 1; @@ -638,7 +655,7 @@ bin_bindkey(char *name, char **argv, char *ops, int func) return 1; } if(ops['e'] || ops['v']) - linkkeymap(km, "main"); + linkkeymap(km, "main", 0); } else { kmname = NULL; km = NULL; @@ -711,7 +728,7 @@ bin_bindkey_del(char *name, char *kmname, Keymap km, char **argv, char *ops, cha int ret = 0; do { - int r = unlinkkeymap(*argv); + int r = unlinkkeymap(*argv, 0); if(r == 1) zwarnnam(name, "keymap name `%s' is protected", *argv, 0); else if(r == 2) @@ -731,7 +748,7 @@ bin_bindkey_link(char *name, char *kmname, Keymap km, char **argv, char *ops, ch if(!km) { zwarnnam(name, "no such keymap `%s'", argv[0], 0); return 1; - } else if(linkkeymap(km, argv[1])) { + } else if(linkkeymap(km, argv[1], 0)) { zwarnnam(name, "keymap name `%s' is protected", argv[1], 0); return 1; } @@ -758,7 +775,7 @@ bin_bindkey_new(char *name, char *kmname, Keymap km, char **argv, char *ops, cha } } else km = NULL; - linkkeymap(newkeymap(km, argv[0]), argv[0]); + linkkeymap(newkeymap(km, argv[0]), argv[0], 0); return 0; } @@ -983,8 +1000,6 @@ init_keymaps(void) lastnamed = refthingy(t_undefinedkey); } -#ifdef MODULE - /* cleanup entry point (for unloading the zle module) */ /**/ @@ -996,8 +1011,6 @@ cleanup_keymaps(void) zfree(keybuf, keybufsz); } -#endif /* MODULE */ - /* Create the default keymaps. For efficiency reasons, this function * * assigns directly to the km->first array. It knows that there are no * * prefix bindings in the way, and that it is using a simple keymap. */ @@ -1054,12 +1067,12 @@ default_bindings(void) * Both standard and keypad modes are supported. */ /* vi command mode: arrow keys */ - bindkey(amap, "\33[A", refthingy(t_uplineorhistory), NULL); - bindkey(amap, "\33[B", refthingy(t_downlineorhistory), NULL); + bindkey(amap, "\33[A", refthingy(t_viuplineorhistory), NULL); + bindkey(amap, "\33[B", refthingy(t_vidownlineorhistory), NULL); bindkey(amap, "\33[C", refthingy(t_viforwardchar), NULL); bindkey(amap, "\33[D", refthingy(t_vibackwardchar), NULL); - bindkey(amap, "\33OA", refthingy(t_uplineorhistory), NULL); - bindkey(amap, "\33OB", refthingy(t_downlineorhistory), NULL); + bindkey(amap, "\33OA", refthingy(t_viuplineorhistory), NULL); + bindkey(amap, "\33OB", refthingy(t_vidownlineorhistory), NULL); bindkey(amap, "\33OC", refthingy(t_viforwardchar), NULL); bindkey(amap, "\33OD", refthingy(t_vibackwardchar), NULL); @@ -1104,20 +1117,18 @@ default_bindings(void) * will be linked to the "emacs" keymap, except that if VISUAL * * or EDITOR contain the string "vi" then it will be linked to * * the "viins" keymap. */ - linkkeymap(vmap, "viins"); - linkkeymap(emap, "emacs"); - linkkeymap(amap, "vicmd"); - linkkeymap(smap, ".safe"); + linkkeymap(vmap, "viins", 0); + linkkeymap(emap, "emacs", 0); + linkkeymap(amap, "vicmd", 0); + linkkeymap(smap, ".safe", 1); if (((ed = zgetenv("VISUAL")) && strstr(ed, "vi")) || ((ed = zgetenv("EDITOR")) && strstr(ed, "vi"))) - linkkeymap(vmap, "main"); + linkkeymap(vmap, "main", 0); else - linkkeymap(emap, "main"); + linkkeymap(emap, "main", 0); /* the .safe map cannot be modified or deleted */ smap->flags |= KM_IMMUTABLE; - ((KeymapName) keymapnamtab->getnode(keymapnamtab, ".safe"))->flags - |= KMN_IMMORTAL; } /*************************/ @@ -1138,7 +1149,12 @@ getkeymapcmd(Keymap km, Thingy *funcp, char **strp) keybuf[0] = 0; while((c = getkeybuf(!!lastlen)) != EOF) { char *s; - Thingy f = keybind(km, keybuf, &s); + Thingy f; + int loc = 1; + + if (!localkeymap || + (f = keybind(localkeymap, keybuf, &s)) == t_undefinedkey) + loc = 0, f = keybind(km, keybuf, &s); if(f != t_undefinedkey) { lastlen = keybuflen; @@ -1146,7 +1162,7 @@ getkeymapcmd(Keymap km, Thingy *funcp, char **strp) str = s; lastc = c; } - if(!keyisprefix(km, keybuf)) + if(!keyisprefix((loc ? localkeymap : km), keybuf)) break; } if(!lastlen && keybuflen) @@ -1188,7 +1204,7 @@ getkeybuf(int w) * Must be executed at most once after each getkeymapcmd(). */ /**/ -void +mod_export void ungetkeycmd(void) { ungetkeys(keybuf, keybuflen); @@ -1197,7 +1213,7 @@ ungetkeycmd(void) /* read a command from the current keymap, with widgets */ /**/ -Thingy +mod_export Thingy getkeycmd(void) { Thingy func; -- cgit 1.4.1