changeset 10720:4526bdcc806e

(mouse-drag-region): Delete the overlay before calling the terminating event's command binding or making a region. (mouse-set-region-1): New function. (mouse-drag-region, mouse-set-region, mouse-save-then-kill): Call it. (mouse-region-match): New function.
author Richard M. Stallman <rms@gnu.org>
date Sun, 12 Feb 1995 04:51:42 +0000
parents 40ae63b409f4
children 3d056c5a8319
files lisp/mouse.el
diffstat 1 files changed, 29 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/mouse.el	Sun Feb 12 04:29:53 1995 +0000
+++ b/lisp/mouse.el	Sun Feb 12 04:51:42 1995 +0000
@@ -292,6 +292,17 @@
     (if (numberp (posn-point posn))
 	(goto-char (posn-point posn)))))
 
+(defvar mouse-last-region-beg nil)
+(defvar mouse-last-region-end nil)
+(defvar mouse-last-region-tick nil)
+
+(defun mouse-region-match ()
+  "Return non-nil if there's an active region that was set with the mouse."
+  (and (mark t) mark-active
+       (eq mouse-last-region-beg (region-beginning))
+       (eq mouse-last-region-end (region-end))
+       (eq mouse-last-region-tick (buffer-modified-tick))))
+
 (defun mouse-set-region (click)
   "Set the region to the text dragged over, and copy to kill ring.
 This should be bound to a mouse drag event."
@@ -313,7 +324,13 @@
     ;; Don't set this-command to kill-region, so that a following
     ;; C-w will not double the text in the kill ring.
     (let (this-command)
-      (copy-region-as-kill (mark) (point)))))
+      (copy-region-as-kill (mark) (point)))
+    (mouse-set-region-1)))
+
+(defun mouse-set-region-1 ()
+  (setq mouse-last-region-beg (region-beginning))
+  (setq mouse-last-region-end (region-end))
+  (setq mouse-last-region-tick (buffer-modified-tick)))
 
 (defvar mouse-scroll-delay 0.25
   "*The pause between scroll steps caused by mouse drags, in seconds.
@@ -420,16 +437,22 @@
 	    (if (and (= (mod mouse-selection-click-count 3) 0) (fboundp fun))
 		(progn
 		  (setq this-command fun)
+		  ;; Delete the overlay before calling the function,
+		  ;; because delete-overlay increases buffer-modified-tick.
+		  (delete-overlay mouse-drag-overlay)
 		  (funcall fun event))
 	      (if (not (= (overlay-start mouse-drag-overlay)
 			  (overlay-end mouse-drag-overlay)))
 		  (let (last-command this-command)
 		    (push-mark (overlay-start mouse-drag-overlay) t t)
 		    (goto-char (overlay-end mouse-drag-overlay))
-		    (copy-region-as-kill (point) (mark t)))
+		    (delete-overlay mouse-drag-overlay)
+		    (copy-region-as-kill (point) (mark t))
+		    (mouse-set-region-1))
 		(goto-char (overlay-end mouse-drag-overlay))
-		(setq this-command 'mouse-set-point)))))
-      (delete-overlay mouse-drag-overlay))))
+		(setq this-command 'mouse-set-point)
+		(delete-overlay mouse-drag-overlay))))
+	(delete-overlay mouse-drag-overlay)))))
 
 ;; Commands to handle xterm-style multiple clicks.
 
@@ -644,6 +667,7 @@
 		;; Replace it with the extended region.
 		;; (It would be annoying to make a separate entry.)
 		(kill-new (buffer-substring (point) (mark t)) t)
+		(mouse-set-region-1)
 		;; Arrange for a repeated mouse-3 to kill this region.
 		(setq mouse-save-then-kill-posn
 		      (list (car kill-ring) (point) click-posn))
@@ -690,6 +714,7 @@
 	    (exchange-point-and-mark)
 	    (kill-ring-save (point) (mark t)))
 	  (mouse-show-mark)
+	  (mouse-set-region-1)
 	  (setq mouse-save-then-kill-posn
 		(list (car kill-ring) (point) click-posn)))))))