zsh-workers
 help / color / mirror / code / Atom feed
* [PATCH] _arguments docs: Add options overview and sections
@ 2015-07-16 23:20 Daniel Shahaf
  2015-07-27 13:52 ` Daniel Shahaf
  0 siblings, 1 reply; 2+ messages in thread
From: Daniel Shahaf @ 2015-07-16 23:20 UTC (permalink / raw)
  To: zsh-workers

[-- Attachment #1: Type: text/plain, Size: 247 bytes --]

Attached for review.  The first patch conslidates the documentation of
all of _arguments' options in one place; that patch is 90% moving text
around and 10% minor text changes.  The second patch divides the long
help docstring into "subsections".

[-- Attachment #2: 0001-_arguments-docs-Add-options-overview.patch --]
[-- Type: text/x-patch, Size: 9360 bytes --]

>From 6d08869e2c4b495cf90e8e1dd876971e8dcec712 Mon Sep 17 00:00:00 2001
From: Daniel Shahaf <d.s@daniel.shahaf.name>
Date: Wed, 15 Jul 2015 18:05:31 +0000
Subject: [PATCH 1/2] _arguments docs: Bring all option descriptions to one place

---
 Doc/Zsh/compsys.yo | 135 +++++++++++++++++++++++++++++++++--------------------
 1 file changed, 84 insertions(+), 51 deletions(-)

diff --git a/Doc/Zsh/compsys.yo b/Doc/Zsh/compsys.yo
index af906bf..5fd8e24 100644
--- a/Doc/Zsh/compsys.yo
+++ b/Doc/Zsh/compsys.yo
@@ -3530,37 +3530,107 @@ xitem(SPACES()[ tt(:) ] var(spec) ...)
 item(tt(_arguments) [ var(opt) ... ] tt(-)tt(-) [ tt(-i) var(pats) ] [ tt(-s) var(pair) ] [ var(helpspec) ... ])(
 This function can be used to give a complete specification for completion
 for a command whose arguments follow standard UNIX option and argument
-conventions.  Options to tt(_arguments) itself must be in separate words,
-i.e. tt(-s -w), not tt(-sw).
+conventions.
 
-When calling tt(_arguments), all var(spec)s that describe options of the
-analyzed command line must precede all var(spec)s that describe non-option
-(aka "normal") arguments of the analyzed line.  To avoid ambiguity, all
+Options to tt(_arguments) itself must be in separate words, i.e., tt(-s -w),
+not tt(-sw).  The options are followed by var(spec)s that describe options and
+arguments of the analyzed command.  var(spec)s that describe option flags must
+precede var(spec)s that describe non-option ("positional" or "normal")
+arguments of the analyzed line.  To avoid ambiguity, all
 options to tt(_arguments) itself may be separated from the var(spec) forms
 by a single colon.
 
-The tt(-s -w -W -A) and tt(-S) options describe how parsing of the command
-line should proceed, and are discussed in context below.  The `tt(-)tt(-)'
+The `tt(-)tt(-)'
 form is used to intuit var(spec) forms from the help output of the command
 being analyzed, and is described in detail below.  The var(opts) for the
 `tt(-)tt(-)' form are otherwise the same options as the first form.  Note
 that `tt(-s)' following `tt(-)tt(-)' has a distinct meaning from `tt(-s)'
 preceding `tt(-)tt(-)', and both may appear.
 
-With the option tt(-n), tt(_arguments) sets the parameter tt(NORMARG)
+The options tt(-s), tt(-S), tt(-A) affect the parsing of the command line,
+and are useful for commands with standard option parsing.
+
+The options of tt(_arguments) have the following meanings:
+
+startitem()
+item(tt(-n))(
+With this option, tt(_arguments) sets the parameter tt(NORMARG)
 to the position of the first normal argument in the tt($words) array,
-i.e. the position after the end of the options.  If that argument
+i.e., the position after the end of the options.  If that argument
 has not been reached, tt(NORMARG) is set to tt(-1).  The caller
 should declare `tt(integer NORMARG)' if the tt(-n) option is passed;
 otherwise the parameter is not used.
+)
+item(tt(-s))(
+Enable em(option stacking) for single-letter options, whereby multiple
+single-letter options may be combined into a single word.  For example,
+the two options `tt(-)var(x)' and `tt(-)var(y)' may be combined into
+a single word `tt(-)var(xy)'.  By default, every word corresponds to a single
+option name (the `tt(-xy)' option).
 
-The option `tt(-M) var(matchspec)' sets a match specification to use to
+Options beginning with a single hyphen or plus sign are eligible for stacking;
+words beginning with two hyphens are not.
+This is suitable for standard GNU options.
+
+Note that tt(-s) after tt(-)tt(-) has a different meaning, and is documented
+below.
+)
+item(tt(-w))(
+In combination with tt(-s), allow option stacking
+even if one or more of the options take
+arguments.  For example, if tt(-x) takes an argument, with no
+tt(-s), `tt(-xy)' is considered as a single (unhandled) option; with
+tt(-s), tt(-xy) is an option with the argument `tt(y)'; with both tt(-s)
+and tt(-w), tt(-xy) may be the option tt(-x) and the option tt(-y) with
+arguments still to come.
+)
+item(tt(-W))(
+This option takes tt(-w) a stage further:  it is possible to
+complete single-letter options even after an argument that occurs in the
+same word.  However, it depends on the action performed whether options
+will really be completed at this point.  For more control, use a
+utility function like tt(_guard) as part of the action.
+)
+item(tt(-C))(
+Modify the tt(curcontext) parameter for an action of the form `tt(->)var(state)'.
+This is discussed in detail below.
+)
+item(tt(-R))(
+Return status 300 instead of zero when a tt($state) is to
+be handled, in the `tt(->)var(string)' syntax.
+)
+item(tt(-S))(
+Do not complete options after a `tt(-)tt(-)' appearing on the line,
+and ignore the `tt(-)tt(-)'.  For example, with tt(-S), in the line
+
+example(foobar -x -- -y)
+
+the `tt(-x)' is considered an option, the `tt(-y)' is considered an
+argument, and the `tt(-)tt(-)' is considered to be neither.
+)
+item(tt(-A) var(pat))(
+Do not complete options after the first non-option
+argument on the line.  var(pat) is a pattern matching
+all strings which are not to be taken as arguments.  For example, to make
+tt(_arguments) stop completing options after the first normal argument, but
+ignoring all strings starting with a hyphen even if they are not described
+by one of the var(optspec)s, the form is `tt(-A "-*")'.
+)
+item(tt(-O) var(name))(
+Pass the elements of the array var(name) as arguments to functions called to
+execute var(action)s.
+This is discussed in detail below.
+)
+item(tt(-M) var(matchspec))(
+Use var(matchspec) as the match specification to use to
 completion option names and values.  The default var(matchspec) is:
 
 example(tt(r:|[_-]=* r:|=*))
 
-This allows partial word completion after `tt(_)' and `tt(-)', for example
+which allows partial word completion after `tt(_)' and `tt(-)', for example
 `tt(-f-b)' can be completed to `tt(-foo-bar)'.
+)
+enditem()
 
 Each of the following forms is a var(spec) describing individual sets of
 options or arguments on the command line being analyzed.
@@ -3601,26 +3671,6 @@ This describes an option.  The colon indicates handling for one or more
 arguments to the option; if it is not present, the option is assumed to
 take no arguments.
 
-By default, options are multi-character name, one `tt(-)var(word)' per
-option.  With tt(-s), options may be single characters, with more than
-one option per word, although words starting with two hyphens, such as
-`tt(-)tt(-prefix)', are still considered complete option names.  This is
-suitable for standard GNU options.
-
-The combination of tt(-s) with tt(-w) allows single-letter options to be
-combined in a single word even if one or more of the options take
-arguments.  For example, if tt(-x) takes an argument, with no
-tt(-s) `tt(-xy)' is considered as a single (unhandled) option; with
-tt(-s) tt(-xy) is an option with the argument `tt(y)'; with both tt(-s)
-and tt(-w), tt(-xy) may be the option tt(-x) and the option tt(-y) with
-arguments still to come.
-
-The option tt(-W) takes this a stage further:  it is possible to
-complete single-letter options even after an argument that occurs in the
-same word.  However, it depends on the action performed whether options
-will really be completed at this point.  For more control, use a
-utility function like tt(_guard) as part of the action.
-
 The following forms are available for the initial var(optspec), whether
 or not the option has arguments.
 
@@ -3682,23 +3732,6 @@ enditem()
 It is possible for options with a literal `tt(PLUS())' or `tt(=)' to
 appear, but that character must be quoted, for example `tt(-\+)'.
 
-The options tt(-S) and tt(-A) are available to simplify the specifications
-for commands with standard option parsing.  With tt(-S), no option will be
-completed after a `tt(-)tt(-)' appearing on its own on the line; this
-argument will otherwise be ignored; hence in the line
-
-example(foobar -x -- -y)
-
-the `tt(-x)' is considered an option but the `tt(-y)' is considered an
-argument, while the `tt(-)tt(-)' is considered to be neither.
-
-With tt(-A), no options will be completed after the first non-option
-argument on the line.  The tt(-A) must be followed by a pattern matching
-all strings which are not to be taken as arguments.  For example, to make
-tt(_arguments) stop completing options after the first normal argument, but
-ignoring all strings starting with a hyphen even if they are not described
-by one of the var(optspec)s, the form is `tt(-A "-*")'.
-
 Each var(optarg) following an var(optspec) must take one of the
 following forms:
 
@@ -3772,9 +3805,9 @@ form below, the var(action) will be executed by calling the
 tt(_all_labels) function to process all tag labels.  No special handling
 of tags is needed unless a function call introduces a new one.
 
-The option `tt(-O) var(name)' specifies the name of an array whose elements
-will be passed as arguments to functions called to execute var(action)s.
-For example, this can be used to pass the same set of options for the
+The functions called to execute var(action)s will be called with the the
+elements of the array named by the `tt(-O) var(name)' option as arguments.
+This can be used, for example, to pass the same set of options for the
 tt(compadd) builtin to all var(action)s.
 
 The forms for var(action) are as follows.
-- 
1.9.1


[-- Attachment #3: 0002-_arguments-docs-Divide-into-subsections.patch --]
[-- Type: text/x-patch, Size: 2916 bytes --]

>From 6ff7fb935d437b55c2bc94d8338332b80460a3a4 Mon Sep 17 00:00:00 2001
From: Daniel Shahaf <d.s@daniel.shahaf.name>
Date: Wed, 15 Jul 2015 18:12:47 +0000
Subject: [PATCH 2/2] _arguments docs: Divide into subsections

---
 Doc/Zsh/compsys.yo | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/Doc/Zsh/compsys.yo b/Doc/Zsh/compsys.yo
index 5fd8e24..a53de8b 100644
--- a/Doc/Zsh/compsys.yo
+++ b/Doc/Zsh/compsys.yo
@@ -3532,6 +3532,8 @@ This function can be used to give a complete specification for completion
 for a command whose arguments follow standard UNIX option and argument
 conventions.
 
+em(Options overview)
+
 Options to tt(_arguments) itself must be in separate words, i.e., tt(-s -w),
 not tt(-sw).  The options are followed by var(spec)s that describe options and
 arguments of the analyzed command.  var(spec)s that describe option flags must
@@ -3632,6 +3634,8 @@ which allows partial word completion after `tt(_)' and `tt(-)', for example
 )
 enditem()
 
+em(var(spec)s: overview)
+
 Each of the following forms is a var(spec) describing individual sets of
 options or arguments on the command line being analyzed.
 
@@ -3799,6 +3803,8 @@ given by an array, and tt(_arguments) is called repeatedly for more
 specific contexts: on the first call `tt(_arguments $global_options)' is
 used, and on subsequent calls `tt(_arguments !$^global_options)'.
 
+em(var(spec)s: actions)
+
 In each of the forms above the var(action) determines how
 completions should be generated.  Except for the `tt(->)var(string)'
 form below, the var(action) will be executed by calling the
@@ -3951,6 +3957,8 @@ example(local curcontext="$curcontext")
 This is useful where it is not possible for multiple states to be valid
 together.
 
+em(Specifying multiple sets of options)
+
 It is possible to specify multiple sets of options and
 arguments with the sets separated by single hyphens.  The specifications
 before the first hyphen (if any) are shared by all the remaining sets.
@@ -3997,6 +4005,8 @@ A useful alternative is often an option specification with rest-arguments
 (as in `tt(-foo:*:...)'); here the option tt(-foo) swallows up all
 remaining arguments as described by the var(optarg) definitions.
 
+em(Intuiting var(spec) forms from the help output)
+
 The option `tt(-)tt(-)' allows tt(_arguments) to work out the names of long
 options that support the `tt(-)tt(-help)' option which is standard in many
 GNU commands.  The command word is called with the argument
@@ -4069,6 +4079,8 @@ as `tt(-)tt(-enable-foo)', but the script also accepts the negated form
 
 example(_arguments -- -s "LPAR()(#s)--enable- --disable-RPAR()")
 
+em(Miscellaneous notes)
+
 Finally, note that tt(_arguments) generally expects to be the primary
 function handling any completion for which it is used.  It may have side
 effects which change the treatment of any matches added by other functions
-- 
1.9.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] _arguments docs: Add options overview and sections
  2015-07-16 23:20 [PATCH] _arguments docs: Add options overview and sections Daniel Shahaf
@ 2015-07-27 13:52 ` Daniel Shahaf
  0 siblings, 0 replies; 2+ messages in thread
From: Daniel Shahaf @ 2015-07-27 13:52 UTC (permalink / raw)
  To: zsh-workers

Daniel Shahaf wrote on Thu, Jul 16, 2015 at 23:20:32 +0000:
> Attached for review.  The first patch conslidates the documentation of
> all of _arguments' options in one place; that patch is 90% moving text
> around and 10% minor text changes.  The second patch divides the long
> help docstring into "subsections".

Here's an additional patch following Oliver's review (thanks!).

Possible further enhancements:

- Clarify terminology throughout: option/flag/argument/switch, as referring to
  _arguments' argv or to the analyzed command line's.

- Clarify documentation of -C

Cheers,

Daniel

diff --git a/Doc/Zsh/compsys.yo b/Doc/Zsh/compsys.yo
index a53de8b..290c85f 100644
--- a/Doc/Zsh/compsys.yo
+++ b/Doc/Zsh/compsys.yo
@@ -3534,7 +3534,7 @@ conventions.
 
 em(Options overview)
 
-Options to tt(_arguments) itself must be in separate words, i.e., tt(-s -w),
+Options to tt(_arguments) itself must be in separate words, i.e. tt(-s -w),
 not tt(-sw).  The options are followed by var(spec)s that describe options and
 arguments of the analyzed command.  var(spec)s that describe option flags must
 precede var(spec)s that describe non-option ("positional" or "normal")
@@ -3549,8 +3549,9 @@ being analyzed, and is described in detail below.  The var(opts) for the
 that `tt(-s)' following `tt(-)tt(-)' has a distinct meaning from `tt(-s)'
 preceding `tt(-)tt(-)', and both may appear.
 
-The options tt(-s), tt(-S), tt(-A) affect the parsing of the command line,
-and are useful for commands with standard option parsing.
+The option switches tt(-s), tt(-S), tt(-A), tt(-w), and tt(-W) affect how
+tt(_arguments) parses the analyzed command line's options.  These switches are
+useful for commands with standard argument parsing.
 
 The options of tt(_arguments) have the following meanings:
 
@@ -3558,7 +3559,7 @@ startitem()
 item(tt(-n))(
 With this option, tt(_arguments) sets the parameter tt(NORMARG)
 to the position of the first normal argument in the tt($words) array,
-i.e., the position after the end of the options.  If that argument
+i.e. the position after the end of the options.  If that argument
 has not been reached, tt(NORMARG) is set to tt(-1).  The caller
 should declare `tt(integer NORMARG)' if the tt(-n) option is passed;
 otherwise the parameter is not used.
@@ -3572,10 +3573,9 @@ option name (the `tt(-xy)' option).
 
 Options beginning with a single hyphen or plus sign are eligible for stacking;
 words beginning with two hyphens are not.
-This is suitable for standard GNU options.
 
-Note that tt(-s) after tt(-)tt(-) has a different meaning, and is documented
-below.
+Note that tt(-s) after tt(-)tt(-) has a different meaning, which is documented
+in the segment entitled `Deriving var(spec) forms from the help output'.
 )
 item(tt(-w))(
 In combination with tt(-s), allow option stacking
@@ -3624,13 +3624,11 @@ execute var(action)s.
 This is discussed in detail below.
 )
 item(tt(-M) var(matchspec))(
-Use var(matchspec) as the match specification to use to
-completion option names and values.  The default var(matchspec) is:
-
+Use the match specification var(matchspec) for completing option names and values.
+The default var(matchspec) allows partial word completion after `tt(_)' and
+`tt(-)', such as completing `tt(-f-b)' to `tt(-foo-bar)'.  The default
+var(matchspec) is:
 example(tt(r:|[_-]=* r:|=*))
-
-which allows partial word completion after `tt(_)' and `tt(-)', for example
-`tt(-f-b)' can be completed to `tt(-foo-bar)'.
 )
 enditem()
 
@@ -3756,7 +3754,7 @@ xitem(tt(:*)var(pattern)tt(::)var(message)tt(:)var(action))
 item(tt(:*)var(pattern)tt(:::)var(message)tt(:)var(action))(
 This describes multiple arguments.  Only the last var(optarg) for
 an option taking multiple arguments may be
-given in this form.  If the var(pattern) is empty (i.e., tt(:*:)), all
+given in this form.  If the var(pattern) is empty (i.e. tt(:*:)), all
 the remaining words on the line are to be completed as described by the
 var(action); otherwise, all the words up to and including a word matching
 the var(pattern) are to be completed using the var(action).
@@ -4005,7 +4003,7 @@ A useful alternative is often an option specification with rest-arguments
 (as in `tt(-foo:*:...)'); here the option tt(-foo) swallows up all
 remaining arguments as described by the var(optarg) definitions.
 
-em(Intuiting var(spec) forms from the help output)
+em(Deriving var(spec) forms from the help output)
 
 The option `tt(-)tt(-)' allows tt(_arguments) to work out the names of long
 options that support the `tt(-)tt(-help)' option which is standard in many


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-07-27 14:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-16 23:20 [PATCH] _arguments docs: Add options overview and sections Daniel Shahaf
2015-07-27 13:52 ` Daniel Shahaf

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).