zsh-workers
 help / color / mirror / code / Atom feed
From: Oliver Kiddle <okiddle@yahoo.co.uk>
To: zsh-workers@zsh.org
Subject: Re: [PATCH 1/1] Squashed commit of the following:
Date: Wed, 30 May 2018 00:00:49 +0200	[thread overview]
Message-ID: <13666.1527631249@thecus> (raw)
In-Reply-To: <20180529153821.nmwa5yojlusioxti@NUC.doronbehar.com>

Doron Behar wrote:
>
> I find that extremely useful when I write completions since it's super
> comfortable with my editor (Vim). Do you have any suggestions? Perhaps
> using EditorConfig?

I don't think editorconfig supports much beyond basic definitions of
indent style. In the case of vim, it supports a variety of foldmethods.
'set foldmethod=syntax' doesn't do such a bad job and if you don't like
it you can define custom expressions.

> Done, used this:
>
> 	local option_deps_modes='--deps-mode=[specify how to handle dependencies]:mode:__luarocks_deps_modes'

That looks fine.

> Besides removing the curly brackets, what is the difference when I use
> '(-.)' in the glob and when I don't? I tried to test this in directories
> where I had files ending with `.rockspec` and in directories where I
> hadn't had files like these and I couldn't tell the difference in
> behaviour. What am I missing?

It can make a difference if you have directories ending in .rockspec.
That perhaps isn't common but in some contexts it can matter.
It is common to setup the file-patterns style to mix directories in with
matched files in which case it is less apparent.
For reference, see the old discussion around workers/19292.

> I couldn't think of a better way of doing this other then just copying
> manually `__git_tags` or using this hack.

Duplicating __git_tags' functionality is just as few lines of code and
less likely to break. This looks rather fragile.

> > In this spec, you already have already specified a message - "LICENSE"
> > so calling _message is superfluous. "LICENSE" can be improved on as a
> > message but I'd avoid constructs like "write a" and use something like
> > 'license (e.g. MIT/X11 or "GNU GPL v3")'
>
> That's a good description, cool. I've come up with this options
> specifications:
>
> 	'--license=[a license string]:license:{_message -e license "(e.g. \"MIT/X11\" or \"GNU GPL v3\")"}'

My point about calling _message being superfluous perhaps wasn't clear.
The second part of the colon-delimited spec IS a message. So you can
just use:

  '--license=[specify a license string]:license (e.g. "MIT/X11" or "GNU GPL v3")'

Note that I also added an initial verb in the description which was a
suggestion I had made earlier but not repeated.

> > Your description, looks like the message for the matches:
> >   '--lib[specify libraries to link against C files]:libraries (comma-separated)'
> > 
> > Or use _sequence or _values if you generate matches.
> > 
>
> I've no idea if this is possible to complete matches for this option. I
> don't have any experience in using this option as well so I'll leave it
> this way. Perhaps it'll be better for the specification to be this:
>
> 	'--lib=[C library files to link to]:'

At least include a message after the colon.

> I'm not sure I understand yet what tags are used for generally in
> completions (RTFD I know but forgive me I'm lazy :/) but anyway the tag
> I chose as the 1st argument for `_call_function` is `subcmd`. Is that
> cool? It looks like that:
>
> 	_call_function subcmd _luarocks_${words[1]}

The first argument to _call_function is not a tag but a variable name.
The return status from the function is assigned to it. Normally, you'll
see "ret".

Tags are used with the zstyle mechanism. zstyle gives you
context-sensitive options where a bunch of information is stuffed into a
context string. For completion,
    :completion:<function>:<completer>:<command>:<arg>:<tag>
Note that the last component is the tag for the current matches.
This is a much more succinct and convenient way to configure things than
if you needed lots of nested if statements.

Taking an example from one of your messages we have:
    zstyle ':completion:*:kill:*' command 'ps -u $USER -o pid,%cpu,tty,cputime,cmd'

As it happens, for kill completion the command style is only looked up
when completing processes but it'd be wise to put the processes tag
into the context there. If you want the style to work for all commands
and not just kill, that'd be essential. Otherwise, it might run ps when
generating some other entirely different sort of matches:

    zstyle ':completion:*:processes' command 'ps -u $USER -o pid,%cpu,tty,cputime,cmd'

(To answer the question in that other post, don't try to emulate that,
just use _pids and leave process selection to the user. ps defaulting to
the current tty made more sense a couple of decades ago.) 

The other thing tags are often used for is for grouping completion
matches. Groups are separate but it is common to use the tag as the
group name which is what you get with:
    zstyle ':completion:*' group-name ''

Finally, tags can be used with the tag-order style to allow users to
try some matches before others.

Oliver


  reply	other threads:[~2018-05-29 22:01 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-26 16:14 [PATCH 0/1] *** Add luarocks completion *** doron.behar
2018-05-26 16:14 ` [PATCH 1/1] Squashed commit of the following: doron.behar
2018-05-28 10:48   ` Oliver Kiddle
2018-05-29 15:38     ` Doron Behar
2018-05-29 22:00       ` Oliver Kiddle [this message]
2018-05-30 12:47         ` Doron Behar
2018-05-30 15:43           ` Oliver Kiddle
2018-06-01  7:18             ` Doron Behar
2018-06-01 13:30               ` Doron Behar
2018-06-01 22:45                 ` Oliver Kiddle
2018-06-03 21:46                   ` Daniel Shahaf
2018-06-05 15:41                   ` Doron Behar
2018-06-07 15:59                     ` Oliver Kiddle
2018-06-07 16:20                       ` Doron Behar

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=13666.1527631249@thecus \
    --to=okiddle@yahoo.co.uk \
    --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).