Mercurial > emacs
comparison lisp/dnd.el @ 72687:eedaad0e9f80
* dnd.el (dnd-protocol-alist): Add what url-handler-mode can handle.
(dnd-open-remote-url): New function.
(dnd-open-remote-file-function): Set to dnd-open-remote-url if
not windows-nt.
2006-09-07 Jason Rumney <jasonr@gnu.org>
* dnd.el (dnd-open-remote-file-function): New variable.
(dnd-open-unc-file): New function.
(dnd-open-file): Call dnd-open-remote-file-function if set.
author | Jan Djärv <jan.h.d@swipnet.se> |
---|---|
date | Thu, 07 Sep 2006 07:44:33 +0000 |
parents | eca94c558ceb |
children | 3ff56e45c67f |
comparison
equal
deleted
inserted
replaced
72686:2f8ec29373d1 | 72687:eedaad0e9f80 |
---|---|
32 | 32 |
33 ;;; Code: | 33 ;;; Code: |
34 | 34 |
35 ;;; Customizable variables | 35 ;;; Customizable variables |
36 | 36 |
37 (eval-when-compile | |
38 (require 'url-handlers)) | |
37 | 39 |
38 ;;;###autoload | 40 ;;;###autoload |
39 (defcustom dnd-protocol-alist | 41 (defcustom dnd-protocol-alist |
40 '( | 42 '(("^file:///" . dnd-open-local-file) ; XDND format. |
41 ("^file:///" . dnd-open-local-file) ; XDND format. | 43 ("^file://" . dnd-open-file) ; URL with host |
42 ("^file://" . dnd-open-file) ; URL with host | 44 ("^file:" . dnd-open-local-file) ; Old KDE, Motif, Sun |
43 ("^file:" . dnd-open-local-file) ; Old KDE, Motif, Sun | 45 ("^\\(https?\\|ftp\\|file\\|nfs\\)://" . dnd-open-file) |
44 ) | 46 ) |
45 | 47 |
46 "The functions to call for different protocols when a drop is made. | 48 "The functions to call for different protocols when a drop is made. |
47 This variable is used by `dnd-handle-one-url' and `dnd-handle-file-name'. | 49 This variable is used by `dnd-handle-one-url' and `dnd-handle-file-name'. |
48 The list contains of (REGEXP . FUNCTION) pairs. | 50 The list contains of (REGEXP . FUNCTION) pairs. |
49 The functions shall take two arguments, URL, which is the URL dropped and | 51 The functions shall take two arguments, URL, which is the URL dropped and |
56 if some action was made, or nil if the URL is ignored." | 58 if some action was made, or nil if the URL is ignored." |
57 :version "22.1" | 59 :version "22.1" |
58 :type '(repeat (cons (regexp) (function))) | 60 :type '(repeat (cons (regexp) (function))) |
59 :group 'dnd) | 61 :group 'dnd) |
60 | 62 |
63 | |
64 (defcustom dnd-open-remote-file-function | |
65 (if (eq system-type 'windows-nt) | |
66 'dnd-open-unc-file | |
67 'dnd-open-remote-url) | |
68 "The function to call when opening a file on a remote machine. | |
69 The function will be called with two arguments; URI and ACTION. See | |
70 `dnd-open-file' for details. | |
71 If nil, then dragging remote files into Emacs will result in an error. | |
72 Predefined functions are `dnd-open-unc-file' and `dnd-open-remote-url'. | |
73 `dnd-open-unc-file' attempts to open the file using its UNC name and is the | |
74 default on MS-Windows. `dnd-open-remote-url' uses `url-handler-mode' and | |
75 is the default except for MS-Windows." | |
76 :version "22.1" | |
77 :type 'function | |
78 :group 'dnd) | |
61 | 79 |
62 | 80 |
63 (defcustom dnd-open-file-other-window nil | 81 (defcustom dnd-open-file-other-window nil |
64 "If non-nil, always use find-file-other-window to open dropped files." | 82 "If non-nil, always use find-file-other-window to open dropped files." |
65 :version "22.1" | 83 :version "22.1" |
156 (find-file-other-window f) | 174 (find-file-other-window f) |
157 (find-file f)) | 175 (find-file f)) |
158 'private) | 176 'private) |
159 (error "Can not read %s" uri)))) | 177 (error "Can not read %s" uri)))) |
160 | 178 |
179 (defun dnd-open-unc-file (uri action) | |
180 "Open a remote file using its unc path. | |
181 The file is opened in the current window, or a new window if | |
182 `dnd-open-file-other-window' is set. URI is the url for the file, | |
183 and must have the format file://hostname/file-name. ACTION is ignored. | |
184 //hostname/file-name is the unc path." | |
185 (let ((unc-file (if (string-match "^file:" uri) | |
186 (substring uri 5)))) | |
187 (if (and unc-file (file-readable-p unc-file)) | |
188 (progn | |
189 (if dnd-open-file-other-window | |
190 (find-file-other-window unc-file) | |
191 (find-file unc-file)) | |
192 'private) | |
193 (error "Invalid file url")))) | |
194 | |
195 (defun dnd-open-remote-url (uri action) | |
196 "Open a remote file with `find-file' and `url-handler-mode'. | |
197 Turns `url-handler-mode' on if not on before. The file is opened in the | |
198 current window, or a new window if `dnd-open-file-other-window' is set. | |
199 URI is the url for the file. ACTION is ignored." | |
200 (progn | |
201 (or url-handler-mode (url-handler-mode)) | |
202 (if dnd-open-file-other-window | |
203 (find-file-other-window uri) | |
204 (find-file uri)) | |
205 'private)) | |
206 | |
207 | |
161 (defun dnd-open-file (uri action) | 208 (defun dnd-open-file (uri action) |
162 "Open a local or remote file. | 209 "Open a local or remote file. |
163 The file is opened in the current window, or a new window if | 210 The file is opened in the current window, or a new window if |
164 `dnd-open-file-other-window' is set. URI is the url for the file, | 211 `dnd-open-file-other-window' is set. URI is the url for the file, |
165 and must have the format file://hostname/file-name. ACTION is ignored. | 212 and must have the format file://hostname/file-name. ACTION is ignored. |
167 | 214 |
168 ;; The hostname may be our hostname, in that case, convert to a local | 215 ;; The hostname may be our hostname, in that case, convert to a local |
169 ;; file. Otherwise return nil. | 216 ;; file. Otherwise return nil. |
170 (let ((local-file (dnd-get-local-file-uri uri))) | 217 (let ((local-file (dnd-get-local-file-uri uri))) |
171 (if local-file (dnd-open-local-file local-file action) | 218 (if local-file (dnd-open-local-file local-file action) |
172 (error "Remote files not supported")))) | 219 (if dnd-open-remote-file-function |
220 (funcall dnd-open-remote-file-function uri action) | |
221 (error "Remote files not supported"))))) | |
173 | 222 |
174 | 223 |
175 (defun dnd-insert-text (window action text) | 224 (defun dnd-insert-text (window action text) |
176 "Insert text at point or push to the kill ring if buffer is read only. | 225 "Insert text at point or push to the kill ring if buffer is read only. |
177 TEXT is the text as a string, WINDOW is the window where the drop happened." | 226 TEXT is the text as a string, WINDOW is the window where the drop happened." |