bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#27530: patch to cut and copy secondary


From: Tak Kunihiro
Subject: bug#27530: patch to cut and copy secondary
Date: Mon, 11 Sep 2017 11:03:58 +0900

I am sending a patch relative to lisp/mouse.el to let user to
set beginning and end of the region from those of the secondary
selection.  I hope this meets your comments and please revise
when it’s not good!


* Change log

2017-09-11  Tak Kunihiro  <tkk@misasa.okayama-u.ac.jp>

        Add functions to set beginning and end of the region from
        those of the secondary selection and vise 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)

* Patch

diff --git a/mouse.260.el b/mouse.el
old mode 100644
new mode 100755
index 2fbaaad..6ca44e0
--- a/mouse.260.el
+++ b/mouse.el
@@ -1916,6 +1916,32 @@ CLICK position, kill the secondary selection."
         (> (length str) 0)
         (gui-set-selection 'SECONDARY str))))
 
+(defun secondary-selection-exist-p ()
+  "Return 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 works when the secondary selection exists and the region
+does not exist in current buffer.  The secondary selection will
+be deleted afterward."
+  (when (and (not (region-active-p))
+             (secondary-selection-exist-p))
+    (let* ((beg (overlay-start mouse-secondary-overlay))
+           (end (overlay-end mouse-secondary-overlay))
+           ;; Restore point to whichever closer.
+           (is-point-front (< (point) (/ (+ beg end) 2))))
+      (push-mark (if is-point-front end beg) t t)
+      (goto-char (if is-point-front beg 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 (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.






reply via email to

[Prev in Thread] Current Thread [Next in Thread]