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

Suggestion for completion interface



Currently coompletion is tightly coupled with several ZLE widgets; it is
impossible to use completion is user-defined widgets, also it impossible
to add extensions to completion (notorious colour-ls patch).

May be, it possible to slightly change interface. The idea is:

  completion should just build a list of possible choices. It can
  return it e.g. in define ZSH variable, let's say COMPLETION_RESULT
  
  ZLE should provide widget(s), which just takes as argument given list
  of choices and implement usual list/menu selection (well, it is no
  more completion)

  then current widgets, like complete-word, list-choices etc can be
  redefined in terms of call to completion followed by call to 
  selection widget.

  hard part is providing hooks to user-extensions. One possibility is,
  that selection widgets operate on two arrays - one with actual choices
  and other with "user visible" ones. It will make colour patch 
  really simple.

All the above has probably some advantages:

  1. there were several requests about calling completion from user
     functions. The above changes make it at least possible to call
     coompletion in widgets (were input is clear defined).

  2. It makes it possible to create custom completion widgets. Currently
     I have to define completion for _every_ command I use. With
     suggested changes it would be possible to create widget
        zle-select-user with contents like
           ZLE_CHOICES=("${(@)${(f@)$(</etc/passwd)}%%:*}")
           zle select-word
     asuming, that select-word operates on ZLE_CHOICES array.

     then I could do "bindkey ^Xu zle-select-user" and use ^Xu in 
     _every_ command to simply complete/select user name in _any_
     command position.

  3. Well, if e.g. selct-word will operate on two arrays (internal and
     user-visible) then colours in ZSH could be implemented as

       zcomplete                # call completion
       ZLE_CHOICES_INTERNAL=COMPLETION_RESULT
       ZLE_CHOICES_USER=...     # what ever needs to be done to colour
                                # file names and so on. stat module comes
                                # handy
       zle menu-select          # calls widget, which presents user
                                # elements of ZLE_CHOICES_USER but
                                # passes to ZSH corresponding elements
                                # ZLE_CHOICES_INTERNAL

     such widget could the be used instead of complete-word.

If course, it is only idea. The widgets should probbaly know much more
about current completion environment than just it's results - such as
what is completed (it could be vars, options and so on - not only files)
so that user widget can decide, if it needs to mark files at all.

Just interested, is it all sounds reasonable.

-------------------------------------------------------------------------
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