* PATCH: Re: (forw) --help able programs and completion]
@ 2000-06-27 13:18 Sven Wischnowsky
2000-06-27 15:02 ` Bart Schaefer
0 siblings, 1 reply; 8+ messages in thread
From: Sven Wischnowsky @ 2000-06-27 13:18 UTC (permalink / raw)
To: zsh-workers
[ moved to workers ]
Bart Schaefer wrote:
> ...
>
> } The one who wrote it probably should have documented it
> } somewhere.
> }
> } I /think/ it wasn't me this time.
>
> This is very interesting.
>
> The earliest mention of _use_lo in the zsh-workers archive is PWS saying
> "What happened to _use_lo? I don't remember removing it." just before he
> made the 3.1.6-test-1 release. That's the first time it shows up in my
> home CVS repository, too. The ChangeLog-Release file doesn't mention it
> at all until Sven started patching it (and the entire contents except for
> the comment at the top have long been Sven's doing, even if he didn't
> create the file originally).
Hm. Ok, ok. Here is a patchlet that also tries to emphasize compdef
because this is almost becoming a FAQ.
> Of course, the ChangeLog also doesn't make any mention of when _arguments
> acquired the internals of _long_options.
Lost when moving to CVS, I guess.
Bye
Sven
Index: Doc/Zsh/compsys.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/compsys.yo,v
retrieving revision 1.73
diff -u -r1.73 compsys.yo
--- Doc/Zsh/compsys.yo 2000/06/22 08:42:36 1.73
+++ Doc/Zsh/compsys.yo 2000/06/27 13:18:41
@@ -277,6 +277,20 @@
)
enditem()
+The tt(compdef) function is the place to turn to when one wants to
+define what the completion system should complete for a certain
+command. The function named can of course be one of the functions
+supplied or one written by the user. For example, if one has a
+command tt(foo) that gets process identifiers as arguments, one could
+do:
+
+example(compdef _pids foo)
+
+using the tt(_pids) function from the distribution to generate the
+process identifiers. Not also the tt(_use_lo) function described
+below, which can be used to complete options for commands that
+understand the `tt(-)tt(-help)' option.
+
texinode(Completion System Configuration)(Control Functions)(Initialization)(Completion System)
sect(Completion System Configuration)
cindex(completion system, configuration)
@@ -2672,6 +2686,25 @@
Like tt(_tags) this function supports the tt(-C) option to give a
different name for the argument context field.
+)
+findex(_use_lo)
+item(tt(_use_lo))(
+This function is a simple wrapper around the tt(_arguments) function
+described below. It can be used to automatically complete long
+options for commands that understand the `tt(-)tt(-help)' option
+(`tt(_use_lo)' is for `use long options'). It is not intended to be
+used from completion functions but as a top-level completion function
+in its own right. For example, to enable option completion for the
+commands tt(foo) and tt(bar), one would call:
+
+example(compdef _use_lo foo bar)
+
+in one of the initialization files after the call to tt(compinit).
+
+The default installation uses this function only to generate
+completions for some GNU-commands because to complete the options, the
+command has to be called and hence it shouldn't be used if one can't
+be sure that the command understands the `tt(-)tt(-help)' option.
)
findex(_arguments)
item(tt(_arguments) var(spec) ...)(
--
Sven Wischnowsky wischnow@informatik.hu-berlin.de
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: PATCH: Re: (forw) --help able programs and completion]
2000-06-27 13:18 PATCH: Re: (forw) --help able programs and completion] Sven Wischnowsky
@ 2000-06-27 15:02 ` Bart Schaefer
0 siblings, 0 replies; 8+ messages in thread
From: Bart Schaefer @ 2000-06-27 15:02 UTC (permalink / raw)
To: zsh-workers
On Jun 27, 3:18pm, Sven Wischnowsky wrote:
} Subject: PATCH: Re: (forw) --help able programs and completion]
}
} Hm. Ok, ok. Here is a patchlet that also tries to emphasize compdef
} because this is almost becoming a FAQ.
Thanks for writing the text, but everything else in that section is
alphabetized now.
This moves _use_lo into alphabetical order and also creates a separate
(very short) entry for _files in its correct alphabetical location. (It's
easier to search for that way, in the info browser.)
Index: Doc/Zsh/compsys.yo
===================================================================
@@ -2687,25 +2687,6 @@
Like tt(_tags) this function supports the tt(-C) option to give a
different name for the argument context field.
)
-findex(_use_lo)
-item(tt(_use_lo))(
-This function is a simple wrapper around the tt(_arguments) function
-described below. It can be used to automatically complete long
-options for commands that understand the `tt(-)tt(-help)' option
-(`tt(_use_lo)' is for `use long options'). It is not intended to be
-used from completion functions but as a top-level completion function
-in its own right. For example, to enable option completion for the
-commands tt(foo) and tt(bar), one would call:
-
-example(compdef _use_lo foo bar)
-
-in one of the initialization files after the call to tt(compinit).
-
-The default installation uses this function only to generate
-completions for some GNU-commands because to complete the options, the
-command has to be called and hence it shouldn't be used if one can't
-be sure that the command understands the `tt(-)tt(-help)' option.
-)
findex(_arguments)
item(tt(_arguments) var(spec) ...)(
This function can be used to complete words on the line by describing the
@@ -3279,6 +3260,16 @@
a similar format; this ensures that user-specified styles are correctly
passed down to the builtins which implement the internals of completion.
)
+findex(_files)
+item(tt(_files))(
+The function tt(_files) uses the tt(file-patterns) style and calls
+tt(_path_files) with all the arguments it was passed except for tt(-g)
+and tt(-/). These two options are used depending on the setting of the
+tt(file-patterns) style.
+
+See tt(_path_files) below for a description of the full set of options
+accepted by tt(_files).
+)
findex(_funcall)
item(tt(_funcall) var(return) var(name) [ var(args) ... ])(
If a function var(name) exists, it is called with the arguments
@@ -3395,18 +3386,12 @@
passed unchanged to the tt(compadd) builtin.
)
findex(_path_files)
-findex(_files)
-item(tt(_path_files) and tt(_files))(
+item(tt(_path_files))(
The function tt(_path_files) is used throughout the completion system
to complete filenames. It allows completion of partial paths. For
example, the string `tt(/u/i/s/sig)' may be completed to
`tt(/usr/include/sys/signal.h)'.
-The function tt(_files) uses the tt(file-patterns) style and calls
-tt(_path_files) with all the arguments it was passed except for tt(-g)
-and tt(-/). These two options are used depending on the setting of the
-tt(file-patterns) style.
-
The options accepted by both tt(_path_files) and tt(_files) are:
startitem()
@@ -3695,6 +3680,25 @@
tt(curcontext) parameter. This allows to make tt(_tags) use a more
specific context name without having to change and reset the
tt(curcontext) parameter (which would otherwise have the same effect).
+)
+findex(_use_lo)
+item(tt(_use_lo))(
+This function is a simple wrapper around the tt(_arguments) function
+described above. It can be used to automatically complete long
+options for commands that understand the `tt(-)tt(-help)' option
+(`tt(_use_lo)' is for `use long options'). It is not intended to be
+used from completion functions but as a top-level completion function
+in its own right. For example, to enable option completion for the
+commands tt(foo) and tt(bar), one would call:
+
+example(compdef _use_lo foo bar)
+
+in one of the initialization files after the call to tt(compinit).
+
+The default installation uses this function only to generate
+completions for some GNU-commands because to complete the options, the
+command has to be called and hence it shouldn't be used if one can't
+be sure that the command understands the `tt(-)tt(-help)' option.
)
findex(_wanted)
item(tt(_wanted) [ tt(-C) var(name) ] [ tt(-12VJ) ] var(tag) var(name) var(descr) var(command) var(args) ...)(
--
Bart Schaefer Brass Lantern Enterprises
http://www.well.com/user/barts http://www.brasslantern.com
Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: PATCH: Re: (forw) --help able programs and completion]
@ 2000-06-29 9:27 Sven Wischnowsky
0 siblings, 0 replies; 8+ messages in thread
From: Sven Wischnowsky @ 2000-06-29 9:27 UTC (permalink / raw)
To: zsh-workers
Peter Stephenson wrote:
> Sven wrote
> > I wrote:
> >
> > > [ the menu style and `yes=<num>' ]
> > >
> > > Another question is if it should mean `if there are less than <num>
> > > matches, start menu completion', because menu completion (at least the
> > > *real* menu completion, not selection) works best with few matches.
>
> I don't understand. I though Bart's original question was `how do I start
> menu completion at a certain number of matches without menu selection?'
> Now we have two ways for turning it off. Surely, if we're going to have
> both, yes should mean `turn it on if at least n' and no should mean `turn
> it off if at least n', so you can set a range?
Ouch. Right. Ahem.
> Unless you want to implement `yes=3' turn on at 3 `yes=-6' turn on to begin
> with then off at 6 `yes=3-6' turn on from 3 to 6. I could get my brain
> round that.
Erm... hm, that's another idea (but if it's allowed for both yes and
no rather irritating).
Bye
Sven
Index: Completion/Core/_main_complete
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Core/_main_complete,v
retrieving revision 1.33
diff -u -r1.33 _main_complete
--- Completion/Core/_main_complete 2000/06/29 07:04:17 1.33
+++ Completion/Core/_main_complete 2000/06/29 09:26:18
@@ -23,7 +23,7 @@
# Failed returns from this code are not real errors
setopt localtraps noerrexit ; trap - ZERR
-local func funcs ret=1 tmp _compskip format nm call match min i num\
+local func funcs ret=1 tmp _compskip format nm call match min max i num\
_completers _completer _completer_num curtag _comp_force_list \
_matchers _matcher _matcher_num _comp_tags _comp_mesg \
context state line opt_args val_args curcontext="$curcontext" \
@@ -181,7 +181,7 @@
sel=( "${(@M)_menu_style:#(yes|true|1|on)*}" )
if (( $#sel )); then
- min=0
+ min=9999999
for i in "$sel[@]"; do
if [[ "$i" = *\=* ]]; then
num="${i#*\=}"
@@ -189,38 +189,36 @@
else
num=$nm
fi
- [[ num -gt min ]] && min="$num"
+ [[ num -lt min ]] && min="$num"
- [[ min -ge nm ]] && break
+ (( min )) || break
done
fi
- if [[ ( -n "$min" && nm -le min ) ||
+ sel=( "${(@M)_menu_style:#(no|false|0|off)*}" )
+
+ if (( $#sel )); then
+ max=9999999
+ for i in "$sel[@]"; do
+ if [[ "$i" = *\=* ]]; then
+ num="${i#*\=}"
+ [[ num -lt 0 ]] && num=0
+ else
+ num=0
+ fi
+ [[ num -lt max ]] && max="$num"
+
+ (( max )) || break
+ done
+ fi
+ if [[ ( -n "$min" && nm -ge min && ( -z "$max" || nm -lt max ) ) ||
( -n "$_menu_style[(r)auto*]" &&
"$compstate[insert]" = automenu ) ]]; then
compstate[insert]=menu
+ elif [[ -n "$max" && nm -ge max ]]; then
+ compstate[insert]=unambiguous
elif [[ -n "$_menu_style[(r)auto*]" &&
"$compstate[insert]" != automenu ]]; then
compstate[insert]=automenu-unambiguous
- else
- sel=( "${(@M)_menu_style:#(no|false|0|off)*}" )
-
- if (( $#sel )); then
- min=9999999
- for i in "$sel[@]"; do
- if [[ "$i" = *\=* ]]; then
- num="${i#*\=}"
- [[ num -lt 0 ]] && num=0
- else
- num=0
- fi
- [[ num -lt min ]] && min="$num"
-
- (( min )) || break
- done
- else
- min=
- fi
- [[ -n "$min" && nm -ge min ]] && compstate[insert]=unambiguous
fi
fi
fi
Index: Doc/Zsh/compsys.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/compsys.yo,v
retrieving revision 1.79
diff -u -r1.79 compsys.yo
--- Doc/Zsh/compsys.yo 2000/06/29 07:10:31 1.79
+++ Doc/Zsh/compsys.yo 2000/06/29 09:26:21
@@ -1595,7 +1595,7 @@
Using the form `tt(yes=)var(num)', where `tt(yes)' may be any of the
true values (`tt(yes)', `tt(true)', `tt(on)' and `tt(1)') turns on
-menu completion if there at most var(num) matches. Using this for one
+menu completion if there at least var(num) matches. Using this for one
of the `false' values (as in `tt(no=10)') makes menu completion
em(not) be used if there are var(num) or more matches. Of course,
this is only useful when menu completion is normally used, e.g. by
--
Sven Wischnowsky wischnow@informatik.hu-berlin.de
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: PATCH: Re: (forw) --help able programs and completion]
2000-06-29 7:02 Sven Wischnowsky
@ 2000-06-29 9:04 ` Peter Stephenson
0 siblings, 0 replies; 8+ messages in thread
From: Peter Stephenson @ 2000-06-29 9:04 UTC (permalink / raw)
To: Zsh hackers list
Sven wrote
> I wrote:
>
> > [ the menu style and `yes=<num>' ]
> >
> > Another question is if it should mean `if there are less than <num>
> > matches, start menu completion', because menu completion (at least the
> > *real* menu completion, not selection) works best with few matches.
I don't understand. I though Bart's original question was `how do I start
menu completion at a certain number of matches without menu selection?'
Now we have two ways for turning it off. Surely, if we're going to have
both, yes should mean `turn it on if at least n' and no should mean `turn
it off if at least n', so you can set a range?
Unless you want to implement `yes=3' turn on at 3 `yes=-6' turn on to begin
with then off at 6 `yes=3-6' turn on from 3 to 6. I could get my brain
round that.
--
Peter Stephenson <pws@cambridgesiliconradio.com>
Cambridge Silicon Radio, Unit 300, Science Park, Milton Road,
Cambridge, CB4 0XL, UK Tel: +44 (0)1223 392070
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: PATCH: Re: (forw) --help able programs and completion]
@ 2000-06-29 7:02 Sven Wischnowsky
2000-06-29 9:04 ` Peter Stephenson
0 siblings, 1 reply; 8+ messages in thread
From: Sven Wischnowsky @ 2000-06-29 7:02 UTC (permalink / raw)
To: zsh-workers
I wrote:
> [ the menu style and `yes=<num>' ]
>
> Another question is if it should mean `if there are less than <num>
> matches, start menu completion', because menu completion (at least the
> *real* menu completion, not selection) works best with few matches.
>
> That's easy to change, though (I'd like to get opinions from menu
> completion users).
This patch does that (as long as I don't get replies, I'll happily
continue hacking).
> > > Does anybody now want support for `no=3'?
> >
> > Which would mean ...?
>
> If one has `setopt menucomplete', setting the menu style to one of the
> `false' values can be used to turn menu completion off for some
> contexts. Allowing `no=<num>' would either mean to turn it of if there
> are more or less than <num> matches, whatever we decide `yes=<num>'
> means.
It also does this (with `if there are at least <num> matches, don't
start menu completion').
> > However, a plain-ol'-menu-completion variant of select=long-list might be
> > interesting.
>
> Hmhm, right.
And it does this (`yes=long-list').
Bye
Sven
Index: Completion/Core/_main_complete
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Core/_main_complete,v
retrieving revision 1.32
diff -u -r1.32 _main_complete
--- Completion/Core/_main_complete 2000/06/28 09:42:51 1.32
+++ Completion/Core/_main_complete 2000/06/29 07:02:03
@@ -170,8 +170,9 @@
_menu_style=( "$_menu_style[@]" "$_def_menu_style[@]" )
- if [[ "$compstate[list]" = *list &&
- -n "$_menu_style[(r)select=long-list]" && tmp -gt LINES ]]; then
+ if [[ "$compstate[list]" = *list && tmp -gt LINES &&
+ ( -n "$_menu_style[(r)select=long-list]" ||
+ -n "$_menu_style[(r)(yes|true|on|1)=long-list]" ) ]]; then
compstate[insert]=menu
elif [[ "$compstate[insert]" = "$_saved_insert" ]]; then
if [[ -n "$_menu_style[(r)select=long]" && tmp -gt LINES ]]; then
@@ -180,28 +181,46 @@
sel=( "${(@M)_menu_style:#(yes|true|1|on)*}" )
if (( $#sel )); then
- min=9999999
+ min=0
for i in "$sel[@]"; do
if [[ "$i" = *\=* ]]; then
num="${i#*\=}"
[[ num -lt 0 ]] && num=0
else
- num=0
+ num=$nm
fi
- [[ num -lt min ]] && min="$num"
+ [[ num -gt min ]] && min="$num"
- (( min )) || break
+ [[ min -ge nm ]] && break
done
fi
- if [[ ( -n "$min" && nm -ge min ) ||
+ if [[ ( -n "$min" && nm -le min ) ||
( -n "$_menu_style[(r)auto*]" &&
"$compstate[insert]" = automenu ) ]]; then
compstate[insert]=menu
elif [[ -n "$_menu_style[(r)auto*]" &&
"$compstate[insert]" != automenu ]]; then
compstate[insert]=automenu-unambiguous
- elif [[ -n "$_menu_style[(r)(no|false|0|off)]" ]]; then
- compstate[insert]=unambiguous
+ else
+ sel=( "${(@M)_menu_style:#(no|false|0|off)*}" )
+
+ if (( $#sel )); then
+ min=9999999
+ for i in "$sel[@]"; do
+ if [[ "$i" = *\=* ]]; then
+ num="${i#*\=}"
+ [[ num -lt 0 ]] && num=0
+ else
+ num=0
+ fi
+ [[ num -lt min ]] && min="$num"
+
+ (( min )) || break
+ done
+ else
+ min=
+ fi
+ [[ -n "$min" && nm -ge min ]] && compstate[insert]=unambiguous
fi
fi
fi
Index: Doc/Zsh/compsys.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/compsys.yo,v
retrieving revision 1.77
diff -u -r1.77 compsys.yo
--- Doc/Zsh/compsys.yo 2000/06/28 09:08:03 1.77
+++ Doc/Zsh/compsys.yo 2000/06/29 07:02:04
@@ -1595,7 +1595,13 @@
Using the form `tt(yes=)var(num)', where `tt(yes)' may be any of the
true values (`tt(yes)', `tt(true)', `tt(on)' and `tt(1)') turns on
-menu completion if there at least var(num) matches.
+menu completion if there at most var(num) matches. Using this for one
+of the `false' values (as in `tt(no=10)') makes menu completion
+em(not) be used if there are var(num) or more matches. Of course,
+this is only useful when menu completion is normally used, e.g. by
+setting the tt(MENU_COMPLETE) option. The `true' values may also be
+used in the form `tt(yes=long-list)' to turn on menu completion
+whenever listing is done and the list does not fit onto the screen.
In addition to (or instead of) the above possibilities, the value may
contain the string `tt(select)', optionally followed by an equal sign and a
--
Sven Wischnowsky wischnow@informatik.hu-berlin.de
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: PATCH: Re: (forw) --help able programs and completion]
@ 2000-06-28 7:08 Sven Wischnowsky
0 siblings, 0 replies; 8+ messages in thread
From: Sven Wischnowsky @ 2000-06-28 7:08 UTC (permalink / raw)
To: zsh-workers
Bart Schaefer wrote:
> On Jun 27, 5:02pm, Sven Wischnowsky wrote:
> > Subject: PATCH: Re: (forw) --help able programs and completion]
> >
> > Bart Schaefer wrote:
> >
> > > What I was expecting, for some reason, was that menu selection would start
> > > immediately if there were more than N matches, not wait for the second TAB
> > > that triggers automenu.
> >
> > Ah. No, but that's easy to add.
>
> Er, thanks, but you didn't really need to add that; all I wanted was a
> yes-or-no answer ...
It was fun writing it (and I needed something to distract me from real
work).
> > I used the same form as for `select', i.e. one can say `yes=3' to turn
> > on menu completion when there are at least three matches.
>
> Hrm.
> zstyle ':completion:*' menu 1=3
>
> Does that look a bit strange to anyone else?
Yes, to me (I wondered if I should point that out yesterday). But with
the select[=val] in place this looked like a easy-to-understand
enhancement.
Another question is if it should mean `if there are less than <num>
matches, start menu completion', because menu completion (at least the
*real* menu completion, not selection) works best with few matches.
That's easy to change, though (I'd like to get opinions from menu
completion users).
> > Does anybody now want support for `no=3'?
>
> Which would mean ...?
If one has `setopt menucomplete', setting the menu style to one of the
`false' values can be used to turn menu completion off for some
contexts. Allowing `no=<num>' would either mean to turn it of if there
are more or less than <num> matches, whatever we decide `yes=<num>'
means.
> However, a plain-ol'-menu-completion variant of select=long-list might be
> interesting.
Hmhm, right.
Bye
Sven
--
Sven Wischnowsky wischnow@informatik.hu-berlin.de
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: PATCH: Re: (forw) --help able programs and completion]
[not found] <200006271502.RAA30019@beta.informatik.hu-berlin.de>
@ 2000-06-27 22:46 ` Bart Schaefer
0 siblings, 0 replies; 8+ messages in thread
From: Bart Schaefer @ 2000-06-27 22:46 UTC (permalink / raw)
To: zsh-workers
On Jun 27, 5:02pm, Sven Wischnowsky wrote:
> Subject: PATCH: Re: (forw) --help able programs and completion]
>
> Bart Schaefer wrote:
>
> > What I was expecting, for some reason, was that menu selection would start
> > immediately if there were more than N matches, not wait for the second TAB
> > that triggers automenu.
>
> Ah. No, but that's easy to add.
Er, thanks, but you didn't really need to add that; all I wanted was a
yes-or-no answer ...
> I used the same form as for `select', i.e. one can say `yes=3' to turn
> on menu completion when there are at least three matches.
Hrm.
zstyle ':completion:*' menu 1=3
Does that look a bit strange to anyone else?
> Does anybody now want support for `no=3'?
Which would mean ...?
However, a plain-ol'-menu-completion variant of select=long-list might be
interesting.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: PATCH: Re: (forw) --help able programs and completion]
@ 2000-06-27 15:06 Sven Wischnowsky
0 siblings, 0 replies; 8+ messages in thread
From: Sven Wischnowsky @ 2000-06-27 15:06 UTC (permalink / raw)
To: zsh-workers
Bart Schaefer wrote:
> ...
>
> Thanks for writing the text, but everything else in that section is
> alphabetized now.
Argh. Sorry.
Bye
Sven
--
Sven Wischnowsky wischnow@informatik.hu-berlin.de
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2000-06-29 9:27 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-06-27 13:18 PATCH: Re: (forw) --help able programs and completion] Sven Wischnowsky
2000-06-27 15:02 ` Bart Schaefer
2000-06-27 15:06 Sven Wischnowsky
[not found] <200006271502.RAA30019@beta.informatik.hu-berlin.de>
2000-06-27 22:46 ` Bart Schaefer
2000-06-28 7:08 Sven Wischnowsky
2000-06-29 7:02 Sven Wischnowsky
2000-06-29 9:04 ` Peter Stephenson
2000-06-29 9:27 Sven Wischnowsky
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).