How can I programmatically define a secondary selection with beginning and end defined?;)

I try to look for this, but only find mouse usage;)

Any pointers?;)

1 Answer 1


You can use library second-sel.el to do what you want (and more) with secondary selections. See description here, along with other info about the secondary selection.

In particular, you can set the secondary selection using Lisp code or using the keyboard. And you can have a ring of secondary selections, just like the ring (kill-ring) of primary selections.

Here are some key bindings you might want to use:

(global-set-key (kbd "C-M-y")               'secondary-yank|select|move|swap)
(define-key esc-map "y"                     'yank-pop-commands)
(define-key isearch-mode-map (kbd "C-M-y")  'isearch-yank-secondary)
(global-set-key (kbd "C-x C-M-SPC")         'set-secondary-start)
(global-set-key (kbd "C-x C-M-<return>")    'secondary-save-then-kill)
(global-set-key (kbd "C-M-<mouse-3>")       'mouse-secondary-save-then-kill)

But the quick answer to your question is to just do this, where BEG and END are the limits you want for the secondary selection:

(secondary-swap-region BEG END)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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