From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17630 invoked from network); 12 Dec 2004 21:07:27 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 12 Dec 2004 21:07:27 -0000 Received: (qmail 37019 invoked from network); 12 Dec 2004 21:07:21 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 12 Dec 2004 21:07:21 -0000 Received: (qmail 24349 invoked by alias); 12 Dec 2004 21:07:02 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 20622 Received: (qmail 24331 invoked from network); 12 Dec 2004 21:07:01 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 12 Dec 2004 21:07:01 -0000 Received: (qmail 36474 invoked from network); 12 Dec 2004 21:07:01 -0000 Received: from mx2.mail.ru (194.67.23.122) by a.mx.sunsite.dk with SMTP; 12 Dec 2004 21:06:59 -0000 Received: from [83.237.195.79] (port=32875 helo=ppp83-237-195-79.pppoe.mtu-net.ru) by mx2.mail.ru with asmtp id 1Cdavi-0000zR-00 for zsh-workers@sunsite.dk; Mon, 13 Dec 2004 00:06:58 +0300 From: Andrey Borzenkov To: zsh-workers@sunsite.dk Subject: Re: Strange _values completion on accept-and-menu-complete and menu selection Date: Mon, 13 Dec 2004 00:06:56 +0300 User-Agent: KMail/1.7.1 References: <200412111311.27916.arvidjaar@mail.ru> <200412121915.34004.arvidjaar@mail.ru> In-Reply-To: MIME-Version: 1.0 Content-Type: Multipart/Mixed; boundary="Boundary-00=_wLLvBRx8qpoYUHo" Message-Id: <200412130006.56691.arvidjaar@mail.ru> X-Spam: Not detected X-Spam-Checker-Version: SpamAssassin 2.63 on a.mx.sunsite.dk X-Spam-Level: X-Spam-Status: No, hits=0.0 required=6.0 tests=none autolearn=no version=2.63 X-Spam-Hits: 0.0 --Boundary-00=_wLLvBRx8qpoYUHo Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline On Sunday 12 December 2004 20:51, Bart Schaefer wrote: > On Sun, 12 Dec 2004, Andrey Borzenkov wrote: > > I attach prototype patch - it adds compstate element that tells > > accept_last to skip suffix removal. It can be used in more general case > > than just _values - what I am not sure how and when this is to be set. > > I wonder if perhaps another state name would be better. "Stay in word" is > a directive, whereas everything else in compstate is, well, state data. > > What if it were compstate[compound_word] and the value is the separator > character to insert? (Or perhaps two characters, corresponding to > "compvalues -s" and "compvalues -S" in that order.) > > Normally compstate[compound_word] would be unset, but "compvalues -i" > would set it based on the parse. I still believe this is more general and should not be limited to _values only. Also -S does not seem to be needed here. Here is updated patch (which also fixes initialization problem). It makes parameter compound_word as scalar but currently tests only for empty value (is it correct way to test for it BTW?) Setting compstate[compound_word] to any string in completion function will stop accept_last from removing suffix (actually, altering string in any way). This also changes _values to set it as appropriate. This still has problems in completing nested calls to _values (should it work?) Try this example: function _foo_val () { _values -s : "subvalues" baz bad bam } function _foo () { _values -s , -S = "test values" \ foo \ "bar:bar values:_foo_val" } compdef _foo foo regards -andrey --Boundary-00=_wLLvBRx8qpoYUHo Content-Type: text/x-diff; charset="iso-8859-1"; name="compound_word.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="compound_word.diff" Index: Completion/Base/Utility/_values =================================================================== RCS file: /cvsroot/zsh/zsh/Completion/Base/Utility/_values,v retrieving revision 1.8 diff -u -p -r1.8 _values --- Completion/Base/Utility/_values 16 Apr 2002 07:55:49 -0000 1.8 +++ Completion/Base/Utility/_values 12 Dec 2004 20:44:45 -0000 @@ -10,10 +10,13 @@ zparseopts -D -E -a garbage C=usecc O:=s if compvalues -i "$@"; then local noargs args opts descr action expl sep argsep subc test='*' - local oldcontext="$curcontext" + local oldcontext="$curcontext" compound=$compstate[compound] compvalues -S argsep - compvalues -s sep && [[ -n "$sep" ]] && test="[^${(q)sep}]#" + compvalues -s sep && [[ -n "$sep" ]] && { + test="[^${(q)sep}]#" + compstate[compound_word]=yes + } if ! compvalues -D descr action; then @@ -148,6 +151,7 @@ if compvalues -i "$@"; then fi fi + compstate[compound]=$compound curcontext="$oldcontext" [[ nm -ne "$compstate[nmatches]" ]] Index: Src/Zle/comp.h =================================================================== RCS file: /cvsroot/zsh/zsh/Src/Zle/comp.h,v retrieving revision 1.14 diff -u -p -r1.14 comp.h --- Src/Zle/comp.h 21 May 2002 08:07:51 -0000 1.14 +++ Src/Zle/comp.h 12 Dec 2004 20:44:46 -0000 @@ -375,9 +375,11 @@ typedef void (*CLPrintFunc)(Cmgroup, Cma #define CP_QUOTES (1 << CPN_QUOTES) #define CPN_IGNORED 25 #define CP_IGNORED (1 << CPN_IGNORED) +#define CPN_COMPOUND 26 +#define CP_COMPOUND (1 << CPN_COMPOUND) -#define CP_KEYPARAMS 26 -#define CP_ALLKEYS ((unsigned int) 0x3ffffff) +#define CP_KEYPARAMS 27 +#define CP_ALLKEYS ((unsigned int) 0x7ffffff) /* Hooks. */ Index: Src/Zle/compcore.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/Zle/compcore.c,v retrieving revision 1.68 diff -u -p -r1.68 compcore.c --- Src/Zle/compcore.c 5 Nov 2004 16:20:24 -0000 1.68 +++ Src/Zle/compcore.c 12 Dec 2004 20:44:49 -0000 @@ -764,6 +764,8 @@ callcompfunc(char *s, char *fn) compoldlist = compoldins = ""; compoldlist = ztrdup(compoldlist); compoldins = ztrdup(compoldins); + zsfree(compcompound); + compcompound = ztrdup(""); incompfunc = 1; startparamscope(); Index: Src/Zle/complete.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/Zle/complete.c,v retrieving revision 1.27 diff -u -p -r1.27 complete.c --- Src/Zle/complete.c 7 Dec 2004 16:55:11 -0000 1.27 +++ Src/Zle/complete.c 12 Dec 2004 20:44:49 -0000 @@ -70,7 +70,8 @@ char *compiprefix, *comptoend, *compoldlist, *compoldins, - *compvared; + *compvared, + *compcompound; /**/ Param *comprpms, *compkpms; @@ -1018,6 +1019,7 @@ static struct compparam compkparams[] = { "list_lines", PM_INTEGER | PM_READONLY, NULL, GSU(listlines_gsu) }, { "all_quotes", PM_SCALAR | PM_READONLY, VAL(compqstack), NULL }, { "ignored", PM_INTEGER | PM_READONLY, VAL(compignored), NULL }, + { "compound_word", PM_SCALAR, VAL(compcompound), NULL }, { NULL, 0, NULL, NULL } }; @@ -1428,7 +1430,7 @@ setup_(UNUSED(Module m)) compquoting = comprestore = complist = compinsert = compexact = compexactstr = comppatmatch = comppatinsert = complastprompt = comptoend = compoldlist = compoldins = - compvared = compqstack = NULL; + compvared = compqstack = compcompound = NULL; complastprefix = ztrdup(""); complastsuffix = ztrdup(""); complistmax = 0; @@ -1508,6 +1510,7 @@ finish_(UNUSED(Module m)) zsfree(compoldlist); zsfree(compoldins); zsfree(compvared); + zsfree(compcompound); hascompmod = 0; Index: Src/Zle/compresult.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/Zle/compresult.c,v retrieving revision 1.52 diff -u -p -r1.52 compresult.c --- Src/Zle/compresult.c 12 Jul 2004 10:05:52 -0000 1.52 +++ Src/Zle/compresult.c 12 Dec 2004 20:44:49 -0000 @@ -1243,14 +1243,16 @@ accept_last(void) int l; cs = minfo.pos + minfo.len + minfo.insc; - iremovesuffix(' ', 1); + if (!compcompound || strlen(compcompound) == 0) + iremovesuffix(' ', 1); l = cs; cs = minfo.pos + minfo.len + minfo.insc - (*(minfo.cur))->qisl; if (cs < l) foredel(l - cs); else if (cs > ll) cs = ll; - inststrlen(" ", 1, 1); + if (!compcompound || strlen(compcompound) == 0) + inststrlen(" ", 1, 1); minfo.insc = minfo.len = 0; minfo.pos = cs; minfo.we = 1; --Boundary-00=_wLLvBRx8qpoYUHo--