Function: mouse-save-then-kill
mouse-save-then-kill is an interactive and byte-compiled function
defined in mouse.el.gz.
Signature
(mouse-save-then-kill CLICK)
Documentation
Set the region according to CLICK; the second time, kill it.
CLICK should be a mouse click event.
If the region is inactive, activate it temporarily. Set mark at the original point, and move point to the position of CLICK.
If the region is already active, adjust it. Normally, do this by moving point or mark, whichever is closer, to CLICK. But if you have selected whole words or lines, move point or mark to the word or line boundary closest to CLICK instead.
If mouse-drag-copy-region is non-nil, this command also saves the
new region to the kill ring (replacing the previous kill if the
previous region was just saved to the kill ring).
If this command is called a second consecutive time with the same
CLICK position, kill the region (or delete it
if mouse-drag-copy-region is non-nil).
Key Bindings
Source Code
;; Defined in /usr/src/emacs/lisp/mouse.el.gz
(defun mouse-save-then-kill (click)
"Set the region according to CLICK; the second time, kill it.
CLICK should be a mouse click event.
If the region is inactive, activate it temporarily. Set mark at
the original point, and move point to the position of CLICK.
If the region is already active, adjust it. Normally, do this by
moving point or mark, whichever is closer, to CLICK. But if you
have selected whole words or lines, move point or mark to the
word or line boundary closest to CLICK instead.
If `mouse-drag-copy-region' is non-nil, this command also saves the
new region to the kill ring (replacing the previous kill if the
previous region was just saved to the kill ring).
If this command is called a second consecutive time with the same
CLICK position, kill the region (or delete it
if `mouse-drag-copy-region' is non-nil)."
(interactive "e")
(mouse-minibuffer-check click)
(let* ((posn (event-start click))
(click-pt (posn-point posn))
(window (posn-window posn))
(buf (window-buffer window))
;; Don't let a subsequent kill command append to this one.
(this-command this-command)
;; Check if the user has multi-clicked to select words/lines.
(click-count
(if (and (eq mouse-selection-click-count-buffer buf)
(with-current-buffer buf (mark t)))
mouse-selection-click-count
0)))
(cond
((not (numberp click-pt)) nil)
;; If the user clicked without moving point, kill the region.
;; This also resets `mouse-selection-click-count'.
((and (eq last-command 'mouse-save-then-kill)
(eq click-pt mouse-save-then-kill-posn)
(eq window (selected-window)))
(if mouse-drag-copy-region
;; Region already saved in the previous click;
;; don't make a duplicate entry, just delete.
(funcall region-extract-function 'delete-only)
(kill-region (mark t) (point) 'region))
(setq mouse-selection-click-count 0)
(setq mouse-save-then-kill-posn nil))
;; Otherwise, if there is a suitable region, adjust it by moving
;; one end (whichever is closer) to CLICK-PT.
((or (with-current-buffer buf (region-active-p))
(and (eq window (selected-window))
(mark t)
(or (and (eq last-command 'mouse-save-then-kill)
mouse-save-then-kill-posn)
(and (memq last-command '(mouse-drag-region
mouse-set-region))
(or mark-even-if-inactive
(not transient-mark-mode))))))
(select-window window)
(let* ((range (mouse-start-end click-pt click-pt click-count)))
(if (< (abs (- click-pt (mark t)))
(abs (- click-pt (point))))
(set-mark (car range))
(goto-char (nth 1 range)))
(setq deactivate-mark nil)
(mouse-set-region-1)
(when mouse-drag-copy-region
;; Region already copied to kill-ring once, so replace.
(kill-new (funcall region-extract-function nil) t))
;; Arrange for a repeated mouse-3 to kill the region.
(setq mouse-save-then-kill-posn click-pt)))
;; Otherwise, set the mark where point is and move to CLICK-PT.
(t
(select-window window)
(mouse-set-mark-fast click)
(let ((before-scroll (with-current-buffer buf point-before-scroll)))
(if before-scroll (goto-char before-scroll)))
(exchange-point-and-mark)
(mouse-set-region-1)
(when (and mouse-drag-copy-region
(or (not (eq mouse-drag-copy-region 'non-empty))
(not (/= (mark t) (point)))))
(kill-new (filter-buffer-substring (mark t) (point))))
(setq mouse-save-then-kill-posn click-pt)))))