emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: file-relative-name and remote files


From: Kai Großjohann
Subject: Re: file-relative-name and remote files
Date: Mon, 24 Mar 2003 12:43:29 +0100
User-agent: Gnus/5.090016 (Oort Gnus v0.16) Emacs/21.3.50 (gnu/linux)

Lars Hansen <address@hidden> writes:

> I suggest the following implementation of file-relative-name.
> It does not require a new file handler operation, it detects
> remote files in the same way as file-remote-p do. Please see
> the doc string for further explanation.

Richard has decided that ".." shall not be used to cross file handler
boundaries.  So file-relative-name needs to be changed to something
like Lars suggested.

I have some comments/questions about this implementation.

> (defun file-relative-name (filename &optional directory separate-trees)
>   "Convert FILENAME to be relative to DIRECTORY (default:
>   default-directory').
> This function returns a relative file name which is equivalent to FILENAME
> when used with that default directory as the default.
> If SEPARATE-TREES is non-nil and FILENAME and DIRECTORY lie on different
> machines or on different drives (DOS/Windows), it returns FILENAME on
> expanded form."

Why the extra arg SEPARATE-TREES?  If I understand Richard correctly,
he wants file-relative-name to always behave as if SEPARATE-TREES was
true.

(Of course, when this message was written, Richard's opinion was
unknown, so it's not your fault, Lars :-)

>   (save-match-data
>     (setq
>       directory
>       (file-name-as-directory (expand-file-name (or directory
>       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
>         (and
>           separate-trees
>           ;; 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
>             (and
>               hf
>               (let ((re (car (rassq hf file-name-handler-alist))))
>                 (not
>                   (equal
>                     (and
>                       (string-match re filename)
>                       (substring filename 0 (match-end 0)))
>                     (and
>                       (string-match re directory)
>                       (substring directory 0 (match-end 0)))))))))

I'm not sure it's a good idea to check this stuff here.  Maybe it
would be better to let each filename handler do that.

For example, Tramp has the concept of a default method, so
/address@hidden:/file and /ssh:address@hidden:/file denote the same file by
default, even though the strings are different.

It seems to me that it is better to let the handler decide.

Opinions?

-- 
A preposition is not a good thing to end a sentence with.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]