comparison lisp/mouse.el @ 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 8ed435ca9650
children 27afcc69725a
comparison
equal deleted inserted replaced
5026:6a3e9555cee3 5027:38980ea73075
160 (point)) 160 (point))
161 161
162 (defvar mouse-drag-overlay (make-overlay 1 1)) 162 (defvar mouse-drag-overlay (make-overlay 1 1))
163 (overlay-put mouse-drag-overlay 'face 'region) 163 (overlay-put mouse-drag-overlay 'face 'region)
164 164
165 (defvar mouse-selection-click-count nil) 165 (defvar mouse-selection-click-count 0)
166 166
167 (defun mouse-drag-region (start-event) 167 (defun mouse-drag-region (start-event)
168 "Set the region to the text that the mouse is dragged over. 168 "Set the region to the text that the mouse is dragged over.
169 Highlight the drag area as you move the mouse. 169 Highlight the drag area as you move the mouse.
170 This must be bound to a button-down mouse event. 170 This must be bound to a button-down mouse event.
376 ;;; A list (TEXT START END), describing the text and position of the last 376 ;;; A list (TEXT START END), describing the text and position of the last
377 ;;; invocation of mouse-save-then-kill. 377 ;;; invocation of mouse-save-then-kill.
378 (defvar mouse-save-then-kill-posn nil) 378 (defvar mouse-save-then-kill-posn nil)
379 379
380 (defun mouse-save-then-kill-delete-region (beg end) 380 (defun mouse-save-then-kill-delete-region (beg end)
381 ;; Delete just one char, so in case buffer is being modified 381 (if (or (= beg end) (eq buffer-undo-list t))
382 ;; for the first time, the undo list records that fact. 382 ;; If we have no undo list in this buffer,
383 (delete-region beg 383 ;; just delete.
384 (+ beg (if (> end beg) 1 -1))) 384 (delete-region beg end)
385 (let ((buffer-undo-list buffer-undo-list)) 385 ;; Delete, but make the undo-list entry share with the kill ring.
386 ;; Undo that deletion--but don't change the undo list! 386 ;; First, delete just one char, so in case buffer is being modified
387 (primitive-undo 1 buffer-undo-list) 387 ;; for the first time, the undo list records that fact.
388 ;; Now delete the rest of the specified region, 388 (delete-region beg
389 ;; but don't record it. 389 (+ beg (if (> end beg) 1 -1)))
390 (setq buffer-undo-list t) 390 (let ((buffer-undo-list buffer-undo-list))
391 (delete-region beg end)) 391 ;; Undo that deletion--but don't change the undo list!
392 (if (not (eq buffer-undo-list t)) 392 (primitive-undo 1 buffer-undo-list)
393 (let ((tail buffer-undo-list)) 393 ;; Now delete the rest of the specified region,
394 ;; Search back in buffer-undo-list for the string 394 ;; but don't record it.
395 ;; that came from the first delete-region. 395 (setq buffer-undo-list t)
396 (while (and tail (not (stringp (car (car tail))))) 396 (delete-region beg end))
397 (setq tail (cdr tail))) 397 (let ((tail buffer-undo-list))
398 ;; Replace it with an entry for the entire deleted text. 398 ;; Search back in buffer-undo-list for the string
399 (and tail 399 ;; that came from deleting one character.
400 (setcar tail (cons (car kill-ring) (min beg end))))))) 400 (while (and tail (not (stringp (car (car tail)))))
401 (setq tail (cdr tail)))
402 ;; Replace it with an entry for the entire deleted text.
403 (and tail
404 (setcar tail (cons (car kill-ring) (min beg end)))))))
401 405
402 (defun mouse-save-then-kill (click) 406 (defun mouse-save-then-kill (click)
403 "Save text to point in kill ring; the second time, kill the text. 407 "Save text to point in kill ring; the second time, kill the text.
404 If the text between point and the mouse is the same as what's 408 If the text between point and the mouse is the same as what's
405 at the front of the kill ring, this deletes the text. 409 at the front of the kill ring, this deletes the text.
439 (setq mouse-save-then-kill-posn 443 (setq mouse-save-then-kill-posn
440 (list (car kill-ring) (point) click-posn)) 444 (list (car kill-ring) (point) click-posn))
441 (mouse-show-mark)) 445 (mouse-show-mark))
442 ;; If we click this button again without moving it, 446 ;; If we click this button again without moving it,
443 ;; that time kill. 447 ;; that time kill.
444 (mouse-save-then-kill-delete-region (point) (mark))) 448 (mouse-save-then-kill-delete-region (point) (mark))
449 (setq mouse-selection-click-count 0)
450 (setq mouse-save-then-kill-posn nil))
445 (if (and (eq last-command 'mouse-save-then-kill) 451 (if (and (eq last-command 'mouse-save-then-kill)
446 mouse-save-then-kill-posn 452 mouse-save-then-kill-posn
447 (eq (car mouse-save-then-kill-posn) (car kill-ring)) 453 (eq (car mouse-save-then-kill-posn) (car kill-ring))
448 (equal (cdr mouse-save-then-kill-posn) (list (point) click-posn))) 454 (equal (cdr mouse-save-then-kill-posn) (list (point) click-posn)))
449 ;; If this is the second time we've called 455 ;; If this is the second time we've called
450 ;; mouse-save-then-kill, delete the text from the buffer. 456 ;; mouse-save-then-kill, delete the text from the buffer.
451 (mouse-save-then-kill-delete-region (point) (mark)) 457 (progn
452 (if (or (eq last-command 'mouse-save-then-kill) 458 (mouse-save-then-kill-delete-region (point) (mark))
459 ;; After we kill, another click counts as "the first time".
460 (setq mouse-save-then-kill-posn nil))
461 (if (or (and (eq last-command 'mouse-save-then-kill)
462 mouse-save-then-kill-posn)
453 (and mark-active transient-mark-mode) 463 (and mark-active transient-mark-mode)
454 (and (eq last-command 'mouse-drag-region) 464 (and (eq last-command 'mouse-drag-region)
455 (or mark-even-if-inactive 465 (or mark-even-if-inactive
456 (not transient-mark-mode)))) 466 (not transient-mark-mode))))
457 ;; We have a selection or suitable region, so adjust it. 467 ;; We have a selection or suitable region, so adjust it.
683 ;; that time kill. 693 ;; that time kill.
684 (progn 694 (progn
685 (mouse-save-then-kill-delete-region 695 (mouse-save-then-kill-delete-region
686 (overlay-start mouse-secondary-overlay) 696 (overlay-start mouse-secondary-overlay)
687 (overlay-end mouse-secondary-overlay)) 697 (overlay-end mouse-secondary-overlay))
698 (setq mouse-save-then-kill-posn nil)
699 (setq mouse-selection-click-count 0)
688 (delete-overlay mouse-secondary-overlay))) 700 (delete-overlay mouse-secondary-overlay)))
689 (if (and (eq last-command 'mouse-secondary-save-then-kill) 701 (if (and (eq last-command 'mouse-secondary-save-then-kill)
690 mouse-save-then-kill-posn 702 mouse-save-then-kill-posn
691 (eq (car mouse-save-then-kill-posn) (car kill-ring)) 703 (eq (car mouse-save-then-kill-posn) (car kill-ring))
692 (equal (cdr mouse-save-then-kill-posn) (list (point) click-posn))) 704 (equal (cdr mouse-save-then-kill-posn) (list (point) click-posn)))
694 ;; mouse-secondary-save-then-kill, delete the text from the buffer. 706 ;; mouse-secondary-save-then-kill, delete the text from the buffer.
695 (progn 707 (progn
696 (mouse-save-then-kill-delete-region 708 (mouse-save-then-kill-delete-region
697 (overlay-start mouse-secondary-overlay) 709 (overlay-start mouse-secondary-overlay)
698 (overlay-end mouse-secondary-overlay)) 710 (overlay-end mouse-secondary-overlay))
711 (setq mouse-save-then-kill-posn nil)
699 (delete-overlay mouse-secondary-overlay)) 712 (delete-overlay mouse-secondary-overlay))
700 (if (overlay-start mouse-secondary-overlay) 713 (if (overlay-start mouse-secondary-overlay)
701 ;; We have a selection, so adjust it. 714 ;; We have a selection, so adjust it.
702 (progn 715 (progn
703 (select-window (posn-window posn)) 716 (select-window (posn-window posn))