From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29380 invoked from network); 20 Apr 2000 08:02:41 -0000 Received: from sunsite.auc.dk (130.225.51.30) by ns1.primenet.com.au with SMTP; 20 Apr 2000 08:02:41 -0000 Received: (qmail 17156 invoked by alias); 20 Apr 2000 08:02:31 -0000 Mailing-List: contact zsh-workers-help@sunsite.auc.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 10854 Received: (qmail 17144 invoked from network); 20 Apr 2000 08:02:30 -0000 Date: Thu, 20 Apr 2000 10:02:29 +0200 (MET DST) Message-Id: <200004200802.KAA26639@beta.informatik.hu-berlin.de> From: Sven Wischnowsky To: zsh-workers@sunsite.auc.dk In-reply-to: Peter Stephenson's message of Wed, 19 Apr 2000 14:55:31 +0100 Subject: PATCH: Re: _expand_word Peter Stephenson wrote: > I was hoping to be able to use _expand_word, bound to ^Xe, as more or less > a drop-in replacement for ^X* --- which is presumably what it should be. > However, you need to set some styles for this to work. I set > > zstyle ':completion:expand-word:*' glob 1 > zstyle ':completion:expand-word:*' substitute 1 > zstyle ':completion:expand-word:*' original false > zstyle ':completion:expand-word:*' tag-order '!original' > > (maybe I don't need substitute) and it now does pretty much what I expect; (_expand doesn't use the `original' style.) > one slight exception is that it leaves the cursor right after the expansion > with no space if there's just the one expansion. That was intentional, don't remember exactly why. It came together with adding slashes to directories (when added as single matches). The patch makes _expand use the add-space style (like _prefix), with almost the same meaning (hence the same style). If it is true (the default) you get slashes for directories and spaces for other stuff. Otherwise you get slashes or the cursor directly after the match. > It would probably be good > if there was some way to have these set by default for expand-word without > stamping on anything supplied by the user, and without affecting the use > of _expand from the completer list. The patch makes glob and substitute default to 1 for _expand_word (but not for _expand). I have not tried to implement some default value for the tag-order style (the !original above) because I didn't want to make _tags have such a default value. Somehow. Maybe I could be convinced that this is a good idea. > Another problem is one we've met before, that things like $PATH have the > `$' stripped before the ever get here and can't be expanded. This is highly > counterintuitive in this case. I'll see if and what we can do about that. But I first have to find out why we did it this way... > A more minor issue is that it would be good to have a way of listing > expansions as a replacment for ^Xg. This could easily be done with a > compdef -K at the top of _expand_word with a binding to e.g. ^Xd. I could > even do that myself. The patch also adds this. Bye Sven Index: Completion/Commands/_expand_word =================================================================== RCS file: /cvsroot/zsh/zsh/Completion/Commands/_expand_word,v retrieving revision 1.1.1.7 diff -u -r1.1.1.7 _expand_word --- Completion/Commands/_expand_word 2000/02/14 13:10:03 1.1.1.7 +++ Completion/Commands/_expand_word 2000/04/20 07:58:18 @@ -1,9 +1,6 @@ -#compdef -k complete-word \C-xe +#compdef -K _expand_word complete-word \C-xe _list_expansions list-choices \C-xd # Simple completion front-end implementing expansion. -# -# If configurations keys with the prefix `expandword_' are -# given they override those starting with `expand_'. local curcontext="$curcontext" Index: Completion/Core/_expand =================================================================== RCS file: /cvsroot/zsh/zsh/Completion/Core/_expand,v retrieving revision 1.2 diff -u -r1.2 _expand --- Completion/Core/_expand 2000/04/01 20:43:43 1.2 +++ Completion/Core/_expand 2000/04/20 07:58:18 @@ -28,7 +28,8 @@ # First try substitution. That weird thing spanning multiple lines # changes quoted spaces, tabs, and newlines into spaces. -zstyle -s ":completion:${curcontext}:" substitute expr && +{ zstyle -s ":completion:${curcontext}:" substitute expr || + [[ "$curcontext" = expand-word:* ]] && expr=1 } && [[ "${(e):-\$[$expr]}" -eq 1 ]] && exp=( "${(e)exp//\\[ ]/ }" ) @@ -41,7 +42,8 @@ # Now try globbing. -zstyle -s ":completion:${curcontext}:" glob expr && +{ zstyle -s ":completion:${curcontext}:" glob expr || + [[ "$curcontext" = expand-word:* ]] && expr=1 } && [[ "${(e):-\$[$expr]}" -eq 1 ]] && exp=( ${~exp} ) @@ -65,28 +67,56 @@ [[ "$sort" = (yes|true|1|on) ]] && exp=( "${(@o)exp}" ) # If there is only one expansion, add a suitable suffix -(($#exp == 1)) && suf='' && [[ -d $exp && "$exp[1]" != */ ]] && suf='/' +if (( $#exp == 1 )); then + if [[ -d $exp && "$exp[1]" != */ ]]; then + suf=/ + elif zstyle -T ":completion:${curcontext}:" add-space; then + suf= + fi +fi + if [[ -z "$compstate[insert]" ]] ;then - _description all-expansions expl 'all expansions' "o:$word" + if [[ "$sort" = menu ]]; then + _description expansions expl expansions "o:$word" + else + _description -V expansions expl expansions "o:$word" + fi - compadd "$expl[@]" -UQ -qS "$suf" - "$exp" + compadd "$expl[@]" -UQ -qS "$suf" - "$exp[@]" else _tags all-expansions expansions original - if _requested all-expansions; then _description all-expansions expl 'all expansions' compadd "$expl[@]" -UQ -qS "$suf" - "$exp" fi if [[ $#exp -gt 1 ]] && _requested expansions; then + local i normal dir + if [[ "$sort" = menu ]]; then _description expansions expl expansions "o:$word" else _description -V expansions expl expansions "o:$word" + fi + if zstyle -T ":completion:${curcontext}:" add-space; then + suf=' ' + else + suf= fi - compadd "$expl[@]" -UQ - "$exp[@]" + normal=() + dir=() + + for i in "$exp[@]"; do + if [[ -d "$i" && "$i" != */ ]]; then + dir=( "$dir[@]" "$i" ) + else + normal=( "$dir[@]" "$i" ) + fi + done + (( $#dir )) && compadd "$expl[@]" -UQ -qS/ - "$dir[@]" + (( $#normal )) && compadd "$expl[@]" -UQ -qS "$suf" - "$normal[@]" fi _requested original expl original && compadd "$expl[@]" -UQ - "$word" Index: Doc/Zsh/compsys.yo =================================================================== RCS file: /cvsroot/zsh/zsh/Doc/Zsh/compsys.yo,v retrieving revision 1.20 diff -u -r1.20 compsys.yo --- Doc/Zsh/compsys.yo 2000/04/19 06:49:36 1.20 +++ Doc/Zsh/compsys.yo 2000/04/20 07:58:20 @@ -74,7 +74,7 @@ tt(compinit) function is called) to make sure that the tt(menu-select) widget defined by it will be redefined, too. -Should you need to use the original copmpletion commands, you can still +Should you need to use the original completion commands, you can still bind keys to the old functions by putting a `tt(.)' in front of the command name, e.g. `tt(.expand-or-complete)'. @@ -761,8 +761,12 @@ ) kindex(add-space, completion style) item(tt(add-space))( -This style is used by the tt(_prefix) completer to decide if a space -should be inserted before the suffix. +This style is used by the tt(_expand) completer. If it `true' (the +default), a space will be inserted after all words resulting forom the +expansion (except for directory names which get a slash). + +It is also used by tt(_prefix) completers to decide if a space should +be inserted before the suffix. ) kindex(ambiguous, completion style) item(tt(ambiguous))( @@ -2263,6 +2267,10 @@ Performs expansion on the current word: equivalent to the standard tt(expand-word) command, but using the tt(_expand) completer. Before calling it, the var(function) field is set to `tt(expand-word)'. + +Different from tt(_expand), this uses a `tt(1)' (one) as default +value for the tt(substitute) and tt(glob) styles, i.e. both types of +expansion will normally be performed. ) findex(_history_complete_word) (\e/) item(tt(_history_complete_word) (\e/))( -- Sven Wischnowsky wischnow@informatik.hu-berlin.de