Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Completion issues
- X-seq: zsh-workers 10425
- From: Sven Wischnowsky <wischnow@xxxxxxxxxxxxxxxxxxxxxxx>
- To: zsh-workers@xxxxxxxxxxxxxx
- Subject: Re: Completion issues
- Date: Mon, 3 Apr 2000 17:25:52 +0200 (MET DST)
- In-reply-to: Peter Stephenson's message of Sat, 01 Apr 2000 21:26:10 +0100
- Mailing-list: contact zsh-workers-help@xxxxxxxxxxxxxx; run by ezmlm
Peter Stephenson wrote:
> ...
>
> I tried this:
> zstyle ':completion:*:*:-command-:*' tag-order \
> 'functions:-non-comp:non-completion\ functions *' functions
> zstyle ':completion:*:functions-non-comp' ignored-patterns '_*'
> pretty much what's in the manual, except with a name. Now listing
> completions for zfl gives me
> Completing non-completion functions
> zfls
> Completing shell function
> zfls
> Completing alias
> zfls
> Forget the last one; arguably you should only get the alias in this case,
> since that's what will actually run, but I can see that's a
> sophistication. It's a bit annoying that I get the same function, for the
> same tag, both with filtering and without. With a long list it's going to
> be worse. Have I missed something?
No, my fault. The patterns should be replaced only with the tags
offered which are not yet given directly in the same string (with or
without a label). I forgot to re-implement that when moving the stuff
from shell code to C.
> ...
>
> The only problem there is I don't really want to upset the
> global tag-order for what is really a local problem for one tag. So I
> replaced the first line with:
> zstyle ':completion:*:functions' tag-order functions:-non-comp
> This doesn't work, and I can understand why it wouldn't --- looking up a
> tag using a tag is distinctly odd. But the manual implies this works with
> options:
> zstyle ':completion:*:options' tag-order 'options:-long:long options
> options:-short:short options
> options:-single-letter:single letter options'
> (formatted here with a ghastly offset of some thirty characters but I
> suppose that's my problem).
Urgh. Of course that should have been only `:completion:*', without
the `options'.
> As a subsidiary question, what happened to the
> backslashes the manual claims are needed for the spaces in the names? More
> importantly, what the heck's going on? Apparently looking up the tag
> `options' will, after all, force a re-lookup with options split into three.
> As far as I can see, this example is the only thing in the manual which
> tells you one way or the other whether you can explicitly split up tags
> into sub-tags like this. I'm now distinctly confused. Explanation?
I copied that from the late tag-aliases style, which could be set for
single tags and got the aliases/labels in separate words -- then I
forgot to remove the `:options' and insert the backslashes.
Hm. Your `don't really want to upset the global tag-order for what is
really a local problem'... that's what I intended the tag-aliases
styles for. But then I thought tag-order is enough -- as in the
example from the manual (once it is corrected by the patch
below). This may look a bit ugly, but if your main concern is speed:
this is done in C now, so it really isn't that expensive.
Hm. Should we add a tag-labels style again (tested for every tag in
tag-order, gives labels to use for this tag in its value)? My main
reason for not liking this that much is the fact that it's in C now --
I wanted to avoid having style-lookups hidden in some C-function.
So the question is: move things in shell code again, and add
tag-labels or leave it as it is. Unless someone sees a way to combine
them, of course.
> I came across the same problem when trying to explain _next_label using the
> code in _mh. Looking at the code, which is this:
> if _wanted sequences; then
> while _next_label sequences expl sequence; do
> compadd "$expl[@]" $(mark $foldnam 2>/dev/null |
> awk -F: '{ print $1 }') &&
> ret=0
> compadd "$expl[@]" reply next cur prev first last all unseen && ret=0
> _files "$expl[@]" -W folddir -g '<->' && ret=0
> (( ret )) || return 0
> done
> I would expect the following to work:
> zstyle ':completion:*:sequences' tag-order sequences:-name sequences:-num
> zstlye ':completion:*:sequences-name' ignored-patterns '<->'
> zstyle ':completion:*:sequences-num' ignored-patterns '^<->'
> prefering named sequences to messages which are just numbers. But it
> doesn't. I noted that despite being inside the _wanted, _files is used
> instead of _path_files, so I thought maybe it was using the files tag, but
> assuming a split into `sequences' and `files' doesn't seem to work either.
> What's the right way of doing this?
The way you did, with the patch below. The problem was that _files
didn't make sure that the ignored patterns also used the ones given to
_files. Another problem was the `(( ret ) || ...'. That shouldn't be
inside the label-loop (after all, we are looping over the labels that
have to be tried at the same time). This was wrong in several
completion functions.
Note, however, that _next_tags currently isn't smart enough to get
switching from one label to the next right. Hm, I've got to think some
more about this...
> By the way, the example given in the manual of ignored-patterns and tag
> labels,
> zstyle ':completion:*:*:-command-:*' tag-order 'functions:-non-comp'
> zstyle ':completion:*:functions-non-comp' ignored-patterns '_*'
> (= in command position, prefer the `functions' tag but use it with the name
> functions-non-comp; anywhere you see that tag, exclude patterns matching
> `_*) isn't particularly good, since the issue only really arises in command
> position after you've typed a character, hence you really need
> correction/approximation to test this, and it's hard to think of an
> example. I've borrowed this from the manual until I or someone else can
> think of another clean, simple example.
`nohup <TAB>'. But I agree, that it's a bad example. In fact, I tried
to think of a better one when I wrote that.
> Another thing: I couldn't get matcher-list to work for a labelled
> completer, e.g. _complete:-extended. When I switched to matcher instead,
> it worked fine. This fit my preconception, when I eventually decided what
> that would have been, because I though matcher-list was decided once right
> at the start. However, the manual explicitly says that you can use
> matcher-list with labelled completers.
And it works for me:
zstyle ':completion:*' completer _complete:-foo
zstyle ':completion:*:complete-foo:*' matcher-list '' 'm:{a-z}={A-Z}'
Note how the name of the completer is changed for lookup.
> Tail-ender: this is a real bug:
> % zsh -f
> % autoload -U compinit; compinit -D
> % zstyle ':completion:*' completer _expand _complete
> % zstyle ':<TAB>
> ^this gets replaced by an character from the upper end of
> ISO-8859-1 which I didn't particularly want to see.
>
> The style subst-globs-only is several times referred to without the
> plural, which is particularly annoying in _zstyle, but also occurs in the
> doc. (No patch, since it's almost half past midnight and I like to eat
> this evening.)
No patch for this yet...
> This is probably known, but _next_tags doesn't work well with menu
> completion. Ideally, it should probably remove the current choice if the
> last command was a menu completion and replace it with the first choice
> from the list generated with the next tag.
> Also, the message at the top
> doesn't change; you still see `Completing TeX or LaTeX file' if you cycle
> through to completing directories. Maybe this is a feature.
That's because the default for the file-patterns style doesn't add
descriptions, so the one given by the calling function is used. I has
always been like that. But I agree that it's particularly irritating
wiht _next_tags.
Bye
Sven
Index: Completion/Core/_files
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Core/_files,v
retrieving revision 1.2
diff -u -r1.2 _files
--- Completion/Core/_files 2000/04/01 20:43:43 1.2
+++ Completion/Core/_files 2000/04/03 15:25:30
@@ -1,12 +1,23 @@
#autoload
-local opts tmp glob pats expl tag i pat descr minus
+local opts tmp glob pats expl tag i pat descr end ign ret=1
zparseopts -a opts \
'/=tmp' 'f=tmp' 'g+:-=tmp' q n 1 2 P: S: r: R: W: X+: M+: F: J+: V+:
type="${(@j::M)${(@)tmp#-}#?}"
(( $tmp[(I)-g*] )) && glob="${(j: :)${(M)tmp:#-g*}#-g}"
+ign=$opts[(I)-F]
+if (( ign )); then
+ ign=( $=opts[ign+1] )
+ if [[ $ign = _comp_ignore ]]; then
+ ign=( $_comp_ignore )
+ else
+ opts[tmp+1]=_comp_ignore
+ fi
+else
+ ign=
+fi
if zstyle -a ":completion:${curcontext}:" file-patterns pats; then
[[ "$type" = */* ]] && glob="$glob *(-/)"
@@ -34,16 +45,24 @@
if [[ i -gt 0 && "$pat" != \ # ]]; then
if [[ "$pats[i]" = *:${tag}:* ]]; then
descr="${pats[i]#*:${tag}:}"
- minus=()
else
descr=file
- minus=(-)
+ end=yes
fi
fi
-
- _wanted "$tag" expl "$descr" \
- _path_files -g "$pat" "$opts[@]" "$minus[@]" && return 0
+ if _wanted "$tag"; then
+ _comp_ignore=()
+ while _next_label "$tag" expl "$descr"; do
+ _comp_ignore=( $_comp_ignored $ign )
+ if [[ -n "$end" ]]; then
+ _path_files -g "$pat" "$opts[@]" "$expl[@]" && ret=0
+ else
+ _path_files "$expl[@]" -g "$pat" "$opts[@]" && ret=0
+ fi
+ done
+ (( ret )) || return 0
+ fi
done
return 1
Index: Completion/User/_gdb
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/User/_gdb,v
retrieving revision 1.2
diff -u -r1.2 _gdb
--- Completion/User/_gdb 2000/04/01 20:43:43 1.2
+++ Completion/User/_gdb 2000/04/03 15:25:30
@@ -23,8 +23,8 @@
-directory\= -cd\= -tty\= && ret=0
compadd "$expl[@]" - -help -h -s -e -c -x -d -nx -n -quiet -q \
-batch -fullname -f -b && ret=0
- (( ret )) || return 0
done
+ (( ret )) || return 0
fi
else
prev="$words[CURRENT-1]"
Index: Completion/User/_getconf
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/User/_getconf,v
retrieving revision 1.2
diff -u -r1.2 _getconf
--- Completion/User/_getconf 2000/04/01 20:43:43 1.2
+++ Completion/User/_getconf 2000/04/03 15:25:30
@@ -29,7 +29,6 @@
_POSIX_NO_TRUNC _POSIX_VDISABLE && ret=0
compadd "$expl[@]" -S ' ' LINK_MAX MAX_CANON MAX_INPUT NAME_MAX \
PATH_MAX PIPE_BUF && ret=0
- (( ret )) || break
done
(( ret )) || return 0
done
Index: Completion/User/_mh
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/User/_mh,v
retrieving revision 1.2
diff -u -r1.2 _mh
--- Completion/User/_mh 2000/04/01 20:43:43 1.2
+++ Completion/User/_mh 2000/04/03 15:25:30
@@ -78,7 +78,6 @@
ret=0
compadd "$expl[@]" reply next cur prev first last all unseen && ret=0
_files "$expl[@]" -W folddir -g '<->' && ret=0
- (( ret )) || return 0
done
fi
return ret
Index: Completion/User/_netscape
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/User/_netscape,v
retrieving revision 1.2
diff -u -r1.2 _netscape
--- Completion/User/_netscape 2000/04/01 20:43:43 1.2
+++ Completion/User/_netscape 2000/04/03 15:25:30
@@ -82,7 +82,6 @@
while _next_label prefixes expl 'URL prefix'; do
compadd "$expl[@]" -S '' about: mocha: javascript: && ret=0
_urls "$@" && ret=0
- (( ret )) || return 0
done
fi
fi
Index: Completion/User/_tiff
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/User/_tiff,v
retrieving revision 1.2
diff -u -r1.2 _tiff
--- Completion/User/_tiff 2000/04/01 20:43:43 1.2
+++ Completion/User/_tiff 2000/04/03 15:25:30
@@ -199,7 +199,6 @@
while _next_label values expl 'compression scheme'; do
compadd "$expl[@]" - none g4 packbits && ret=0
compadd "$expl[@]" -qS: - lzw zip jpeg g3 && ret=0
- (( ret )) || return 0
done
fi
fi
Index: Completion/User/_urls
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/User/_urls,v
retrieving revision 1.2
diff -u -r1.2 _urls
--- Completion/User/_urls 2000/04/01 20:43:43 1.2
+++ Completion/User/_urls 2000/04/03 15:25:30
@@ -59,7 +59,6 @@
[[ -d $urls_path/bookmark ]] &&
compadd "$expl[@]" -S '' bookmark: && ret=0
compadd "$expl[@]" -S '' file: ftp:// gopher:// http:// && ret=0
- (( ret )) || return 0
done
return ret
fi
@@ -83,7 +82,6 @@
elif [[ -z "$PREFIX" ]]; then
compadd "$expl[@]" -S '/' -r '/' - "${PWD%/}" && ret=0
fi
- (( ret )) || return 0
done
return ret
fi
@@ -100,7 +98,6 @@
_path_files -W "$urls_path/$scheme" "$expl[@]" -S '' -g '*(^/)' &&
ret=0
_path_files -W "$urls_path/$scheme" -S/ -r '/' -/ && ret=0
- (( ret )) || return 0
done
fi
fi
@@ -116,7 +113,6 @@
(( $#uhosts )) || _hosts -S/ && ret=0
[[ "$scheme" = http ]] && uhosts=($uhosts $localhttp_servername)
compadd "$expl[@]" -S/ - $uhosts && ret=0
- (( ret )) || return 0
done
return ret
fi
@@ -136,20 +132,17 @@
while _next_label files expl 'local file'; do
_path_files "$expl[@]" -W ~$user/$localhttp_userdir -g '*(^/)' && ret=0
_path_files "$expl[@]" -W ~$user/$localhttp_userdir -S/ -r '/' -/ && ret=0
- (( ret )) || return 0
done
else
while _next_label files expl 'local file'; do
_path_files "$expl[@]" -W $localhttp_documentroot -g '*(^/)' && ret=0
_path_files "$expl[@]" -W $localhttp_documentroot -S/ -r '/' -/ && ret=0
- (( ret )) || return 0
done
fi
else
while _next_label files expl 'local file'; do
_path_files "$expl[@]" -W $urls_path/$scheme/$host -g '*(^/)' && ret=0
_path_files "$expl[@]" -W $urls_path/$scheme/$host -S/ -r '/' -/ && ret=0
- (( ret )) || return 0
done
fi
return $ret
Index: Completion/X/_xmodmap
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/X/_xmodmap,v
retrieving revision 1.2
diff -u -r1.2 _xmodmap
--- Completion/X/_xmodmap 2000/04/01 20:43:43 1.2
+++ Completion/X/_xmodmap 2000/04/03 15:25:30
@@ -86,7 +86,6 @@
while _next_label commands expl command; do
compadd "$expl[@]" -S ' ' keycode keysym clear add remove && ret=0
compadd "$expl[@]" -S ' = ' pointer && ret=0
- (( ret )) || return 0
done
fi
fi
Index: Doc/Zsh/compsys.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/compsys.yo,v
retrieving revision 1.4
diff -u -r1.4 compsys.yo
--- Doc/Zsh/compsys.yo 2000/04/03 13:13:02 1.4
+++ Doc/Zsh/compsys.yo 2000/04/03 15:25:31
@@ -1651,10 +1651,10 @@
Of course, this can also be used to split the matches for one tag into
different groups. For example:
-example(zstyle ':completion:*:options' tag-order \
- 'options:-long:long options
- options:-short:short options
- options:-single-letter:single letter options'
+example(zstyle ':completion:*' tag-order \
+ 'options:-long:long\ options
+ options:-short:short\ options
+ options:-single-letter:single\ letter\ options'
zstyle ':completion:*:options-long' ignored-patterns '[-+](|-|[^-]*)'
zstyle ':completion:*:options-short' ignored-patterns '--*' '[-+]?'
Index: Src/Zle/computil.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/computil.c,v
retrieving revision 1.2
diff -u -r1.2 computil.c
--- Src/Zle/computil.c 2000/04/01 20:49:48 1.2
+++ Src/Zle/computil.c 2000/04/03 15:25:32
@@ -2405,7 +2405,7 @@
while (*s) {
while (*s && iblank(*s))
s++;
- for (p = q = s, c = NULL; *s && !iblank(*s); s++) {
+ for (p = q = s, c = NULL; *s && !inblank(*s); s++) {
if (!c && *s == ':')
c = p;
if (*s == '\\' && s[1])
@@ -2423,12 +2423,26 @@
tokenize(qq);
if (haswilds(qq)) {
Patprog prog;
+ LinkNode node;
if ((prog = patcompile(qq, PAT_STATIC, NULL))) {
char **a, *n;
int l = (c ? strlen(c + 1) + 2 : 1), al;
for (a = all; *a; a++) {
+ for (node = firstnode(list); node;
+ incnode(node)) {
+ char *as, *ls;
+
+ for (as = *a, ls = (char *) getdata(node);
+ *as && *ls && *ls != ':'; as++, ls++)
+ if (*as != *ls)
+ break;
+ if (!*as && (!*ls || *ls == ':'))
+ break;
+ }
+ if (node)
+ continue;
if (pattry(prog, *a)) {
n = (char *) zhalloc((al = strlen(*a)) + l);
strcpy(n, *a);
--
Sven Wischnowsky wischnow@xxxxxxxxxxxxxxxxxxxxxxx
Messages sorted by:
Reverse Date,
Date,
Thread,
Author