From: YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
To: Reuben Thomas <rrt@sc3d.org>
Cc: 13442@debbugs.gnu.org
Subject: bug#13442: 24.1; Please add a function to hexify paths to url-util, e.g. the attached
Date: Tue, 15 Jan 2013 11:35:10 +0900 [thread overview]
Message-ID: <wlpq17uqap.wl%mituharu@math.s.chiba-u.ac.jp> (raw)
In-Reply-To: <87fw23s8jj.fsf@sc3d.org>
>>>>> On Mon, 14 Jan 2013 22:29:20 +0000, Reuben Thomas <rrt@sc3d.org> said:
> Sometimes, one needs to escape a path that will be made part of a URL. The code here:
> https://github.com/MassimoLauria/dotemacs/blob/master/init-latex.el
> shows a need for it, namely, escaping a filename to pass as part of a
> URL to DBus as part of the use of SyncTeX.
> As far as I can tell, there's no function that does this currently.
> Something like the code at the above-mentioned URL seems to work nicely,
> e.g.:
> (defun url-hexify-path (path)
> "Handle special characters for urlify. `/' is added temporarily
> to `url-unreserved-chars', so that `url-hexify-string' won't
> escape path separators."
> (let ((url-unreserved-chars (cons ?/ url-unreserved-chars)))
> (url-hexify-string path)))
> though I imagine this could be more neatly done. Since '/' is the only
> special character in paths that needs to be retained in URLs, the
> algorithm seems sound, at least.
I usually do that like this:
;; Suppose we have an absolute file name in `file-name'.
(let* ((coding (or file-name-coding-system
default-file-name-coding-system))
(encoded-file-name (if coding (encode-coding-string file-name coding)
file-name)))
(concat "file://localhost"
(mapconcat 'url-hexify-string
(split-string encoded-file-name "/") "/")))
BTW, I think it is not a good idea to provide a function that simply
"escapes" a file name string. Such a function should always return a
well-formed URL. See also
http://lists.gnu.org/archive/html/emacs-devel/2007-09/msg01168.html
and
http://lists.gnu.org/archive/html/emacs-devel/2006-05/msg01060.html .
YAMAMOTO Mitsuharu
mituharu@math.s.chiba-u.ac.jp
prev parent reply other threads:[~2013-01-15 2:35 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-01-14 22:29 bug#13442: 24.1; Please add a function to hexify paths to url-util, e.g. the attached Reuben Thomas
2013-01-15 2:35 ` YAMAMOTO Mitsuharu [this message]
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=wlpq17uqap.wl%mituharu@math.s.chiba-u.ac.jp \
--to=mituharu@math.s.chiba-u.ac.jp \
--cc=13442@debbugs.gnu.org \
--cc=rrt@sc3d.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 public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).