diff options
Diffstat (limited to 'lisp/dnd.el')
-rw-r--r-- | lisp/dnd.el | 50 |
1 files changed, 24 insertions, 26 deletions
diff --git a/lisp/dnd.el b/lisp/dnd.el index 905659e817b..815a4afbecd 100644 --- a/lisp/dnd.el +++ b/lisp/dnd.el @@ -1,4 +1,4 @@ -;;; dnd.el --- drag and drop support +;;; dnd.el --- drag and drop support -*- lexical-binding: t; -*- ;; Copyright (C) 2005-2020 Free Software Foundation, Inc. @@ -33,6 +33,9 @@ ;;; Customizable variables +(defgroup dnd nil + "Handling data from drag and drop." + :group 'environment) ;;;###autoload (defcustom dnd-protocol-alist @@ -54,14 +57,13 @@ If no match is found, the URL is inserted as text by calling `dnd-insert-text'. The function shall return the action done (move, copy, link or private) if some action was made, or nil if the URL is ignored." :version "22.1" - :type '(repeat (cons (regexp) (function))) - :group 'dnd) + :type '(repeat (cons (regexp) (function)))) (defcustom dnd-open-remote-file-function (if (eq system-type 'windows-nt) - 'dnd-open-local-file - 'dnd-open-remote-url) + #'dnd-open-local-file + #'dnd-open-remote-url) "The function to call when opening a file on a remote machine. The function will be called with two arguments, URI and ACTION. See `dnd-open-file' for details. @@ -71,15 +73,13 @@ Predefined functions are `dnd-open-local-file' and `dnd-open-remote-url'. is the default on MS-Windows. `dnd-open-remote-url' uses `url-handler-mode' and is the default except for MS-Windows." :version "22.1" - :type 'function - :group 'dnd) + :type 'function) (defcustom dnd-open-file-other-window nil "If non-nil, always use find-file-other-window to open dropped files." :version "22.1" - :type 'boolean - :group 'dnd) + :type 'boolean) ;; Functions @@ -87,13 +87,11 @@ and is the default except for MS-Windows." (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 happened, ACTION is the action for the drop, -URL is what has been dropped. -Returns ACTION." - (require 'browse-url) +If no match is found here, `browse-url-handlers' and +`browse-url-default-handlers' are searched for a match. +If no match is found, just call `dnd-insert-text'. WINDOW is +where the drop happened, ACTION is the action for the drop, URL +is what has been dropped. Returns ACTION." (let (ret) (or (catch 'done @@ -102,14 +100,13 @@ Returns ACTION." (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)) + (catch 'done + (let ((browser (browse-url-select-handler url 'internal))) + (when browser + (setq ret 'private) + (funcall browser url action) + (throw 'done t))) + nil) (progn (dnd-insert-text window action url) (setq ret 'private))) @@ -136,7 +133,8 @@ Return nil if URI is not a local file." (string-equal sysname-no-dot hostname))) (concat "file://" (substring uri (+ 7 (length hostname)))))))) -(defsubst dnd-unescape-uri (uri) +(defun dnd--unescape-uri (uri) + ;; Merge with corresponding code in URL library. (replace-regexp-in-string "%[[:xdigit:]][[:xdigit:]]" (lambda (arg) @@ -160,7 +158,7 @@ Return nil if URI is not a local file." 'utf-8 (or file-name-coding-system default-file-name-coding-system)))) - (and f (setq f (decode-coding-string (dnd-unescape-uri f) coding))) + (and f (setq f (decode-coding-string (dnd--unescape-uri f) coding))) (when (and f must-exist (not (file-readable-p f))) (setq f nil)) f)) |