zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-workers@zsh.org
Subject: Re: trying to understand how the zsh completer works
Date: Thu, 28 Feb 2013 21:56:32 -0800	[thread overview]
Message-ID: <130228215632.ZM9327@torch.brasslantern.com> (raw)
In-Reply-To: <CAHjjW15xdpu12e9k9XgUjkK_h82ccr5d2TO2pNVXevj2OCarSA@mail.gmail.com>

I'm wondering if this doesn't belong on zsh-users rather than -workers?

On Feb 28,  6:38pm, joe M wrote:
}
} I am trying to tell the completer to use a different completer based
} on context.
}
} In this situation, I am trying to tell it to use the _approximate
} completer when completing the argument-rest context of grep.

Unfortunately this is one of the things that mostly doesn't work.  The
set of completers is determined very early in the process when the
context is still very non-specific -- because it is the completers
themselves that supply the semantic analysis to fill out the rest of
the context.

Note that the definition of a the zstyle context for completion is

    :completion:FUNCTION:COMPLETER:COMMAND:ARGUMENT:tag

This roughly corresponds to how far down into the completion process
the current operation has progressed.  More detail is appended to the
context at each stage.

The current completer is the third component; by the time the context
has been built up to the fifth component, it's way too late for the
style "completer" to be meaningful.  It can only be usefully looked
up at the very beginning (:completion:) or during the first FUNCTION
(:completion:hist-complete: to use one of your examples).

In retrospect it might have been useful to split the context analysis
from the generation of matches, rather than having a single function
responsible for doing both parts for each command name.  On the other
hand that would have doubled the number of functions (or at least the
number of call signatures) and we'd probably never have gotten done
with the implementation. :-}

If you do put _approximate in the global list of completers, you can
see where it appears in the context -- see how it's "upstream" from
*:grep:argument-rest: ?

tags in context :completion::approximate:::
    corrections original  (_approximate)
tags in context :completion::approximate-1:grep::
    argument-rest options  (_arguments _grep (eval))
tags in context :completion::approximate-1:grep:argument-rest:
    globbed-files  (_files _arguments _grep (eval))
tags in context :completion::approximate-1:grep:options:
    options  (_describe _arguments _grep (eval))
tags in context :completion::complete:grep::
    argument-rest options  (_arguments _grep (eval))
tags in context :completion::complete:grep:argument-rest:
    globbed-files  (_files _arguments _grep (eval))

This means that _approximate is (indirectly) calling _grep, not the
other way around as you might expect.

The only workaround for this is to do your own context analysis and
embed that in the style value via "zstyle -e".  Something like:

zstyle -e ':completion:*' completer \
 'reply=(_complete); \
  (( $CURRENT > 2 )) && [[ $words[1] = grep ]] && reply+=(_approximate)'

Yes, this could get ugly quickly if you want to customize a lot of
completers for individual commands or word positions.


  reply	other threads:[~2013-03-01  5:56 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-28 23:38 joe M
2013-03-01  5:56 ` Bart Schaefer [this message]
2013-03-03  6:09   ` Bart Schaefer
2013-03-03 15:56     ` joe M
2013-03-03 18:05       ` Bart Schaefer

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=130228215632.ZM9327@torch.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --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).