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

Re: cdablevars and cd completion in 3.1.5



On Dec 1,  1:52pm, Sven Wischnowsky wrote:
} Subject: Re: cdablevars and cd completion in 3.1.5
}
} Bart Schaefer wrote:
} > ...
} >     compctl -x 'S[/][~][./][../]' -/ \
} > 	    - 'n[-1,/], s[]' -K cdmatch -S '/' -q \
} > 	    -- cd pushd
} > ...
} > zsh% cd HE/zshfun
} >          ^
} > 	 With the cursor here, pressing tab does NOT call cdmatch!
} > 	 Why not?
} 
} 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.

If the current word can't be completed because of the position of the
cursor, then shouldn't the position of the cursor also determine whether
the pattern matches the word in the first place?  Why would you ever
WANT a pattern to match and then NOT call the corresponding completion?

}     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,/]'.

Hm; I'd have expected them to be cumulative (though possibly overlapping),
but I can see where that'd be a mess particularly for something strange
like
	compctl -x 'n[1,/] n[-1,/]' ...

However, that doesn't work, because it stops ignoring the stuff up to
the last /, so now all the completions cdmatch puts in $reply have to
include that prefix when completing anything *after* that slash.  I.e.

zsh% cd HOME/z<TAB>

feeps because reply=(zshfun) and the code wants reply=(HOME/zshfun).

Your alternate compctl has the same problem.  It's probably possible to
fix my cdmatch to handle that, but it isn't straightforward, as it can't
simply use tilde-expansion and then lop off the path tail; instead it
has to convert the path head back into the corresponding named dir.  I
suppose a trick with print -P could be used, but that's another $().

(The other possibility would be to use the -U option and thus expand the
variable name into the full path it represents.)

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

That can complete to impossible paths because it doesn't check whether
the stuff in $2 really is a subdirectory of the named dir in $pref.  To
check correctly again requires tilde-expanding and then converting back
into a named dir.

So I think, all things considered, I'd give up completeinword on cdable
variables and take my original function and compctl.

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com



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