unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* CORRECT VERSION:  tramp (2.0.51); tramp and file-name-all-completions
@ 2005-10-15 22:04 Kim F. Storm
  2005-10-17  4:49 ` Michael Albinus
  0 siblings, 1 reply; 8+ messages in thread
From: Kim F. Storm @ 2005-10-15 22:04 UTC (permalink / raw)
  Cc: emacs-devel


PLEASE IGNORE MY PREVIOUS POST 
(Due to temporary brain power failure, I had swapped the args to
file-name-all-completions, so the reported ERROR/OK was swapped too).

THIS IS THE PROPER BUG REPORT.

I'm trying to make ido work sensibly with tramp syntax -- but
getting a grip on file-name-all-completions is really a nightmare.

Ido uses file-name-all-completions to get a list of all possible
completions of "the next component" to be entered by the user.

Now, consider these tramp file name:

     /method:user@host:/file
     /user@host:/file
     /host:/file

Ideally, ido would like to call file-name-all-completions like this:

         (file-name-all-completions "" "/method:")
         (file-name-all-completions "" "/method:user@")
         (file-name-all-completions "" "/method:user@host:")
         (file-name-all-completions "" "/method:user@host:/file")
                                       
         (file-name-all-completions "" "/user@")
         (file-name-all-completions "" "/user@host:")
                                       
         (file-name-all-completions "" "/host:")

However, this does not always work -- look at these examples:

========

(file-name-all-completions "" "/telnet:")
=> ERROR: "Login Failed"

Swapping the args works:

(file-name-all-completions "/telnet:" "")
=> OK

========

(file-name-all-completions "" "/telnet:kfs@")
=> ERROR: Login Failed

The desired result can be obtained with this call
(swap args, remove leading / of first arg, add / to second arg):

(file-name-all-completions "telnet:kfs@" "/")
=> OK

========

(file-name-all-completions "" "/telnet:kfs@localhost:")
=> OK

========

(file-name-all-completions "" "/telnet:kfs@localhost:/tmp")
=> OK

========

(file-name-all-completions "" "/kfs@")
=> (file-error "Opening directory" "no such file or directory" "/kfs@")

Swapping the args works:

(file-name-all-completions "/kfs@" "")
=> OK

========

(file-name-all-completions "" "/kfs@localhost:")
=> OK

========

(file-name-all-completions "" "/localhost:")
=> OK

========

I have made ido adapt to all these strange rules, but it is not very
nice -- and I have to know whether /xxx: is a method or a host, since:

(file-name-all-completions "" "/localhost:")
=> OK

(file-name-all-completions "" "/telnet:")
=> ERROR

(file-name-all-completions "/telnet:" "")
=> OK

Emacs  : GNU Emacs 22.0.50.54 (i686-pc-linux-gnu, X toolkit, Xaw3d scroll bars)
 of 2005-10-14 on kfs-l.imdomain.dk
Package: tramp (2.0.51)


--
Kim F. Storm <storm@cua.dk> http://www.cua.dk

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

* Re: CORRECT VERSION:  tramp (2.0.51); tramp and file-name-all-completions
  2005-10-15 22:04 CORRECT VERSION: tramp (2.0.51); tramp and file-name-all-completions Kim F. Storm
@ 2005-10-17  4:49 ` Michael Albinus
  2005-10-17 13:58   ` Kim F. Storm
  0 siblings, 1 reply; 8+ messages in thread
From: Michael Albinus @ 2005-10-17  4:49 UTC (permalink / raw)
  Cc: tramp-devel, emacs-devel

"Kim F. Storm" <storm@cua.dk> writes:

> I'm trying to make ido work sensibly with tramp syntax -- but
> getting a grip on file-name-all-completions is really a nightmare.

I've committed a new tramp.el into Emacs CVS, please try this. Note
that that I have set tramp-default-method to "ftp", therefore the
results are slightly different. And my telnetd is disabled by default;
I've used ssh therefore.

> ========
>
> (file-name-all-completions "" "/telnet:")
> => ERROR: "Login Failed"

(file-name-all-completions "" "/ssh:")

OK

> ========
>
> (file-name-all-completions "" "/telnet:kfs@")
> => ERROR: Login Failed

(file-name-all-completions "" "/ssh:albinus@")

OK

> ========
>
> (file-name-all-completions "" "/telnet:kfs@localhost:")
> => OK

(file-name-all-completions "" "/ssh:albinus@localhost:")

OK

> ========
>
> (file-name-all-completions "" "/telnet:kfs@localhost:/tmp")
> => OK

(file-name-all-completions "" "/ssh:albinus@localhost:/tmp")

OK

> ========
>
> (file-name-all-completions "" "/kfs@")
> => (file-error "Opening directory" "no such file or directory" "/kfs@")

(file-name-all-completions "" "/albinus@")

OK

> ========
>
> (file-name-all-completions "" "/kfs@localhost:")
> => OK

(file-name-all-completions "" "/albinus@localhost:")

This returns nil. Likely it is an ange-ftp behaviour. Nevertheless,
(file-name-all-completions "" "/albinus@localhost:./") returns the
desired values.

> ========
>
> (file-name-all-completions "" "/localhost:")
> => OK

(file-name-all-completions "" "/localhost:")

Also nil, which can be masqued by
(file-name-all-completions "" "/localhost:./")

Best regards, Michael.

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

* Re: CORRECT VERSION:  tramp (2.0.51); tramp and file-name-all-completions
  2005-10-17  4:49 ` Michael Albinus
@ 2005-10-17 13:58   ` Kim F. Storm
  2005-10-17 15:14     ` Michael Albinus
  0 siblings, 1 reply; 8+ messages in thread
From: Kim F. Storm @ 2005-10-17 13:58 UTC (permalink / raw)
  Cc: tramp-devel, emacs-devel

Michael Albinus <michael.albinus@gmx.de> writes:

> I've committed a new tramp.el into Emacs CVS, please try this. Note
> that that I have set tramp-default-method to "ftp", therefore the
> results are slightly different. And my telnetd is disabled by default;
> I've used ssh therefore.

Initial testing shows that it works much better than before.
Thanks!

>
> (file-name-all-completions "" "/albinus@localhost:")
> This returns nil. Likely it is an ange-ftp behaviour.

Seems like it, yes.  Works OK with telnet.

> (file-name-all-completions "" "/albinus@localhost:./") returns the
> desired values.
> (file-name-all-completions "" "/localhost:./")

Thanks for the tips.

I used it in ido, and it seems to work:

	       ;; work around bug in ange-ftp.
	       ;; /ftp:user@host: => nil
	       ;; /ftp:user@host:./ => ok
	       (and
	        (not (string= "/ftp:" dir))
		(or
		 (string-match "\\`/ftp:.*:\\'" dir)
		 (and (string= tramp-default-method "ftp")
		      (string-match "\\`/[^/:]+:\\'" dir)))
		(file-name-all-completions "" (concat dir "./"))))))



There are still a small problem (I have worked around them in ido,
so a fix is not urgent.)

E.g. if I try

(file-directory-p "/telnet:kfs@")
 or
(file-directory-p "/telnet:kfs@:")

tramp signals "Login failure" in both cases.  

Similar things happens for expand-file-name.


Here is a backtrace:

Debugger entered--Lisp error: (error "Login failed")
  signal(error ("Login failed"))
  error("Login failed")
  tramp-process-actions(#<process *tramp/ssh telnet*> nil nil nil "telnet" ((tramp-password-prompt-regexp tramp-action-password) (tramp-login-prompt-regexp tramp-action-login) (shell-prompt-pattern tramp-action-succeed) (tramp-shell-prompt-pattern tramp-action-succeed) (tramp-wrong-passwd-regexp tramp-action-permission-denied) (tramp-yesno-prompt-regexp tramp-action-yesno) (tramp-yn-prompt-regexp tramp-action-yn) (tramp-terminal-prompt-regexp tramp-action-terminal) (tramp-process-alive-regexp tramp-action-process-alive)))
  tramp-open-connection-rsh(nil nil nil "telnet")
  tramp-maybe-open-connection(nil nil nil "telnet")
  tramp-send-command(nil nil nil "telnet" "cd ~; pwd" t)
  tramp-handle-expand-file-name("/telnet:kfs@" "/home/kfs/fsf/latest/")
  apply(tramp-handle-expand-file-name ("/telnet:kfs@" "/home/kfs/fsf/latest/"))
  tramp-sh-file-name-handler(expand-file-name "/telnet:kfs@" "/home/kfs/fsf/latest/")
  apply(tramp-sh-file-name-handler expand-file-name ("/telnet:kfs@" "/home/kfs/fsf/latest/"))
  tramp-file-name-handler(expand-file-name "/telnet:kfs@" "/home/kfs/fsf/latest/")
  expand-file-name("/telnet:kfs@" "/home/kfs/fsf/latest/")
  apply(expand-file-name ("/telnet:kfs@" "/home/kfs/fsf/latest/"))
  tramp-completion-run-real-handler(expand-file-name ("/telnet:kfs@" "/home/kfs/fsf/latest/"))
  tramp-completion-handle-expand-file-name("/telnet:kfs@" "/home/kfs/fsf/latest/")
  apply(tramp-completion-handle-expand-file-name ("/telnet:kfs@" "/home/kfs/fsf/latest/"))
  tramp-completion-file-name-handler(expand-file-name "/telnet:kfs@" "/home/kfs/fsf/latest/")
  file-directory-p("/telnet:kfs@")
  eval((file-directory-p "/telnet:kfs@"))
  eval-last-sexp-1(nil)
  eval-last-sexp(nil)
  call-interactively(eval-last-sexp)


-- 
Kim F. Storm <storm@cua.dk> http://www.cua.dk

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

* Re: CORRECT VERSION:  tramp (2.0.51); tramp and file-name-all-completions
  2005-10-17 13:58   ` Kim F. Storm
@ 2005-10-17 15:14     ` Michael Albinus
  2005-10-17 17:46       ` Stefan Monnier
  2005-10-17 23:05       ` Kim F. Storm
  0 siblings, 2 replies; 8+ messages in thread
From: Michael Albinus @ 2005-10-17 15:14 UTC (permalink / raw)
  Cc: tramp-devel, emacs-devel

storm@cua.dk (Kim F. Storm) writes:

> I used it in ido, and it seems to work:
>
> 	       ;; work around bug in ange-ftp.
> 	       ;; /ftp:user@host: => nil
> 	       ;; /ftp:user@host:./ => ok
> 	       (and
> 	        (not (string= "/ftp:" dir))
> 		(or
> 		 (string-match "\\`/ftp:.*:\\'" dir)
> 		 (and (string= tramp-default-method "ftp")
> 		      (string-match "\\`/[^/:]+:\\'" dir)))
> 		(file-name-all-completions "" (concat dir "./"))))))

This works for Tramp 2.0. It will work for Tramp 2.1 too, but there
are also other means to derive a default methold. For the time being
you might use a comment for this.

> There are still a small problem (I have worked around them in ido,
> so a fix is not urgent.)
>
> E.g. if I try
>
> (file-directory-p "/telnet:kfs@")
>  or
> (file-directory-p "/telnet:kfs@:")
>
> tramp signals "Login failure" in both cases.  

I know. This problem has eaten most of the time yesterday. In fact I
don't know a safe decision whether a file name shall be completed only
or "applied". Therefore I've introduced a new variable
tramp-completion-mode, which is set in
file-name-all-completions. Sensible Tramp file name functions, which
need to behave depending on the mode, check this variable (beside
other checks). So you might use it as well (untested, I'm @work):

(let ((tramp-completion-mode t))
  (file-directory-p "/telnet:kfs@"))

Best regards, Michael.

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

* Re: CORRECT VERSION:  tramp (2.0.51); tramp and file-name-all-completions
  2005-10-17 15:14     ` Michael Albinus
@ 2005-10-17 17:46       ` Stefan Monnier
  2005-10-18  8:51         ` Michael Albinus
  2005-10-17 23:05       ` Kim F. Storm
  1 sibling, 1 reply; 8+ messages in thread
From: Stefan Monnier @ 2005-10-17 17:46 UTC (permalink / raw)
  Cc: tramp-devel, emacs-devel, Kim F. Storm

> or "applied". Therefore I've introduced a new variable
> tramp-completion-mode, which is set in
> file-name-all-completions.

The name "tramp-completion-mode" doesn't say what the variable does.
Could you find a better name?  I'm not sure I understand what it does so
I'm not sure what other name to propose.
Could it be something like "tramp-ignore-errors"?


        Stefan

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

* Re: CORRECT VERSION:  tramp (2.0.51); tramp and file-name-all-completions
  2005-10-17 15:14     ` Michael Albinus
  2005-10-17 17:46       ` Stefan Monnier
@ 2005-10-17 23:05       ` Kim F. Storm
  2005-10-18  8:47         ` Michael Albinus
  1 sibling, 1 reply; 8+ messages in thread
From: Kim F. Storm @ 2005-10-17 23:05 UTC (permalink / raw)
  Cc: tramp-devel, emacs-devel

Michael Albinus <michael.albinus@gmx.de> writes:

> storm@cua.dk (Kim F. Storm) writes:
>
>> I used it in ido, and it seems to work:
>>
>> 	       ;; work around bug in ange-ftp.
>> 	       ;; /ftp:user@host: => nil
>> 	       ;; /ftp:user@host:./ => ok
>> 	       (and
>> 	        (not (string= "/ftp:" dir))
>> 		(or
>> 		 (string-match "\\`/ftp:.*:\\'" dir)
>> 		 (and (string= tramp-default-method "ftp")
>> 		      (string-match "\\`/[^/:]+:\\'" dir)))
>> 		(file-name-all-completions "" (concat dir "./"))))))
>
> This works for Tramp 2.0. It will work for Tramp 2.1 too, but there
> are also other means to derive a default methold. For the time being
> you might use a comment for this.

What code will I need to be 2.1 compatible?

>>
>> (file-directory-p "/telnet:kfs@")
>>  or
>> (file-directory-p "/telnet:kfs@:")
>>
>> tramp signals "Login failure" in both cases.  
>
> I know. This problem has eaten most of the time yesterday. In fact I
> don't know a safe decision whether a file name shall be completed only
> or "applied". Therefore I've introduced a new variable
> tramp-completion-mode, which is set in
> file-name-all-completions. Sensible Tramp file name functions, which
> need to behave depending on the mode, check this variable (beside
> other checks). So you might use it as well (untested, I'm @work):
>
> (let ((tramp-completion-mode t))
>   (file-directory-p "/telnet:kfs@"))

This still cause the "Login Failed" error...

In any case, I don't quite understand how to use this.  How can ido
know whether it makes sense to set tramp-completion-mode or not?

I have this function in ido to identify filename which may be handled
by a tramp file name handler.  Is there a better way?

(defun ido-is-tramp-root (&optional dir)
  (and ido-enable-tramp-completion
       (string-match "\\`/[^/]+[@:]\\'"
		     (or dir ido-current-directory))))


My best solution is to try to eliminate such calls.

-- 
Kim F. Storm <storm@cua.dk> http://www.cua.dk

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

* Re: CORRECT VERSION:  tramp (2.0.51); tramp and file-name-all-completions
  2005-10-17 23:05       ` Kim F. Storm
@ 2005-10-18  8:47         ` Michael Albinus
  0 siblings, 0 replies; 8+ messages in thread
From: Michael Albinus @ 2005-10-18  8:47 UTC (permalink / raw)
  Cc: tramp-devel, emacs-devel

storm@cua.dk (Kim F. Storm) writes:

>>> I used it in ido, and it seems to work:
>>>
>>> 	       ;; work around bug in ange-ftp.
>>> 	       ;; /ftp:user@host: => nil
>>> 	       ;; /ftp:user@host:./ => ok
>>> 	       (and
>>> 	        (not (string= "/ftp:" dir))
>>> 		(or
>>> 		 (string-match "\\`/ftp:.*:\\'" dir)
>>> 		 (and (string= tramp-default-method "ftp")
>>> 		      (string-match "\\`/[^/:]+:\\'" dir)))
>>> 		(file-name-all-completions "" (concat dir "./"))))))
>>
>> This works for Tramp 2.0. It will work for Tramp 2.1 too, but there
>> are also other means to derive a default methold. For the time being
>> you might use a comment for this.
>
> What code will I need to be 2.1 compatible?

Tramp uses internally `tramp-ftp-file-name-p' for ange-ftp and
`tramp-efs-file-name-p' for efs. Both functions expect a proper Tramp
file name syntax; you should check it before. Something like this:

;; work around bug in ange-ftp.
;; /ftp:user@host: => nil
;; /ftp:user@host:./ => ok
(and
 (tramp-tramp-file-p dir)
 (fboundp 'tramp-ftp-file-name-p dir)
 (funcall 'tramp-ftp-file-name-p dir)
 (string-match ":\\'" dir)
 (file-name-all-completions "" (concat dir "./")))

This should work for both Tramp 2.0 and 2.1; there are no plans to
change the interface.

>>> (file-directory-p "/telnet:kfs@")
>>>  or
>>> (file-directory-p "/telnet:kfs@:")
>>>
>>> tramp signals "Login failure" in both cases.  
>>
>> I know. This problem has eaten most of the time yesterday. In fact I
>> don't know a safe decision whether a file name shall be completed only
>> or "applied". Therefore I've introduced a new variable
>> tramp-completion-mode, which is set in
>> file-name-all-completions. Sensible Tramp file name functions, which
>> need to behave depending on the mode, check this variable (beside
>> other checks). So you might use it as well (untested, I'm @work):
>>
>> (let ((tramp-completion-mode t))
>>   (file-directory-p "/telnet:kfs@"))
>
> This still cause the "Login Failed" error...
>
> In any case, I don't quite understand how to use this.  How can ido
> know whether it makes sense to set tramp-completion-mode or not?

It cannot, because my proposal was nonsense.

The problem is that `file-directory-p' can give only an answer when it
accesses the remote host. If it is urged to just reply nil under
special circumstances, it is not worth to be called.

When you're doing file name completion, the file name is not complete,
and calling `file-directory-p' would try to access a host which does
not exist.

What we could do is to introduce an option saying "access this host
only if there is already a connection". This would avoid the "Login
Failed" error you've mentioned.

The question is what `file-directory-p' should return in case there
isn't a connection yet: nil, or a dont-know value as Richard did
suggest?

Best regards, Michael.

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

* Re: CORRECT VERSION:  tramp (2.0.51); tramp and file-name-all-completions
  2005-10-17 17:46       ` Stefan Monnier
@ 2005-10-18  8:51         ` Michael Albinus
  0 siblings, 0 replies; 8+ messages in thread
From: Michael Albinus @ 2005-10-18  8:51 UTC (permalink / raw)
  Cc: tramp-devel, emacs-devel, Kim F. Storm

Stefan Monnier <monnier@iro.umontreal.ca> writes:

> The name "tramp-completion-mode" doesn't say what the variable does.
> Could you find a better name?  I'm not sure I understand what it does so
> I'm not sure what other name to propose.

You're right; -mode has a predefined meaning already. I'll try to find
another name.

> Could it be something like "tramp-ignore-errors"?

No, because you still have the side effect accessing a wrong host and
being asked for a password etc. See my other message for discussion.

>         Stefan

Best regards, Michael.

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

end of thread, other threads:[~2005-10-18  8:51 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-10-15 22:04 CORRECT VERSION: tramp (2.0.51); tramp and file-name-all-completions Kim F. Storm
2005-10-17  4:49 ` Michael Albinus
2005-10-17 13:58   ` Kim F. Storm
2005-10-17 15:14     ` Michael Albinus
2005-10-17 17:46       ` Stefan Monnier
2005-10-18  8:51         ` Michael Albinus
2005-10-17 23:05       ` Kim F. Storm
2005-10-18  8:47         ` Michael Albinus

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).