zsh-workers
 help / color / mirror / code / Atom feed
From: Daniel Shahaf <d.s@daniel.shahaf.name>
To: zsh-workers@zsh.org
Subject: Re: PATCH: list units in brackets at the end of completion group descriptions
Date: Wed, 1 Dec 2021 03:27:58 +0000	[thread overview]
Message-ID: <20211201032758.GB10648@tarpaulin.shahaf.local2> (raw)
In-Reply-To: <95929-1637616276.991515@RrFC.b73W.RtQH>

Oliver Kiddle wrote on Mon, Nov 22, 2021 at 22:24:36 +0100:
> Attached is an updated version of the patch from 49532 to add a helper
> for completing numbers with unit suffixes and for separating out
> defaults, ranges and units in descriptions.

It looks like some documentation is duplicated between top of the file
and the manual.  Recommend to de-duplicate, otherwise the two copies
will inveitably get out of sync with each other.

Maybe mention the addition of _numbers in NEWS?

Cheers,

Daniel


> +++ b/Completion/Base/Utility/_numbers
> @@ -0,0 +1,87 @@
> +#autoload
> +
> +# Usage: _numbers [compadd options] [-t tag] [-f|-N] [-u units] [-l min] [-m max] \
> +#                 [-d default] ["description"] [unit-suffix...]
> +
> +#   -t : specify a tag (defaults to 'numbers')
> +#   -u : indicate the units, e.g. seconds
> +#   -l : lowest possible value
> +#   -m : maximum possible value
> +#   -d : default value
> +#   -N : allow negative numbers (implied by range including a negative)
> +#   -f : allow decimals (float)
> +
> +# For a unit-suffix, an initial colon indicates a unit that asserts the default
> +# otherwise, colons allow for descriptions, e.g:
> +
> +#   :s:seconds m:minutes h:hours
> +
> +# unit-suffixes are not sorted by the completion system when listed
> +# Specify them in order of magnitude, this tends to be ascending unless
> +# the default is of a higher magnitude, in which case, descending.
> +# So for, example
> +#   bytes kB MB GB
> +#   s ms us ns
> +# Where the compadd options include matching control or suffixes, these
> +# are applied to the units
> +
> +# For each unit-suffix, the format style is looked up with the
> +# unit-suffixes tag and the results concatenated. Specs used are:
> +#   x : the suffix
> +#   X : suffix description
> +#   d : indicate suffix is for the default unit
> +#   i : list index
> +#   r : reverse list index
> +# The latter three of these are useful with ternary expressions.
> +
> +# _description is called with the x token set to make the completed
> +# list of suffixes available to the normal format style
> +++ b/Doc/Zsh/compsys.yo
> @@ -4496,8 +4496,22 @@ not contain an explanation string to be displayed above the matches.
> @@ -4773,6 +4787,69 @@ checked.  If it is set completion is terminated at that point even if
>  no matches have been found.  This is the same effect as in the
>  tt(-first-) context.
>  )
> +findex(_numbers)
> +item(tt(_numbers) [ var(option) ... ] [ var(description) ] [ var(suffix) ... ])(
> +This can be used where a number is followed by a suffix to indicate the units.
> +The unit suffixes are completed and can also be included in the description
> +used when completion is invoked for the preceding number.
> +
> +In addition to common tt(compadd) options, tt(_numbers) accepts the following
> +options:
> +
> +startitem()
> +item(tt(-t) var(tag))(
> +Specify a tag to use instead of the default of tt(numbers).
> +)
> +item(tt(-u) var(units))(
> +Indicate the default units for the number, e.g. tt(bytes).
> +)
> +item(tt(-l) var(min))(
> +Specify the lowest possible value for the number.
> +)
> +item(tt(-m) var(max))(
> +Specify the highest possible value for the number.
> +)
> +item(tt(-d) var(default))(
> +Specify the default value.
> +)
> +item(tt(-N))(
> +Allow negative numbers.  This is implied if the range includes a negative.
> +)
> +item(tt(-f))(
> +Allow decimal numbers.
> +)
> +enditem()
> +
> +Where a particular suffix represents the default units for a number, it
> +should be prefixed with a colon.  Additionally, suffixes can be followed
> +by a colon and a description.  So for example, the following allows the
> +age of something to be specified, either in seconds or with an optional
> +suffix with a longer unit of time:
> +
> +example(_numbers -u seconds age :s:seconds m:minutes h:hours d:days)
> +
> +It is typically helpful for units to be presented in order of magnitude
> +when completed.  To facilitate this, the order in which they are given
> +is preserved.
> +
> +When the tt(format) style is looked up with the tt(descriptions) tag or
> +the tag specified with tt(-t), the list of suffixes is available as a
> +`tt(%x)' escape sequence. This is in addition to the usual sequences
> +documented under the tt(format) style. The form this list takes can also
> +be configured. To this end, the tt(format) style is first looked up with
> +the tag tt(unit-suffixes). The retrieved format is applied to each
> +suffix in turn and the results are then concatenated to form the
> +completed list. For the tt(unit-suffixes) format, `tt(%x)' expands to
> +the individual suffix and `tt(%X)' to its description. tt(%d)' indicates
> +a default suffix and can be used in a condition. The index and reverse
> +index are set in `tt(%i)' and `tt(%r)' respectively and are useful for
> +text included only with the first and last suffixes in the list. So for
> +example, the following joins the suffixes together as a comma-separated
> +list:
> +
> +example(zstyle ':completion:*:unit-suffixes' format '%x%(r::,)')
> +)
> +
>  findex(_options)
>  item(tt(_options))(
>  This can be used to complete the names of shell options.  It provides a
> 


  reply	other threads:[~2021-12-01  3:28 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-27 11:52 Oliver Kiddle
2021-08-27 12:10 ` Daniel Shahaf
2021-10-27 20:51   ` Oliver Kiddle
2021-11-02 12:08     ` Jun T
2021-11-07  1:16       ` Oliver Kiddle
2021-11-08 10:56         ` Jun T
2021-11-10 23:08           ` PATCH: zformat (was list units in brackets at the end of completion group descriptions) Oliver Kiddle
2021-11-22 21:24           ` PATCH: list units in brackets at the end of completion group descriptions Oliver Kiddle
2021-12-01  3:27             ` Daniel Shahaf [this message]
2021-08-27 14:44 ` Mikael Magnusson
2021-08-27 16:14   ` Oliver Kiddle

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=20211201032758.GB10648@tarpaulin.shahaf.local2 \
    --to=d.s@daniel.shahaf.name \
    --cc=zsh-workers@zsh.org \
    /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).