zsh-workers
 help / color / mirror / code / Atom feed
* "pws non-canonical hack" problems
@ 2008-08-23  7:24 Alexey I. Froloff
  2008-08-23 14:55 ` Bart Schaefer
  0 siblings, 1 reply; 5+ messages in thread
From: Alexey I. Froloff @ 2008-08-23  7:24 UTC (permalink / raw)
  To: zsh-workers

[-- Attachment #1: Type: text/plain, Size: 1318 bytes --]

I am having problems with "pws non-caninical hack" in
_path_files.  Let me explain with screenshot:

_path_files:
377       # pws non-canonical hack which seems to work so far...
378       # if we didn't match by globbing, check that there is
379       # something to match by explicit name.  This is for
380       # `clever' filing systems where names pop into existence
381       # when referenced.
382       if (( ! $#tmp1 )); then
383           for tmp3 in "$tmp2[@]"; do
384               if [[ -n $tmp3 && $tmp3 != */ ]]; then
385                   tmp3+=/
386               fi
387               if [[ -e "$tmp3${(Q)PREFIX}${(Q)SUFFIX}" ]] then
388                   tmp1+=("$tmp3${(Q)PREFIX}${(Q)SUFFIX}")
389               fi
390           done
391       fi

When I completing directory, sometimes file is being completed.

$ touch foo foobar
$ cd fo<Tab>
Sorry. No match for: `local directory'
$ cd foo<Tab>
$ cd foo (file name is completed)
$ touch foo<Tab>
---- file ----
foo     foobar
$ zstyle ':completion:*' list-dirs-first true
$ touch foo<Tab>
---- directories ----
foo
---- file ----
foo     foobar

I think I can forge more examples where this code will fail.  Can
it be controlled via zstyle, please, so anyone can turn this off?

-- 
Regards,
Sir Raorn.

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: "pws non-canonical hack" problems
  2008-08-23  7:24 "pws non-canonical hack" problems Alexey I. Froloff
@ 2008-08-23 14:55 ` Bart Schaefer
  2008-08-25 16:47   ` Peter Stephenson
  0 siblings, 1 reply; 5+ messages in thread
From: Bart Schaefer @ 2008-08-23 14:55 UTC (permalink / raw)
  To: zsh-workers

On Aug 23, 11:24am, Alexey I. Froloff wrote:
}
} _path_files:
} 377       # pws non-canonical hack which seems to work so far...
} 378       # if we didn't match by globbing, check that there is
} 379       # something to match by explicit name.  This is for
} 380       # `clever' filing systems where names pop into existence
} 381       # when referenced.
} 382       if (( ! $#tmp1 )); then
} 383           for tmp3 in "$tmp2[@]"; do
} 384               if [[ -n $tmp3 && $tmp3 != */ ]]; then
} 385                   tmp3+=/
} 386               fi
} 387               if [[ -e "$tmp3${(Q)PREFIX}${(Q)SUFFIX}" ]] then
} 388                   tmp1+=("$tmp3${(Q)PREFIX}${(Q)SUFFIX}")
} 389               fi
} 390           done
} 391       fi
} 
} When I completing directory, sometimes file is being completed.

The problem is that this code should not unconditionally append something
to tmp1.  It has to test again (probably by using some variant of the call
to compfiles that appears 20 or so lines above) that some new file really
was created that matches the qualifiers in the generated glob pattern.

Really this whole idea of attempting to complete things that don't exist
yet puts a huge amount of overhead on the cases where nothing ever will.

-- 


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: "pws non-canonical hack" problems
  2008-08-23 14:55 ` Bart Schaefer
@ 2008-08-25 16:47   ` Peter Stephenson
  2008-08-26  1:19     ` Bart Schaefer
  0 siblings, 1 reply; 5+ messages in thread
From: Peter Stephenson @ 2008-08-25 16:47 UTC (permalink / raw)
  To: zsh-workers

On Sat, 23 Aug 2008 07:55:49 -0700
Bart Schaefer <schaefer@brasslantern.com> wrote:
> On Aug 23, 11:24am, Alexey I. Froloff wrote:
> }
> } _path_files:
> } 377       # pws non-canonical hack which seems to work so far...
> } 378       # if we didn't match by globbing, check that there is
> } 379       # something to match by explicit name.  This is for
> } 380       # `clever' filing systems where names pop into existence
> } 381       # when referenced.
> } 382       if (( ! $#tmp1 )); then
> } 383           for tmp3 in "$tmp2[@]"; do
> } 384               if [[ -n $tmp3 && $tmp3 != */ ]]; then
> } 385                   tmp3+=/
> } 386               fi
> } 387               if [[ -e "$tmp3${(Q)PREFIX}${(Q)SUFFIX}" ]] then
> } 388                   tmp1+=("$tmp3${(Q)PREFIX}${(Q)SUFFIX}")
> } 389               fi
> } 390           done
> } 391       fi
> } 
> } When I completing directory, sometimes file is being completed.
> 
> The problem is that this code should not unconditionally append something
> to tmp1.  It has to test again (probably by using some variant of the call
> to compfiles that appears 20 or so lines above) that some new file really
> was created that matches the qualifiers in the generated glob pattern.

Er, isn't that what the -e test does?  What I think you mean is there
may be options to compfiles that don't get taken account of at this point.

Unfortunately, the file completion code was never very intelligible and
there are way too many cases.  If anyone can come up with a way of
limiting this test in the right way, great.

-- 
Peter Stephenson <p.w.stephenson@ntlworld.com>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: "pws non-canonical hack" problems
  2008-08-25 16:47   ` Peter Stephenson
@ 2008-08-26  1:19     ` Bart Schaefer
  2008-09-01 17:14       ` Peter Stephenson
  0 siblings, 1 reply; 5+ messages in thread
From: Bart Schaefer @ 2008-08-26  1:19 UTC (permalink / raw)
  To: zsh-workers

On Aug 25,  5:47pm, Peter Stephenson wrote:
}
} On Sat, 23 Aug 2008 07:55:49 -0700
} > }
} > } _path_files:
} > } 387               if [[ -e "$tmp3${(Q)PREFIX}${(Q)SUFFIX}" ]] then
} > } 388                   tmp1+=("$tmp3${(Q)PREFIX}${(Q)SUFFIX}")
} > } 389               fi
} > } 
} > } When I completing directory, sometimes file is being completed.
} > 
} > The problem is that this code should not unconditionally append
} > something to tmp1. It has to test again (probably by using some
} > variant of the call to compfiles that appears 20 or so lines above)
} > that some new file really was created that matches the qualifiers in
} > the generated glob pattern.
} 
} Er, isn't that what the -e test does?  What I think you mean is there
} may be options to compfiles that don't get taken account of at this point.

I guess that's what I mean.  The -e test is not sufficient; compfiles
may have left tmp1 empty because "$tmp3${(Q)PREFIX}${(Q)SUFFIX}" names
a file that exists but is not a directory.  The -e test only confirms
that the name exists after attempting to access it, not that (a) that
name did not exist before and (b) it names the right type of object.
 
} Unfortunately, the file completion code was never very intelligible
} and there are way too many cases. If anyone can come up with a way of
} limiting this test in the right way, great.

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.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: "pws non-canonical hack" problems
  2008-08-26  1:19     ` Bart Schaefer
@ 2008-09-01 17:14       ` Peter Stephenson
  0 siblings, 0 replies; 5+ messages in thread
From: Peter Stephenson @ 2008-09-01 17:14 UTC (permalink / raw)
  To: zsh-workers

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2008-09-01 17:14 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-08-23  7:24 "pws non-canonical hack" problems 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

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).