changeset 5027:38980ea73075

(mouse-save-then-kill-delete-region): Take args BEG and END. Update the undo list properly. (mouse-save-then-kill): Pass those args. When we kill, clear mouse-save-then-kill-posn and mouse-selection-click-count. (mouse-secondary-save-then-kill): Likewise. Delete the overlay after deleting the selection text. (mouse-selection-click-count): Initialize to 0. (mouse-save-then-kill-delete-region): Handle buffers with no undo list. Handle empty regions. Handle end < beg.
author Richard M. Stallman <rms@gnu.org>
date Mon, 15 Nov 1993 09:56:05 +0000
parents 6a3e9555cee3
children d7ca9a9d179e
files lisp/mouse.el
diffstat 1 files changed, 37 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/mouse.el	Mon Nov 15 09:25:17 1993 +0000
+++ b/lisp/mouse.el	Mon Nov 15 09:56:05 1993 +0000
@@ -162,7 +162,7 @@
 (defvar mouse-drag-overlay (make-overlay 1 1))
 (overlay-put mouse-drag-overlay 'face 'region)
 
-(defvar mouse-selection-click-count nil)
+(defvar mouse-selection-click-count 0)
 
 (defun mouse-drag-region (start-event)
   "Set the region to the text that the mouse is dragged over.
@@ -378,26 +378,30 @@
 (defvar mouse-save-then-kill-posn nil)
 
 (defun mouse-save-then-kill-delete-region (beg end)
-  ;; Delete just one char, so in case buffer is being modified
-  ;; for the first time, the undo list records that fact.
-  (delete-region beg
-		 (+ beg (if (> end beg) 1 -1)))
-  (let ((buffer-undo-list buffer-undo-list))
-    ;; Undo that deletion--but don't change the undo list!
-    (primitive-undo 1 buffer-undo-list)
-    ;; Now delete the rest of the specified region,
-    ;; but don't record it.
-    (setq buffer-undo-list t)
-    (delete-region beg end))
-  (if (not (eq buffer-undo-list t))
-      (let ((tail buffer-undo-list))
-	;; Search back in buffer-undo-list for the string
-	;; that came from the first delete-region.
-	(while (and tail (not (stringp (car (car tail)))))
-	  (setq tail (cdr tail)))
-	;; Replace it with an entry for the entire deleted text.
-	(and tail
-	     (setcar tail (cons (car kill-ring) (min beg end)))))))
+  (if (or (= beg end) (eq buffer-undo-list t))
+      ;; If we have no undo list in this buffer,
+      ;; just delete.
+      (delete-region beg end)
+    ;; Delete, but make the undo-list entry share with the kill ring.
+    ;; First, delete just one char, so in case buffer is being modified
+    ;; for the first time, the undo list records that fact.
+    (delete-region beg
+		   (+ beg (if (> end beg) 1 -1)))
+    (let ((buffer-undo-list buffer-undo-list))
+      ;; Undo that deletion--but don't change the undo list!
+      (primitive-undo 1 buffer-undo-list)
+      ;; Now delete the rest of the specified region,
+      ;; but don't record it.
+      (setq buffer-undo-list t)
+      (delete-region beg end))
+    (let ((tail buffer-undo-list))
+      ;; Search back in buffer-undo-list for the string
+      ;; that came from deleting one character.
+      (while (and tail (not (stringp (car (car tail)))))
+	(setq tail (cdr tail)))
+      ;; Replace it with an entry for the entire deleted text.
+      (and tail
+	   (setcar tail (cons (car kill-ring) (min beg end)))))))
 
 (defun mouse-save-then-kill (click)
   "Save text to point in kill ring; the second time, kill the text.
@@ -441,15 +445,21 @@
 	      (mouse-show-mark))
 	  ;; If we click this button again without moving it,
 	  ;; that time kill.
-	  (mouse-save-then-kill-delete-region (point) (mark)))
+	  (mouse-save-then-kill-delete-region (point) (mark))
+	  (setq mouse-selection-click-count 0)
+	  (setq mouse-save-then-kill-posn nil))
       (if (and (eq last-command 'mouse-save-then-kill)
 	       mouse-save-then-kill-posn
 	       (eq (car mouse-save-then-kill-posn) (car kill-ring))
 	       (equal (cdr mouse-save-then-kill-posn) (list (point) click-posn)))
 	  ;; If this is the second time we've called
 	  ;; mouse-save-then-kill, delete the text from the buffer.
-	  (mouse-save-then-kill-delete-region (point) (mark))
-	(if (or (eq last-command 'mouse-save-then-kill)
+	  (progn
+	    (mouse-save-then-kill-delete-region (point) (mark))
+	    ;; After we kill, another click counts as "the first time".
+	    (setq mouse-save-then-kill-posn nil))
+	(if (or (and (eq last-command 'mouse-save-then-kill)
+		     mouse-save-then-kill-posn)
 		(and mark-active transient-mark-mode)
 		(and (eq last-command 'mouse-drag-region)
 		     (or mark-even-if-inactive
@@ -685,6 +695,8 @@
 	    (mouse-save-then-kill-delete-region
 	     (overlay-start mouse-secondary-overlay)
 	     (overlay-end mouse-secondary-overlay))
+	    (setq mouse-save-then-kill-posn nil)
+	    (setq mouse-selection-click-count 0)
 	    (delete-overlay mouse-secondary-overlay)))
       (if (and (eq last-command 'mouse-secondary-save-then-kill)
 	       mouse-save-then-kill-posn
@@ -696,6 +708,7 @@
 	    (mouse-save-then-kill-delete-region
 	     (overlay-start mouse-secondary-overlay)
 	     (overlay-end mouse-secondary-overlay))
+	    (setq mouse-save-then-kill-posn nil)
 	    (delete-overlay mouse-secondary-overlay))
 	(if (overlay-start mouse-secondary-overlay)
 	    ;; We have a selection, so adjust it.