unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* On DOS/Windows, unnecessary load of tramp by `file-relative-name'
@ 2003-04-24 10:54 David PONCE
  2003-04-24 14:12 ` Kai Großjohann
  2003-04-29 21:38 ` Stefan Monnier
  0 siblings, 2 replies; 6+ messages in thread
From: David PONCE @ 2003-04-24 10:54 UTC (permalink / raw)


Hi All,

Since the following change to files.el:

2003-03-29  Kai Großjohann  <kai.grossjohann@gmx.net>

        * files.el (file-relative-name): If FILENAME and DIRECTORY are
        on different drives (on DOS/Windows) or use different
        handlers, do like `expand-file-name' on FILENAME and return an
        absolute name.
        From Lars Hansen <larsh@math.ku.dk>.

I noticed that each time `file-relative-name' is called, tramp.el is
auto loaded, even if I don't access to remote files.

After some investigation, I found that `file-relative-name' put a
leading slash on file and directory names before comparing them to
find the relative name.  On DOS/Windows, when the name begins with a
drive letter, for example "c:/emacs", `file-relative-name' actually
use this form internally: "/c:/emacs".  Unfortunately that form
matches `tramp-file-name-regexp', which causes "tramp.el" to be loaded
when `file-relative-name' then calls `file-name-as-directory'.

To fix that, I propose the following patch to files.el:

Index: lisp/files.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/files.el,v
retrieving revision 1.653
diff -c -r1.653 files.el
*** lisp/files.el	24 Apr 2003 01:58:40 -0000	1.653
--- lisp/files.el	24 Apr 2003 09:45:22 -0000
***************
*** 2884,2899 ****
  							default-directory))))
      (setq filename (expand-file-name filename))
      (let ((hf (find-file-name-handler filename 'file-local-copy))
!           (hd (find-file-name-handler directory 'file-local-copy)))
        (when (and hf (not (get hf 'file-remote-p))) (setq hf nil))
        (when (and hd (not (get hd 'file-remote-p))) (setq hd nil))
        (if ;; Conditions for separate trees
  	  (or
  	   ;; Test for different drives on DOS/Windows
! 	   (and
! 	    (memq system-type '(ms-dos cygwin windows-nt))
! 	    (not (string-equal (substring filename  0 2)
! 			       (substring directory 0 2))))
  	   ;; Test for different remote file handlers
  	   (not (eq hf hd))
  	   ;; Test for different remote file system identification
--- 2884,2899 ----
  							default-directory))))
      (setq filename (expand-file-name filename))
      (let ((hf (find-file-name-handler filename 'file-local-copy))
!           (hd (find-file-name-handler directory 'file-local-copy))
!           (test-drive (memq system-type '(ms-dos cygwin windows-nt))))
        (when (and hf (not (get hf 'file-remote-p))) (setq hf nil))
        (when (and hd (not (get hd 'file-remote-p))) (setq hd nil))
        (if ;; Conditions for separate trees
  	  (or
  	   ;; Test for different drives on DOS/Windows
! 	   (and test-drive
!                 (not (string-equal (substring filename  0 2)
!                                    (substring directory 0 2))))
  	   ;; Test for different remote file handlers
  	   (not (eq hf hd))
  	   ;; Test for different remote file system identification
***************
*** 2909,2917 ****
  		 (string-match re directory)
  		 (substring directory 0 (match-end 0))))))))
  	  filename
!         (unless (eq (aref filename 0) ?/)
  	  (setq filename (concat "/" filename)))
!         (unless (eq (aref directory 0) ?/)
  	  (setq directory (concat "/" directory)))
          (let ((ancestor ".")
  	      (filename-dir (file-name-as-directory filename)))
--- 2909,2922 ----
  		 (string-match re directory)
  		 (substring directory 0 (match-end 0))))))))
  	  filename
!         ;; On DOS/Windows, don't prefix filename with / if it starts
!         ;; with a drive letter.  That prevents unecessary loading of
!         ;; "tramp", because "/C:" matches `tramp-file-name-regexp'!
!         (unless (or (eq (aref filename 0) ?/)
!                     (and test-drive (string-match "^[A-Za-z]:" filename)))
  	  (setq filename (concat "/" filename)))
!         (unless (or (eq (aref directory 0) ?/)
!                     (and test-drive (string-match "^[A-Za-z]:" directory)))
  	  (setq directory (concat "/" directory)))
          (let ((ancestor ".")
  	      (filename-dir (file-name-as-directory filename)))

Maybe is there a better way to fix that?
What do you think?

Sincerely,
David

In GNU Emacs 21.3.50.1 (i386-mingw-nt4.0.1381)
 of 2003-04-24 on EBAT311
configured using `configure --with-gcc (3.2)'

Important settings:
  value of $LC_ALL: nil
  value of $LC_COLLATE: nil
  value of $LC_CTYPE: nil
  value of $LC_MESSAGES: nil
  value of $LC_MONETARY: nil
  value of $LC_NUMERIC: nil
  value of $LC_TIME: nil
  value of $LANG: ENU
  locale-coding-system: iso-latin-1
  default-enable-multibyte-characters: t

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

* Re: On DOS/Windows, unnecessary load of tramp by `file-relative-name'
  2003-04-24 10:54 David PONCE
@ 2003-04-24 14:12 ` Kai Großjohann
  2003-04-29 21:38 ` Stefan Monnier
  1 sibling, 0 replies; 6+ messages in thread
From: Kai Großjohann @ 2003-04-24 14:12 UTC (permalink / raw)


David PONCE <david.ponce@wanadoo.fr> writes:

> !         (unless (eq (aref filename 0) ?/)
>   	  (setq filename (concat "/" filename)))

> Maybe is there a better way to fix that?
> What do you think?

Instead of using (eq (aref filename 0) ?/), how about using
(file-name-absolute-p filename)?  Does that work?

-- 
file-error; Data: (Opening input file no such file or directory ~/.signature)

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

* Re: On DOS/Windows, unnecessary load of tramp by `file-relative-name'
@ 2003-04-24 14:44 David PONCE
  2003-04-25 13:23 ` Kai Großjohann
  0 siblings, 1 reply; 6+ messages in thread
From: David PONCE @ 2003-04-24 14:44 UTC (permalink / raw)
  Cc: emacs-devel

Hi Kai,

> Instead of using (eq (aref filename 0) ?/), how about using
> (file-name-absolute-p filename)?  Does that work?

Yes that works!  And that is a better solution ;-)
Thanks!

Here is a new patch:

Index: lisp/files.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/files.el,v
retrieving revision 1.653
diff -c -r1.653 files.el
*** lisp/files.el	24 Apr 2003 01:58:40 -0000	1.653
--- lisp/files.el	24 Apr 2003 14:35:48 -0000
***************
*** 2909,2917 ****
  		 (string-match re directory)
  		 (substring directory 0 (match-end 0))))))))
  	  filename
!         (unless (eq (aref filename 0) ?/)
  	  (setq filename (concat "/" filename)))
!         (unless (eq (aref directory 0) ?/)
  	  (setq directory (concat "/" directory)))
          (let ((ancestor ".")
  	      (filename-dir (file-name-as-directory filename)))
--- 2909,2917 ----
  		 (string-match re directory)
  		 (substring directory 0 (match-end 0))))))))
  	  filename
!         (unless (file-name-absolute-p filename)
  	  (setq filename (concat "/" filename)))
!         (unless (file-name-absolute-p directory)
  	  (setq directory (concat "/" directory)))
          (let ((ancestor ".")
  	      (filename-dir (file-name-as-directory filename)))

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

* Re: On DOS/Windows, unnecessary load of tramp by `file-relative-name'
  2003-04-24 14:44 On DOS/Windows, unnecessary load of tramp by `file-relative-name' David PONCE
@ 2003-04-25 13:23 ` Kai Großjohann
  0 siblings, 0 replies; 6+ messages in thread
From: Kai Großjohann @ 2003-04-25 13:23 UTC (permalink / raw)


David PONCE <david.ponce@wanadoo.fr> writes:

> Here is a new patch:

Committing.  (I did it manually, I hope I didn't goof it up.)
-- 
file-error; Data: (Opening input file no such file or directory ~/.signature)

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

* Re: On DOS/Windows, unnecessary load of tramp by `file-relative-name'
  2003-04-24 10:54 David PONCE
  2003-04-24 14:12 ` Kai Großjohann
@ 2003-04-29 21:38 ` Stefan Monnier
  2003-04-30  8:21   ` Kai Großjohann
  1 sibling, 1 reply; 6+ messages in thread
From: Stefan Monnier @ 2003-04-29 21:38 UTC (permalink / raw)
  Cc: emacs-devel

> After some investigation, I found that `file-relative-name' put a
> leading slash on file and directory names before comparing them to
> find the relative name.  On DOS/Windows, when the name begins with a
> drive letter, for example "c:/emacs", `file-relative-name' actually
> use this form internally: "/c:/emacs".  Unfortunately that form
> matches `tramp-file-name-regexp', which causes "tramp.el" to be loaded
> when `file-relative-name' then calls `file-name-as-directory'.
[...]
> !    (unless (eq (aref filename 0) ?/)
>        (setq filename (concat "/" filename)))
> !    (unless (eq (aref directory 0) ?/)
>        (setq directory (concat "/" directory)))

Actually even after the change to file-name-absolute-p, the above
code looks bogus since both `filename' and `directory' have
passed through expand-file-name and should thus be absolute
already.

I suspect the four lines should purely and simply be removed.


	Stefan

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

* Re: On DOS/Windows, unnecessary load of tramp by `file-relative-name'
  2003-04-29 21:38 ` Stefan Monnier
@ 2003-04-30  8:21   ` Kai Großjohann
  0 siblings, 0 replies; 6+ messages in thread
From: Kai Großjohann @ 2003-04-30  8:21 UTC (permalink / raw)


"Stefan Monnier" <monnier+gnu/emacs@rum.cs.yale.edu> writes:

> I suspect the four lines should purely and simply be removed.

Indeed.

-- 
file-error; Data: (Opening input file no such file or directory ~/.signature)

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

end of thread, other threads:[~2003-04-30  8:21 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-04-24 14:44 On DOS/Windows, unnecessary load of tramp by `file-relative-name' David PONCE
2003-04-25 13:23 ` Kai Großjohann
  -- strict thread matches above, loose matches on Subject: below --
2003-04-24 10:54 David PONCE
2003-04-24 14:12 ` Kai Großjohann
2003-04-29 21:38 ` Stefan Monnier
2003-04-30  8:21   ` Kai Großjohann

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