From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8889 invoked from network); 23 Jun 1999 08:03:25 -0000 Received: from sunsite.auc.dk (130.225.51.30) by ns1.primenet.com.au with SMTP; 23 Jun 1999 08:03:25 -0000 Received: (qmail 24442 invoked by alias); 23 Jun 1999 08:03:07 -0000 Mailing-List: contact zsh-workers-help@sunsite.auc.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 6796 Received: (qmail 24434 invoked from network); 23 Jun 1999 08:03:03 -0000 Date: Wed, 23 Jun 1999 10:03:01 +0200 (MET DST) Message-Id: <199906230803.KAA05929@beta.informatik.hu-berlin.de> From: Sven Wischnowsky To: zsh-workers@sunsite.auc.dk Subject: PATCH: widget listing/testing This makes `zle -la' list the names of all widgets, including the builtin ones (and only the names). It also makes `zle -l [-a]' accept optional arguments: in this case nothing will be printed, but the return status is set to aero if all arguments name existing widgets and to one if at least one argument is not the name of a widget. I.e. you can easily test if a widget is defined by saying `zle -la foo && ...'. There is also a hunk for compinit that `zle -c's menu-select if it is defined. (We could also try automatic loading of `complist' here...) Bye Sven diff -u os/Zle/zle_main.c Src/Zle/zle_main.c --- os/Zle/zle_main.c Tue Jun 22 21:03:51 1999 +++ Src/Zle/zle_main.c Tue Jun 22 21:18:59 1999 @@ -955,7 +955,7 @@ static struct builtin bintab[] = { BUILTIN("bindkey", 0, bin_bindkey, 0, -1, 0, "evaMldDANmrsLR", NULL), BUILTIN("vared", 0, bin_vared, 1, 7, 0, NULL, NULL), - BUILTIN("zle", 0, bin_zle, 0, -1, 0, "lDANCLmMgGcR", NULL), + BUILTIN("zle", 0, bin_zle, 0, -1, 0, "lDANCLmMgGcRa", NULL), }; /* The order of the entries in this table has to match the *HOOK diff -u os/Zle/zle_thingy.c Src/Zle/zle_thingy.c --- os/Zle/zle_thingy.c Tue Jun 22 21:03:51 1999 +++ Src/Zle/zle_thingy.c Tue Jun 22 21:21:47 1999 @@ -318,9 +318,10 @@ /* * The available operations are: * - * -l list user-defined widgets (no arguments) + * -l list widgets/test for existence * -D delete widget names * -A link the two named widgets (2 arguments) + * -C create completion widget (3 arguments) * -N create new user-defined widget (1 or 2 arguments) * invoke a widget (1 argument) */ @@ -334,7 +335,7 @@ int (*func) _((char *, char **, char *, char)); int min, max; } const opns[] = { - { 'l', bin_zle_list, 0, 0 }, + { 'l', bin_zle_list, 0, -1 }, { 'D', bin_zle_del, 1, -1 }, { 'A', bin_zle_link, 2, 2 }, { 'N', bin_zle_new, 1, 2 }, @@ -373,8 +374,21 @@ static int bin_zle_list(char *name, char **args, char *ops, char func) { - scanhashtable(thingytab, 1, 0, DISABLED, scanlistwidgets, ops['L']); - return 0; + if (!*args) { + scanhashtable(thingytab, 1, 0, DISABLED, scanlistwidgets, + (ops['a'] ? -1 : ops['L'])); + return 0; + } else { + int ret = 0; + Thingy t; + + for (; *args && !ret; args++) { + if (!(t = (Thingy) thingytab->getnode2(thingytab, *args)) || + (!ops['a'] && (t->widget->flags & WIDGET_INT))) + ret = 1; + } + return ret; + } } /**/ @@ -405,6 +419,10 @@ Thingy t = (Thingy) hn; Widget w = t->widget; + if(list < 0) { + printf("%s\n", hn->nam); + return; + } if(w->flags & WIDGET_INT) return; if(list) { diff -u od/Zsh/mod_zle.yo Doc/Zsh/mod_zle.yo --- od/Zsh/mod_zle.yo Tue Jun 22 21:03:37 1999 +++ Doc/Zsh/mod_zle.yo Tue Jun 22 21:31:16 1999 @@ -161,7 +161,7 @@ cindex(calling widgets) cindex(widgets, defining) cindex(defining widgets) -xitem(tt(zle) tt(-l) [ tt(-L) ]) +xitem(tt(zle) tt(-l) [ tt(-L) ] [ tt(-a) ] [ var(string) ... ]) xitem(tt(zle) tt(-D) var(widget) ...) xitem(tt(zle) tt(-A) var(old-widget) var(new-widget)) xitem(tt(zle) tt(-N) var(widget) [ var(function) ]) @@ -176,7 +176,15 @@ List all existing user-defined widgets. If the tt(-L) option is used, list in the form of tt(zle) commands to create the widgets. -Built-in widgets are not listed. + +When combined with the tt(-a) option, all widget names are listed, +including the builtin ones. In this case the tt(-L) option is ignored. + +If at least one var(string) is given, nothing will be printed but the +return status will be zero if all var(string)s are names of existing +widgets (or of user-defined widgets if the tt(-a) flag is not given) +and non-zero if at least one var(string) is not a name of an defined +widget. ) item(tt(-D) var(widget) ...)( Delete the named var(widget)s. diff -u oc/Core/compinit Completion/Core/compinit --- oc/Core/compinit Tue Jun 22 14:01:43 1999 +++ Completion/Core/compinit Tue Jun 22 21:37:31 1999 @@ -346,6 +346,7 @@ menu-expand-or-complete reverse-menu-complete; do zle -C $_i_line .$_i_line _main_complete done +zle -la menu-select && zle -C menu-select .menu-select _main_complete _i_done='' -- Sven Wischnowsky wischnow@informatik.hu-berlin.de