X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/142e26a72e9b8bbbec23c6bf7234e9f2544b5f89..e17816e57e4795e0fd69ab561278c8a302c96771:/lisp/dnd.el diff --git a/lisp/dnd.el b/lisp/dnd.el index 7eb6395e28..19b9501617 100644 --- a/lisp/dnd.el +++ b/lisp/dnd.el @@ -1,10 +1,11 @@ -;;; dnd.el --- drag and drop support. +;;; dnd.el --- drag and drop support. -*- coding: utf-8 -*- -;; Copyright (C) 2005, 2006, 2007, 2008 Free Software Foundation, Inc. +;; Copyright (C) 2005-2011 Free Software Foundation, Inc. -;; Author: Jan Dj,Ad(Brv +;; Author: Jan Djärv ;; Maintainer: FSF ;; Keywords: window, drag, drop +;; Package: emacs ;; This file is part of GNU Emacs. @@ -35,10 +36,10 @@ ;;;###autoload (defcustom dnd-protocol-alist - '(("^file:///" . dnd-open-local-file) ; XDND format. - ("^file://" . dnd-open-file) ; URL with host - ("^file:" . dnd-open-local-file) ; Old KDE, Motif, Sun - ("^\\(https?\\|ftp\\|file\\|nfs\\)://" . dnd-open-file) + `((,(purecopy "^file:///") . dnd-open-local-file) ; XDND format. + (,(purecopy "^file://") . dnd-open-file) ; URL with host + (,(purecopy "^file:") . dnd-open-local-file) ; Old KDE, Motif, Sun + (,(purecopy "^\\(https?\\|ftp\\|file\\|nfs\\)://") . dnd-open-file) ) "The functions to call for different protocols when a drop is made. @@ -133,6 +134,16 @@ Return nil if URI is not a local file." (string-equal system-name-no-dot hostname))) (concat "file://" (substring uri (+ 7 (length hostname))))))) +(defsubst dnd-unescape-uri (uri) + (replace-regexp-in-string + "%[A-Fa-f0-9][A-Fa-f0-9]" + (lambda (arg) + (let ((str (make-string 1 0))) + (aset str 0 (string-to-number (substring arg 1) 16)) + str)) + uri t t)) + +;; http://lists.gnu.org/archive/html/emacs-devel/2006-05/msg01060.html (defun dnd-get-local-file-name (uri &optional must-exist) "Return file name converted from file:/// or file: syntax. URI is the uri for the file. If MUST-EXIST is given and non-nil, @@ -142,21 +153,12 @@ Return nil if URI is not a local file." (substring uri (1- (match-end 0)))) ((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-Fa-f0-9][A-Fa-f0-9]" - (lambda (arg) - (let ((str (make-string 1 0))) - (aset str 0 (string-to-number (substring arg 1) 16)) - str)) - f t t)) - (let* ((decoded-f (decode-coding-string - f - (or file-name-coding-system - default-file-name-coding-system))) - (try-f (if (file-readable-p decoded-f) decoded-f f))) - (when (file-readable-p try-f) try-f))))) - + (and f (setq f (decode-coding-string (dnd-unescape-uri f) + (or file-name-coding-system + default-file-name-coding-system)))) + (when (and f must-exist (not (file-readable-p f))) + (setq f nil)) + f)) (defun dnd-open-local-file (uri action) "Open a local file. @@ -224,5 +226,4 @@ TEXT is the text as a string, WINDOW is the window where the drop happened." (provide 'dnd) -;; arch-tag: 0472f6a5-2e8f-4304-9e44-1a0877c771b7 ;;; dnd.el ends here