diff options
| author | Richard M. Stallman | 1993-11-14 06:26:02 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1993-11-14 06:26:02 +0000 |
| commit | 26d280b955a757c21b2c06f2dd9742fa73f63c17 (patch) | |
| tree | a9807deafe2ab5ff36377e90a80ce5849e962391 | |
| parent | 18e90c58467bc1ef12b3905f929c4ca3ca78938b (diff) | |
| download | emacs-26d280b955a757c21b2c06f2dd9742fa73f63c17.tar.gz emacs-26d280b955a757c21b2c06f2dd9742fa73f63c17.zip | |
(mouse-save-then-kill-delete-region): Take args BEG and END.
Update the undo list properly.
(mouse-save-then-kill): Pass those args.
(mouse-secondary-save-then-kll): Pass those args.
Delete the overlay after deleting the selection text.
| -rw-r--r-- | lisp/mouse.el | 41 |
1 files changed, 25 insertions, 16 deletions
diff --git a/lisp/mouse.el b/lisp/mouse.el index 7bdcae71c8d..f6b1fa34bb2 100644 --- a/lisp/mouse.el +++ b/lisp/mouse.el | |||
| @@ -194,7 +194,6 @@ release the mouse button. Otherwise, it does not." | |||
| 194 | (setq event (read-event)) | 194 | (setq event (read-event)) |
| 195 | (or (mouse-movement-p event) | 195 | (or (mouse-movement-p event) |
| 196 | (eq (car-safe event) 'switch-frame))) | 196 | (eq (car-safe event) 'switch-frame))) |
| 197 | |||
| 198 | (if (eq (car-safe event) 'switch-frame) | 197 | (if (eq (car-safe event) 'switch-frame) |
| 199 | nil | 198 | nil |
| 200 | (setq end (event-end event) | 199 | (setq end (event-end event) |
| @@ -378,15 +377,18 @@ This does not delete the region; it acts like \\[kill-ring-save]." | |||
| 378 | ;;; invocation of mouse-save-then-kill. | 377 | ;;; invocation of mouse-save-then-kill. |
| 379 | (defvar mouse-save-then-kill-posn nil) | 378 | (defvar mouse-save-then-kill-posn nil) |
| 380 | 379 | ||
| 381 | (defun mouse-save-then-kill-delete-region () | 380 | (defun mouse-save-then-kill-delete-region (beg end) |
| 382 | ;; Delete just one char, so in case buffer is being modified | 381 | ;; Delete just one char, so in case buffer is being modified |
| 383 | ;; for the first time, the undo list records that fact. | 382 | ;; for the first time, the undo list records that fact. |
| 384 | (delete-region (point) | 383 | (delete-region beg |
| 385 | (+ (point) (if (> (mark) (point)) 1 -1))) | 384 | (+ beg (if (> end beg) 1 -1))) |
| 386 | ;; Now delete the rest of the specified region, | 385 | (let ((buffer-undo-list buffer-undo-list)) |
| 387 | ;; but don't record it. | 386 | ;; Undo that deletion--but don't change the undo list! |
| 388 | (let ((buffer-undo-list t)) | 387 | (primitive-undo 1 buffer-undo-list) |
| 389 | (delete-region (point) (mark))) | 388 | ;; Now delete the rest of the specified region, |
| 389 | ;; but don't record it. | ||
| 390 | (setq buffer-undo-list t) | ||
| 391 | (delete-region beg end)) | ||
| 390 | (if (not (eq buffer-undo-list t)) | 392 | (if (not (eq buffer-undo-list t)) |
| 391 | (let ((tail buffer-undo-list)) | 393 | (let ((tail buffer-undo-list)) |
| 392 | ;; Search back in buffer-undo-list for the string | 394 | ;; Search back in buffer-undo-list for the string |
| @@ -395,7 +397,7 @@ This does not delete the region; it acts like \\[kill-ring-save]." | |||
| 395 | (setq tail (cdr tail))) | 397 | (setq tail (cdr tail))) |
| 396 | ;; Replace it with an entry for the entire deleted text. | 398 | ;; Replace it with an entry for the entire deleted text. |
| 397 | (and tail | 399 | (and tail |
| 398 | (setcar tail (cons (car kill-ring) (point))))))) | 400 | (setcar tail (cons (car kill-ring) (min beg end))))))) |
| 399 | 401 | ||
| 400 | (defun mouse-save-then-kill (click) | 402 | (defun mouse-save-then-kill (click) |
| 401 | "Save text to point in kill ring; the second time, kill the text. | 403 | "Save text to point in kill ring; the second time, kill the text. |
| @@ -439,14 +441,14 @@ If you do this twice in the same position, the selection is killed." | |||
| 439 | (mouse-show-mark)) | 441 | (mouse-show-mark)) |
| 440 | ;; If we click this button again without moving it, | 442 | ;; If we click this button again without moving it, |
| 441 | ;; that time kill. | 443 | ;; that time kill. |
| 442 | (mouse-save-then-kill-delete-region)) | 444 | (mouse-save-then-kill-delete-region (point) (mark))) |
| 443 | (if (and (eq last-command 'mouse-save-then-kill) | 445 | (if (and (eq last-command 'mouse-save-then-kill) |
| 444 | mouse-save-then-kill-posn | 446 | mouse-save-then-kill-posn |
| 445 | (eq (car mouse-save-then-kill-posn) (car kill-ring)) | 447 | (eq (car mouse-save-then-kill-posn) (car kill-ring)) |
| 446 | (equal (cdr mouse-save-then-kill-posn) (list (point) click-posn))) | 448 | (equal (cdr mouse-save-then-kill-posn) (list (point) click-posn))) |
| 447 | ;; If this is the second time we've called | 449 | ;; If this is the second time we've called |
| 448 | ;; mouse-save-then-kill, delete the text from the buffer. | 450 | ;; mouse-save-then-kill, delete the text from the buffer. |
| 449 | (mouse-save-then-kill-delete-region) | 451 | (mouse-save-then-kill-delete-region (point) (mark)) |
| 450 | (if (or (eq last-command 'mouse-save-then-kill) | 452 | (if (or (eq last-command 'mouse-save-then-kill) |
| 451 | (and mark-active transient-mark-mode) | 453 | (and mark-active transient-mark-mode) |
| 452 | (and (eq last-command 'mouse-drag-region) | 454 | (and (eq last-command 'mouse-drag-region) |
| @@ -541,17 +543,20 @@ This must be bound to a button-down mouse event." | |||
| 541 | (save-excursion | 543 | (save-excursion |
| 542 | (set-buffer (window-buffer start-window)) | 544 | (set-buffer (window-buffer start-window)) |
| 543 | (setq mouse-selection-click-count click-count) | 545 | (setq mouse-selection-click-count click-count) |
| 544 | ;; Cancel any preexisting secondary selection. | ||
| 545 | (or mouse-secondary-overlay | 546 | (or mouse-secondary-overlay |
| 546 | (setq mouse-secondary-overlay | 547 | (setq mouse-secondary-overlay |
| 547 | (make-overlay (point) (point)))) | 548 | (make-overlay (point) (point)))) |
| 549 | (overlay-put mouse-secondary-overlay 'face 'secondary-selection) | ||
| 548 | (if (> click-count 0) | 550 | (if (> click-count 0) |
| 551 | ;; Double or triple press: make an initial selection | ||
| 552 | ;; of one word or line. | ||
| 549 | (let ((range (mouse-start-end start-point start-point click-count))) | 553 | (let ((range (mouse-start-end start-point start-point click-count))) |
| 550 | (set-marker mouse-secondary-start nil) | 554 | (set-marker mouse-secondary-start nil) |
| 551 | (move-overlay mouse-secondary-overlay 1 1 | 555 | (move-overlay mouse-secondary-overlay 1 1 |
| 552 | (window-buffer start-window)) | 556 | (window-buffer start-window)) |
| 553 | (move-overlay mouse-secondary-overlay (car range) (nth 1 range) | 557 | (move-overlay mouse-secondary-overlay (car range) (nth 1 range) |
| 554 | (window-buffer start-window))) | 558 | (window-buffer start-window))) |
| 559 | ;; Single-press: cancel any preexisting secondary selection. | ||
| 555 | (or mouse-secondary-start | 560 | (or mouse-secondary-start |
| 556 | (setq mouse-secondary-start (make-marker))) | 561 | (setq mouse-secondary-start (make-marker))) |
| 557 | (set-marker mouse-secondary-start start-point) | 562 | (set-marker mouse-secondary-start start-point) |
| @@ -677,8 +682,10 @@ If you do this twice in the same position, the selection is killed." | |||
| 677 | ;; If we click this button again without moving it, | 682 | ;; If we click this button again without moving it, |
| 678 | ;; that time kill. | 683 | ;; that time kill. |
| 679 | (progn | 684 | (progn |
| 680 | (delete-overlay mouse-secondary-overlay) | 685 | (mouse-save-then-kill-delete-region |
| 681 | (mouse-save-then-kill-delete-region))) | 686 | (overlay-start mouse-secondary-overlay) |
| 687 | (overlay-end mouse-secondary-overlay)) | ||
| 688 | (delete-overlay mouse-secondary-overlay))) | ||
| 682 | (if (and (eq last-command 'mouse-secondary-save-then-kill) | 689 | (if (and (eq last-command 'mouse-secondary-save-then-kill) |
| 683 | mouse-save-then-kill-posn | 690 | mouse-save-then-kill-posn |
| 684 | (eq (car mouse-save-then-kill-posn) (car kill-ring)) | 691 | (eq (car mouse-save-then-kill-posn) (car kill-ring)) |
| @@ -686,8 +693,10 @@ If you do this twice in the same position, the selection is killed." | |||
| 686 | ;; If this is the second time we've called | 693 | ;; If this is the second time we've called |
| 687 | ;; mouse-secondary-save-then-kill, delete the text from the buffer. | 694 | ;; mouse-secondary-save-then-kill, delete the text from the buffer. |
| 688 | (progn | 695 | (progn |
| 689 | (delete-overlay mouse-secondary-overlay) | 696 | (mouse-save-then-kill-delete-region |
| 690 | (mouse-save-then-kill-delete-region)) | 697 | (overlay-start mouse-secondary-overlay) |
| 698 | (overlay-end mouse-secondary-overlay)) | ||
| 699 | (delete-overlay mouse-secondary-overlay)) | ||
| 691 | (if (overlay-start mouse-secondary-overlay) | 700 | (if (overlay-start mouse-secondary-overlay) |
| 692 | ;; We have a selection, so adjust it. | 701 | ;; We have a selection, so adjust it. |
| 693 | (progn | 702 | (progn |