[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] emacs-26 31e1d9e: Support setting region from secondary se
From: |
Eli Zaretskii |
Subject: |
[Emacs-diffs] emacs-26 31e1d9e: Support setting region from secondary selection and vice versa |
Date: |
Thu, 21 Sep 2017 04:27:55 -0400 (EDT) |
branch: emacs-26
commit 31e1d9ef2f70937cd0f93f67399620201ded300b
Author: Tak Kunihiro <address@hidden>
Commit: Eli Zaretskii <address@hidden>
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.
---
etc/NEWS | 7 +++++++
lisp/mouse.el | 28 ++++++++++++++++++++++++++++
2 files changed, 35 insertions(+)
diff --git a/etc/NEWS b/etc/NEWS
index a685a9f..280ab64 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -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 3f448f0..4a4fe52 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.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Emacs-diffs] emacs-26 31e1d9e: Support setting region from secondary selection and vice versa,
Eli Zaretskii <=