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

Re: PATCH: 3.1.2-zefram3: history completion



I like the idea, but I totally disagree with implementation (sorry). It
continues the trend to add to base ZSH every feature someone finds to be
useful. I strongly believe, that base zsh must provide general enough
tools to do such sort of things in user space (or as separate module if
anybody will suffer from performance).

Speaking about completion - it should really be redefined to provide

  - completion pure

    It must deal with actual completion in the sense of building list of
    possible matches for a given line. There must exist interface on
    source level (for possible use in modules) and in user space
    (for use with user defined widgets).

  - anything else really belongs to ZLE. After I have list of matches,
    the way they are presented (menu, list or anything else) has 
    nothing to do with completion per se. It also would provide
    a nice way to do selection from user-defined lists (some thing
    I did miss - you cannot defined "context independent" completion.
    E.g. it doesn't make sense to define *all* command which use
    user name as argument - but if I had a way to say "select
    from user list" I could bind it and use with any command).

ZLE should probably provide general purpose widget(s) for selection from
given list (a la existing menu/list/beep completion). Assuming, that
zcomplete does completion returning possible matches and
zle-select-from-list provides user interface to select from matches array,
the whole story would look like

function history-complete-word () {
    set -A matches  $(zcomplete \
      -l $BUFFER           <= current line
      -c $CURSOR           <= current position
      -r '-s "$(fc -l 1 -1 | sed \"s/^[WS TAB]*[0-9]*[WS TAB]*//\")"' \
       ^^^^ actual completion rules (take words from history and select
            matching ones)
      )

    zle zle-select-from-list
        ^^^ takes over TAB if menu completion desired
}

zle -N history-complete-word history-complete-word

bindkey '\M-/' history-complete-word
          
(sed is needed only to strip history numbers).

I hope, the idea is not completely insane ...

-------------------------------------------------------------------------
Andrej Borsenkow 		Fax:   +7 (095) 252 01 05
SNI ITS Moscow			Tel:   +7 (095) 252 13 88

NERV:  borsenkow.msk		E-Mail: borsenkow.msk@xxxxxx
-------------------------------------------------------------------------








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