]> git.eshelyaron.com Git - emacs.git/commitdiff
(mouse-save-then-kill-delete-region): Take args BEG and END.
authorRichard M. Stallman <rms@gnu.org>
Mon, 15 Nov 1993 09:56:05 +0000 (09:56 +0000)
committerRichard M. Stallman <rms@gnu.org>
Mon, 15 Nov 1993 09:56:05 +0000 (09:56 +0000)
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.

lisp/mouse.el

index f6b1fa34bb21b66f2c04d926438f97fb4ec72032..302e2cf18bc2e3e4df5185a24d9d2a16ec2d6c6b 100644 (file)
@@ -162,7 +162,7 @@ Upon exit, point is at the far edge of the newly visible text."
 (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 @@ This does not delete the region; it acts like \\[kill-ring-save]."
 (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 @@ If you do this twice in the same position, the selection is killed."
              (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 @@ If you do this twice in the same position, the selection is killed."
            (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 @@ If you do this twice in the same position, the selection is killed."
            (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.