comparison lisp/dnd.el @ 90601:a1a25ac6c88a

Merge from emacs--devo--0 Patches applied: * emacs--devo--0 (patch 427-436) - Update from CVS - Merge from gnus--rel--5.10 * gnus--rel--5.10 (patch 134-136) - Merge from emacs--devo--0 - Update from CVS Revision: emacs@sv.gnu.org/emacs--unicode--0--patch-110
author Miles Bader <miles@gnu.org>
date Thu, 14 Sep 2006 09:24:00 +0000
parents 3ff56e45c67f
children 1c4d17d3a136
comparison
equal deleted inserted replaced
90600:84dd84b43e1b 90601:a1a25ac6c88a
35 ;;; Customizable variables 35 ;;; Customizable variables
36 36
37 37
38 ;;;###autoload 38 ;;;###autoload
39 (defcustom dnd-protocol-alist 39 (defcustom dnd-protocol-alist
40 '( 40 '(("^file:///" . dnd-open-local-file) ; XDND format.
41 ("^file:///" . dnd-open-local-file) ; XDND format. 41 ("^file://" . dnd-open-file) ; URL with host
42 ("^file://" . dnd-open-file) ; URL with host 42 ("^file:" . dnd-open-local-file) ; Old KDE, Motif, Sun
43 ("^file:" . dnd-open-local-file) ; Old KDE, Motif, Sun 43 ("^\\(https?\\|ftp\\|file\\|nfs\\)://" . dnd-open-file)
44 ) 44 )
45 45
46 "The functions to call for different protocols when a drop is made. 46 "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'. 47 This variable is used by `dnd-handle-one-url' and `dnd-handle-file-name'.
48 The list contains of (REGEXP . FUNCTION) pairs. 48 The list contains of (REGEXP . FUNCTION) pairs.
49 The functions shall take two arguments, URL, which is the URL dropped and 49 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." 56 if some action was made, or nil if the URL is ignored."
57 :version "22.1" 57 :version "22.1"
58 :type '(repeat (cons (regexp) (function))) 58 :type '(repeat (cons (regexp) (function)))
59 :group 'dnd) 59 :group 'dnd)
60 60
61
62 (defcustom dnd-open-remote-file-function
63 (if (eq system-type 'windows-nt)
64 'dnd-open-unc-file
65 'dnd-open-remote-url)
66 "The function to call when opening a file on a remote machine.
67 The function will be called with two arguments; URI and ACTION. See
68 `dnd-open-file' for details.
69 If nil, then dragging remote files into Emacs will result in an error.
70 Predefined functions are `dnd-open-unc-file' and `dnd-open-remote-url'.
71 `dnd-open-unc-file' attempts to open the file using its UNC name and is the
72 default on MS-Windows. `dnd-open-remote-url' uses `url-handler-mode' and
73 is the default except for MS-Windows."
74 :version "22.1"
75 :type 'function
76 :group 'dnd)
61 77
62 78
63 (defcustom dnd-open-file-other-window nil 79 (defcustom dnd-open-file-other-window nil
64 "If non-nil, always use find-file-other-window to open dropped files." 80 "If non-nil, always use find-file-other-window to open dropped files."
65 :version "22.1" 81 :version "22.1"
156 (find-file-other-window f) 172 (find-file-other-window f)
157 (find-file f)) 173 (find-file f))
158 'private) 174 'private)
159 (error "Can not read %s" uri)))) 175 (error "Can not read %s" uri))))
160 176
177 (defun dnd-open-unc-file (uri action)
178 "Open a remote file using its unc path.
179 The file is opened in the current window, or a new window if
180 `dnd-open-file-other-window' is set. URI is the url for the file,
181 and must have the format file://hostname/file-name. ACTION is ignored.
182 //hostname/file-name is the unc path."
183 (let ((unc-file (if (string-match "^file:" uri)
184 (substring uri 5))))
185 (if (and unc-file (file-readable-p unc-file))
186 (progn
187 (if dnd-open-file-other-window
188 (find-file-other-window unc-file)
189 (find-file unc-file))
190 'private)
191 (error "Invalid file url"))))
192
193 (defun dnd-open-remote-url (uri action)
194 "Open a remote file with `find-file' and `url-handler-mode'.
195 Turns `url-handler-mode' on if not on before. The file is opened in the
196 current window, or a new window if `dnd-open-file-other-window' is set.
197 URI is the url for the file. ACTION is ignored."
198 (progn
199 (require 'url-handlers)
200 (or url-handler-mode (url-handler-mode))
201 (if dnd-open-file-other-window
202 (find-file-other-window uri)
203 (find-file uri))
204 'private))
205
206
161 (defun dnd-open-file (uri action) 207 (defun dnd-open-file (uri action)
162 "Open a local or remote file. 208 "Open a local or remote file.
163 The file is opened in the current window, or a new window if 209 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, 210 `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. 211 and must have the format file://hostname/file-name. ACTION is ignored.
167 213
168 ;; The hostname may be our hostname, in that case, convert to a local 214 ;; The hostname may be our hostname, in that case, convert to a local
169 ;; file. Otherwise return nil. 215 ;; file. Otherwise return nil.
170 (let ((local-file (dnd-get-local-file-uri uri))) 216 (let ((local-file (dnd-get-local-file-uri uri)))
171 (if local-file (dnd-open-local-file local-file action) 217 (if local-file (dnd-open-local-file local-file action)
172 (error "Remote files not supported")))) 218 (if dnd-open-remote-file-function
219 (funcall dnd-open-remote-file-function uri action)
220 (error "Remote files not supported")))))
173 221
174 222
175 (defun dnd-insert-text (window action text) 223 (defun dnd-insert-text (window action text)
176 "Insert text at point or push to the kill ring if buffer is read only. 224 "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." 225 TEXT is the text as a string, WINDOW is the window where the drop happened."