>>>>> "Joe" == Joe Stoy <[EMAIL PROTECTED]> writes:
> But, listen, why am I looking at all these crazy directories anyway?
> After all, I've typed the first few characters of the name I'm trying
> to find: why can't we restrict the search to them? I've probably typed
> enough to cut the search down considerably, so sending a complete
> listing of a long directory, and then some of it again, seems a waste
> of bandwidth or something. Below is a suggestion of how it might be
> done -- I've gone back to using ls for the second listing (of the
> directories), since I think it may have been I who prompted you to do
> anything different in the first place, and the "permission denied"
> failure is annoying. I don't know whether there are any pathologies I
> haven't coped with.
You're right. Listing the whole thing and then filtering with
`all-completions' is not only wasteful but leads to the hanging-mounts
problems more often than necessary.
There are actually some obvious bugs in that code. I'm think
particularly of:
(format "find . -type d \\! -name . -prune -print 2>/dev/null"
(tramp-get-ls-command multi-method method user host)
(tramp-shell-quote-argument filename)))
There's no magic % sequence in the format string, so the
two arguments will be ignored.
> 2.
> Is there another problem with filename completion too? If I do it
> completely locally, for example with "tramp.", I can if I press TAB
> often enough, get it to offer me "tramp.el", "tramp.el~" and
> "tramp.elc". Doing it remotely, it tries to tell me that "tramp.el" is
> the "[sole completion]" (even though the other ones are there). It
> seems that the "hidden extensions" keep themselves too hidden.
I think filtering completion-ignored-extensions is a mistake indeed.
It should be (and most likely is) done in the function that call
file-name-all-completions.
> (tramp-send-command
> multi-method method user host
> (format "%s -ad %s* 2>/dev/null | cat"
> (tramp-get-ls-command multi-method method user host)
> filename))
Using shell-globbing is a problem since it can fail in really long
directories. I know that recent Unixen have a max-arg-length
much higher than what it used to be, but I'd rather not rely on it.
Also passing filename unquoted will not do the right thing.
How about
(format "%s -a 2>/dev/null | fgrep %s"
(tramp-get-ls-command multi-method method user host)
(tramp-shell-quote-argument filename))
It will match more than what we need (since fgrep does a `substring match'
rather than a `prefix match'), but the subsequent all-completions call
will filter out the few false-positives.
Sadly, the fgrep will fail if `filename' starts with a dash :-(
> ;; Now get a list of directories in a similar way.
> (tramp-send-command multi-method method user host
> (format "%s -d %s*/ 2>/dev/null | cat"
> (tramp-get-ls-command multi-method method user host)
> filename))
I don't think that the `permission denied' is a big issue.
I'd rather do something like
(format "find . -name %s\\* -type d \\! -name . -prune -print 2>/dev/null"
(tramp-shell-quote-argument
(replace-regexp-in-string "[[*?]" "\\\\\\&" filename)))
although I'm not sure that the requoting is done quite right.
(and replace-regexp-in-string is an Emacs-21'ism).
Stefan