all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Add a predicate for canonical file name
@ 2016-09-12  8:23 Tino Calancha
  2016-09-12 17:13 ` Eli Zaretskii
  0 siblings, 1 reply; 11+ messages in thread
From: Tino Calancha @ 2016-09-12  8:23 UTC (permalink / raw)
  To: Emacs developers; +Cc: tino.calancha


Hi,

i dont see in Emacs a predicate for a file name being canonical.
We have a predicate for absolute file names, `file-name-absolute-p'.
In some cases we might want to check if the file name is canonical.
For instance, following might fail to set point in simple.el line:
it fails when `dired-goto-file' argument is not canonical:

(let* ((dir (expand-file-name "lisp" source-directory))
        (file (expand-file-name "simple.el" dir)))
   (when (file-name-absolute-p file)
     (dired-other-window dir)
     (goto-char (point-min))
     (dired-goto-file (abbreviate-file-name file))))
     ;; (dired-goto-file file))) ; This works.


Do you think has sense to add a predicate as follows?:
If the answer is yes: where should be defined?

(defsubst myfile-name-canonical-p (filename)
   "Return non-nil if FILENAME specifies an absolute canonical file name."
   (string= filename (expand-file-name filename)))

Following is a simple comparison `file-name-absolute-p' with
`myfile-name-canonical-p':

(let ((dirs '("./foo" "../foo" "/foo//bar" "/foo/./bar" "/foo/../bar" 
"~/bar"
               "//foo/bar" "/foo/bar" "/foo/bar/" 
"/sudo:baz@-pc:/foo/bar/")))
   (mapcar 'file-name-absolute-p dirs))
=> (nil nil t t t t t t t t)

(let ((dirs '("./foo" "../foo" "/foo//bar" "/foo/./bar" "/foo/../bar" 
"~/bar"
               "//foo/bar" "/foo/bar" "/foo/bar/" 
"/sudo:baz@-pc:/foo/bar/")))
   (mapcar 'myfile-name-canonical-p dirs))
=> (nil nil nil nil nil nil t t t t)




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

end of thread, other threads:[~2016-10-16 10:42 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-09-12  8:23 Add a predicate for canonical file name Tino Calancha
2016-09-12 17:13 ` Eli Zaretskii
2016-09-12 20:01   ` Stefan Monnier
2016-09-13  6:54     ` Philipp Stephani
2016-09-13 12:14       ` Stefan Monnier
2016-10-14 21:39     ` John Yates
2016-10-15 22:05       ` Richard Stallman
2016-10-15 23:07         ` Kalle Olavi Niemitalo
2016-10-16  0:02           ` John Yates
2016-10-16  1:05             ` Kalle Olavi Niemitalo
2016-10-16 10:42           ` Richard Stallman

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.