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

Re: disable substring match on command name




----- Original Message -----
From: Oliver Kiddle <okiddle@xxxxxxxxxxx>

> Bart wrote:
>>   zstyle -e ':completion:*' matcher-list \
>>     'zstyle -a "word-${CURRENT}:completion:$curcontext" matcher-list reply'

> That's very nifty. I wouldn't even call "hackish". You're just allowing
> pattern matching to extend to fields that aren't in the standard list.



Umm, actually I am evaluating which solution would be faster?

Mine OR Bart's?

Then I will switch to one which is faster. (and efficient)


I am not sure how zstyle internally works but let me try.

(Also not sure if this belongs to users maillist or workers)


Case 1:
-------

a) zstyle 'word-*:completion:*' matcher-list \ '' 'r:|[._-]=** r:|=**' 'l:|=* r:|=*'
b) zstyle 'word-1:completion:*' matcher-list ''
c) zstyle -e ':completion:*' matcher-list \ 'zstyle -a "word-${CURRENT}:completion:$curcontext" matcher-list reply'
zstyle pattern matching order, is based on most specific to least specific.

So I think here specific-ness order in this case is b, a, c.



So for each context (not just :completion:) it will:


1) First pattern match with b (which will always fail)
2) Second pattern match with a (again will always fail)
3) Third pattern match with c
   i) Continue to 4) if its :completion: context
  ii) Stop matching

4) Evalute another zstyle (word-1, word-2, ...)
5) When CURRENT is 1, b matches (so just 1 lookup)
   i) Return matcher-list b) arguments
6) When CURRENT is >1, b fails and a matches (so 2 lookups)
   i) Return matcher-list a) arguments
7) Do matcher-list matching as per what is returned by 5 OR 6

Points to note:
Each matcher-list possibly calls matcher internally.

For step 1, 2 pattern match fail on first character (w) itself.
So 1, 2 almost takes not time.

4 = I dont know how expensive evaluate is, it is called every time.

7 = I dont know how expensive reply back is?

One disadvantage is that you can not match context just for files
and directories. Partial match may apply to command arguments,
which may not be what you want.

For e.g ls --li<TAB> will show you
--literal

--dereference-command-line

Possibly there is no way to restrict this.

Case-2:
-------

(Note: I have modified tag-order line a bit to avoid re-checking all tags)

a) zstyle ':completion:*' tag-order '*' 'all-files*:-afrr' 'all-files*:-aflr'
b) zstyle ':completion:*:all-files-afrr' matcher 'r:|[._-]=** r:|=**'
c) zstyle ':completion:*:all-files-aflr' matcher 'l:|=* r:|=*'Here order of checking would be b,c (for matcher style)

So for each context (not just :completion:) it will:

1) Pattern match with a, if :completion: remember tag-order
2) Pattern match with b (will always fail)
3) Pattern match with c (will always fail)
4) Try normal command line completion, if succeeded stop
5) If 1) had matched and tag all-files exist?
   i) NO, then stop
  ii) YES then try tag all-files-afrr (goto 6)
6) Pattern match with b (will always succeed)
7) Check matcher b) arguments, if matched stop, else goto 8
8) Try tag with all-files-aflr
9) Pattern match with b (will always fail)
10) Pattern match with c (will always succeed)
11) Check matcher c) arguments

So steps in this case are higher but its more or less just
string comparison. There is no zstyle evaluation.

One advantage over case 1) is you can match on any tag
(files / directory etc) so you get more flexibility.

You can block matching on aliases / command
options etc. (Unlike in case 1)


So now I am interested in knowing what would actually be
faster? Can there be cases when 1 is faster other is
slower and reverse in some other cases?

Please give your inputs.

Amm.




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