* PATCH: return value for `compcall'
@ 1999-02-12 11:02 Sven Wischnowsky
1999-02-12 15:50 ` Bart Schaefer
0 siblings, 1 reply; 3+ messages in thread
From: Sven Wischnowsky @ 1999-02-12 11:02 UTC (permalink / raw)
To: zsh-workers
The patch below makes `compcall' return something hopefully useful. It
is zero if no `compctl' was found and non-zero if one was found. More
exactly, it is `1' if a normal compctl was found, `2' if a `pattern compctl'
was found, and `3' if both were found.
The example file `__default' (to which the call to `compcall' was
moved, btw, I forgot to mention this) now uses this return value.
And another thing I forgot: I will write a manual for the new style
completion stuff soon. I don't know if I will finish this today,
though. (Maybe at the weekend, but then again, maybe not).
Bye
Sven
diff -u os/Zle/comp1.c Src/Zle/comp1.c
--- os/Zle/comp1.c Fri Feb 12 11:33:23 1999
+++ Src/Zle/comp1.c Fri Feb 12 11:50:12 1999
@@ -61,7 +61,7 @@
void (*makecomplistcallptr) _((Compctl));
/**/
-void (*makecomplistctlptr) _((int));
+int (*makecomplistctlptr) _((int));
/* Hash table for completion info for commands */
diff -u os/Zle/compctl.c Src/Zle/compctl.c
--- os/Zle/compctl.c Fri Feb 12 11:33:23 1999
+++ Src/Zle/compctl.c Fri Feb 12 11:50:24 1999
@@ -1806,9 +1806,8 @@
zerrnam(name, "can only be called from completion function", NULL, 0);
return 1;
}
- makecomplistctlptr((ops['T'] ? 0 : CFN_FIRST) |
- (ops['D'] ? 0 : CFN_DEFAULT));
- return 0;
+ return makecomplistctlptr((ops['T'] ? 0 : CFN_FIRST) |
+ (ops['D'] ? 0 : CFN_DEFAULT));
}
#define VAR(X) ((void *) (&(X)))
diff -u os/Zle/zle_tricky.c Src/Zle/zle_tricky.c
--- os/Zle/zle_tricky.c Fri Feb 12 11:33:24 1999
+++ Src/Zle/zle_tricky.c Fri Feb 12 11:54:42 1999
@@ -3640,11 +3640,13 @@
#define MAX_CDEPTH 16
/**/
-void
+int
makecomplistctl(int flags)
{
+ int ret;
+
if (cdepth == MAX_CDEPTH)
- return;
+ return 0;
cdepth++;
SWITCHHEAPS(compheap) {
@@ -3668,9 +3670,10 @@
*q = NULL;
offs = lip + lp;
incompfunc = 2;
- makecomplistglobal(str,
- (!clwpos && !strcmp(compcontext, "command")),
- COMP_COMPLETE, flags);
+ ret = makecomplistglobal(str,
+ (!clwpos &&
+ !strcmp(compcontext, "command")),
+ COMP_COMPLETE, flags);
incompfunc = 1;
offs = ooffs;
compnmatches = mnum;
@@ -3683,13 +3686,15 @@
} LASTALLOC;
} SWITCHBACKHEAPS;
cdepth--;
+
+ return ret;
}
/* This function gets the compctls for the given command line and *
* adds all completions for them. */
/**/
-static void
+static int
makecomplistglobal(char *os, int incmd, int lst, int flags)
{
Compctl cc;
@@ -3721,46 +3726,48 @@
} else if (linredir)
/* In redirections use default completion. */
cc = &cc_default;
- else {
+ else
/* Otherwise get the matches for the command. */
- makecomplistcmd(os, incmd, flags);
- cc = NULL;
- }
+ return makecomplistcmd(os, incmd, flags);
+
if (cc) {
/* First, use the -T compctl. */
if (!(flags & CFN_FIRST)) {
makecomplistcc(&cc_first, os, incmd);
if (!(ccont & CC_CCCONT))
- return;
+ return 0;
}
makecomplistcc(cc, os, incmd);
+ return 1;
}
+ return 0;
}
/* This produces the matches for a command. */
/**/
-static void
+static int
makecomplistcmd(char *os, int incmd, int flags)
{
Compctl cc;
Compctlp ccp;
char *s;
+ int ret = 0;
/* First, use the -T compctl. */
if (!(flags & CFN_FIRST)) {
makecomplistcc(&cc_first, os, incmd);
if (!(ccont & CC_CCCONT))
- return;
+ return 0;
}
/* Then search the pattern compctls, with the command name and the *
* full pathname of the command. */
if (cmdstr) {
- makecomplistpc(os, incmd);
+ ret |= makecomplistpc(os, incmd);
if (!(ccont & CC_CCCONT))
- return;
+ return ret;
}
/* If the command string starts with `=', try the path name of the *
* command. */
@@ -3785,31 +3792,36 @@
(ccp = (Compctlp) compctltab->getnode(compctltab, s)) &&
(cc = ccp->cc))))) {
if (flags & CFN_DEFAULT)
- return;
+ return ret;
cc = &cc_default;
- }
+ } else
+ ret|= 1;
makecomplistcc(cc, os, incmd);
+ return ret;
}
/* This add the matches for the pattern compctls. */
/**/
-static void
+static int
makecomplistpc(char *os, int incmd)
{
Patcomp pc;
Comp pat;
char *s = findcmd(cmdstr, 1);
+ int ret = 0;
for (pc = patcomps; pc; pc = pc->next) {
if ((pat = parsereg(pc->pat)) &&
(domatch(cmdstr, pat, 0) ||
(s && domatch(s, pat, 0)))) {
makecomplistcc(pc->cc, os, incmd);
+ ret |= 2;
if (!(ccont & CC_CCCONT))
- return;
+ return ret;
}
}
+ return ret;
}
/* This produces the matches for one compctl. */
diff -u om/Completion/__default Misc/Completion/__default
--- om/Completion/__default Fri Feb 12 10:55:15 1999
+++ Misc/Completion/__default Fri Feb 12 11:54:24 1999
@@ -2,11 +2,12 @@
# We first try the `compctl's. This is without first (-T) and default (-D)
# completion. If you want them add `-T' and/or `-D' to this command.
-# If this produces any matches, we don't try new style completion. If you
-# want to have that tried anyway, remove the `[[ -nmatches ... ]] ...'
-# below.
+# If there is a `compctl' for the command we are working on, we return
+# immediatly. If you want to use new style completion anyway, remove the
+# `|| return'. Also, you may want to use new style completion if the
+# `compctl' didn't produce any matches. In that case remove the `|| return'
+# and at the line `[[ -nmatches 0 ]] || return' after `compcall'.
-compcall
-[[ -nmatches 0 ]] || return
+compcall || return
__files
--
Sven Wischnowsky wischnow@informatik.hu-berlin.de
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: PATCH: return value for `compcall'
1999-02-12 11:02 PATCH: return value for `compcall' Sven Wischnowsky
@ 1999-02-12 15:50 ` Bart Schaefer
1999-02-12 16:11 ` Peter Stephenson
0 siblings, 1 reply; 3+ messages in thread
From: Bart Schaefer @ 1999-02-12 15:50 UTC (permalink / raw)
To: zsh-workers
On Feb 12, 12:02pm, Sven Wischnowsky wrote:
} Subject: PATCH: return value for `compcall'
}
} The patch below makes `compcall' return something hopefully useful.
This is not exactly on topic, but why is all this stuff in Misc/ rather
than in Functions/ ?
--
Bart Schaefer Brass Lantern Enterprises
http://www.well.com/user/barts http://www.brasslantern.com
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: PATCH: return value for `compcall'
1999-02-12 15:50 ` Bart Schaefer
@ 1999-02-12 16:11 ` Peter Stephenson
0 siblings, 0 replies; 3+ messages in thread
From: Peter Stephenson @ 1999-02-12 16:11 UTC (permalink / raw)
To: zsh-workers
"Bart Schaefer" wrote:
> This is not exactly on topic, but why is all this stuff in Misc/ rather
> than in Functions/ ?
anyone want to vote? I hope there will be a pws-8 tomorrow. The real
reason is that it started off as new-completion-examples, which was
definitely miscellaneous.
--
Peter Stephenson <pws@ibmth.df.unipi.it> Tel: +39 050 844536
WWW: http://www.ifh.de/~pws/
Dipartimento di Fisica, Via Buonarroti 2, 56127 Pisa, Italy
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~1999-02-12 16:28 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-02-12 11:02 PATCH: return value for `compcall' Sven Wischnowsky
1999-02-12 15:50 ` Bart Schaefer
1999-02-12 16:11 ` Peter Stephenson
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).