1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-09-10 12:40:58 +02:00

zsh-workers/7798

This commit is contained in:
Tanaka Akira 1999-09-13 10:45:28 +00:00
parent 7eb928e266
commit a4ed24438b
7 changed files with 145 additions and 93 deletions

View file

@ -1,25 +1,31 @@
#compdef -brace-parameter- #compdef -brace-parameter-
setopt localoptions extendedglob _parameters -e
local lp ls n q
if [[ "$SUFFIX" = *\}* ]]; then # Without the `-e' option, we would use the following (see the file
ISUFFIX="${SUFFIX#*\}}$ISUFFIX" # Core/_parameters for more enlightenment).
SUFFIX="${SUFFIX%%\}*}"
suf=()
elif [[ "$LBUFFER" = *\$\{[^}]#\$\{[^}]#$PREFIX ||
"$compstate[insert]" = *menu* ]]; then
suf=(-b '')
else
suf=(-b ' ')
fi
lp="$LBUFFER[1,-${#PREFIX}-1]" # setopt localoptions extendedglob
ls="$RBUFFER[${#SUFFIX}+1,-1]"
n=${(M)#ls##\"#}
q=${(M)lp%%\"#}
[[ n -gt 0 ]] && suf='' # local lp ls n q
_parameters "$suf[@]" -Qs "${q[1,-n-1]}" -r '-:?#%+=[/}' # 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 '-:?#%+=[/}'

View file

@ -1,7 +1,12 @@
#compdef -parameter- #compdef -parameter-
if [[ "$compstate[insert]" = *menu* ]]; then _parameters -e
_parameters -s ''
else # Without the `-e' option, we would use the following (see the file
_parameters -s ' ' # Core/_parameters for more enlightenment).
fi
# if [[ "$compstate[insert]" = *menu* ]]; then
# _parameters -s ''
# else
# _parameters -s ' '
# fi

View file

@ -2,76 +2,94 @@
# This should be used to complete parameter names if you need some of the # This should be used to complete parameter names if you need some of the
# extra options of compadd. It completes only non-local parameters. # extra options of compadd. It completes only non-local parameters.
setopt localoptions extendedglob
local pars expl
_description expl parameter
if zmodload -e parameter; then
pars=( ${(k)parameters[(R)^*local*]} )
else
pars=( ${${${(f)"$(typeset +)"}:#*local *}##* } )
fi
compadd "$expl[@]" "$@" - $pars
# The `-e' option does everything for parameter expansions of us. If
# we wouldn't have it, we would use something like:
# If the first argument is `-s' or `-b' auto_param_slash will be tested # 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 # and slashes will be added to parameters containing a directory. `-s' is
# for parameter expansions without braces and `-b' is for expansions with # for parameter expansions without braces and `-b' is for expansions with
# braces. A `-' as the first argument is ignored and in all cases all # braces. A `-' as the first argument is ignored and in all cases all
# other arguments will be given to `compadd'. # other arguments will be given to `compadd'.
# setopt localoptions extendedglob
setopt localoptions extendedglob # local pars expl slash suf
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
if [[ "$1" = -s ]]; then # _description expl parameter
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
if [[ -n "$slash" && -o autoparamslash ]]; then # dirs=()
local i dirs nodirs ret=1 # nodirs=()
dirs=() # if zmodload -e parameter; then
nodirs=() # 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
if zmodload -e parameter; then # for i in $pars; do
setopt localoptions extendedglob # if [[ -d "${(P)i}" ]]; then
nodirs=( ${(k)parameters[(R)undefined]} ) # dirs=( $dirs $i )
pars=( ${(k)parameters[(R)^*(local|undefined)*]} ) # else
else # nodirs=( $nodirs $i )
nodirs=( ${${(M)${(f)"$(typeset +)"}:#undefined *}##* } ) # fi
pars=( ${${${(f)"$(typeset +)"}:#*(local|undefined) *}##* } ) # done
fi
for i in $pars; do # if [[ "$slash" = normal ]]; then
if [[ -d "${(P)i}" ]]; then # compadd -S "/${suf%% #}" -r ' [/:' "$expl[@]" "$@" - $dirs && ret=0
dirs=( $dirs $i ) # compadd -S "$suf" -r ' [:' "$expl[@]" "$@" - $nodirs && ret=0
else # elif [[ "$slash" = brace ]]; then
nodirs=( $nodirs $i ) # compadd -S "}/${suf%% #}" -r '-:?#%+=[/}' "$expl[@]" "$@" - $dirs && ret=0
fi # compadd -S "}$suf" -r '-:?#%+=[/}' "$expl[@]" "$@" - $nodirs && ret=0
done # fi
if [[ "$slash" = normal ]]; then # return ret
compadd -S "/${suf%% #}" -r ' [/:' "$expl[@]" "$@" - $dirs && ret=0 # else
compadd -S "$suf" -r ' [:' "$expl[@]" "$@" - $nodirs && ret=0 # if zmodload -e parameter; then
elif [[ "$slash" = brace ]]; then # pars=( ${(k)parameters[(R)^*local*]} )
compadd -S "}/${suf%% #}" -r '-:?#%+=[/}' "$expl[@]" "$@" - $dirs && ret=0 # else
compadd -S "}$suf" -r '-:?#%+=[/}' "$expl[@]" "$@" - $nodirs && ret=0 # pars=( ${${${(f)"$(typeset +)"}:#*local *}##* } )
fi # fi
return ret # if [[ "$slash" = normal ]]; then
else # compadd -S "$suf" -r ' [:' "$expl[@]" "$@" - $pars
if zmodload -e parameter; then # elif [[ "$slash" = brace ]]; then
setopt localoptions extendedglob # compadd -S "}$suf" -r '-:?#%+=[/}' "$expl[@]" "$@" - $pars
pars=( ${(k)parameters[(R)^*local*]} ) # else
else # compadd "$expl[@]" "$@" - $pars
pars=( ${${${(f)"$(typeset +)"}:#*local *}##* } ) # fi
fi # 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

View file

@ -366,7 +366,7 @@ otherwise.
) )
findex(compadd) findex(compadd)
cindex(completion widgets, adding specified matches) 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(prefix) ] [ tt(-S) var(suffix) ])
xitem([ tt(-p) var(hidden-prefix) ] [ tt(-s) var(hidden-suffix) ]) xitem([ tt(-p) var(hidden-prefix) ] [ tt(-s) var(hidden-suffix) ])
xitem([ tt(-i) var(ignored-prefix) ] [ tt(-I) var(ignored-suffix) ]) xitem([ tt(-i) var(ignored-prefix) ] [ tt(-I) var(ignored-suffix) ])
@ -486,6 +486,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 be shown. This also forces a slash to be added when the name of a
directory is completed. 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))( item(tt(-W) var(file-prefix))(
This option has the same meaning as for the tt(compctl) and This option has the same meaning as for the tt(compctl) and
tt(compgen) builtin commands. Here, however, only one string may be tt(compgen) builtin commands. Here, however, only one string may be

View file

@ -226,9 +226,10 @@ struct cmatch {
#define CMF_FILE 1 /* this is a file */ #define CMF_FILE 1 /* this is a file */
#define CMF_REMOVE 2 /* remove the suffix */ #define CMF_REMOVE 2 /* remove the suffix */
#define CMF_PARBR 4 /* paramter expansion with a brace */ #define CMF_ISPAR 4 /* is paramter expansion */
#define CMF_PARNEST 8 /* nested paramter expansion */ #define CMF_PARBR 8 /* paramter expansion with a brace */
#define CMF_NOLIST 16 /* should not be listed */ #define CMF_PARNEST 16 /* nested paramter expansion */
#define CMF_NOLIST 32 /* should not be listed */
/* Stuff for completion matcher control. */ /* Stuff for completion matcher control. */

View file

@ -1751,6 +1751,9 @@ bin_compadd(char *name, char **argv, char *ops, int func)
case 'f': case 'f':
dat.flags |= CMF_FILE; dat.flags |= CMF_FILE;
break; break;
case 'e':
dat.flags |= CMF_ISPAR;
break;
case 'F': case 'F':
sp = &(dat.ign); sp = &(dat.ign);
e = "string expected after -%c"; e = "string expected after -%c";

View file

@ -197,6 +197,10 @@ static int noreal;
static char *parpre; 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 * /* This is either zero or equal to the special character the word we are *
* trying to complete starts with (e.g. Tilde or Equals). */ * trying to complete starts with (e.g. Tilde or Equals). */
@ -812,7 +816,8 @@ check_param(char *s, int set, int test)
parq = eparq = 0; parq = eparq = 0;
/* Save the prefix. */ /* Save the prefix. */
if (incompfunc) { if (compfunc) {
parflags = (br >= 2 ? CMF_PARBR : 0);
sav = *b; sav = *b;
*b = '\0'; *b = '\0';
untokenize(parpre = ztrdup(s)); untokenize(parpre = ztrdup(s));
@ -3801,6 +3806,8 @@ addmatches(Cadata dat, char **argv)
Patprog cp = NULL; Patprog cp = NULL;
LinkList aparl = NULL, oparl = NULL, dparl = NULL; LinkList aparl = NULL, oparl = NULL, dparl = NULL;
if (dat->flags & CMF_ISPAR)
dat->flags |= parflags;
if (compquote && (qc = *compquote)) { if (compquote && (qc = *compquote)) {
if (qc == '`') { if (qc == '`') {
instring = 0; instring = 0;
@ -4562,7 +4569,8 @@ docompletion(char *s, int lst, int incmd)
cs = origcs; cs = origcs;
} }
/* Print the explanation strings if needed. */ /* 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; Cmgroup g = amatches;
Cexpl *e; Cexpl *e;
int up = 0, tr = 1, nn = 0; int up = 0, tr = 1, nn = 0;
@ -7751,6 +7759,7 @@ do_single(Cmatch m)
{ {
int l, sr = 0, scs; int l, sr = 0, scs;
int havesuff = 0; 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; char *str = m->str, *ppre = m->ppre, *psuf = m->psuf, *prpre = m->prpre;
if (!prpre) prpre = ""; if (!prpre) prpre = "";
@ -7799,7 +7808,7 @@ do_single(Cmatch m)
/* There is no user-specified suffix, * /* There is no user-specified suffix, *
* so generate one automagically. */ * so generate one automagically. */
cs = scs; cs = scs;
if (m->ripre && (m->flags & CMF_PARBR)) { if (partest && (m->flags & CMF_PARBR)) {
int pq; int pq;
/*{{*/ /*{{*/
@ -7815,7 +7824,7 @@ do_single(Cmatch m)
if (m->flags & CMF_PARNEST) if (m->flags & CMF_PARNEST)
havesuff = 1; 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 * /* If we have a filename or we completed a parameter name *
* and AUTO_PARAM_SLASH is set, lets see if it is a directory. * * and AUTO_PARAM_SLASH is set, lets see if it is a directory. *
* If it is, we append a slash. */ * If it is, we append a slash. */
@ -7827,11 +7836,14 @@ do_single(Cmatch m)
t = 1; t = 1;
else { else {
/* Build the path name. */ /* Build the path name. */
if (m->ripre && !*psuf && !(m->flags & CMF_PARNEST)) { if (partest && !*psuf && !(m->flags & CMF_PARNEST)) {
int ne = noerrs; int ne = noerrs;
p = (char *) zhalloc(strlen(m->ripre) + strlen(str) + 2); p = (char *) zhalloc(strlen((m->flags & CMF_ISPAR) ?
sprintf(p, "%s%s%c", m->ripre, str, 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')); ((m->flags & CMF_PARBR) ? Outbrace : '\0'));
noerrs = 1; noerrs = 1;
parsestr(p); parsestr(p);
@ -7841,7 +7853,8 @@ do_single(Cmatch m)
} else { } else {
p = (char *) zhalloc(strlen(prpre) + strlen(str) + p = (char *) zhalloc(strlen(prpre) + strlen(str) +
strlen(psuf) + 3); 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. */ /* And do the stat. */
t = (!(sr = ztat(p, &buf, 0)) && S_ISDIR(buf.st_mode)); t = (!(sr = ztat(p, &buf, 0)) && S_ISDIR(buf.st_mode));
@ -7900,7 +7913,7 @@ do_single(Cmatch m)
makesuffix(1); 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); makeparamsuffix(((m->flags & CMF_PARBR) ? 1 : 0), minfo.insc - parq);
if ((menucmp && !minfo.we) || !movetoend) { if ((menucmp && !minfo.we) || !movetoend) {