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: Wed, 20 Sep 2017 21:39:23 +0900 (JST)

Thank you for the response.

>> +(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."
> 
> The doc string should describe where we put point and mark as result
> of this.

I add a sentence to infer explicitly.

      "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."

>> +  (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)))
> 
> Is it perhaps better to always put point at the end and mark at the
> beginning of the overlay?  The heuristic seems to be complicating
> matters for applications, which will have to perform the same
> calculations to know in advance where point will be.

I changed the logic.  Now the function puts mark and point at the
beginning and end of the secondary overlay.

>> +(defun secondary-selection-from-region ()
>> +  "Set beginning and end of the secondary selection to those of the region."
> 
> This doc string should tell what happens if there's no active region.

I add a sentence.  Now it reads below.

      "Set beginning and end of the secondary selection to those of the region.
    >>>>When there is no region, this does nothing.<<<<"

> Please also add a NEWS entry.

I made a NEWS entry.

Following is the revised NEWS, change log, news, and patch.



* NEWS

** Add new functions 'secondary-selection-to-region' and 
'secondary-selection-from-region'.
These functions let you set the beginning and the end of the region
from those of the secondary selection and vise versa.

* Change log

2017-09-20  Tak Kunihiro  <address@hidden>

        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/lisp/mouse.el b/lisp/mouse.el
index 3f448f0..c73c227 100755
--- a/lisp/mouse.el
+++ b/lisp/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 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."
+  (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 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.





reply via email to

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