summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog9
-rw-r--r--Completion/Unix/Type/_path_files21
-rw-r--r--Doc/Zsh/compsys.yo17
3 files changed, 39 insertions, 8 deletions
diff --git a/ChangeLog b/ChangeLog
index b7ce3e22a..e9f6e04d5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2010-04-14  Peter Stephenson  <pws@csr.com>
+
+	* users/15011: Completion/Unix/Type/_path_files,
+	Doc/Zsh/compsys.yo: add path-completion style to allow
+	completion of preceeding directories in files to be be turned
+	off.
+
 2010-04-13  Peter Stephenson  <pws@csr.com>
 
 	* unposted: Functions/Calendar/calendar, Functions/Calendar/calendar_add,
@@ -13010,5 +13017,5 @@
 
 *****************************************************
 * This is used by the shell to define $ZSH_PATCHLEVEL
-* $Revision: 1.4953 $
+* $Revision: 1.4954 $
 *****************************************************
diff --git a/Completion/Unix/Type/_path_files b/Completion/Unix/Type/_path_files
index acc11542d..fa02656d0 100644
--- a/Completion/Unix/Type/_path_files
+++ b/Completion/Unix/Type/_path_files
@@ -32,6 +32,7 @@ local tmp1 tmp2 tmp3 tmp4 i orig eorig pre suf tpre tsuf opre osuf cpre
 local pats haspats ignore pfx pfxsfx sopt gopt opt sdirs ignpar cfopt listsfx
 local nm=$compstate[nmatches] menu matcher mopts sort mid accex fake
 local listfiles listopts tmpdisp origtmp1 Uopt
+local accept_exact_dirs path_completion
 integer npathcheck
 local -a Mopts
 
@@ -191,6 +192,11 @@ zstyle -a ":completion:${curcontext}:" fake-files fake
 
 zstyle -s ":completion:${curcontext}:" ignore-parents ignpar
 
+zstyle -t ":completion:${curcontext}:paths" accept-exact-dirs &&
+  accept_exact_dirs=1
+zstyle -T ":completion:${curcontext}:paths" path-completion &&
+  path_completion=1
+
 if [[ -n "$compstate[pattern_match]" ]]; then
   if { [[ -z "$SUFFIX" ]] && _have_glob_qual "$PREFIX" complete } ||
     _have_glob_qual "$SUFFIX" complete; then
@@ -350,16 +356,17 @@ for prepath in "$prepaths[@]"; do
   skipped=
   cpre=
 
-  if zstyle -t ":completion:${curcontext}:paths" accept-exact-dirs &&
-    [[ $pre = (#b)(*)/([^/]#) ]]; then
-    # We've been told that we can accept an exact directory
-    # prefix immediately.  Try this with the longest path prefix
-    # first:  this saves stats in the simple case and may get around
-    # automount behaviour if early components don't yet exist.
+  if [[ ( -n $accept_exact_dirs || -z $path_completion ) && \
+        $pre = (#b)(*)/([^/]#) ]]; then
+    # We've been told either that we can accept an exact directory prefix
+    # immediately, or that path expansion is inhibited.  Try the longest
+    # path prefix first: in the first case, this saves stats in the simple
+    # case and may get around automount behaviour if early components don't
+    # yet exist, and in the second case this is the prefix we want to keep.
     tmp1=$match[1]
     tpre=$match[2]
     while true; do
-      if [[ -d $prepath$realpath$donepath$tmp1 ]]; then
+      if [[ -z $path_completion || -d $prepath$realpath$donepath$tmp1 ]]; then
 	donepath=$donepath$tmp1/
 	pre=$tpre
 	break
diff --git a/Doc/Zsh/compsys.yo b/Doc/Zsh/compsys.yo
index 034540d3e..88eec25f1 100644
--- a/Doc/Zsh/compsys.yo
+++ b/Doc/Zsh/compsys.yo
@@ -1123,6 +1123,9 @@ When this style is true, any prefix of a path that matches an existing
 directory is accepted without any attempt to complete it further.
 Hence, in the given example, the path tt(/usr/bin/) is accepted
 immediately and completion tried in that directory.
+
+If you wish to inhibit this behaviour entirely, set the tt(path-completion)
+style (see below) to tt(false).
 )
 kindex(add-space, completion style)
 item(tt(add-space))(
@@ -2259,6 +2262,20 @@ containing color names in the format of an X11 tt(rgb.txt) file.  If
 the style is not set but this file is found in one of various standard
 locations it will be used as the default.
 )
+item(tt(path-completion))(
+This is used by filename completion.  By default, filename completion
+examines all components of a path to see if there are completions of
+that component.  For example, tt(/u/b/z) can be completed to
+tt(/usr/bin/zsh).  Explicitly setting this style to tt(false) inhibits this
+behaviour for path components before the cursor; this overrides the
+setting of tt(accept-exact-dirs).
+
+Even with the style set to tt(false), it is still possible to complete
+multiple paths by setting the option tt(COMPLETE_IN_WORD) and moving the
+cursor back to the first component in the path to be completed.  For
+example, tt(/u/b/z) can be completed to tt(/usr/bin/zsh) if the cursor is
+after the tt(/u).
+)
 kindex(pine-directory, completion style)
 item(tt(pine-directory))(
 If set, specifies the directory containing PINE mailbox files.  There