Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Completions from file with zcompsys



On Tue, Jun 20, 2017 at 10:27:27AM -0700, Bart Schaefer wrote:
> On Jun 20,  8:46am, Dominik Vogt wrote:
> }
> } Are there some quick instructions instructions or a
> } cheat sheet on the new completion system somewhere?
> 
> http://zsh.sourceforge.net/Guide/zshguide06.html#l144   (perhaps?)
> 
> } And I want to type things like
> } 
> }   $ foo Cheno<TAB>alb<TAB>   # -> Chenopodium album
> }   $ foo Che*a<TAB>           # -> Chenopodium a
> } 
> } (using menu completion, not expanding the * to all matching
> } completions).
> 
> The latter one could be tricky because you will have to prevent the "*"
> from being expanded as a file glob.

If a different "globbing" character would be easier to implement,
or a completely different way to allow partial searches in both
words of the plant name at the same time, that's fine as well.  It
does not have to be the asterisk.  Maybe just moving the cursor to
the beginning of the second word before pressing <TAB> is good
enough.

> Do you want the expansions exactly as you wrote them, or should the
> spaces be quoted?  E.g. do you want to end up with something like one
> of
> 
>     $ foo 'Chenopodium album'
>     $ foo Chenopodium\ album          <-- this one is the easy one below

Yep.  All the command will do is print its arguments, one per
line, so the spaces need to be quoted.  The purpose of the
"command" is to transfer lists of plants I've seen outside from
a notebook (paper) to a file.  Such names are very repetitive so
completion would save a lot of work, and it perfectly suits the
problem to solve.

> You can also pass a string to be eval'd to compdef, so the simplest answer
> to your question is (guessing at a file name)
> 
>     compdef 'compadd ${(f)"$(<~/latin-plant-names.txt)"}' foo

Ah, that seems to be even simpler than the old system.  Since I've
switched to the new completion system I really had no need to
define custom completions, so there was no chance to learn about
it.  :-)

> Then to get the "*"-expansion you will need to add the _match function
> to your completer zstyle.  Example might be
> 
>     zstyle ':completion:*' completer _complete _match
> 
> but adjust the placement of _match to fit whatever your current list of
> completers contains.  It would normally be anywhere after _complete.

Okay, I'll read up on this part to figure out how it works
exactly.  Thanks for your advice.

--

Trying that there is a slight problem.  The file has 9529 lines;
now, when you type something like

  Chenopodium x<TAB>

(where no such taxon exists in the file), zsh starts gobbling 100%
cpu for about half a minute before completing an approximate
match.  This has probably to do with these zstyle lines:

  zstyle ':completion:*' completer _complete _match _approximate
  zstyle ':completion:*:match:*' original only
  zstyle -e ':completion:*:approximate:*' max-errors 'reply=($((($#PREFIX+$#SUFFIX)/3))numeric)'

Hm, it even takes a lot of time with just

  zstyle ':completion:*:approximate:*' max-errors 1 numeric

(zsh-4.3.17)

Ciao

Dominik ^_^  ^_^

-- 

Dominik Vogt



Messages sorted by: Reverse Date, Date, Thread, Author