zsh-users
 help / color / mirror / code / Atom feed
From: Mikael Magnusson <mikachu@gmail.com>
To: Bart Schaefer <schaefer@brasslantern.com>
Cc: zsh-users@zsh.org
Subject: Re: context for globbing qualifiers based on command
Date: Wed, 29 Feb 2012 19:33:57 +0100	[thread overview]
Message-ID: <CAHYJk3Rv6QN_jL1HhBy6=-5Uwf3AMu=NMs95a9VEayQ0UaMFQQ@mail.gmail.com> (raw)
In-Reply-To: <CAHYJk3QOtFEeqRQeM3nGGt6OR1i9ynio_ZtGh5pv6aGhJ=O99g@mail.gmail.com>

On 29 February 2012 19:32, Mikael Magnusson <mikachu@gmail.com> wrote:
> On 29 February 2012 19:22, Bart Schaefer <schaefer@brasslantern.com> wrote:
>> (It wasn't necessary to send this inquiry twice.  It sometimes takes a
>> little while for a response.)
>>
>> On Feb 27, 11:20am, Martin Richter wrote:
>>>
>>> Is it possible to tweak the completion such that shell functions are
>>> grouped at the top when pressing TAB when using (:e...) on a given command?
>>>   print -l *(e:TAB --> gives a lot of possible functions etc
>>> but
>>>   special_command *(e:TAB
>>> gives only shell function matching some regexp or gives only the single
>>> function 'foo' or members of an array of functions?
>>
>> Unfortunately, no.  The zstyle context after *(e: is identical to the
>> context in any other command position.
>>
>> However, the $words array hasn't been altered, so you could write a
>> function to be installed in your "completer" style that examines the
>> values of $words[1] and $words[CURRENT], something like this:
>>
>> _special_command_glob_completer() {
>>  if [[ CURRENT -gt 1 &&
>>        "$words[1]" = 'special_command' &&
>>        "$words[CURRENT]" = *\(*e:* ]]
>>  then
>>    compset -p ${#words[CURRENT]}
>>    compadd -J special-globbers sum_equals product_equals
>>    return 0
>>  else
>>    return 1
>>  fi
>> }
>>
>> zstyle ':completion:*' completer _expand \
>>        _special_command_glob_completer \
>>        _complete _match _ignored _approximate _prefix
>>
>> (the rest of that completer style is just for example, but you probably
>> want at least _complete in there after your special one).
>>
>> It might also be possible to do this more generically with a "matcher"
>> zstyle in the context :completion::complete:-command-::* but I'll leave
>> that for someone else to work out.  (It'd have to use "zstyle -e" and
>> some kind of test similar to the "if" above.)
>
> You can probably do this a bit less fragilely with $zsh_eval_context:
>
> % print -l $(echo .(e:'reply=($zsh_eval_context)':))
> cmdsubst
> globqual
> toplevel

Ignore that :).

-- 
Mikael Magnusson


      reply	other threads:[~2012-02-29 18:40 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-27 10:20 Martin Richter
2012-02-29 18:22 ` Bart Schaefer
2012-02-29 18:28   ` Martin Richter
2012-02-29 18:59     ` Bart Schaefer
2012-02-29 18:32   ` Mikael Magnusson
2012-02-29 18:33     ` Mikael Magnusson [this message]

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='CAHYJk3Rv6QN_jL1HhBy6=-5Uwf3AMu=NMs95a9VEayQ0UaMFQQ@mail.gmail.com' \
    --to=mikachu@gmail.com \
    --cc=schaefer@brasslantern.com \
    --cc=zsh-users@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).