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

Re: _history-complete-older problems with $(



On 12 January 2016 at 01:15, Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> The following produces the correct set of completion matches (pardon the
> unimaginative name) but is a bit of a hack (it breaks _complete_debug
> and _complete_help):

I think the hacks are acceptable if the code will be used only by
Alt-/ (_history-complete-older). How to accomplish this, btw? Probably
the context should be changed:

>   zstyle ':completion:*' completer _widen_for_history _complete

but I don't know how to do this exactly. Can you help?

>   _widen_for_history () {
>     local -a left=( "${(z)LBUFFER}" )
>     local right="${words[CURRENT]#${left[-1]}}"
>     words=( "${(z)BUFFER}" )
>     CURRENT=${#left}
>     *
>     PREFIX="${left[-1]}"

I've added following line where * is:

echo -e "\nCURRENT: $CURRENT, NEWCUR: $CURRENT, CURSR: $CURSOR, lft:
|$left|, rght: |$left|, words: >""$words[@]""<"

Example outputs are:
# ls<TAB>
CURRENT: 1, NEWCUR: 1, CURSR: 2, lft: |ls|, rght: |ls|, words: >ls<
# ls <TAB>
CURRENT: 1, NEWCUR: 1, CURSR: 3, lft: |ls|, rght: |ls|, words: >ls<
# $(<TAB>
CURRENT: 1, NEWCUR: 1, CURSR: 2, lft: |$(|, rght: |$(|, words: >$(<
# $( TAB
CURRENT: 1, NEWCUR: 1, CURSR: 3, lft: |$( |, rght: |$( |, words: >$( <

Are this expected values? Because despite proposing $(( 0 + 1 ))
correctly after $(<TAB>  (btw., not after $(<Alt-/>), the completer
behaves weird. For "ls <TAB>" it doesn't propose any files.

> This needs some work around the issue of empty words, i.e., when
> completing in empty parens such as $(<TAB>) then $words[CURRENT] is
> empty and the trailing paren must be copied from $RBUFFER to SUFFIX.
> I haven't dived into that detail.

I would gladly perform the work but the code is quite difficult. Could
you state in one sentence what it is doing? Variables $CURRENT, $word
aren't documented in zshzle.1. What does the {} always {} block of
code do? Next, I would guess that "builtin compadd -O found "$@""
performs one run of matching, is this correct? Why second comadd, and
what does "${(@)${(@)found#$PREFIX}%$SUFFIX}" do?

> Another approach would be to create a custom key binding for a widget
> which
>
> - inserts an open quote before the current word
> - invokes completion with completer style set to _history
> - removes quoting again
>
> but that has its own complications if the word on the line is already
> quoted, etc.

Maybe I could get the complications resolved for Zew. The separate key
binding seems close to what I want for Alt-/

Best regards,
Sebastian Gniazdowski



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