unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* %-escapes in file URL
@ 2006-05-15  8:12 YAMAMOTO Mitsuharu
  2006-05-15  9:59 ` Jan Djärv
  2006-05-19  2:03 ` Richard Stallman
  0 siblings, 2 replies; 14+ messages in thread
From: YAMAMOTO Mitsuharu @ 2006-05-15  8:12 UTC (permalink / raw)


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
				mituharu@math.s.chiba-u.ac.jp

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

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2006-05-20 17:05 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-05-15  8:12 %-escapes in file URL YAMAMOTO Mitsuharu
2006-05-15  9:59 ` Jan Djärv
2006-05-15 12:55   ` YAMAMOTO Mitsuharu
2006-05-15 13:26     ` Jan Djärv
2006-05-19  2:03 ` Richard Stallman
2006-05-19  8:09   ` YAMAMOTO Mitsuharu
2006-05-19  9:33     ` Jan Djärv
2006-05-20  4:43       ` YAMAMOTO Mitsuharu
2006-05-20  5:04     ` Richard Stallman
2006-05-20  5:23       ` YAMAMOTO Mitsuharu
2006-05-20 17:05         ` If mail bounces Richard Stallman
2006-05-20  5:04     ` %-escapes in file URL Richard Stallman
2006-05-20  5:33       ` YAMAMOTO Mitsuharu
2006-05-20 17:05         ` Richard Stallman

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