about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog6
-rw-r--r--Completion/Commands/_expand_word13
-rw-r--r--Completion/Core/_expand44
-rw-r--r--Doc/Zsh/compsys.yo14
4 files changed, 67 insertions, 10 deletions
diff --git a/ChangeLog b/ChangeLog
index 95067ff07..7b540eeea 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2000-04-20  Sven Wischnowsky  <wischnow@informatik.hu-berlin.de>
+
+	* 10854: Completion/Commands/_expand_word, Completion/Core/_expand,
+ 	Doc/Zsh/compsys.yo: default values for styles in _expand_word,
+ 	listing expansions with ^Xd, _expand uses add-space style
+	
 2000-04-20  Oliver Kiddle  <opk@zsh.org>
 
 	* 10848: Completion/Builtins/_print, Completion/Core/.distfiles,
diff --git a/Completion/Commands/_expand_word b/Completion/Commands/_expand_word
new file mode 100644
index 000000000..9b71dc830
--- /dev/null
+++ b/Completion/Commands/_expand_word
@@ -0,0 +1,13 @@
+#compdef -K _expand_word complete-word \C-xe _list_expansions list-choices \C-xd
+
+# Simple completion front-end implementing expansion.
+
+local curcontext="$curcontext"
+
+if [[ -z "$curcontext" ]]; then
+  curcontext="expand-word:::"
+else
+  curcontext="expand-word:${curcontext#*:}"
+fi
+
+_main_complete _expand
diff --git a/Completion/Core/_expand b/Completion/Core/_expand
index eff8d8601..2557af884 100644
--- a/Completion/Core/_expand
+++ b/Completion/Core/_expand
@@ -28,7 +28,8 @@ exp=("$word")
 # 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 @@ subd=("$exp[@]")
 
 # 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 @@ zstyle -s ":completion:${curcontext}:" sort sort
 [[ "$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
-    compadd "$expl[@]" -UQ - "$exp[@]"
+    if zstyle -T ":completion:${curcontext}:" add-space; then
+      suf=' '
+    else
+      suf=
+    fi
+    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"
diff --git a/Doc/Zsh/compsys.yo b/Doc/Zsh/compsys.yo
index 547db492b..332dc2702 100644
--- a/Doc/Zsh/compsys.yo
+++ b/Doc/Zsh/compsys.yo
@@ -74,7 +74,7 @@ to be loaded before the completion system is initialized (i.e. the
 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 @@ accepted.
 )
 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 @@ item(tt(_expand_word (^Xe)))(
 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/))(