From: Sven Wischnowsky <wischnow@informatik.hu-berlin.de>
To: zsh-workers@sunsite.auc.dk
Subject: Re: PATCH: compadd (+ questions)
Date: Fri, 12 Feb 1999 11:32:16 +0100 (MET) [thread overview]
Message-ID: <199902121032.LAA09201@beta.informatik.hu-berlin.de> (raw)
In-Reply-To: Peter Stephenson's message of Wed, 10 Feb 1999 17:26:57 +0100
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 <string>' 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 <spec>' option as with `compctl' and `complist',
# but only as the first argument.
#
+# This function also accepts an optional `-F <string>' option as its first
+# argument or just after the `-W <spec>'. 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
next reply other threads:[~1999-02-12 10:33 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
1999-02-12 10:32 Sven Wischnowsky [this message]
-- strict thread matches above, loose matches on Subject: below --
1999-02-18 15:22 Sven Wischnowsky
1999-02-12 13:39 Sven Wischnowsky
1999-02-12 8:42 Sven Wischnowsky
1999-02-13 19:19 ` Bart Schaefer
1999-02-11 9:09 Sven Wischnowsky
1999-02-11 9:11 ` Peter Stephenson
1999-02-11 9:38 ` Sven Wischnowsky
1999-02-11 18:25 ` Bart Schaefer
1999-02-01 9:10 PATCH: compadd Sven Wischnowsky
1999-02-10 16:26 ` PATCH: compadd (+ questions) Peter Stephenson
1999-02-11 7:50 ` Bart Schaefer
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=199902121032.LAA09201@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).