zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@csr.com>
To: zsh-workers@sunsite.dk
Subject: Re: "pws non-canonical hack" problems
Date: Mon, 1 Sep 2008 18:14:25 +0100	[thread overview]
Message-ID: <20080901181425.48494272@news01> (raw)
In-Reply-To: <080825181954.ZM27367@torch.brasslantern.com>

On Mon, 25 Aug 2008 18:19:54 -0700
Bart Schaefer <schaefer@brasslantern.com> wrote:
> It's pretty difficult for me to test because I don't have a file
> system that behaves in this magical way.  But the answer, I think, is
> to skip the tmp1+= inside the loop and call compfiles again after the
> loop is finished.

I think this works for the simple case of automounted directories... at
least it triggered and generated the right completions after I eventually
found all the styles I needed to change to check it (accept-exact-dirs,
fake-files, completer).

Index: Completion/Unix/Type/_path_files
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Unix/Type/_path_files,v
retrieving revision 1.34
diff -u -r1.34 _path_files
--- Completion/Unix/Type/_path_files	30 Jul 2008 14:57:29 -0000	1.34
+++ Completion/Unix/Type/_path_files	1 Sep 2008 17:10:25 -0000
@@ -7,7 +7,8 @@
 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
+local listfiles listopts tmpdisp origtmp1
+integer npathcheck
 local -a match mbegin mend
 
 typeset -U prepaths exppaths
@@ -351,8 +352,11 @@
 
   tmp1=( "$prepath$realpath$donepath$tmp2" )
 
+  # count of attemps for pws non-canonical hack
+  (( npathcheck = 0 ))
   while true; do
 
+    origtmp1=("${tmp1[@]}")
     # Get the prefix and suffix for matching.
 
     if [[ "$tpre" = */* ]]; then
@@ -403,15 +407,26 @@
       # something to match by explicit name.  This is for
       # `clever' filing systems where names pop into existence
       # when referenced.
-      if (( ! $#tmp1 )); then
-	  for tmp3 in "$tmp2[@]"; do
-	      if [[ -n $tmp3 && $tmp3 != */ ]]; then
-		  tmp3+=/
-	      fi
-	      if [[ -e "$tmp3${(Q)PREFIX}${(Q)SUFFIX}" ]] then
-		  tmp1+=("$tmp3${(Q)PREFIX}${(Q)SUFFIX}")
-	      fi
-	  done
+      #
+      # As suggested by Bart, to make sure the "compfiles" checks
+      # still work we repeat the tests above if we successfully
+      # find something that might need adding, but we make sure
+      # we only do this once for completion of each path segment.
+      if (( ! $#tmp1 && npathcheck == 0 )); then
+	(( npathcheck = 1 ))
+	for tmp3 in "$tmp2[@]"; do
+	  if [[ -n $tmp3 && $tmp3 != */ ]]; then
+	    tmp3+=/
+	  fi
+	  if [[ -e "$tmp3${(Q)PREFIX}${(Q)SUFFIX}" ]] then
+	    (( npathcheck = 2 ))
+	  fi
+	done
+	if (( npathcheck == 2 )); then
+	  # repeat loop with same arguments
+	  tmp1=("$origtmp1[@]")
+	  continue
+	fi
       fi
 
       if (( ! $#tmp1 )); then
@@ -518,6 +533,7 @@
     else
       skipped=/
     fi
+    (( npathcheck = 0 ))
   done
 
   # The next loop searches the first ambiguous component.


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


      reply	other threads:[~2008-09-01 17:14 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-23  7:24 Alexey I. Froloff
2008-08-23 14:55 ` Bart Schaefer
2008-08-25 16:47   ` Peter Stephenson
2008-08-26  1:19     ` Bart Schaefer
2008-09-01 17:14       ` Peter Stephenson [this message]

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=20080901181425.48494272@news01 \
    --to=pws@csr.com \
    --cc=zsh-workers@sunsite.dk \
    /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).