X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/a225e738abdeb149e9b4bc87d5f9d9a201160aa2..b38a3aa6638889ec772a0e26083e570f051a6cab:/lisp/x-dnd.el diff --git a/lisp/x-dnd.el b/lisp/x-dnd.el index 32645bd601..df902e78c9 100644 --- a/lisp/x-dnd.el +++ b/lisp/x-dnd.el @@ -58,8 +58,8 @@ The default value for this variable is `x-dnd-default-test-function'." ) "The functions to call for different protocols when a drop is made. -This variable is used by `x-dnd-handle-uri-list' and `x-dnd-handle-moz-url'. -The list contains of (REGEXP . FUNCTION) pairs. +This variable is used by `x-dnd-handle-uri-list', `x-dnd-handle-file-name' +and `x-dnd-handle-moz-url'. The list contains of (REGEXP . FUNCTION) pairs. The functions shall take two arguments, URL, which is the URL dropped and ACTION which is the action to be performed for the drop (move, copy, link, private or ask). @@ -104,9 +104,7 @@ is successful, nil if not." :type 'boolean :group 'x) -;; Internal variables - -(defvar x-dnd-known-types +(defcustom x-dnd-known-types '("text/uri-list" "text/x-moz-url" "_NETSCAPE_URL" @@ -121,7 +119,12 @@ is successful, nil if not." "TEXT" ) "The types accepted by default for dropped data. -The types are chosen in the order they appear in the list.") +The types are chosen in the order they appear in the list." + :type '(repeat string) + :group 'x +) + +;; Internal variables (defvar x-dnd-current-state nil "The current state for a drop. @@ -309,14 +312,13 @@ and must have the format file:file-name or file:///file-name. The last / in file:/// is part of the file name. ACTION is ignored." (let* ((f (x-dnd-get-local-file-name uri t))) - (when f - (if (file-readable-p f) - (progn - (if x-dnd-open-file-other-window - (find-file-other-window f) - (find-file f)) - 'private) - (error "Can not read %s (%s)" f uri))))) + (if (and f (file-readable-p f)) + (progn + (if x-dnd-open-file-other-window + (find-file-other-window f) + (find-file f)) + 'private) + (error "Can not read %s" uri)))) (defun x-dnd-open-file (uri action) "Open a local or remote file. @@ -328,7 +330,8 @@ The last / in file://hostname/ is part of the file name." ;; The hostname may be our hostname, in that case, convert to a local ;; file. Otherwise return nil. (let ((local-file (x-dnd-get-local-file-uri uri))) - (when local-file (x-dnd-open-local-file local-file action)))) + (if local-file (x-dnd-open-local-file local-file action) + (error "Remote files not supported")))) (defun x-dnd-handle-moz-url (window action data) @@ -337,7 +340,12 @@ WINDOW is the window where the drop happened. ACTION is ignored. DATA is the moz-url, which is formatted as two strings separated by \r\n. The first string is the URL, the second string is the title of that URL. DATA is encoded in utf-16. Decode the URL and call `x-dnd-handle-uri-list'." - (let* ((string (decode-coding-string data 'utf-16le)) ;; ALWAYS LE??? + ;; Mozilla and applications based on it (Galeon for example) uses + ;; text/unicode, but it is impossible to tell if it is le or be. Use what + ;; the machine Emacs runs on use. This looses if dropping between machines + ;; with different endian, but it is the best we can do. + (let* ((coding (if (eq (byteorder) ?B) 'utf-16be 'utf-16le)) + (string (decode-coding-string data coding)) (strings (split-string string "[\r\n]" t)) ;; Can one drop more than one moz-url ?? Assume not. (url (car strings)) @@ -352,7 +360,9 @@ TEXT is the text as a string, WINDOW is the window where the drop happened." (defun x-dnd-insert-utf16-text (window action text) "Decode the UTF-16 text and insert it at point. TEXT is the text as a string, WINDOW is the window where the drop happened." - (x-dnd-insert-text window action (decode-coding-string text 'utf-16le))) + ;; See comment in x-dnd-handle-moz-url about coding. + (let ((coding (if (eq (byteorder) ?B) 'utf-16be 'utf-16le))) + (x-dnd-insert-text window action (decode-coding-string text coding)))) (defun x-dnd-insert-ctext (window action text) "Decode the compound text and insert it at point. @@ -859,7 +869,7 @@ FORMAT is 32 (not used). MESSAGE is the data part of an XClientMessageEvent." timestamp) (x-dnd-forget-drop frame))) - (t (error "Unknown Motif DND message %s %s" message data))))) + (t (error "Unknown Motif DND message %s %s" message-atom data))))) ;;;