Function: mouse-secondary-save-then-kill
mouse-secondary-save-then-kill is an interactive and byte-compiled
function defined in mouse.el.gz.
Signature
(mouse-secondary-save-then-kill CLICK)
Documentation
Set the secondary selection and save it to the kill ring.
The second time, kill it. CLICK should be a mouse click event.
If you have not called mouse-start-secondary in the clicked
buffer, activate the secondary selection and set it between point
and the click position CLICK.
Otherwise, adjust the bounds of the secondary selection. Normally, do this by moving its beginning or end, whichever is closer, to CLICK. But if you have selected whole words or lines, adjust to the word or line boundary closest to CLICK instead.
If this command is called a second consecutive time with the same CLICK position, kill the secondary selection.
Probably introduced at or before Emacs version 19.22.
Key Bindings
Source Code
;; Defined in /usr/src/emacs/lisp/mouse.el.gz
(defun mouse-secondary-save-then-kill (click)
"Set the secondary selection and save it to the kill ring.
The second time, kill it. CLICK should be a mouse click event.
If you have not called `mouse-start-secondary' in the clicked
buffer, activate the secondary selection and set it between point
and the click position CLICK.
Otherwise, adjust the bounds of the secondary selection.
Normally, do this by moving its beginning or end, whichever is
closer, to CLICK. But if you have selected whole words or lines,
adjust to the word or line boundary closest to CLICK instead.
If this command is called a second consecutive time with the same
CLICK position, kill the secondary selection."
(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 (eq (overlay-buffer mouse-secondary-overlay) buf)
mouse-secondary-click-count
0))
(beg (overlay-start mouse-secondary-overlay))
(end (overlay-end mouse-secondary-overlay)))
(cond
((not (numberp click-pt)) nil)
;; If the secondary selection is not active in BUF, activate it.
((not (eq buf (or (overlay-buffer mouse-secondary-overlay)
(if mouse-secondary-start
(marker-buffer mouse-secondary-start)))))
(select-window window)
(setq mouse-secondary-start (make-marker))
(move-marker mouse-secondary-start (point))
(move-overlay mouse-secondary-overlay (point) click-pt buf)
(kill-ring-save (point) click-pt))
;; If the user clicked without moving point, delete the secondary
;; selection. This also resets `mouse-secondary-click-count'.
((and (eq last-command 'mouse-secondary-save-then-kill)
(eq click-pt mouse-save-then-kill-posn)
(eq window (selected-window)))
(mouse-save-then-kill-delete-region beg end)
(delete-overlay mouse-secondary-overlay)
(setq mouse-secondary-click-count 0)
(setq mouse-save-then-kill-posn nil))
;; Otherwise, if there is a suitable secondary selection overlay,
;; adjust it by moving one end (whichever is closer) to CLICK-PT.
((and beg (eq buf (overlay-buffer mouse-secondary-overlay)))
(let* ((range (mouse-start-end click-pt click-pt click-count)))
(if (< (abs (- click-pt beg))
(abs (- click-pt end)))
(move-overlay mouse-secondary-overlay (car range) end)
(move-overlay mouse-secondary-overlay beg (nth 1 range))))
(setq deactivate-mark nil)
(if (eq last-command 'mouse-secondary-save-then-kill)
;; If the front of the kill ring comes from an immediately
;; previous use of this command, replace the entry.
(kill-new
(buffer-substring (overlay-start mouse-secondary-overlay)
(overlay-end mouse-secondary-overlay))
t)
(let (deactivate-mark)
(copy-region-as-kill (overlay-start mouse-secondary-overlay)
(overlay-end mouse-secondary-overlay))))
(setq mouse-save-then-kill-posn click-pt))
;; Otherwise, set the secondary selection overlay.
(t
(select-window window)
(if mouse-secondary-start
;; All we have is one end of a selection, so put the other
;; end here.
(let ((start (+ 0 mouse-secondary-start)))
(kill-ring-save start click-pt)
(move-overlay mouse-secondary-overlay start click-pt)))
(setq mouse-save-then-kill-posn click-pt))))
;; Finally, set the window system's secondary selection.
(let (str)
(and (overlay-buffer mouse-secondary-overlay)
(setq str (buffer-substring (overlay-start mouse-secondary-overlay)
(overlay-end mouse-secondary-overlay)))
(> (length str) 0)
(gui-set-selection 'SECONDARY str))))