Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
PATCH: compadd parameter flag
- X-seq: zsh-workers 7798
- From: Sven Wischnowsky <wischnow@xxxxxxxxxxxxxxxxxxxxxxx>
- To: zsh-workers@xxxxxxxxxxxxxx
- Subject: PATCH: compadd parameter flag
- Date: Mon, 13 Sep 1999 12:43:40 +0200 (MET DST)
- Mailing-list: contact zsh-workers-help@xxxxxxxxxxxxxx; run by ezmlm
We discussed this some time ago...
Doing the auto_param_slash-test in shell code is a bit slow. This adds
the `-e' flags (for `expansion') to `compadd' which says that the
matches added should be interpreted as parameter names and the usual
suffix handling should be done. With that the `_parameter' functions
become really simple. I've kept the old functions in comments, though,
so that we can easily go back if enough people say that we *should* do
this in shell code.
Ok, that's the last of my weekend-patches. Now for the mails...
Bye
Sven
diff -u od/Zsh/compwid.yo Doc/Zsh/compwid.yo
--- od/Zsh/compwid.yo Thu Sep 9 16:31:34 1999
+++ Doc/Zsh/compwid.yo Sun Sep 12 21:53:08 1999
@@ -366,7 +366,7 @@
)
findex(compadd)
cindex(completion widgets, adding specified matches)
-xitem(tt(compadd) [ tt(-qQfnUam) ] [ tt(-F) var(array) ])
+xitem(tt(compadd) [ tt(-qQfenUam) ] [ tt(-F) var(array) ])
xitem([ tt(-P) var(prefix) ] [ tt(-S) var(suffix) ])
xitem([ tt(-p) var(hidden-prefix) ] [ tt(-s) var(hidden-suffix) ])
xitem([ tt(-i) var(ignored-prefix) ] [ tt(-I) var(ignored-suffix) ])
@@ -485,6 +485,12 @@
characters describing the types of the files in the completion lists will
be shown. This also forces a slash to be added when the name of a
directory is completed.
+)
+item(tt(-e))(
+This flag can be used to tell the completion code that the matches
+added are parameter names for a parameter expansion. This will make
+the tt(AUTO_PARAM_SLASH) and tt(AUTO_PARAM_KEYS) options be used for
+the matches.
)
item(tt(-W) var(file-prefix))(
This option has the same meaning as for the tt(compctl) and
diff -u -r os/Zle/comp.h Src/Zle/comp.h
--- os/Zle/comp.h Thu Sep 9 16:32:13 1999
+++ Src/Zle/comp.h Sun Sep 12 21:15:25 1999
@@ -226,9 +226,10 @@
#define CMF_FILE 1 /* this is a file */
#define CMF_REMOVE 2 /* remove the suffix */
-#define CMF_PARBR 4 /* paramter expansion with a brace */
-#define CMF_PARNEST 8 /* nested paramter expansion */
-#define CMF_NOLIST 16 /* should not be listed */
+#define CMF_ISPAR 4 /* is paramter expansion */
+#define CMF_PARBR 8 /* paramter expansion with a brace */
+#define CMF_PARNEST 16 /* nested paramter expansion */
+#define CMF_NOLIST 32 /* should not be listed */
/* Stuff for completion matcher control. */
diff -u -r os/Zle/compctl.c Src/Zle/compctl.c
--- os/Zle/compctl.c Thu Sep 9 16:32:13 1999
+++ Src/Zle/compctl.c Sun Sep 12 21:19:39 1999
@@ -1751,6 +1751,9 @@
case 'f':
dat.flags |= CMF_FILE;
break;
+ case 'e':
+ dat.flags |= CMF_ISPAR;
+ break;
case 'F':
sp = &(dat.ign);
e = "string expected after -%c";
diff -u -r os/Zle/zle_tricky.c Src/Zle/zle_tricky.c
--- os/Zle/zle_tricky.c Thu Sep 9 16:32:15 1999
+++ Src/Zle/zle_tricky.c Sun Sep 12 21:35:38 1999
@@ -197,6 +197,10 @@
static char *parpre;
+/* Flags for parameter expansions for new style completion. */
+
+static int parflags;
+
/* This is either zero or equal to the special character the word we are *
* trying to complete starts with (e.g. Tilde or Equals). */
@@ -812,7 +816,8 @@
parq = eparq = 0;
/* Save the prefix. */
- if (incompfunc) {
+ if (compfunc) {
+ parflags = (br >= 2 ? CMF_PARBR : 0);
sav = *b;
*b = '\0';
untokenize(parpre = ztrdup(s));
@@ -3801,6 +3806,8 @@
Patprog cp = NULL;
LinkList aparl = NULL, oparl = NULL, dparl = NULL;
+ if (dat->flags & CMF_ISPAR)
+ dat->flags |= parflags;
if (compquote && (qc = *compquote)) {
if (qc == '`') {
instring = 0;
@@ -4562,7 +4569,8 @@
cs = origcs;
}
/* Print the explanation strings if needed. */
- if (!showinglist && validlist && usemenu != 2 && nmatches != 1) {
+ if (!showinglist && validlist && usemenu != 2 && nmatches != 1 &&
+ (!oldlist || !listshown)) {
Cmgroup g = amatches;
Cexpl *e;
int up = 0, tr = 1, nn = 0;
@@ -7747,6 +7759,7 @@
{
int l, sr = 0, scs;
int havesuff = 0;
+ int partest = (m->ripre || ((m->flags & CMF_ISPAR) && parpre));
char *str = m->str, *ppre = m->ppre, *psuf = m->psuf, *prpre = m->prpre;
if (!prpre) prpre = "";
@@ -7795,7 +7808,7 @@
/* There is no user-specified suffix, *
* so generate one automagically. */
cs = scs;
- if (m->ripre && (m->flags & CMF_PARBR)) {
+ if (partest && (m->flags & CMF_PARBR)) {
int pq;
/*{{*/
@@ -7811,7 +7824,7 @@
if (m->flags & CMF_PARNEST)
havesuff = 1;
}
- if ((m->flags & CMF_FILE) || (m->ripre && isset(AUTOPARAMSLASH))) {
+ if ((m->flags & CMF_FILE) || (partest && isset(AUTOPARAMSLASH))) {
/* If we have a filename or we completed a parameter name *
* and AUTO_PARAM_SLASH is set, lets see if it is a directory. *
* If it is, we append a slash. */
@@ -7823,11 +7836,14 @@
t = 1;
else {
/* Build the path name. */
- if (m->ripre && !*psuf && !(m->flags & CMF_PARNEST)) {
+ if (partest && !*psuf && !(m->flags & CMF_PARNEST)) {
int ne = noerrs;
- p = (char *) zhalloc(strlen(m->ripre) + strlen(str) + 2);
- sprintf(p, "%s%s%c", m->ripre, str,
+ p = (char *) zhalloc(strlen((m->flags & CMF_ISPAR) ?
+ parpre : m->ripre) +
+ strlen(str) + 2);
+ sprintf(p, "%s%s%c",
+ ((m->flags & CMF_ISPAR) ? parpre : m->ripre), str,
((m->flags & CMF_PARBR) ? Outbrace : '\0'));
noerrs = 1;
parsestr(p);
@@ -7837,7 +7853,8 @@
} else {
p = (char *) zhalloc(strlen(prpre) + strlen(str) +
strlen(psuf) + 3);
- sprintf(p, "%s%s%s", (prpre && *prpre) ? prpre : "./", str, psuf);
+ sprintf(p, "%s%s%s", ((prpre && *prpre) ?
+ prpre : "./"), str, psuf);
}
/* And do the stat. */
t = (!(sr = ztat(p, &buf, 0)) && S_ISDIR(buf.st_mode));
@@ -7896,7 +7913,7 @@
makesuffix(1);
}
}
- if (minfo.we && m->ripre && isset(AUTOPARAMKEYS))
+ if (minfo.we && partest && isset(AUTOPARAMKEYS))
makeparamsuffix(((m->flags & CMF_PARBR) ? 1 : 0), minfo.insc - parq);
if ((menucmp && !minfo.we) || !movetoend) {
diff -u -r oldcompletion/Base/_brace_parameter Completion/Base/_brace_parameter
--- oldcompletion/Base/_brace_parameter Mon Sep 13 10:37:18 1999
+++ Completion/Base/_brace_parameter Sun Sep 12 21:49:57 1999
@@ -1,25 +1,31 @@
#compdef -brace-parameter-
-setopt localoptions extendedglob
+_parameters -e
-local lp ls n q
-if [[ "$SUFFIX" = *\}* ]]; then
- ISUFFIX="${SUFFIX#*\}}$ISUFFIX"
- SUFFIX="${SUFFIX%%\}*}"
- suf=()
-elif [[ "$LBUFFER" = *\$\{[^}]#\$\{[^}]#$PREFIX ||
- "$compstate[insert]" = *menu* ]]; then
- suf=(-b '')
-else
- suf=(-b ' ')
-fi
-
-lp="$LBUFFER[1,-${#PREFIX}-1]"
-ls="$RBUFFER[${#SUFFIX}+1,-1]"
-n=${(M)#ls##\"#}
-q=${(M)lp%%\"#}
+# Without the `-e' option, we would use the following (see the file
+# Core/_parameters for more enlightenment).
-[[ n -gt 0 ]] && suf=''
+# setopt localoptions extendedglob
-_parameters "$suf[@]" -Qs "${q[1,-n-1]}" -r '-:?#%+=[/}'
+# local lp ls n q
+
+# if [[ "$SUFFIX" = *\}* ]]; then
+# ISUFFIX="${SUFFIX#*\}}$ISUFFIX"
+# SUFFIX="${SUFFIX%%\}*}"
+# suf=()
+# elif [[ "$LBUFFER" = *\$\{[^}]#\$\{[^}]#$PREFIX ||
+# "$compstate[insert]" = *menu* ]]; then
+# suf=(-b '')
+# else
+# suf=(-b ' ')
+# fi
+
+# lp="$LBUFFER[1,-${#PREFIX}-1]"
+# ls="$RBUFFER[${#SUFFIX}+1,-1]"
+# n=${(M)#ls##\"#}
+# q=${(M)lp%%\"#}
+
+# [[ n -gt 0 ]] && suf=''
+
+# _parameters "$suf[@]" -Qs "${q[1,-n-1]}" -r '-:?#%+=[/}'
diff -u -r oldcompletion/Base/_parameter Completion/Base/_parameter
--- oldcompletion/Base/_parameter Mon Sep 13 10:37:18 1999
+++ Completion/Base/_parameter Sun Sep 12 21:46:45 1999
@@ -1,7 +1,12 @@
#compdef -parameter-
-if [[ "$compstate[insert]" = *menu* ]]; then
- _parameters -s ''
-else
- _parameters -s ' '
-fi
+_parameters -e
+
+# Without the `-e' option, we would use the following (see the file
+# Core/_parameters for more enlightenment).
+
+# if [[ "$compstate[insert]" = *menu* ]]; then
+# _parameters -s ''
+# else
+# _parameters -s ' '
+# fi
diff -u -r oldcompletion/Core/_parameters Completion/Core/_parameters
--- oldcompletion/Core/_parameters Mon Sep 13 10:37:51 1999
+++ Completion/Core/_parameters Sun Sep 12 21:49:40 1999
@@ -2,76 +2,94 @@
# This should be used to complete parameter names if you need some of the
# extra options of compadd. It completes only non-local parameters.
-# If the first argument is `-s' or `-b' auto_param_slash will be tested
-# and slashes will be added to parameters containing a directory. `-s' is
-# for parameter expansions without braces and `-b' is for expansions with
-# braces. A `-' as the first argument is ignored and in all cases all
-# other arguments will be given to `compadd'.
-
setopt localoptions extendedglob
-local pars expl slash suf
+local pars expl
+
+_description expl parameter
-if [[ "$1" = -s ]]; then
- slash=normal
- suf="$2"
- shift 2
-elif [[ "$1" = -b ]]; then
- slash=brace
- suf="$2"
- shift 2
-elif [[ "$1" = - ]]; then
- shift
+if zmodload -e parameter; then
+ pars=( ${(k)parameters[(R)^*local*]} )
+else
+ pars=( ${${${(f)"$(typeset +)"}:#*local *}##* } )
fi
-_description expl parameter
+compadd "$expl[@]" "$@" - $pars
-if [[ -n "$slash" && -o autoparamslash ]]; then
- local i dirs nodirs ret=1
- dirs=()
- nodirs=()
- if zmodload -e parameter; then
- setopt localoptions extendedglob
- nodirs=( ${(k)parameters[(R)undefined]} )
- pars=( ${(k)parameters[(R)^*(local|undefined)*]} )
- else
- nodirs=( ${${(M)${(f)"$(typeset +)"}:#undefined *}##* } )
- pars=( ${${${(f)"$(typeset +)"}:#*(local|undefined) *}##* } )
- fi
-
- for i in $pars; do
- if [[ -d "${(P)i}" ]]; then
- dirs=( $dirs $i )
- else
- nodirs=( $nodirs $i )
- fi
- done
-
- if [[ "$slash" = normal ]]; then
- compadd -S "/${suf%% #}" -r ' [/:' "$expl[@]" "$@" - $dirs && ret=0
- compadd -S "$suf" -r ' [:' "$expl[@]" "$@" - $nodirs && ret=0
- elif [[ "$slash" = brace ]]; then
- compadd -S "}/${suf%% #}" -r '-:?#%+=[/}' "$expl[@]" "$@" - $dirs && ret=0
- compadd -S "}$suf" -r '-:?#%+=[/}' "$expl[@]" "$@" - $nodirs && ret=0
- fi
+# The `-e' option does everything for parameter expansions of us. If
+# we wouldn't have it, we would use something like:
- return ret
-else
- if zmodload -e parameter; then
- setopt localoptions extendedglob
- pars=( ${(k)parameters[(R)^*local*]} )
- else
- pars=( ${${${(f)"$(typeset +)"}:#*local *}##* } )
- fi
-
- if [[ "$slash" = normal ]]; then
- compadd -S "$suf" -r ' [:' "$expl[@]" "$@" - $pars
- elif [[ "$slash" = brace ]]; then
- compadd -S "}$suf" -r '-:?#%+=[/}' "$expl[@]" "$@" - $pars
- else
- compadd "$expl[@]" "$@" - $pars
- fi
-fi
+# If the first argument is `-s' or `-b' auto_param_slash will be tested
+# and slashes will be added to parameters containing a directory. `-s' is
+# for parameter expansions without braces and `-b' is for expansions with
+# braces. A `-' as the first argument is ignored and in all cases all
+# other arguments will be given to `compadd'.
+
+# setopt localoptions extendedglob
+
+# local pars expl slash suf
+
+# if [[ "$1" = -s ]]; then
+# slash=normal
+# suf="$2"
+# shift 2
+# elif [[ "$1" = -b ]]; then
+# slash=brace
+# suf="$2"
+# shift 2
+# elif [[ "$1" = - ]]; then
+# shift
+# fi
+
+# _description expl parameter
+
+# if [[ -n "$slash" && -o autoparamslash ]]; then
+# local i dirs nodirs ret=1
+
+# dirs=()
+# nodirs=()
+
+# if zmodload -e parameter; then
+# setopt localoptions extendedglob
+# nodirs=( ${(k)parameters[(R)undefined]} )
+# pars=( ${(k)parameters[(R)^*(local|undefined)*]} )
+# else
+# nodirs=( ${${(M)${(f)"$(typeset +)"}:#undefined *}##* } )
+# pars=( ${${${(f)"$(typeset +)"}:#*(local|undefined) *}##* } )
+# fi
+
+# for i in $pars; do
+# if [[ -d "${(P)i}" ]]; then
+# dirs=( $dirs $i )
+# else
+# nodirs=( $nodirs $i )
+# fi
+# done
+
+# if [[ "$slash" = normal ]]; then
+# compadd -S "/${suf%% #}" -r ' [/:' "$expl[@]" "$@" - $dirs && ret=0
+# compadd -S "$suf" -r ' [:' "$expl[@]" "$@" - $nodirs && ret=0
+# elif [[ "$slash" = brace ]]; then
+# compadd -S "}/${suf%% #}" -r '-:?#%+=[/}' "$expl[@]" "$@" - $dirs && ret=0
+# compadd -S "}$suf" -r '-:?#%+=[/}' "$expl[@]" "$@" - $nodirs && ret=0
+# fi
+
+# return ret
+# else
+# if zmodload -e parameter; then
+# pars=( ${(k)parameters[(R)^*local*]} )
+# else
+# pars=( ${${${(f)"$(typeset +)"}:#*local *}##* } )
+# fi
+
+# if [[ "$slash" = normal ]]; then
+# compadd -S "$suf" -r ' [:' "$expl[@]" "$@" - $pars
+# elif [[ "$slash" = brace ]]; then
+# compadd -S "}$suf" -r '-:?#%+=[/}' "$expl[@]" "$@" - $pars
+# else
+# compadd "$expl[@]" "$@" - $pars
+# fi
+# fi
--
Sven Wischnowsky wischnow@xxxxxxxxxxxxxxxxxxxxxxx
Messages sorted by:
Reverse Date,
Date,
Thread,
Author