all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Tino Calancha <tino.calancha@gmail.com>
To: Emacs developers <emacs-devel@gnu.org>
Cc: tino.calancha@gmail.com
Subject: Add a predicate for canonical file name
Date: Mon, 12 Sep 2016 17:23:03 +0900 (JST)	[thread overview]
Message-ID: <alpine.DEB.2.20.1609121718560.31277@calancha-pc> (raw)


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)




             reply	other threads:[~2016-09-12  8:23 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-12  8:23 Tino Calancha [this message]
2016-09-12 17:13 ` Add a predicate for canonical file name 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.DEB.2.20.1609121718560.31277@calancha-pc \
    --to=tino.calancha@gmail.com \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.