From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: MON KEY Newsgroups: gmane.emacs.bugs Subject: bug#4819: file-truename's undocumented behavior Date: Wed, 28 Oct 2009 16:01:32 -0400 Message-ID: References: Reply-To: MON KEY , 4819@emacsbugs.donarmstrong.com NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary=000e0cd5c6c0df2f8a04770442ad X-Trace: ger.gmane.org 1256761769 28253 80.91.229.12 (28 Oct 2009 20:29:29 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 28 Oct 2009 20:29:29 +0000 (UTC) Cc: 4819@emacsbugs.donarmstrong.com, bug-gnu-emacs@gnu.org To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Oct 28 21:29:22 2009 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1N3F8r-0008Aw-Bc for geb-bug-gnu-emacs@m.gmane.org; Wed, 28 Oct 2009 21:29:20 +0100 Original-Received: from localhost ([127.0.0.1]:56845 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N3F8q-0008Sy-Qw for geb-bug-gnu-emacs@m.gmane.org; Wed, 28 Oct 2009 16:29:12 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1N3F75-0006MH-8Q for bug-gnu-emacs@gnu.org; Wed, 28 Oct 2009 16:27:23 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1N3F70-0006H0-Ej for bug-gnu-emacs@gnu.org; Wed, 28 Oct 2009 16:27:22 -0400 Original-Received: from [199.232.76.173] (port=53076 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N3F70-0006GM-5R for bug-gnu-emacs@gnu.org; Wed, 28 Oct 2009 16:27:18 -0400 Original-Received: from rzlab.ucr.edu ([138.23.92.77]:49769) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1N3F6z-00082E-7w for bug-gnu-emacs@gnu.org; Wed, 28 Oct 2009 16:27:17 -0400 Original-Received: from rzlab.ucr.edu (rzlab.ucr.edu [127.0.0.1]) by rzlab.ucr.edu (8.14.3/8.14.3/Debian-5) with ESMTP id n9SKREpl020013; Wed, 28 Oct 2009 13:27:14 -0700 Original-Received: (from debbugs@localhost) by rzlab.ucr.edu (8.14.3/8.14.3/Submit) id n9SKA77P018532; Wed, 28 Oct 2009 13:10:07 -0700 Resent-Date: Wed, 28 Oct 2009 13:10:07 -0700 X-Loop: owner@emacsbugs.donarmstrong.com Resent-From: MON KEY Original-Sender: stan@derbycityprints.com Resent-To: bug-submit-list@donarmstrong.com Resent-CC: Emacs Bugs 2Resent-Date: Wed, 28 Oct 2009 20:10:06 +0000 Resent-Message-ID: Resent-Sender: owner@emacsbugs.donarmstrong.com X-Emacs-PR-Message: followup 4819 X-Emacs-PR-Package: emacs X-Emacs-PR-Keywords: Original-Received: via spool by 4819-submit@emacsbugs.donarmstrong.com id=B4819.125676009917258 (code B ref 4819); Wed, 28 Oct 2009 20:10:06 +0000 Original-Received: (at 4819) by emacsbugs.donarmstrong.com; 28 Oct 2009 20:01:39 +0000 X-Spam-Bayes: score:0.5 Bayes not run. spammytokens:Tokens not available. hammytokens:Tokens not available. Original-Received: from mail-yw0-f179.google.com (mail-yw0-f179.google.com [209.85.211.179]) by rzlab.ucr.edu (8.14.3/8.14.3/Debian-5) with ESMTP id n9SK1bVY017255 for <4819@emacsbugs.donarmstrong.com>; Wed, 28 Oct 2009 13:01:39 -0700 Original-Received: by ywh9 with SMTP id 9so1026783ywh.19 for <4819@emacsbugs.donarmstrong.com>; Wed, 28 Oct 2009 13:01:32 -0700 (PDT) Original-Received: by 10.150.171.17 with SMTP id t17mr8690819ybe.303.1256760092335; Wed, 28 Oct 2009 13:01:32 -0700 (PDT) In-Reply-To: X-Google-Sender-Auth: 28579b3c0fb5da9f X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 2) Resent-Date: Wed, 28 Oct 2009 16:27:22 -0400 X-BeenThere: bug-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:32265 Archived-At: --000e0cd5c6c0df2f8a04770442ad Content-Type: text/plain; charset=UTF-8 On Tue, Oct 27, 2009 at 9:52 PM, Stefan Monnier wrote: >> This form returns a value. >> (file-truename "") > >> WHY? > > Why not? What value did you expect? I assumed nil. I'm not sure what I would expect esp. having since noted that: (file-relative-name "") ;=> "." (file-exists-p "") ;=> t (file-readable-p "") ;=> t (file-directory-p "") ;=> t (file-name-as-directory "") ;=> "./" However, discarding the state of my "least surprisedness", I would _not_ expect that file-truename would step all over the match-data, and where it does so not before first: a) Using string-match-p where applicable; b) Noting that it does so in the documention. i.e. as per `split-string'. > >> I just spent 2 1/2 hours in a break-loop three functions away trying >> to debug _undocumented_ behavior. > > Which part of the documentation do you think this behavior contradicts? > This part: (file-name-absolute-p "") ;=> nil (file-symlink-p "") ;=> nil On which systems/platforms does "" denote an absolute filename? On which systems/platforms does "" denote a symbolic link for a filename? ,---- (documentation 'file-truename) | Return the truename of filename, which should be absolute. | The truename of a file name is found by chasing symbolic links | both at the level of the file and at the level of the directories | containing it, until no links are left at any level. `---- And, this other part where documentation: a) Neglects to mention that this function invokes repeatedly invokes `string-match' twice per invokation. {...} (unless (string-match "[[*?]" filename) (string-match "~[^/]*/?" filename)) {...} {...} ((and (string= (substring filename 0 1) "~") (string-match "~[^/]*/?" filename)) {...} b) Neglects to mention that the remaining args COUNTER and PREV-DIRS are iterative counters for operations on recursive calls. Which means that where file-truename recurses `string-match' may be invoked more than twice times. ,---- Comments in the definition of `file-truename' in files.el |;; Don't document the optional arguments. |;; COUNTER and PREV-DIRS are only used in recursive calls. |;; COUNTER can be a cons cell whose car is the count of how many |;; more links to chase before getting an error. |;; PREV-DIRS can be a cons cell whose car is an alist |;; of truenames we've just recently computed. `---- It was only as a late afterthought that I realized that it wasn't _MY-CODE+ clobbering the match-data - as is usual : ) but maybe Emacs'. The realization was elusive because the recursion only happens when the w32 conditional which drops into a recursion predicated on the return value of `w32-long-file-name'. {...} (setq filename (concat (file-truename rest) missing)) {...} Why not mention in the docs that on w32 `w32-long-file-name' may be a more suitable alternative esp. as it is a primitive and as it will expand "8.3 DOS" short name aliases in the process. (Again, per _existing_ comments in body of `file-truename's definition). I understand _why_ the optional args have been left undocumented - they are essentially hacks which the user shouldn't rely on. However, I don't understand _why_ the w32 hack isn't made known esp. where the hack is applicable for user code and is indicated as the preferred solution... W/re the string-match vs. string-matchp doesn't the following accomplish the same: ;;; ============================== *** /files.el-p 2009-10-28 15:49:38.843750000 -0400 --- /emacs/lisp/files.el 2009-06-30 15:51:22.000000000 -0400 *************** *** 893,904 **** (setq filename (expand-file-name filename)) (if (string= filename "") (setq filename "/"))) ! ((and (string= (substring filename 0 1) "~") ! (string-match-p "~[^/]*/?" filename)) ! (string-match "~[^/]*/?" filename) ! (let ((first-part ! (substring filename 0 (match-end 0))) ! (rest (substring filename (match-end 0)))) (setq filename (concat (expand-file-name first-part) rest))))) (or counter (setq counter (list 100))) --- 893,903 ---- (setq filename (expand-file-name filename)) (if (string= filename "") (setq filename "/"))) ! ((and (string= (substring filename 0 1) "~") ! (string-match "~[^/]*/?" filename)) ! (let ((first-part ! (substring filename 0 (match-end 0))) ! (rest (substring filename (match-end 0)))) (setq filename (concat (expand-file-name first-part) rest))))) (or counter (setq counter (list 100))) *************** *** 930,936 **** (if handler (setq filename (funcall handler 'file-truename filename)) ;; If filename contains a wildcard, newname will be the old name. ! (unless (string-match-p "[[*?]" filename) ;; If filename exists, use the long name. If it doesn't exist, ;; drill down until we find a directory that exists, and use ;; the long name of that, with the extra non-existent path --- 929,935 ---- (if handler (setq filename (funcall handler 'file-truename filename)) ;; If filename contains a wildcard, newname will be the old name. ! (unless (string-match "[[*?]" filename) ;; If filename exists, use the long name. If it doesn't exist, ;; drill down until we find a directory that exists, and use ;; the long name of that, with the extra non-existent path --000e0cd5c6c0df2f8a04770442ad Content-Type: application/octet-stream; name="diff.files.el" Content-Disposition: attachment; filename="diff.files.el" Content-Transfer-Encoding: base64 X-Attachment-Id: f_g1ciforc0 KioqIC9maWxlcy5lbC1wIDIwMDktMTAtMjggMTU6NDk6MzguODQzNzUwMDAwIC0wNDAwCi0tLSAv ZW1hY3MvbGlzcC9maWxlcy5lbAkyMDA5LTA2LTMwIDE1OjUxOjIyLjAwMDAwMDAwMCAtMDQwMAoq KioqKioqKioqKioqKioKKioqIDg5Myw5MDQgKioqKgogIAkgKHNldHEgZmlsZW5hbWUgKGV4cGFu ZC1maWxlLW5hbWUgZmlsZW5hbWUpKQogIAkgKGlmIChzdHJpbmc9IGZpbGVuYW1lICIiKQogIAkg ICAgIChzZXRxIGZpbGVuYW1lICIvIikpKQohICAgICAgICAgKChhbmQgKHN0cmluZz0gKHN1YnN0 cmluZyBmaWxlbmFtZSAwIDEpICJ+IikKISAgICAgICAgICAgICAgIChzdHJpbmctbWF0Y2gtcCAi flteL10qLz8iIGZpbGVuYW1lKSkKISAgICAgICAgICAoc3RyaW5nLW1hdGNoICJ+W14vXSovPyIg ZmlsZW5hbWUpCiEgICAgICAgICAgKGxldCAoKGZpcnN0LXBhcnQKISAgICAgICAgICAgICAgICAg KHN1YnN0cmluZyBmaWxlbmFtZSAwIChtYXRjaC1lbmQgMCkpKQohICAgICAgICAgICAgICAgIChy ZXN0IChzdWJzdHJpbmcgZmlsZW5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