diff options
| author | Tak Kunihiro | 2017-09-21 11:26:00 +0300 |
|---|---|---|
| committer | Eli Zaretskii | 2017-09-21 11:26:00 +0300 |
| commit | 31e1d9ef2f70937cd0f93f67399620201ded300b (patch) | |
| tree | 4b956d0f55bf4df22f95f3ed6075c160c0ecf775 | |
| parent | 047f02f00f602b9aef63ae8938e12f3f0ab481eb (diff) | |
| download | emacs-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.
| -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'. | |||
| 1819 | ** New pcase pattern 'rx' to match against a rx-style regular expression. | 1819 | ** New pcase pattern 'rx' to match against a rx-style regular expression. |
| 1820 | For details, see the doc string of 'rx--pcase-macroexpander'. | 1820 | For details, see the doc string of 'rx--pcase-macroexpander'. |
| 1821 | 1821 | ||
| 1822 | --- | ||
| 1823 | ** New functions to set region from secondary selection and vice versa. | ||
| 1824 | The new functions 'secondary-selection-to-region' and | ||
| 1825 | 'secondary-selection-from-region' let you set the beginning and the | ||
| 1826 | end of the region from those of the secondary selection and vise | ||
| 1827 | versa. | ||
| 1828 | |||
| 1822 | 1829 | ||
| 1823 | * Changes in Emacs 26.1 on Non-Free Operating Systems | 1830 | * Changes in Emacs 26.1 on Non-Free Operating Systems |
| 1824 | 1831 | ||
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. | ||
| 1925 | This puts mark and point at the beginning and the end of the | ||
| 1926 | secondary selection, respectively. This works when the secondary | ||
| 1927 | selection exists and the region does not exist in current buffer; | ||
| 1928 | the secondary selection will be deleted afterward. | ||
| 1929 | If the region is active, or the secondary selection doesn't exist, | ||
| 1930 | this 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. | ||
| 1942 | When 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. |