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

Re: cdablevars and cd completion in 3.1.5



Bart Schaefer wrote:

>
> ...
>
>     compctl -x 'S[/][~][./][../]' -/ \
> 	    - 'n[-1,/], s[]' -K cdmatch -S '/' -q \
> 	    -- cd pushd
>
> ...
> 
> Now the obligatory bit of zsh arcana that still confuses me:
> 
> zsh% echo ~/zshfun
> /home/schaefer/zshfun
> zsh% cd HE
>          ^
> 	 With cursor here, this calls cdmatch and completes HOME/.
> 	 But if instead I have
> zsh% cd HE/zshfun
>          ^
> 	 With the cursor here, pressing tab does NOT call cdmatch!
> 	 Why not?  I have completeinword set.  The word under the
> 	 cursor contains a /, so it should match n[-1,/].  I expected
> 	 it to call cdmatch with 1=H 2=E/zshfun and to be able to
> 	 read HE/zshfun into $pref.  If Instead I have
> zsh% cd HOME/zn
>               ^
> 	      with the cursor here, I can complete to HOME/zshfun.
> 
> I have the feeling this is something I once knew, but maybe it needs to
> be written down somewhere.

The reason was that the `n[-1,/]' makes the part before the `/' be
ignored so that the cursor isn't in a part that is considered for
completion.
Interestingly I first parsed your compctl wrongly and that led me to a 
nice little workaround for this:

    compctl -x 'S[/][~][./][../]' -/ \
	    - 'n[-1,/] s[], s[]' -K cdmatch -S '/' -q \
	    -- cd pushd

The interesting bit is the `s[]' before the comma. It makes the
completion code use the prefix specified by `s[]' be ignored instead
of the prefix specified by `n[-1,/]'. So with this the function will
be called and we only have to change it accordingly, i.e.:

    reply=( ${${${(M)$(set):#${pref:-[A-Za-z]}*${2:h}*\=/*}:#*(PWD|:)*}%\=/*}${(M)2%%/*} )

(adding the last `${(M)...}').

Btw. I would use this compctl instead:

    compctl -/ -K cdmatch -S/ -q -x 'S[/][~][./][../]' -/ -- cd pushd


Bye
 Sven

P.S.: Yes, we probably should document the above, but I'm terribly
      busy the next few days...

--
Sven Wischnowsky                         wischnow@xxxxxxxxxxxxxxxxxxxxxxx



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