From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3474 invoked from network); 12 Feb 1999 10:33:18 -0000 Received: from sunsite.auc.dk (130.225.51.30) by ns1.primenet.com.au with SMTP; 12 Feb 1999 10:33:18 -0000 Received: (qmail 5975 invoked by alias); 12 Feb 1999 10:33:05 -0000 Mailing-List: contact zsh-workers-help@sunsite.auc.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 5352 Received: (qmail 5968 invoked from network); 12 Feb 1999 10:33:03 -0000 Date: Fri, 12 Feb 1999 11:32:16 +0100 (MET) Message-Id: <199902121032.LAA09201@beta.informatik.hu-berlin.de> From: Sven Wischnowsky To: zsh-workers@sunsite.auc.dk In-reply-to: Peter Stephenson's message of Wed, 10 Feb 1999 17:26:57 +0100 Subject: Re: PATCH: compadd (+ questions) Peter Stephenson wrote: > > Another small addition: the option `-F' says that fignore should be > > used (in the same way as it's done by `compctl'). > > Would it not be just as easy to be able to specify a $fignore-type > variable (maybe in the `compctl -k ...' fmt so you can add literals)? > If it isn't, it doesn't matter, but I thought maybe that's no > harder than hard-wiring $fignore in. The patch below changes the `-F' option to compadd to take such a string. It also changes the `__files' example function to accept a optional `-F ' option which uses this (the handling in the function could be improved). E.g. now you can do things like `__files -F "(.o .pro)"'. Bye Sven diff -u os/Zle/comp.h Src/Zle/comp.h --- os/Zle/comp.h Fri Feb 12 10:55:40 1999 +++ Src/Zle/comp.h Fri Feb 12 11:09:22 1999 @@ -281,5 +281,4 @@ #define CAF_MENU 2 #define CAF_NOSORT 4 #define CAF_ALT 8 -#define CAF_FIGNORE 16 -#define CAF_MATCH 32 +#define CAF_MATCH 16 diff -u os/Zle/comp1.c Src/Zle/comp1.c --- os/Zle/comp1.c Fri Feb 12 10:55:40 1999 +++ Src/Zle/comp1.c Fri Feb 12 11:09:53 1999 @@ -49,7 +49,7 @@ /* pointers to functions required by compctl and defined by zle */ /**/ -void (*addmatchesptr) _((char *, char *, char *, char *, char *, char *, char *, char *, int, int, Cmatcher, char **)); +void (*addmatchesptr) _((char *, char *, char *, char *, char *, char *, char *, char *, char *, int, int, Cmatcher, char **)); /**/ char *(*comp_strptr) _((int*,int*)); diff -u os/Zle/compctl.c Src/Zle/compctl.c --- os/Zle/compctl.c Fri Feb 12 10:55:40 1999 +++ Src/Zle/compctl.c Fri Feb 12 11:09:41 1999 @@ -1676,6 +1676,7 @@ char *p, **sp, *e; char *ipre = NULL, *ppre = NULL, *psuf = NULL, *prpre = NULL; char *pre = NULL, *suf = NULL, *group = NULL, *m = NULL, *rs = NULL; + char *ign = NULL; int f = 0, a = 0, dm; Cmatcher match = NULL; @@ -1698,7 +1699,8 @@ f |= CMF_FILE; break; case 'F': - a |= CAF_FIGNORE; + sp = &ign; + e = "string expected after -%c"; break; case 'n': f |= CMF_NOLIST; @@ -1790,7 +1792,7 @@ match = cpcmatcher(match); addmatchesptr(ipre, ppre, psuf, prpre, pre, suf, group, - rs, f, a, match, argv); + rs, ign, f, a, match, argv); freecmatcher(match); return 0; diff -u os/Zle/zle_tricky.c Src/Zle/zle_tricky.c --- os/Zle/zle_tricky.c Fri Feb 12 10:55:42 1999 +++ Src/Zle/zle_tricky.c Fri Feb 12 11:12:39 1999 @@ -2458,10 +2458,10 @@ /**/ void addmatches(char *ipre, char *ppre, char *psuf, char *prpre, char *pre, - char *suf, char *group, char *rems, + char *suf, char *group, char *rems, char *ign, int flags, int aflags, Cmatcher match, char **argv) { - char *s, *t, *e, *te, *ms, *lipre = NULL, *lpre, *lsuf; + char *s, *t, *e, *te, *ms, *lipre = NULL, *lpre, *lsuf, **aign = NULL; int lpl, lsl, i, pl, sl, test, bpl, bsl, lsm, llpl; Aminfo ai; Cline lc = NULL; @@ -2486,6 +2486,9 @@ } if ((aflags & CAF_MENU) && isset(AUTOMENU)) usemenu = 1; + if (ign) + aign = get_user_var(ign); + SWITCHHEAPS(compheap) { HEAPALLOC { if (aflags & CAF_MATCH) { @@ -2540,8 +2543,8 @@ ms = NULL; bpl = brpl; bsl = brsl; - if ((!psuf || !*psuf) && (aflags & CAF_FIGNORE)) { - char **pt = fignore; + if ((!psuf || !*psuf) && aign) { + char **pt = aign; int filell; for (test = 1; test && *pt; pt++) diff -u om/Completion/__path_files Misc/Completion/__path_files --- om/Completion/__path_files Fri Feb 12 10:55:16 1999 +++ Misc/Completion/__path_files Fri Feb 12 11:30:08 1999 @@ -12,13 +12,18 @@ # You may also give the `-W ' option as with `compctl' and `complist', # but only as the first argument. # +# This function also accepts an optional `-F ' option as its first +# argument or just after the `-W '. This can be used to define file +# name extension (a la `fignore'). Files with such an extension will not +# be considered possible completions. +# # This function behaves as if you have a matcher definition like: # compctl -M 'r:|[-.,_/]=* r:|=* m:{a-z}={A-Z} m:-=_ m:.=,' \ # 'm:{a-z}={A-Z} l:|=* r:|=*' # so you may want to modify this. local nm prepaths str linepath realpath donepath patstr prepath testpath rest -local tmp1 collect tmp2 suffixes i +local tmp1 collect tmp2 suffixes i ignore setopt localoptions nullglob rcexpandparam globdots extendedglob unsetopt markdirs globsubst shwordsplit nounset @@ -38,38 +43,54 @@ prepaths=( '' ) fi +# Get the optional `-F' option and its argument. +if [[ "$1" = -F ]]; then + ignore=(-F "$2") + shift 2 +else + ignore='' +fi + # str holds the whole string from the command line with a `*' between # the prefix and the suffix. str="${PREFIX:q}*${SUFFIX:q}" -# We will first try normal completion called with `complist', first build -# an array containing the `-W' option, if there is any and we want to use -# it. We don't want to use it the string from the command line is a non- -# relative path. +# We will first try normal completion called with `complist', but only if we +# weren't given a `-F' option. -if [[ -z "$tmp1[1]" || "$str[1]" = [~/] || "$str" = (.|..)/* ]]; then - tmp1=() -else - tmp1=(-W "( $ppres )") -fi +if [[ -z "$ignore" ]]; then + # First build an array containing the `-W' option, if there is any and we + # want to use it. We don't want to use it if the string from the command line + # is a absolute path or relative to the current directory. + + if [[ -z "$tmp1[1]" || "$str[1]" = [~/] || "$str" = (.|..)/* ]]; then + tmp1=() + else + tmp1=(-W "( $ppres )") + fi -# Now call complist. + # Now call complist. -nm=$NMATCHES -if [[ $# -eq 0 ]]; then - complist "$tmp1[@]" -f -elif [[ "$1" = -g ]]; then - complist "$tmp1[@]" -g "$argv[2,-1]" - shift -else - complist "$tmp1[@]" $1 - shift -fi + nm=$NMATCHES + if [[ $# -eq 0 ]]; then + complist "$tmp1[@]" -f + elif [[ "$1" = -g ]]; then + complist "$tmp1[@]" -g "$argv[2,-1]" + shift + else + complist "$tmp1[@]" $1 + shift + fi + + # If this generated any matches, we don't wnat to do in-path completion. -# If this generated any matches, we don't wnat to do in-path completion. + [[ -nmatches nm ]] || return -[[ -nmatches nm ]] || return + # No `-F' option, so we want to use `fignore'. + + ignore=(-F fignore) +fi # If we weren't given any file patterns as arguments, we trick ourselves # into believing that we were given the pattern `*'. This is just to simplify @@ -215,7 +236,7 @@ # (the `-f' and `-F' options). for i in $collect; do - compadd -p "$linepath$testpath" -W "$tmp1" -s "/${i#*/}" -fF -- "${i%%/*}" + compadd -p "$linepath$testpath" -W "$tmp1" -s "/${i#*/}" -f "$ignore[@]" -- "${i%%/*}" done # We have just finished handling all the matches from above, so we @@ -247,5 +268,5 @@ suffixes=( $str$@ ) suffixes=( "${(@)suffixes:gs.**.*.}" ) tmp2=( $~tmp1(#l)$~suffixes ) - compadd -p "$linepath$testpath" -W "$prepath$realpath$testpath" -fF -- ${tmp2#$tmp1} + compadd -p "$linepath$testpath" -W "$prepath$realpath$testpath" -f "$ignore[@]" -- ${tmp2#$tmp1} done -- Sven Wischnowsky wischnow@informatik.hu-berlin.de