zsh-users
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@csr.com>
To: zsh-users@zsh.org
Subject: Re: Zsh autocompletion with no access to a parent directory
Date: Wed, 14 Apr 2010 10:47:47 +0100	[thread overview]
Message-ID: <201004140947.o3E9llgG010201@news01.csr.com> (raw)
In-Reply-To: <201004140914.o3E9EPkL009936@news01.csr.com>

Peter Stephenson wrote:
> Matt Wright wrote:
> > Another thought, is it possible to get it to /never/ expand directories.
> 
> (i.e. directories up to the / before the cursor).
>...
> you might have imagined that it wouldn't be too
> difficult to extend accept-exact-dirs, which in turn wasn't so difficult
> to add.

Well, it seems to work...  as well as checking this does what I think it
should, it would be good if anyone trying this out could ensure it
corresponds to the documentation, too.  There is at least a reasonable
chance it hasn't broken existing behaviour.

Note I called the style path-completion because expansion is a
completely different activity in zsh terms, and that it's assumed to be
true if you don't set it to get the current behaviour.

Index: Completion/Unix/Type/_path_files
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Unix/Type/_path_files,v
retrieving revision 1.49
diff -p -u -r1.49 _path_files
--- Completion/Unix/Type/_path_files	14 Sep 2009 08:40:49 -0000	1.49
+++ Completion/Unix/Type/_path_files	14 Apr 2010 09:44:22 -0000
@@ -32,6 +32,7 @@ local tmp1 tmp2 tmp3 tmp4 i orig eorig p
 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}:" f
 
 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
Index: Doc/Zsh/compsys.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/compsys.yo,v
retrieving revision 1.226
diff -p -u -r1.226 compsys.yo
--- Doc/Zsh/compsys.yo	17 Feb 2010 06:16:31 -0000	1.226
+++ Doc/Zsh/compsys.yo	14 Apr 2010 09:44:23 -0000
@@ -1123,6 +1123,9 @@ When this style is true, any prefix of a
 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 
 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 cursorl; 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

-- 
Peter Stephenson <pws@csr.com>            Software Engineer
Tel: +44 (0)1223 692070                   Cambridge Silicon Radio Limited
Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, UK


Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom


  reply	other threads:[~2010-04-14  9:47 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-04-13 16:33 Matt Wright
2010-04-13 16:45 ` Peter Stephenson
2010-04-13 17:11   ` Matt Wright
2010-04-13 20:33   ` Matt Wright
2010-04-14  9:14     ` Peter Stephenson
2010-04-14  9:47       ` Peter Stephenson [this message]
2010-04-14 10:01         ` Peter Stephenson
2010-04-14 17:20           ` Matt Wright
2010-04-23 15:01         ` Matt Wright
2010-04-23 21:44           ` Peter Stephenson
2010-04-29 21:38             ` Peter Stephenson
2010-04-29 22:14               ` Matt Wright
2010-04-30  8:32                 ` Peter Stephenson
2010-04-30 16:05                   ` Matt Wright
2010-05-05  4:55                   ` Matt Wright
2010-05-05  9:58                     ` Peter Stephenson
2010-07-29 15:46                   ` Matt Wright
2010-08-03 12:59                     ` Peter Stephenson
2010-04-30 16:14               ` Bart Schaefer
2010-06-25 12:27 Yves Frederix

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=201004140947.o3E9llgG010201@news01.csr.com \
    --to=pws@csr.com \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).