-;;; dnd.el --- drag and drop support.
+;;; dnd.el --- drag and drop support. -*- coding: utf-8 -*-
-;; Copyright (C) 2005, 2006, 2007 Free Software Foundation, Inc.
+;; Copyright (C) 2005-2014 Free Software Foundation, Inc.
-;; Author: Jan Dj\e,Ad\e(Brv <jan.h.d@swipnet.se>
-;; Maintainer: FSF
+;; Author: Jan Djรคrv <jan.h.d@swipnet.se>
+;; Maintainer: emacs-devel@gnu.org
;; Keywords: window, drag, drop
+;; Package: emacs
;; This file is part of GNU Emacs.
-;; GNU Emacs is free software; you can redistribute it and/or modify
+;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 3, or (at your option)
-;; any later version.
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs; see the file COPYING. If not, write to the
-;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-;; Boston, MA 02110-1301, USA.
+;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;;;###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.
(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,
(let ((f (cond ((string-match "^file:///" uri) ; XDND format.
(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)))))
-
-
-(defun dnd-open-local-file (uri action)
+ (substring uri (match-end 0)))))
+ (coding (if (equal system-type 'windows-nt)
+ ;; W32 pretends that file names are UTF-8 encoded.
+ 'utf-8
+ (or file-name-coding-system
+ default-file-name-coding-system))))
+ (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))
+
+(defun dnd-open-local-file (uri _action)
"Open a local file.
The file is opened in the current window, or a new window if
`dnd-open-file-other-window' is set. URI is the url for the file,
'private)
(error "Can not read %s" uri))))
-(defun dnd-open-remote-url (uri action)
+(defun dnd-open-remote-url (uri _action)
"Open a remote file with `find-file' and `url-handler-mode'.
Turns `url-handler-mode' on if not on before. The file is opened in the
current window, or a new window if `dnd-open-file-other-window' is set.
(provide 'dnd)
-;; arch-tag: 0472f6a5-2e8f-4304-9e44-1a0877c771b7
;;; dnd.el ends here