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?

Drew
  • 75,699
  • 9
  • 109
  • 225
ideasman42
  • 8,375
  • 1
  • 28
  • 105

2 Answers2

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)

xuchunyang
  • 14,302
  • 1
  • 18
  • 39
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)
      )
    )
  )
ideasman42
  • 8,375
  • 1
  • 28
  • 105