From: Sven Wischnowsky <wischnow@informatik.hu-berlin.de>
To: zsh-workers@sunsite.auc.dk
Subject: Re: -subscript- completion for assoc array
Date: Tue, 16 Mar 1999 11:49:28 +0100 (MET) [thread overview]
Message-ID: <199903161049.LAA25462@beta.informatik.hu-berlin.de> (raw)
In-Reply-To: Peter Stephenson's message of Mon, 15 Mar 1999 17:18:38 +0100
Peter Stephenson wrote:
> I wouldn't have thought it would be too hard just to pass the whole string
> to the -subscript- handler, and inside that, if the parameter is not an
> assoc, simply IPREFIXify anything which is not alphanumeric before handing
> the rest on to the -math- handler. You don't even need special handling
> for variables with funny names, since they're always a single character so
> can't be completed further. Unless I've missed something.
Ok, the patch below makes completion functions get the whole string --
almost. This has a small problem with things like `(( 8*((x-1+f<TAB>'.
Here it stops at the `((' before the `x', thinking it is the beginning
of a `((...' or a `$((...'.
And this finally could me implement a `ISUFFIX' parameter, so that we
could make this correctly if there is something after the cursor. I've
been wishing for this when implementing `_tilde' already. Maybe I
build this into the tricky.c-cleanup I'm currently busy with.
> (Except, of course, when calling old completion, in which case you've got
> to do as much as is reasonable in C.)
This will behave the same way it ever did, i.e. I haven't built in
some magic to complete the keys of assoc arrays.
> By the way, it's a bit annoying that the command is called `compdef' while
> the lines at the tops of the functions to do the same thing automatically
> are still `defcomp' etc. If it's not yet too late, it might be a good idea
> to change these to `compdef', `compdefpat' and `compdefkey'.
Yes, I've been thinking about this, too. Although I probably would
prefer `#compdef -p ...' and `#compdef -k ...'.
Bye
Sven
diff -u os/Zle/zle_tricky.c Src/Zle/zle_tricky.c
--- os/Zle/zle_tricky.c Mon Mar 15 16:57:14 1999
+++ Src/Zle/zle_tricky.c Tue Mar 16 11:38:47 1999
@@ -1346,12 +1346,35 @@
}
}
if (inwhat == IN_MATH) {
- /* In mathematical expression, we complete parameter names (even *
- * if they don't have a `$' in front of them). So we have to *
- * find that name. */
- for (we = cs; iident(line[we]); we++);
- for (wb = cs; --wb >= 0 && iident(line[wb]););
- wb++;
+ if (compfunc) {
+ int lev;
+ char *p;
+
+ for (wb = cs - 1, lev = 0; wb > 0; wb--)
+ if (line[wb] == ']' || line[wb] == ')')
+ lev++;
+ else if (line[wb] == '[') {
+ if (!lev--)
+ break;
+ } else if (line[wb] == '(') {
+ if (!lev && line[wb - 1] == '(')
+ break;
+ if (lev)
+ lev--;
+ }
+ wb++;
+ p = (char *) line + wb;
+ if (wb && (*p == '[' || *p == '(') &&
+ !skipparens(*p, (*p == '[' ? ']' : ')'), &p))
+ we = p - (char *) line;
+ } else {
+ /* In mathematical expression, we complete parameter names *
+ * (even if they don't have a `$' in front of them). So we *
+ * have to find that name. */
+ for (we = cs; iident(line[we]); we++);
+ for (wb = cs; --wb >= 0 && iident(line[wb]););
+ wb++;
+ }
zsfree(s);
s = zalloc(we - wb + 1);
strncpy(s, (char *) line + wb, we - wb);
@@ -5240,14 +5263,20 @@
zsfree(compprefix);
zsfree(compsuffix);
if (unset(COMPLETEINWORD)) {
- tmp = quotename(s, NULL, NULL, NULL);
+ if (inwhat == IN_MATH)
+ tmp = s;
+ else
+ tmp = quotename(s, NULL, NULL, NULL);
untokenize(tmp);
compprefix = ztrdup(tmp);
compsuffix = ztrdup("");
} else {
char *ss = s + offs, sav;
- tmp = quotename(s, &ss, NULL, NULL);
+ if (inwhat == IN_MATH)
+ tmp = s;
+ else
+ tmp = quotename(s, &ss, NULL, NULL);
sav = *ss;
*ss = '\0';
untokenize(tmp);
diff -u oc/Base/_math Completion/Base/_math
--- oc/Base/_math Tue Mar 16 10:29:34 1999
+++ Completion/Base/_math Tue Mar 16 11:43:35 1999
@@ -0,0 +1,6 @@
+#defcomp -math-
+
+IPREFIX="$IPREFIX${PREFIX%[a-zA-Z0-9_]*}"
+PREFIX="${PREFIX##*[^a-zA-Z0-9_]}"
+
+compgen -v
diff -u oc/Base/_vars Completion/Base/_vars
--- oc/Base/_vars Mon Mar 15 16:57:24 1999
+++ Completion/Base/_vars Tue Mar 16 10:29:20 1999
@@ -1,3 +1,3 @@
-#defcomp -math- getopts read unset vared
+#defcomp getopts read unset vared
compgen -v
--
Sven Wischnowsky wischnow@informatik.hu-berlin.de
next reply other threads:[~1999-03-17 8:52 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
1999-03-16 10:49 Sven Wischnowsky [this message]
-- strict thread matches above, loose matches on Subject: below --
1999-03-15 16:00 Sven Wischnowsky
1999-03-15 16:18 ` Peter Stephenson
1999-03-15 15:10 Peter Stephenson
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=199903161049.LAA25462@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).