Index: lisp/mouse.el =================================================================== RCS file: /sources/emacs/emacs/lisp/mouse.el,v retrieving revision 1.327 diff -u -d -r1.327 mouse.el --- lisp/mouse.el 7 Feb 2008 06:20:25 -0000 1.327 +++ lisp/mouse.el 13 Feb 2008 01:53:32 -0000 @@ -1394,6 +1394,19 @@ (kill-ring-save (point) (mark t))) (mouse-show-mark)) +(defcustom mouse-save-then-kill-copy-region t + "Says how many clicks are needed for \\[mouse-save-then-kill] to save then kill. + +Never: only adjust region, never kill. +Single: adjust region and save on single click, kill on second click. +Double: adjust region on first click, save on second, kill on third." + +:type '(choice (const :tag "Never" nil) + (const :tag "Single" t) + (const :tag "Double" :double)) +:group 'mouse +:version "23.1") + ;;; This function used to delete the text between point and the mouse ;;; whenever it was equal to the front of the kill ring, but some ;;; people found that confusing. @@ -1437,7 +1450,14 @@ (undo-boundary)) (defun mouse-save-then-kill (click) - "Save text to point in kill ring; the second time, kill the text. + "Depending on click count, adjust region, save to kill ring, or kill. + +Behaviour customized by `mouse-save-then-kill-copy-region'. If that +is nil, clicking merely adjusts the region. If :double, single +clicking adjusts the region, double clicking saves text to kill +ring, triple clicking kills the text. If t, single clicking saves +text to kill ring, double clicking kills. + If the text between point and the mouse is the same as what's at the front of the kill ring, this deletes the text. Otherwise, it adds the text to the kill ring, like \\[kill-ring-save], @@ -1446,7 +1466,7 @@ If you have selected words or lines, this command extends the selection through the word or line clicked on. If you do this again in a different position, it extends the selection again. -If you do this twice in the same position, the selection is killed." +" (interactive "e") (let ((before-scroll (with-current-buffer (window-buffer (posn-window (event-start click))) @@ -1462,6 +1482,7 @@ ;; Don't be fooled by a recent click in some other buffer. (eq mouse-selection-click-count-buffer (current-buffer))))) + ;; moving by words/lines (if (not (and (eq last-command 'mouse-save-then-kill) (equal click-posn (car (cdr-safe (cdr-safe mouse-save-then-kill-posn)))))) @@ -1475,30 +1496,58 @@ (abs (- click-posn (point)))) (set-mark (car range)) (goto-char (nth 1 range))) - ;; We have already put the old region in the kill ring. - ;; Replace it with the extended region. - ;; (It would be annoying to make a separate entry.) - (kill-new (buffer-substring (point) (mark t)) t) + + (cond ((eq mouse-save-then-kill-copy-region t) ; save on first click + ;; We have already put the old region in the kill ring. + ;; Replace it with the extended region. + ;; (It would be annoying to make a separate entry.) + (kill-new (buffer-substring (point) (mark t)) t) + ;; Arrange for a repeated mouse-3 to kill this region. + (setq mouse-save-then-kill-posn + (list (car kill-ring) (point) click-posn))) + ((eq mouse-save-then-kill-copy-region :double) ; no save on first click + ;; no save on first click, but need to know region + ;; from first. nil for saved kill ring top used for + ;; limbo between second and third clicks + (setq mouse-save-then-kill-posn + (list nil (point) click-posn)))) (mouse-set-region-1) - ;; Arrange for a repeated mouse-3 to kill this region. - (setq mouse-save-then-kill-posn - (list (car kill-ring) (point) click-posn)) (mouse-show-mark)) - ;; If we click this button again without moving it, - ;; that time kill. - (mouse-save-then-kill-delete-region (mark) (point)) - (setq mouse-selection-click-count 0) - (setq mouse-save-then-kill-posn nil)) - (if (and (eq last-command 'mouse-save-then-kill) + (cond ((eq mouse-save-then-kill-copy-region t) ; kill on second click + ;; If we click this button again without moving it, + ;; that time kill. + (mouse-save-then-kill-delete-region (mark) (point)) + (setq mouse-selection-click-count 0) + (setq mouse-save-then-kill-posn nil)) + ((eq mouse-save-then-kill-copy-region :double) ;save on second/kill on third + (if (car-safe mouse-save-then-kill-posn) ; kill on third + (progn + (mouse-save-then-kill-delete-region (mark) (point)) + (setq mouse-selection-click-count 0) + (setq mouse-save-then-kill-posn nil)) + (progn ; save on second + (kill-new (buffer-substring (point) (mark t)) t) + (setq mouse-save-then-kill-posn + (list (car kill-ring) (point) click-posn))))))) + ;; moving by chars + (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. - (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)) + (equal (cdr-safe mouse-save-then-kill-posn) (list (point) click-posn))) + (cond ((eq mouse-save-then-kill-copy-region t) ; kill on second click + ;; 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)) + ;; After we kill, another click counts as "the first time". + (setq mouse-save-then-kill-posn nil)) + ((eq mouse-save-then-kill-copy-region :double) ; save on second / kill on third + (if (car-safe mouse-save-then-kill-posn) ; kill on third + (progn + (mouse-save-then-kill-delete-region (point) (mark)) + (setq mouse-save-then-kill-posn nil)) + (progn ; save on second + (kill-new (buffer-substring (point) (mark t)) t) + (setq mouse-save-then-kill-posn + (list (car kill-ring) (point) click-posn)))))) ;; This is not a repetition. ;; We are adjusting an old selection or creating a new one. (if (or (and (eq last-command 'mouse-save-then-kill) @@ -1520,17 +1569,26 @@ (goto-char new) (set-mark new)) (setq deactivate-mark nil))) - (kill-new (buffer-substring (point) (mark t)) t)) + (and (eq mouse-save-then-kill-copy-region t) ; save on first click + (kill-new (buffer-substring (point) (mark t)) t))) ;; Set the mark where point is, then move where clicked. (mouse-set-mark-fast click) (if before-scroll (goto-char before-scroll)) (exchange-point-and-mark) ;Why??? --Stef - (kill-new (buffer-substring (point) (mark t)))) - (mouse-show-mark) + (and (eq mouse-save-then-kill-copy-region t) ; save on first click + (kill-new (buffer-substring (point) (mark t))))) + (cond ((eq mouse-save-then-kill-copy-region t) ; save on first click + (setq mouse-save-then-kill-posn + (list (car kill-ring) (point) click-posn))) + ((eq mouse-save-then-kill-copy-region :double) ; no save on first click + ;; no save on first click, but need to know region from first + ;; nil for saved kill ring top used for limbo between + ;; second and third clicks + (setq mouse-save-then-kill-posn + (list nil (point) click-posn)))) (mouse-set-region-1) - (setq mouse-save-then-kill-posn - (list (car kill-ring) (point) click-posn))))))) + (mouse-show-mark)))))) (global-set-key [M-mouse-1] 'mouse-start-secondary) (global-set-key [M-drag-mouse-1] 'mouse-set-secondary)