zsh-users
 help / color / mirror / code / Atom feed
* Zsh completion configuration
@ 2013-02-25 19:47 joe M
  2013-02-26 16:05 ` Bart Schaefer
  0 siblings, 1 reply; 5+ messages in thread
From: joe M @ 2013-02-25 19:47 UTC (permalink / raw)
  To: zsh-users

Hello,

I am trying to figure out how to add "history-words" as a group within
_complete, similar to aliases or functions.

I see that the file Completion/Zsh/Type/_command_names adds the
different tags using compadd -k.

But, I could not figure out what compadd does from the zsh source. Any
thoughts on what compadd does, or, how I can add another tag to the
list of tags suggested by _command_names?

Thanks
Joe


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

* Re: Zsh completion configuration
  2013-02-25 19:47 Zsh completion configuration joe M
@ 2013-02-26 16:05 ` Bart Schaefer
  2013-02-27  0:41   ` joe M
  0 siblings, 1 reply; 5+ messages in thread
From: Bart Schaefer @ 2013-02-26 16:05 UTC (permalink / raw)
  To: zsh-users

On Feb 25,  2:47pm, joe M wrote:
} 
} I am trying to figure out how to add "history-words" as a group within
} _complete, similar to aliases or functions.
} 
} But, I could not figure out what compadd does from the zsh source. Any
} thoughts on what compadd does, or, how I can add another tag to the
} list of tags suggested by _command_names?

Unless I'm misunderstanding your intent, you don't actually want to
change the tags from _command_names -- you just want to add another tag
that appears in completion output along with the _command_names tags?

To do this you want to replace the completer function for "-command-"
context.  By default this is the _autocd completer (which is only the
default because _autocd is the only file in the completion library that
begins with "#compdef -command-").

So first make yourself a little function patterned on _autocd:

    _history_or_autocd () {
      _history
      local ret=$?
      _autocd || return ret
    }

And then install it for the context:

    compdef _history_or_autocd -command-

To explain a bit further, the completers in the completer style are in
general attempted until one returns a zero (true, success) status, at
which point the set of possible matches is assumed to be finished.  To
merge the results of several completers you have to save the staus, try
the next one, and then return success if any of those completers was
successful.

If you instead wanted to complete history and only try the defaults if no
history words matched, you could have shortcut this as

    compdef '_history || _autocd' -command-

Of course whichever of these you choose has to happen after compinit is
run, otherwise _autocd will step on it when loaded.


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

* Re: Zsh completion configuration
  2013-02-26 16:05 ` Bart Schaefer
@ 2013-02-27  0:41   ` joe M
  2013-02-27  3:26     ` Bart Schaefer
  0 siblings, 1 reply; 5+ messages in thread
From: joe M @ 2013-02-27  0:41 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: zsh-users

Hello Bart,

Thanks for responding. It works like a charm.

tags in context :completion::complete:-command-::
    history-words
                (_history _history_or_autocd (eval))
    commands builtins functions aliases suffix-aliases reserved-words
jobs parameters  (_alternative _command_names _autocd
_history_or_autocd (eval))
    commands
                (_path_commands _alternative _command_names _autocd
_history_or_autocd (eval))
    path-dirs
                (_path_commands _alternative _command_names _autocd
_history_or_autocd (eval))
    jobs
                (_jobs _alternative _command_names _autocd
_history_or_autocd (eval))
    parameters
                (_parameters _alternative _command_names _autocd
_history_or_autocd (eval))
    local-directories named-directories
                (_alternative _cd _autocd _history_or_autocd (eval))
    users named-directories directory-stack
                (_tilde _alternative _cd _autocd _history_or_autocd
(eval))
    users
                (_users _tilde _alternative _cd _autocd
_history_or_autocd (eval))
tags in context :completion::history:::
    history-words  (_history)

> Unless I'm misunderstanding your intent, you don't actually want to
> change the tags from _command_names -- you just want to add another tag
> that appears in completion output along with the _command_names tags?

yes, that is exactly what I wanted to do.

> And then install it for the context:
>
>     compdef _history_or_autocd -command-

I do not understand the "install" process. Is it good enough to have
the function file (_history_or_autocd) anywhere in the $fpath? Or,
does it have to be after the directory with _autocd?

I added this "zstyle ':completion::complete:-command-:*'
_history_or_autocd" to my zshrc, in addition to deleting my zcompdump
and then running the above "compdef _history_or_autocd -command-"
command. Just a rehash did not do the job. Any thoughts, please?

> To explain a bit further, the completers in the completer style are in
> general attempted until one returns a zero (true, success) status, at
> which point the set of possible matches is assumed to be finished.  To
> merge the results of several completers you have to save the staus, try
> the next one, and then return success if any of those completers was
> successful.
>
> If you instead wanted to complete history and only try the defaults if no
> history words matched, you could have shortcut this as
>
>     compdef '_history || _autocd' -command-
>
> Of course whichever of these you choose has to happen after compinit is
> run, otherwise _autocd will step on it when loaded.

Thanks a lot for the explanation. The code makes so much more sense now.

Thanks again,
Joe


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

* Re: Zsh completion configuration
  2013-02-27  0:41   ` joe M
@ 2013-02-27  3:26     ` Bart Schaefer
  2013-02-27 15:54       ` joe M
  0 siblings, 1 reply; 5+ messages in thread
From: Bart Schaefer @ 2013-02-27  3:26 UTC (permalink / raw)
  To: zsh-users

On Feb 26,  7:41pm, joe M wrote:
}
} > And then install it for the context:
} >
} >     compdef _history_or_autocd -command-
} 
} I do not understand the "install" process. Is it good enough to have
} the function file (_history_or_autocd) anywhere in the $fpath? Or,
} does it have to be after the directory with _autocd?

Sorry, I wrote that as if you were going to put it in ~/.zshrc.  To put
it in a file by itself, it has to be in a directory in $fpath that is
listed BEFORE the directory containing _autocd, and the file should look
like

    #compdef -command-
    _history
    local ret=$?
    _autocd || return ret

(without the indentation, of course).

} I added this "zstyle ':completion::complete:-command-:*'
} _history_or_autocd" to my zshrc

No, you don't need that.  Either the compdef command in ~/.zshrc, or the
file formatted as above with #compdef, is all that's necessary.

} Just a rehash did not do the job. Any thoughts, please?

Rehash doesn't reload functions, nor does it reset completion definitions
(the _comps variable).  To install just the one function, use compdef as
a command.  To reload the entire completion system, delete ~/.zcompdump
and run "compinit" (which has the effect of executing a whole bunch of
"compdef" commands computed from the #compdef lines).

-- 
Barton E. Schaefer


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

* Re: Zsh completion configuration
  2013-02-27  3:26     ` Bart Schaefer
@ 2013-02-27 15:54       ` joe M
  0 siblings, 0 replies; 5+ messages in thread
From: joe M @ 2013-02-27 15:54 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: zsh-users

> Rehash doesn't reload functions, nor does it reset completion definitions
> (the _comps variable).  To install just the one function, use compdef as
> a command.  To reload the entire completion system, delete ~/.zcompdump
> and run "compinit" (which has the effect of executing a whole bunch of
> "compdef" commands computed from the #compdef lines).
>
> --
> Barton E. Schaefer

It worked like a charm.

Thanks,
Joe


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

end of thread, other threads:[~2013-02-27 15:54 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-02-25 19:47 Zsh completion configuration joe M
2013-02-26 16:05 ` Bart Schaefer
2013-02-27  0:41   ` joe M
2013-02-27  3:26     ` Bart Schaefer
2013-02-27 15:54       ` joe M

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