bug-gnu-emacs
[Top][All Lists]
Advanced

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

bug#13442: 24.1; Please add a function to hexify paths to url-util, e.g.


From: YAMAMOTO Mitsuharu
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
User-agent: Wanderlust/2.14.0 (Africa) SEMI/1.14.6 (Maruoka) FLIM/1.14.8 (Shijō) APEL/10.6 Emacs/22.3 (sparc-sun-solaris2.8) MULE/5.0 (SAKAKI)

>>>>> 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





reply via email to

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