zsh-workers
 help / color / mirror / code / Atom feed
From: Sven Wischnowsky <wischnow@informatik.hu-berlin.de>
To: zsh-workers@sunsite.auc.dk
Subject: Re: Completion problems.
Date: Mon, 2 Aug 1999 12:58:55 +0200 (MET DST)	[thread overview]
Message-ID: <199908021058.MAA12713@beta.informatik.hu-berlin.de> (raw)
In-Reply-To: Tanaka Akira's message of 27 Jul 1999 18:53:19 +0900


Tanaka Akira wrote:

> I found a problem about the conditional expression for completion.
> 
> is27e1u11% autoload -U compinit; compinit -D
> is27e1u11% _tst () { if [[ -prefix */ ]]; then compadd ../t; else compadd ../f; fi }
> is27e1u11% compdef _tst tst
> is27e1u11% tst ../<TAB>
> 
> Then, I get:
> 
> is27e1u11% tst ../f 
> 
> I think it should be "../t ".

Definitely, yes. The problem was that cond_str() always returned an
untokenized string. The patch gives a new argument to it which may be
non-zero to get the tokenized form. Then there were some missing tests 
for `if (mod)' in do_comp_vars() (mod says if the special parameters
should be modified). Some of the new tests are superfluous for the
condition codes we have now, but if someone once changes this, the
tests will already be there.

> Hm. compset -P is bit dangerous for quoted characters.
> 
> is27e1u11% autoload -U compinit; compinit -D
> is27e1u11% _tst () { compset -P '*/'; compadd tst }
> is27e1u11% compdef _tst tst
> is27e1u11% tst \#/<TAB>
> 
> Then, I get:
> 
> is27e1u11% tst \\\#/tst 

That's wrong, too. Again, this is a problem with the recently changed
quoting behaviour. The prefix is reported in quoted form and appended
and prepended to IPREFIX/ISUFFIX -- which will be quoted again when it 
is inserted.

Bye
 Sven

diff -u os/cond.c Src/cond.c
--- os/cond.c	Mon Aug  2 11:44:45 1999
+++ Src/cond.c	Mon Aug  2 11:56:31 1999
@@ -303,12 +303,13 @@
 
 /**/
 char *
-cond_str(char **args, int num)
+cond_str(char **args, int num, int raw)
 {
     char *s = args[num];
 
     singsub(&s);
-    untokenize(s);
+    if (!raw)
+	untokenize(s);
 
     return s;
 }
diff -u os/Zle/compctl.c Src/Zle/compctl.c
--- os/Zle/compctl.c	Mon Aug  2 11:44:52 1999
+++ Src/Zle/compctl.c	Mon Aug  2 12:51:28 1999
@@ -1888,7 +1888,7 @@
     char *tmp, sav = compprefix[l];
 
     compprefix[l] = '\0';
-    tmp = tricat(compiprefix, compprefix, "");
+    tmp = tricat(compiprefix, rembslash(compprefix), "");
     zsfree(compiprefix);
     compiprefix = tmp;
     compprefix[l] = sav;
@@ -1903,7 +1903,7 @@
     char *tmp, sav;
 
     l = strlen(compsuffix) - l;
-    tmp = tricat(compsuffix + l, compisuffix, "");
+    tmp = tricat(rembslash(compsuffix + l), compisuffix, "");
     zsfree(compisuffix);
     compisuffix = tmp;
     sav = compsuffix[l];
@@ -1947,8 +1947,8 @@
 
 	    if (compcurrent - 1 < na || compcurrent - 1 > nb)
 		return 0;
-
-	    restrict_range(na, nb);
+	    if (mod)
+		restrict_range(na, nb);
 	    return 1;
 	}
     case CVT_RANGEPAT:
@@ -1989,7 +1989,7 @@
 	    }
 	    if (e < b)
 		t = 0;
-	    if (t)
+	    if (t && mod)
 		restrict_range(b, e);
 	    return t;
 	}
@@ -2043,8 +2043,8 @@
 		}
 		if (!l)
 		    return 0;
-
-		ignore_prefix(p - compprefix);
+		if (mod)
+		    ignore_prefix(p - compprefix);
 	    } else {
 		int l, ol, add;
 		char *p;
@@ -2065,8 +2065,8 @@
 
 		if (!l)
 		    return 0;
-
-		ignore_suffix(ol - (p - compsuffix));
+		if (mod)
+		    ignore_suffix(ol - (p - compsuffix));
 	    }
 	    return 1;
 	}
@@ -2469,10 +2469,10 @@
 {
     if (comp_check()) {
 	if (a[1])
-	    return do_comp_vars(id, cond_val(a, 0), cond_str(a, 1),
+	    return do_comp_vars(id, cond_val(a, 0), cond_str(a, 1, 1),
 				0, NULL, 0);
 	else
-	    return do_comp_vars(id, -1, cond_str(a, 0), 0, NULL, 0);
+	    return do_comp_vars(id, -1, cond_str(a, 0, 1), 0, NULL, 0);
     }
     return 0;
 }
@@ -2481,8 +2481,8 @@
 static int
 cond_range(char **a, int id)
 {
-    return do_comp_vars(CVT_RANGEPAT, 0, cond_str(a, 0), 0,
-			(id ? cond_str(a, 1) : NULL), 0);
+    return do_comp_vars(CVT_RANGEPAT, 0, cond_str(a, 0, 1), 0,
+			(id ? cond_str(a, 1, 1) : NULL), 0);
 }
 
 static struct builtin bintab[] = {
--- Util/zsh-development-guide.old	Mon Aug  2 11:58:18 1999
+++ Util/zsh-development-guide	Mon Aug  2 11:59:03 1999
@@ -285,11 +285,12 @@
 no substitutions are performed on them and that they will be
 tokenized. There are three helper functions available:
 
-  - char *cond_str(args, num)
+  - char *cond_str(args, num, raw)
     The first argument is the array of strings the handler function
     got as an argument and the second one is an index into this array.
     The return value is the num'th string from the array with
-    substitutions performed and untokenized.
+    substitutions performed. If the last argument is zero, the string
+    will also be untokenized.
   - long cond_val(args, num)
     The arguments are the same as for cond_str(). The return value is
     the result of the mathematical evaluation of the num'th string

--
Sven Wischnowsky                         wischnow@informatik.hu-berlin.de


             reply	other threads:[~1999-08-02 10:59 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-08-02 10:58 Sven Wischnowsky [this message]
1999-08-02 18:03 ` Tanaka Akira
  -- strict thread matches above, loose matches on Subject: below --
1999-08-09  9:58 Sven Wischnowsky
1999-08-05 10:56 Sven Wischnowsky
1999-08-04  9:37 Sven Wischnowsky
1999-08-04 17:00 ` Bart Schaefer
1999-08-06 18:53 ` Tanaka Akira
1999-08-04  7:36 Sven Wischnowsky
1999-07-27  9:53 Tanaka Akira
1999-04-27 16:12 completion problems Sven Wischnowsky
1999-04-28 20:32 ` Tanaka Akira
1999-04-28 21:45   ` Vin Shelton
1999-04-27 14:26 Tanaka Akira

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=199908021058.MAA12713@beta.informatik.hu-berlin.de \
    --to=wischnow@informatik.hu-berlin.de \
    --cc=zsh-workers@sunsite.auc.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).