Merge from emacs-23 branch, up to 2010-05-20T21:33:58Z!juri@jurta.org.
[bpt/emacs.git] / lisp / x-dnd.el
index f10506a..23108d5 100644 (file)
@@ -1,11 +1,12 @@
-;;; x-dnd.el --- drag and drop support for X.
+;;; x-dnd.el --- drag and drop support for X  -*- coding: utf-8 -*-
 
-;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009
+;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
 ;;   Free Software Foundation, Inc.
 
-;; Author: Jan Dj\e,Ad\e(Brv <jan.h.d@swipnet.se>
+;; Author: Jan Djรคrv <jan.h.d@swipnet.se>
 ;; Maintainer: FSF
 ;; Keywords: window, drag, drop
+;; Package: emacs
 
 ;; This file is part of GNU Emacs.
 
@@ -52,19 +53,19 @@ The default value for this variable is `x-dnd-default-test-function'."
 
 
 (defcustom x-dnd-types-alist
-  '(
-    ("text/uri-list" . x-dnd-handle-uri-list)
-    ("text/x-moz-url" . x-dnd-handle-moz-url)
-    ("_NETSCAPE_URL" . x-dnd-handle-uri-list)
-    ("FILE_NAME" . x-dnd-handle-file-name)
-    ("UTF8_STRING" . x-dnd-insert-utf8-text)
-    ("text/plain;charset=UTF-8" . x-dnd-insert-utf8-text)
-    ("text/plain;charset=utf-8" . x-dnd-insert-utf8-text)
-    ("text/unicode" . x-dnd-insert-utf16-text)
-    ("text/plain" . dnd-insert-text)
-    ("COMPOUND_TEXT" . x-dnd-insert-ctext)
-    ("STRING" . dnd-insert-text)
-    ("TEXT"   . dnd-insert-text)
+  `(
+    (,(purecopy "text/uri-list") . x-dnd-handle-uri-list)
+    (,(purecopy "text/x-moz-url") . x-dnd-handle-moz-url)
+    (,(purecopy "_NETSCAPE_URL") . x-dnd-handle-uri-list)
+    (,(purecopy "FILE_NAME") . x-dnd-handle-file-name)
+    (,(purecopy "UTF8_STRING") . x-dnd-insert-utf8-text)
+    (,(purecopy "text/plain;charset=UTF-8") . x-dnd-insert-utf8-text)
+    (,(purecopy "text/plain;charset=utf-8") . x-dnd-insert-utf8-text)
+    (,(purecopy "text/unicode") . x-dnd-insert-utf16-text)
+    (,(purecopy "text/plain") . dnd-insert-text)
+    (,(purecopy "COMPOUND_TEXT") . x-dnd-insert-ctext)
+    (,(purecopy "STRING") . dnd-insert-text)
+    (,(purecopy "TEXT")   . dnd-insert-text)
     )
   "Which function to call to handle a drop of that type.
 If the type for the drop is not present, or the function is nil,
@@ -79,6 +80,7 @@ if drop is successful, nil if not."
   :group 'x)
 
 (defcustom x-dnd-known-types
+  (mapcar 'purecopy
   '("text/uri-list"
     "text/x-moz-url"
     "_NETSCAPE_URL"
@@ -91,7 +93,7 @@ if drop is successful, nil if not."
     "COMPOUND_TEXT"
     "STRING"
     "TEXT"
-    )
+    ))
   "The types accepted by default for dropped data.
 The types are chosen in the order they appear in the list."
   :version "22.1"
@@ -174,10 +176,10 @@ action and type we got from `x-dnd-test-function'."
   (let ((buffer (when (window-live-p window)
                  (window-buffer window)))
        (current-state (x-dnd-get-state-for-frame window)))
-    (when (or (not (equal buffer (aref current-state 0)))
-             (not (equal window (aref current-state 1)))
-             (not (equal action (aref current-state 3))))
-      (save-excursion
+    (unless (and (equal buffer (aref current-state 0))
+                 (equal window (aref current-state 1))
+                 (equal action (aref current-state 3)))
+      (save-current-buffer
        (when buffer (set-buffer buffer))
        (let* ((action-type (funcall x-dnd-test-function
                                     window
@@ -218,7 +220,7 @@ 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'."
   ;; 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
+  ;; the machine Emacs runs on use.  This loses 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))
@@ -372,7 +374,7 @@ Currently XDND, Motif and old KDE 1.x protocols are recognized."
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;;  XDND protocol.
 
-(defvar x-dnd-xdnd-to-action
+(defconst x-dnd-xdnd-to-action
   '(("XdndActionPrivate" . private)
     ("XdndActionCopy" . copy)
     ("XdndActionMove" . move)
@@ -764,5 +766,4 @@ FORMAT is 32 (not used).  MESSAGE is the data part of an XClientMessageEvent."
 
 (provide 'x-dnd)
 
-;; arch-tag: b621fb7e-50da-4323-850b-5fc71ae64621
 ;;; x-dnd.el ends here