diff options
author | Tak Kunihiro <tkk@misasa.okayama-u.ac.jp> | 2017-09-21 11:26:00 +0300 |
---|---|---|
committer | Eli Zaretskii <eliz@gnu.org> | 2017-09-21 11:26:00 +0300 |
commit | 31e1d9ef2f70937cd0f93f67399620201ded300b (patch) | |
tree | 4b956d0f55bf4df22f95f3ed6075c160c0ecf775 | |
parent | 047f02f00f602b9aef63ae8938e12f3f0ab481eb (diff) | |
download | emacs-31e1d9ef2f70937cd0f93f67399620201ded300b.tar.gz |
Support setting region from secondary selection and vice versa
* lisp/mouse.el (secondary-selection-exist-p): New function to
allow callers to tell existence of the secondary selection
in current buffer.
(secondary-selection-to-region): New function to set
beginning and end of the region from those of the secondary
selection.
(secondary-selection-from-region): New function to set
beginning and end of the secondary selection from those of
the region. (Bug#27530)
* etc/NEWS: Mention the new functions.
-rw-r--r-- | etc/NEWS | 7 | ||||
-rw-r--r-- | lisp/mouse.el | 28 |
2 files changed, 35 insertions, 0 deletions
@@ -1819,6 +1819,13 @@ can be replicated simply by setting 'comment-auto-fill-only-comments'. ** New pcase pattern 'rx' to match against a rx-style regular expression. For details, see the doc string of 'rx--pcase-macroexpander'. +--- +** New functions to set region from secondary selection and vice versa. +The new functions 'secondary-selection-to-region' and +'secondary-selection-from-region' let you set the beginning and the +end of the region from those of the secondary selection and vise +versa. + * Changes in Emacs 26.1 on Non-Free Operating Systems diff --git a/lisp/mouse.el b/lisp/mouse.el index 3f448f018a4..4a4fe52c872 100644 --- a/lisp/mouse.el +++ b/lisp/mouse.el @@ -1916,6 +1916,34 @@ CLICK position, kill the secondary selection." (> (length str) 0) (gui-set-selection 'SECONDARY str)))) +(defun secondary-selection-exist-p () + "Return non-nil if there is the secondary selection in current buffer." + (memq mouse-secondary-overlay (overlays-in (point-min) (point-max)))) + +(defun secondary-selection-to-region () + "Set beginning and end of the region to those of the secondary selection. +This puts mark and point at the beginning and the end of the +secondary selection, respectively. This works when the secondary +selection exists and the region does not exist in current buffer; +the secondary selection will be deleted afterward. +If the region is active, or the secondary selection doesn't exist, +this function does nothing." + (when (and (not (region-active-p)) + (secondary-selection-exist-p)) + (let ((beg (overlay-start mouse-secondary-overlay)) + (end (overlay-end mouse-secondary-overlay))) + (push-mark beg t t) + (goto-char end)) + ;; Delete the secondary selection on current buffer. + (delete-overlay mouse-secondary-overlay))) + +(defun secondary-selection-from-region () + "Set beginning and end of the secondary selection to those of the region. +When there is no region, this function does nothing." + (when (region-active-p) ; Create the secondary selection from the region. + (delete-overlay mouse-secondary-overlay) ; Delete the secondary selection even on a different buffer. + (move-overlay mouse-secondary-overlay (region-beginning) (region-end)))) + (defcustom mouse-buffer-menu-maxlen 20 "Number of buffers in one pane (submenu) of the buffer menu. |