emacs-devel
[Top][All Lists]
Advanced

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

%-escapes in file URL


From: YAMAMOTO Mitsuharu
Subject: %-escapes in file URL
Date: Mon, 15 May 2006 17:12:53 +0900
User-agent: Wanderlust/2.14.0 (Africa) SEMI/1.14.6 (Maruoka) FLIM/1.14.6 (Marutamachi) APEL/10.6 Emacs/22.0.50 (sparc-sun-solaris2.8) MULE/5.0 (SAKAKI)

In dnd-handle-one-url, %-escapes in the given file URL is decoded
immediately.  But I think that should be done when extracting the file
name from it (i.e., in dnd-get-local-file-name) in order to cope with
applications outside Emacs via browse-url.  On the other hand,
%-escapes are needed when constructing a file URL from a file name.

Below is a patch for such changes.  The w32-win.el part is by M.Fujii.

                                     YAMAMOTO Mitsuharu
                                address@hidden

Index: lisp/dnd.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/dnd.el,v
retrieving revision 1.8
diff -c -r1.8 dnd.el
*** lisp/dnd.el 6 Feb 2006 14:33:32 -0000       1.8
--- lisp/dnd.el 15 May 2006 07:48:02 -0000
***************
*** 69,107 ****
  
  ;; Functions
  
! (defun dnd-handle-one-url (window action arg)
    "Handle one dropped url by calling the appropriate handler.
  The handler is first located by looking at `dnd-protocol-alist'.
  If no match is found here, and the value of `browse-url-browser-function'
  is a pair of (REGEXP . FUNCTION), those regexps are tried for a match.
  If no match is found, just call `dnd-insert-text'.
  WINDOW is where the drop happend, ACTION is the action for the drop,
! ARG is the URL that has been dropped.
  Returns ACTION."
    (require 'browse-url)
!   (let* ((uri (replace-regexp-in-string
!              "%[A-Z0-9][A-Z0-9]"
!              (lambda (arg)
!                (format "%c" (string-to-number (substring arg 1) 16)))
!              arg))
!        ret)
      (or
       (catch 'done
         (dolist (bf dnd-protocol-alist)
!        (when (string-match (car bf) uri)
!          (setq ret (funcall (cdr bf) uri action))
           (throw 'done t)))
         nil)
       (when (not (functionp browse-url-browser-function))
         (catch 'done
         (dolist (bf browse-url-browser-function)
!          (when (string-match (car bf) uri)
             (setq ret 'private)
!            (funcall (cdr bf) uri action)
             (throw 'done t)))
         nil))
       (progn
!        (dnd-insert-text window action uri)
         (setq ret 'private)))
      ret))
  
--- 69,102 ----
  
  ;; Functions
  
! (defun dnd-handle-one-url (window action url)
    "Handle one dropped url by calling the appropriate handler.
  The handler is first located by looking at `dnd-protocol-alist'.
  If no match is found here, and the value of `browse-url-browser-function'
  is a pair of (REGEXP . FUNCTION), those regexps are tried for a match.
  If no match is found, just call `dnd-insert-text'.
  WINDOW is where the drop happend, ACTION is the action for the drop,
! URL is what has been dropped.
  Returns ACTION."
    (require 'browse-url)
!   (let (ret)
      (or
       (catch 'done
         (dolist (bf dnd-protocol-alist)
!        (when (string-match (car bf) url)
!          (setq ret (funcall (cdr bf) url action))
           (throw 'done t)))
         nil)
       (when (not (functionp browse-url-browser-function))
         (catch 'done
         (dolist (bf browse-url-browser-function)
!          (when (string-match (car bf) url)
             (setq ret 'private)
!            (funcall (cdr bf) url action)
             (throw 'done t)))
         nil))
       (progn
!        (dnd-insert-text window action url)
         (setq ret 'private)))
      ret))
  
***************
*** 134,139 ****
--- 129,139 ----
                 ((string-match "^file:" uri)           ; Old KDE, Motif, Sun
                  (substring uri (match-end 0))))))
      (when (and f must-exist)
+       (setq f (replace-regexp-in-string
+              "%[A-Z0-9][A-Z0-9]"
+              (lambda (arg)
+                (format "%c" (string-to-number (substring arg 1) 16)))
+              f))
        (let* ((decoded-f (decode-coding-string
                         f
                         (or file-name-coding-system
Index: lisp/x-dnd.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/x-dnd.el,v
retrieving revision 1.19
diff -c -r1.19 x-dnd.el
*** lisp/x-dnd.el       6 Feb 2006 14:33:35 -0000       1.19
--- lisp/x-dnd.el       15 May 2006 07:48:02 -0000
***************
*** 263,269 ****
        retval)
      (dolist (bf uri-list)
        ;; If one URL is handeled, treat as if the whole drop succeeded.
!       (let* ((file-uri (concat "file://" bf))
             (did-action (dnd-handle-one-url window action file-uri)))
        (when did-action (setq retval did-action))))
      retval))
--- 263,274 ----
        retval)
      (dolist (bf uri-list)
        ;; If one URL is handeled, treat as if the whole drop succeeded.
!       (setq bf
!           (encode-coding-string bf (or file-name-coding-system
!                                        default-file-name-coding-system)))
!       (let* ((file-uri (concat "file://"
!                              (mapconcat 'url-hexify-string
!                                         (split-string bf "/") "/")))
             (did-action (dnd-handle-one-url window action file-uri)))
        (when did-action (setq retval did-action))))
      retval))
Index: lisp/term/mac-win.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/term/mac-win.el,v
retrieving revision 1.70
diff -c -r1.70 mac-win.el
*** lisp/term/mac-win.el        10 May 2006 08:22:39 -0000      1.70
--- lisp/term/mac-win.el        15 May 2006 07:48:02 -0000
***************
*** 1627,1633 ****
    (let ((ae (mac-event-ae event)))
      (dolist (file-name (mac-ae-list ae nil 'undecoded-file-name))
        (if file-name
!         (dnd-open-local-file (concat "file:" file-name) nil)))
      (let ((selection-range (mac-ae-selection-range ae))
          (search-text (mac-ae-text-for-search ae)))
        (cond (selection-range
--- 1616,1625 ----
    (let ((ae (mac-event-ae event)))
      (dolist (file-name (mac-ae-list ae nil 'undecoded-file-name))
        (if file-name
!         (dnd-open-local-file
!          (concat "file://"
!                  (mapconcat 'url-hexify-string
!                             (split-string file-name "/") "/")) nil)))
      (let ((selection-range (mac-ae-selection-range ae))
          (search-text (mac-ae-text-for-search ae)))
        (cond (selection-range
Index: lisp/term/w32-win.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/term/w32-win.el,v
retrieving revision 1.76
diff -c -r1.76 w32-win.el
*** lisp/term/w32-win.el        18 Mar 2006 13:13:30 -0000      1.76
--- lisp/term/w32-win.el        15 May 2006 07:48:02 -0000
***************
*** 112,117 ****
--- 112,125 ----
        (if (and (> x 0) (> y 0))
          (set-frame-selected-window nil window))
        (mapcar (lambda (file-name)
+               (let ((f (subst-char-in-string ?\\ ?/ file-name))
+                     (coding (or file-name-coding-system
+                                 default-file-name-coding-system)))
+                 (setq file-name
+                       (mapconcat 'url-hexify-string
+                                  (split-string (encode-coding-string f coding)
+                                                "/")
+                                  "/")))
                (dnd-handle-one-url window 'private
                                    (concat "file:" file-name)))
                (car (cdr (cdr event)))))




reply via email to

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