emacs-devel
[Top][All Lists]
Advanced

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

Add a predicate for canonical file name


From: Tino Calancha
Subject: Add a predicate for canonical file name
Date: Mon, 12 Sep 2016 17:23:03 +0900 (JST)
User-agent: Alpine 2.20 (DEB 67 2015-01-07)


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:address@hidden:/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:address@hidden:/foo/bar/")))
  (mapcar 'myfile-name-canonical-p dirs))
=> (nil nil nil nil nil nil t t t t)




reply via email to

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