From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: kai.grossjohann@uni-duisburg.de (Kai =?iso-8859-1?q?Gro=DFjohann?=) Newsgroups: gmane.emacs.devel Subject: Re: file-relative-name and remote files Date: Mon, 24 Mar 2003 12:43:29 +0100 Organization: University of Duisburg, Germany Sender: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Message-ID: <8465q93s7y.fsf@lucy.is.informatik.uni-duisburg.de> References: <3E5E6F20.6030905@math.ku.dk> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: main.gmane.org 1048506648 11601 80.91.224.249 (24 Mar 2003 11:50:48 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Mon, 24 Mar 2003 11:50:48 +0000 (UTC) Original-X-From: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Mon Mar 24 12:50:45 2003 Return-path: Original-Received: from quimby.gnus.org ([80.91.224.244]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 18xQSw-0002yX-00 for ; Mon, 24 Mar 2003 12:50:10 +0100 Original-Received: from monty-python.gnu.org ([199.232.76.173]) by quimby.gnus.org with esmtp (Exim 3.12 #1 (Debian)) id 18xQTN-0007gS-00 for ; Mon, 24 Mar 2003 12:50:38 +0100 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.10.13) id 18xQS5-0005j0-01 for emacs-devel@quimby.gnus.org; Mon, 24 Mar 2003 06:49:17 -0500 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.10.13) id 18xQQk-0004aI-00 for emacs-devel@gnu.org; Mon, 24 Mar 2003 06:47:54 -0500 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.10.13) id 18xQNP-0002zM-00 for emacs-devel@gnu.org; Mon, 24 Mar 2003 06:44:29 -0500 Original-Received: from main.gmane.org ([80.91.224.249]) by monty-python.gnu.org with esmtp (Exim 4.10.13) id 18xQMw-0002IJ-00 for emacs-devel@gnu.org; Mon, 24 Mar 2003 06:43:59 -0500 Original-Received: from list by main.gmane.org with local (Exim 3.35 #1 (Debian)) id 18xQMp-0002aL-00 for ; Mon, 24 Mar 2003 12:43:51 +0100 X-Injected-Via-Gmane: http://gmane.org/ Original-To: emacs-devel@gnu.org Original-Received: from news by main.gmane.org with local (Exim 3.35 #1 (Debian)) id 18xQMo-0002aB-00 for ; Mon, 24 Mar 2003 12:43:50 +0100 Original-Lines: 77 Original-X-Complaints-To: usenet@main.gmane.org User-Agent: Gnus/5.090016 (Oort Gnus v0.16) Emacs/21.3.50 (gnu/linux) Cancel-Lock: sha1:MT3flWj+6fXT0oWtQskxcXE8KVk= X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1b5 Precedence: list List-Id: Emacs development discussions. List-Help: List-Post: List-Subscribe: , List-Archive: List-Unsubscribe: , Errors-To: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Xref: main.gmane.org gmane.emacs.devel:12562 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:12562 Lars Hansen 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 /user@host:/file and /ssh:user@host:/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.