aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman1995-01-26 07:21:05 +0000
committerRichard M. Stallman1995-01-26 07:21:05 +0000
commitb64548c7851dd063fd5a138e39eff00af1087ed4 (patch)
tree358ce91d4f55137f0d661f61f440c42fc6c85453
parent8f37c4f3dfb99fe1d534eeb93d08979345ea8957 (diff)
downloademacs-b64548c7851dd063fd5a138e39eff00af1087ed4.tar.gz
emacs-b64548c7851dd063fd5a138e39eff00af1087ed4.zip
(mouse-save-then-kill): When we don't use existing
region, put where click and put mark at the other end. Use point-before-scroll if non-nil. Recognize mouse-set-region as a previous command that makes a region we should use. (mouse-drag-region): When we run the final click's binding, set this-command.
-rw-r--r--lisp/mouse.el139
1 files changed, 73 insertions, 66 deletions
diff --git a/lisp/mouse.el b/lisp/mouse.el
index 48ec86079a3..276d67da286 100644
--- a/lisp/mouse.el
+++ b/lisp/mouse.el
@@ -418,7 +418,9 @@ release the mouse button. Otherwise, it does not."
418 ;; In the case of a multiple click, it gives the wrong results, 418 ;; In the case of a multiple click, it gives the wrong results,
419 ;; because it would fail to set up a region. 419 ;; because it would fail to set up a region.
420 (if (and (= (mod mouse-selection-click-count 3) 0) (fboundp fun)) 420 (if (and (= (mod mouse-selection-click-count 3) 0) (fboundp fun))
421 (funcall fun event) 421 (progn
422 (setq this-command fun)
423 (funcall fun event))
422 (if (not (= (overlay-start mouse-drag-overlay) 424 (if (not (= (overlay-start mouse-drag-overlay)
423 (overlay-end mouse-drag-overlay))) 425 (overlay-end mouse-drag-overlay)))
424 (let (last-command this-command) 426 (let (last-command this-command)
@@ -618,73 +620,78 @@ selection through the word or line clicked on. If you do this
618again in a different position, it extends the selection again. 620again in a different position, it extends the selection again.
619If you do this twice in the same position, the selection is killed." 621If you do this twice in the same position, the selection is killed."
620 (interactive "e") 622 (interactive "e")
621 (mouse-minibuffer-check click) 623 (let ((before-scroll point-before-scroll))
622 (let ((click-posn (posn-point (event-start click))) 624 (mouse-minibuffer-check click)
623 ;; Don't let a subsequent kill command append to this one: 625 (let ((click-posn (posn-point (event-start click)))
624 ;; prevent setting this-command to kill-region. 626 ;; Don't let a subsequent kill command append to this one:
625 (this-command this-command)) 627 ;; prevent setting this-command to kill-region.
626 (if (and (mark t) (> (mod mouse-selection-click-count 3) 0)) 628 (this-command this-command))
627 (if (not (and (eq last-command 'mouse-save-then-kill) 629 (if (and (mark t) (> (mod mouse-selection-click-count 3) 0))
628 (equal click-posn 630 (if (not (and (eq last-command 'mouse-save-then-kill)
629 (car (cdr-safe (cdr-safe mouse-save-then-kill-posn)))))) 631 (equal click-posn
630 ;; Find both ends of the object selected by this click. 632 (car (cdr-safe (cdr-safe mouse-save-then-kill-posn))))))
631 (let* ((range 633 ;; Find both ends of the object selected by this click.
632 (mouse-start-end click-posn click-posn 634 (let* ((range
633 mouse-selection-click-count))) 635 (mouse-start-end click-posn click-posn
634 ;; Move whichever end is closer to the click. 636 mouse-selection-click-count)))
635 ;; That's what xterm does, and it seems reasonable. 637 ;; Move whichever end is closer to the click.
636 (if (< (abs (- click-posn (mark t))) 638 ;; That's what xterm does, and it seems reasonable.
637 (abs (- click-posn (point)))) 639 (if (< (abs (- click-posn (mark t)))
638 (set-mark (car range)) 640 (abs (- click-posn (point))))
639 (goto-char (nth 1 range))) 641 (set-mark (car range))
640 ;; We have already put the old region in the kill ring. 642 (goto-char (nth 1 range)))
641 ;; Replace it with the extended region. 643 ;; We have already put the old region in the kill ring.
642 ;; (It would be annoying to make a separate entry.) 644 ;; Replace it with the extended region.
643 (kill-new (buffer-substring (point) (mark t)) t) 645 ;; (It would be annoying to make a separate entry.)
644 ;; Arrange for a repeated mouse-3 to kill this region. 646 (kill-new (buffer-substring (point) (mark t)) t)
645 (setq mouse-save-then-kill-posn 647 ;; Arrange for a repeated mouse-3 to kill this region.
646 (list (car kill-ring) (point) click-posn)) 648 (setq mouse-save-then-kill-posn
647 (mouse-show-mark)) 649 (list (car kill-ring) (point) click-posn))
648 ;; If we click this button again without moving it, 650 (mouse-show-mark))
649 ;; that time kill. 651 ;; If we click this button again without moving it,
650 (mouse-save-then-kill-delete-region (point) (mark)) 652 ;; that time kill.
651 (setq mouse-selection-click-count 0)
652 (setq mouse-save-then-kill-posn nil))
653 (if (and (eq last-command 'mouse-save-then-kill)
654 mouse-save-then-kill-posn
655 (eq (car mouse-save-then-kill-posn) (car kill-ring))
656 (equal (cdr mouse-save-then-kill-posn) (list (point) click-posn)))
657 ;; If this is the second time we've called
658 ;; mouse-save-then-kill, delete the text from the buffer.
659 (progn
660 (mouse-save-then-kill-delete-region (point) (mark)) 653 (mouse-save-then-kill-delete-region (point) (mark))
661 ;; After we kill, another click counts as "the first time". 654 (setq mouse-selection-click-count 0)
662 (setq mouse-save-then-kill-posn nil)) 655 (setq mouse-save-then-kill-posn nil))
663 (if (or (and (eq last-command 'mouse-save-then-kill) 656 (if (and (eq last-command 'mouse-save-then-kill)
664 mouse-save-then-kill-posn) 657 mouse-save-then-kill-posn
665 (and mark-active transient-mark-mode) 658 (eq (car mouse-save-then-kill-posn) (car kill-ring))
666 (and (eq last-command 'mouse-drag-region) 659 (equal (cdr mouse-save-then-kill-posn) (list (point) click-posn)))
667 (or mark-even-if-inactive 660 ;; If this is the second time we've called
668 (not transient-mark-mode)))) 661 ;; mouse-save-then-kill, delete the text from the buffer.
669 ;; We have a selection or suitable region, so adjust it. 662 (progn
670 (let* ((posn (event-start click)) 663 (mouse-save-then-kill-delete-region (point) (mark))
671 (new (posn-point posn))) 664 ;; After we kill, another click counts as "the first time".
672 (select-window (posn-window posn)) 665 (setq mouse-save-then-kill-posn nil))
673 (if (numberp new) 666 (if (or (and (eq last-command 'mouse-save-then-kill)
674 (progn 667 mouse-save-then-kill-posn)
675 ;; Move whichever end of the region is closer to the click. 668 (and mark-active transient-mark-mode)
676 ;; That is what xterm does, and it seems reasonable. 669 (and (memq last-command
677 (if (< (abs (- new (point))) (abs (- new (mark t)))) 670 '(mouse-drag-region mouse-set-region))
678 (goto-char new) 671 (or mark-even-if-inactive
679 (set-mark new)) 672 (not transient-mark-mode))))
680 (setq deactivate-mark nil))) 673 ;; We have a selection or suitable region, so adjust it.
681 (kill-new (buffer-substring (point) (mark t)) t)) 674 (let* ((posn (event-start click))
682 ;; We just have point, so set mark here. 675 (new (posn-point posn)))
683 (mouse-set-mark-fast click) 676 (select-window (posn-window posn))
684 (kill-ring-save (point) (mark t))) 677 (if (numberp new)
685 (mouse-show-mark) 678 (progn
686 (setq mouse-save-then-kill-posn 679 ;; Move whichever end of the region is closer to the click.
687 (list (car kill-ring) (point) click-posn)))))) 680 ;; That is what xterm does, and it seems reasonable.
681 (if (< (abs (- new (point))) (abs (- new (mark t))))
682 (goto-char new)
683 (set-mark new))
684 (setq deactivate-mark nil)))
685 (kill-new (buffer-substring (point) (mark t)) t))
686 ;; Set the mark where point is, then move where clicked.
687 (mouse-set-mark-fast click)
688 (if before-scroll
689 (goto-char before-scroll))
690 (exchange-point-and-mark)
691 (kill-ring-save (point) (mark t)))
692 (mouse-show-mark)
693 (setq mouse-save-then-kill-posn
694 (list (car kill-ring) (point) click-posn)))))))
688 695
689(global-set-key [M-mouse-1] 'mouse-start-secondary) 696(global-set-key [M-mouse-1] 'mouse-start-secondary)
690(global-set-key [M-drag-mouse-1] 'mouse-set-secondary) 697(global-set-key [M-drag-mouse-1] 'mouse-set-secondary)