From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23668 invoked from network); 3 Jul 2000 08:03:58 -0000 Received: from sunsite.auc.dk (130.225.51.30) by ns1.primenet.com.au with SMTP; 3 Jul 2000 08:03:58 -0000 Received: (qmail 20208 invoked by alias); 3 Jul 2000 08:03:33 -0000 Mailing-List: contact zsh-workers-help@sunsite.auc.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 12134 Received: (qmail 20200 invoked from network); 3 Jul 2000 08:03:32 -0000 Date: Mon, 3 Jul 2000 10:03:25 +0200 (MET DST) Message-Id: <200007030803.KAA04527@beta.informatik.hu-berlin.de> From: Sven Wischnowsky To: zsh-workers@sunsite.auc.dk Subject: PATCH: a-a-i-n-h without matches in menu selection This makes a-a-i-n-h in menu selection work if that completion attempt doesn't generate any matches. If the completion produces no messages, a default message is shown, otherwise the C-code just thinks that the message(s) shown are enough to tell the user what's up. To make things more clean, I changed the format style for the warnings tag a bit. Namely, I removed the special behaviour if the format doesn't contain a `%'. But I added the new sequence `%D' which is replaced with the descriptions separated by newlines (which is even better readable than what we had before). I.e., to get something similar to the old behaviour, one can set: zstyle ':completion:*:warnings' format 'No matches for: %D' One could say that menu selection goes into a special mode after a a-a-i-n-h without matches, where undo brings one back to the previous level and every other widget leaves menu selection and makes that widget be executed immediately (except for send-break, which only leaves menu selection). The default message is just `no matches', should we change that to something more verbose? E.g.: `no matches found, use undo to go back'? Bye Sven Index: Completion/Core/_main_complete =================================================================== RCS file: /cvsroot/zsh/zsh/Completion/Core/_main_complete,v retrieving revision 1.34 diff -u -r1.34 _main_complete --- Completion/Core/_main_complete 2000/06/29 09:32:05 1.34 +++ Completion/Core/_main_complete 2000/07/03 08:02:46 @@ -25,7 +25,7 @@ local func funcs ret=1 tmp _compskip format nm call match min max i num\ _completers _completer _completer_num curtag _comp_force_list \ - _matchers _matcher _matcher_num _comp_tags _comp_mesg \ + _matchers _matcher _matcher_num _comp_tags _comp_mesg mesg str \ context state line opt_args val_args curcontext="$curcontext" \ _last_nmatches=-1 _last_menu_style _def_menu_style _menu_style sel \ _saved_exact="${compstate[exact]}" \ @@ -266,23 +266,17 @@ compstate[list]='list force' compstate[insert]='' - if [[ "$format" = *%d* ]]; then - local str mesg + tmp=( "\`${(@)^_lastdescr:#}'" ) - _lastdescr=( "\`${(@)^_lastdescr:#}'" ) - - case $#_lastdescr in - 1) str="$_lastdescr[1]";; - 2) str="$_lastdescr[1] or $_lastdescr[2]";; - *) str="${(j:, :)_lastdescr[1,-2]}, or $_lastdescr[-1]";; - esac - - zformat -f mesg "$format" "d:$str" - compadd -UX "$mesg" -n - '' - else - _setup warnings - compadd -UQX "$format" -V warnings - "${(@)_lastdescr:#}" - fi + case $#tmp in + 1) str="$tmp[1]";; + 2) str="$tmp[1] or $tmp[2]";; + *) str="${(j:, :)tmp[1,-2]}, or $tmp[-1]";; + esac + + _setup warnings + zformat -f mesg "$format" "d:$str" "D:${(F)${(@)_lastdescr:#}}" + compadd -x "$mesg" fi [[ "$_comp_force_list" = always || Index: Doc/Zsh/compsys.yo =================================================================== RCS file: /cvsroot/zsh/zsh/Doc/Zsh/compsys.yo,v retrieving revision 1.80 diff -u -r1.80 compsys.yo --- Doc/Zsh/compsys.yo 2000/06/29 09:32:05 1.80 +++ Doc/Zsh/compsys.yo 2000/07/03 08:02:51 @@ -1143,12 +1143,9 @@ Finally, when set with the tt(warnings) tag, the format string is printed when no matches could be generated at all. In this case the `tt(%d)' is -replaced with the descriptions for the matches that were expected. If the -value does not contain a `tt(%d)', then those descriptions are added in the -same way as matches are added, i.e. they appear below the value for the -tt(format) style laid out in columns. The descriptions are added as if for -the tag tt(warnings) so that you can use the tt(list-colors) style for that -tag to highlight them. +replaced with the descriptions for the matches that were expected +separated by spaces and the sequence `tt(%D)' is replaced with those +descriptions separated by newlines. The `tt(%)' for the sequences that are replaced by strings provided by the completion functions like the `tt(%d)' may be followed by field Index: Doc/Zsh/mod_complist.yo =================================================================== RCS file: /cvsroot/zsh/zsh/Doc/Zsh/mod_complist.yo,v retrieving revision 1.10 diff -u -r1.10 mod_complist.yo --- Doc/Zsh/mod_complist.yo 2000/06/03 16:37:25 1.10 +++ Doc/Zsh/mod_complist.yo 2000/07/03 08:02:51 @@ -267,7 +267,11 @@ item(tt(accept-and-infer-next-history))( accepts the current match and then tries completion with menu-selection again; in the case of files this allows one to select -a directory and immediately attempt to complete files in it +a directory and immediately attempt to complete files in it; if there +are no matches, a message is shown and one can use tt(undo) to go back +to completion on the previous level, every other key leaves menu +selection (including the other zle functions which are otherwise +special during menu selection) ) item(tt(undo))( removes matches inserted during the menu selection by one of the three Index: Src/Zle/comp.h =================================================================== RCS file: /cvsroot/zsh/zsh/Src/Zle/comp.h,v retrieving revision 1.7 diff -u -r1.7 comp.h --- Src/Zle/comp.h 2000/06/19 10:48:21 1.7 +++ Src/Zle/comp.h 2000/07/03 08:02:52 @@ -388,6 +388,7 @@ struct chdata { Cmgroup matches; /* the matches generated */ int num; /* the number of matches */ + int nmesg; /* the number of messages */ Cmatch cur; /* current match or NULL */ }; Index: Src/Zle/compcore.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/Zle/compcore.c,v retrieving revision 1.34 diff -u -r1.34 compcore.c --- Src/Zle/compcore.c 2000/06/28 07:29:59 1.34 +++ Src/Zle/compcore.c 2000/07/03 08:02:53 @@ -350,8 +350,9 @@ if (comppatmatch && *comppatmatch && comppatmatch != opm) haspattern = 1; if (iforcemenu) { - do_ambig_menu(); - ret = 0; + if (nmatches) + do_ambig_menu(); + ret = !nmatches; } else if (useline < 0) ret = selfinsert(zlenoargs); else if (!useline && uselist) { @@ -511,6 +512,7 @@ cdat.matches = amatches; cdat.num = nmatches; + cdat.nmesg = nmessages; cdat.cur = NULL; if ((ret = runhookdef(MENUSTARTHOOK, (void *) &cdat))) { dat[1] = 0; Index: Src/Zle/complist.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/Zle/complist.c,v retrieving revision 1.31 diff -u -r1.31 complist.c --- Src/Zle/complist.c 2000/06/28 13:59:50 1.31 +++ Src/Zle/complist.c 2000/07/03 08:02:54 @@ -1632,6 +1632,7 @@ Menustack u = NULL; int i = 0, acc = 0, wishcol = 0, setwish = 0, oe = onlyexpl, wasnext = 0; int space, lbeg = 0, step = 1, wrap, pl = nlnct, broken = 0, first = 1; + int nolist = 0; char *s; if (fdat || (dummy && (!(s = getsparam("MENUSELECT")) || @@ -1639,6 +1640,7 @@ if (fdat) { fdat->matches = dat->matches; fdat->num = dat->num; + fdat->nmesg = dat->nmesg; } return 0; } @@ -1753,9 +1755,14 @@ } setwish = wasnext = 0; + getk: + if (!(cmd = getkeycmd()) || cmd == Th(z_sendbreak)) { zbeep(); break; + } else if (nolist && cmd != Th(z_undo)) { + ungetkeycmd(); + break; } else if (cmd == Th(z_acceptline)) { acc = 1; break; @@ -1794,10 +1801,24 @@ iforcemenu = 0; if (dat->num < 1 || !minfo.cur || !*(minfo.cur)) { - noselect = clearlist = listshown = 1; - onlyexpl = 0; - zrefresh(); - break; + nolist = 1; + if (dat->nmesg || nmessages) { + showinglist = -2; + zrefresh(); + } else { + trashzle(); + zsetterm(); + if (tccan(TCCLEAREOD)) + tcout(TCCLEAREOD); + fputs("no matches\r", shout); + fflush(shout); + tcmultout(TCUP, TCMULTUP, nlnct); + showinglist = clearlist = 0; + clearflag = 1; + zrefresh(); + showinglist = clearlist = 0; + } + goto getk; } clearlist = listshown = 1; mselect = (*(minfo.cur))->gnum; @@ -1861,7 +1882,7 @@ break; handleundo(); - cs = 0; + cs = nolist = 0; foredel(ll); spaceinline(l = strlen(u->line)); strncpy((char *) line, u->line, l); @@ -1879,7 +1900,7 @@ lastmatches = u->lastmatches; lastlmatches = u->lastlmatches; nmatches = u->nmatches; - hasoldlist = 1; + hasoldlist = validlist = 1; } freebrinfo(brbeg); freebrinfo(brend); -- Sven Wischnowsky wischnow@informatik.hu-berlin.de