]> git.eshelyaron.com Git - emacs.git/commitdiff
* w32-fns.el (x-selection-owner-p): New function.
authorChong Yidong <cyd@stupidchicken.com>
Fri, 17 Jul 2009 15:45:08 +0000 (15:45 +0000)
committerChong Yidong <cyd@stupidchicken.com>
Fri, 17 Jul 2009 15:45:08 +0000 (15:45 +0000)
* mouse.el (mouse-drag-track): Call deactivate-mark earlier.
(mouse-yank-at-click): If select-active-regions is non-nil,
deactivate the mark before insertion.

* simple.el (deactivate-mark, set-mark): Only save selection if we
own it.

lisp/ChangeLog
lisp/mouse.el
lisp/simple.el
lisp/w32-fns.el

index b17cac00cd63815a7f7cbf518671cb06a566be7a..e3a342032a2d1df24e7f0d8fdb802e8e3abd0cc1 100644 (file)
@@ -1,3 +1,14 @@
+2009-07-17  David De La Harpe Golden  <david@harpegolden.net>
+
+       * w32-fns.el (x-selection-owner-p): New function.
+
+       * mouse.el (mouse-drag-track): Call deactivate-mark earlier.
+       (mouse-yank-at-click): If select-active-regions is non-nil,
+       deactivate the mark before insertion.
+
+       * simple.el (deactivate-mark, set-mark): Only save selection if we
+       own it.
+
 2009-07-17  Kenichi Handa  <handa@m17n.org>
 
        * case-table.el (describe-buffer-case-table): Fix for the case
index 03f73ba8d9ce7886d647761255c29ad50edc4727..7b7f6927debce28d3771563d944b05b8afaf1d50 100644 (file)
@@ -927,6 +927,11 @@ will be deleted after return.  DO-MOUSE-DRAG-REGION-POST-PROCESS
 should only be used by mouse-drag-region."
   (mouse-minibuffer-check start-event)
   (setq mouse-selection-click-count-buffer (current-buffer))
+  ;; We must call deactivate-mark before repositioning point.
+  ;; Otherwise, for select-active-regions non-nil, we get the wrong
+  ;; selection if the user drags a region, clicks elsewhere to
+  ;; reposition point, then middle-clicks to paste the selection.
+  (deactivate-mark)
   (let* ((original-window (selected-window))
          ;; We've recorded what we needed from the current buffer and
          ;; window, now let's jump to the place of the event, where things
@@ -971,7 +976,6 @@ should only be used by mouse-drag-region."
     (mouse-move-drag-overlay mouse-drag-overlay start-point start-point
                              click-count)
     (overlay-put mouse-drag-overlay 'window start-window)
-    (deactivate-mark)
     (let (event end end-point last-end-point)
       (track-mouse
        (while (progn
@@ -1360,10 +1364,16 @@ Also move point to one end of the text thus inserted (normally the end),
 and set mark at the beginning.
 Prefix arguments are interpreted as with \\[yank].
 If `mouse-yank-at-point' is non-nil, insert at point
-regardless of where you click."
+regardless of where you click.
+If `select-active-regions' is non-nil, the mark is deactivated
+before inserting the text."
   (interactive "e\nP")
   ;; Give temporary modes such as isearch a chance to turn off.
   (run-hooks 'mouse-leave-buffer-hook)
+  (when select-active-regions
+    ;; Without this, confusing things happen upon e.g. inserting into
+    ;; the middle of an active region.
+    (deactivate-mark t))
   (or mouse-yank-at-point (mouse-set-point click))
   (setq this-command 'yank)
   (setq mouse-selection-click-count 0)
index 959076b11cbdfa0ed558f0ec6802c24eb6b5a3c7..1e0f83152cfb5708ce686a83f2a9f7b992fcf79c 100644 (file)
@@ -3489,6 +3489,7 @@ This function also runs `deactivate-mark-hook'."
     ;; Copy the latest region into the primary selection, if desired.
     (and select-active-regions
         mark-active
+        (x-selection-owner-p 'PRIMARY)
         (x-set-selection 'PRIMARY (buffer-substring-no-properties
                                    (region-beginning) (region-end))))
     (if (and (null force)
@@ -3533,8 +3534,12 @@ store it in a Lisp variable.  Example:
       (progn
        (setq mark-active t)
        (run-hooks 'activate-mark-hook)
-       (when select-active-regions
-         (x-set-selection 'PRIMARY (current-buffer)))
+       (and select-active-regions
+            ;; Only set the selection if we already own PRIMARY.  The
+            ;; initial selection grab happens in `activate-mark', but
+            ;; it is necessary to update it here.
+            (x-selection-owner-p 'PRIMARY)
+            (x-set-selection 'PRIMARY (current-buffer)))
        (set-marker (mark-marker) pos (current-buffer)))
     ;; Normally we never clear mark-active except in Transient Mark mode.
     ;; But when we actually clear out the mark value too, we must
index 379dd63eb17be48f57461d9efbebf5f6873de24f..c0aab365070fc57360cf7a17cb16b1a7354dbd7d 100644 (file)
@@ -294,12 +294,15 @@ shell requires it (see `w32-shell-dos-semantics')."
 
 ;;; Fix interface to (X-specific) mouse.el
 (defun x-set-selection (type data)
-  (or type (setq type 'PRIMARY))
-  (put 'x-selections type data))
+  (put 'x-selections (or type 'PRIMARY) data))
 
 (defun x-get-selection (&optional type data-type)
-  (or type (setq type 'PRIMARY))
-  (get 'x-selections type))
+  (get 'x-selections (or type 'PRIMARY)))
+
+;; x-selection-owner-p is used in simple.el
+(defun x-selection-owner-p (&optional type)
+  (and (memq type '(nil PRIMARY SECONDARY))
+       (get 'x-selections (or type 'PRIMARY))))
 
 (defun set-w32-system-coding-system (coding-system)
   "Set the coding system used by the Windows system to CODING-SYSTEM.