0

Emacs has a secondary selection (not the X11 selection, rather the mouse-secondary-overlay).

On my system holding Alt-LMB dragging sets it.

How would I check if there this selection is set in elisp?

I tried checking;

(if mouse-secondary-overlay
  ... do something ...)

however this always prints "Have Second Select"

How can this be tested?

2
(gui-get-selection 'SECONDARY)

returns nil if there is no secondary selection. (if your Emacs is older than 25.1, use x-get-selection instead)

1
  • Minor detail, I don't want to get the actual text, just to know if a secondary selection exists. – ideasman42 Oct 31 '16 at 16:17
1

This can be done by checking if the start of (overlay-start mouse-secondary-overlay) is not nil.

This is a function that uses the secondary selection, then the primary as a fallback.

(defun mouse-yank-secondary-and-deselect (click)
  "Deselect after yanking, for quick select-copy. Uses primary as fallback."
  (interactive "*p")
  (if (overlay-start mouse-secondary-overlay)
      (progn
        ;; use the secondary buffer and clear it
        (mouse-yank-secondary click)
        (delete-overlay mouse-secondary-overlay)
        )
    (progn
      ;; fallback to primary buffer
      (mouse-yank-primary click)
      )
    )
  )

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.