aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorTak Kunihiro2017-09-21 11:26:00 +0300
committerEli Zaretskii2017-09-21 11:26:00 +0300
commit31e1d9ef2f70937cd0f93f67399620201ded300b (patch)
tree4b956d0f55bf4df22f95f3ed6075c160c0ecf775 /lisp
parent047f02f00f602b9aef63ae8938e12f3f0ab481eb (diff)
downloademacs-31e1d9ef2f70937cd0f93f67399620201ded300b.tar.gz
emacs-31e1d9ef2f70937cd0f93f67399620201ded300b.zip
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.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/mouse.el28
1 files changed, 28 insertions, 0 deletions
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."
1916 (> (length str) 0) 1916 (> (length str) 0)
1917 (gui-set-selection 'SECONDARY str)))) 1917 (gui-set-selection 'SECONDARY str))))
1918 1918
1919(defun secondary-selection-exist-p ()
1920 "Return non-nil if there is the secondary selection in current buffer."
1921 (memq mouse-secondary-overlay (overlays-in (point-min) (point-max))))
1922
1923(defun secondary-selection-to-region ()
1924 "Set beginning and end of the region to those of the secondary selection.
1925This puts mark and point at the beginning and the end of the
1926secondary selection, respectively. This works when the secondary
1927selection exists and the region does not exist in current buffer;
1928the secondary selection will be deleted afterward.
1929If the region is active, or the secondary selection doesn't exist,
1930this function does nothing."
1931 (when (and (not (region-active-p))
1932 (secondary-selection-exist-p))
1933 (let ((beg (overlay-start mouse-secondary-overlay))
1934 (end (overlay-end mouse-secondary-overlay)))
1935 (push-mark beg t t)
1936 (goto-char end))
1937 ;; Delete the secondary selection on current buffer.
1938 (delete-overlay mouse-secondary-overlay)))
1939
1940(defun secondary-selection-from-region ()
1941 "Set beginning and end of the secondary selection to those of the region.
1942When there is no region, this function does nothing."
1943 (when (region-active-p) ; Create the secondary selection from the region.
1944 (delete-overlay mouse-secondary-overlay) ; Delete the secondary selection even on a different buffer.
1945 (move-overlay mouse-secondary-overlay (region-beginning) (region-end))))
1946
1919 1947
1920(defcustom mouse-buffer-menu-maxlen 20 1948(defcustom mouse-buffer-menu-maxlen 20
1921 "Number of buffers in one pane (submenu) of the buffer menu. 1949 "Number of buffers in one pane (submenu) of the buffer menu.