unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#27530: patch to cut and copy secondary
@ 2017-06-29 12:43 Tak Kunihiro
  2017-06-29 13:41 ` Drew Adams
  2017-09-05  3:11 ` Tak Kunihiro
  0 siblings, 2 replies; 26+ messages in thread
From: Tak Kunihiro @ 2017-06-29 12:43 UTC (permalink / raw)
  To: 27530; +Cc: tkk

I found secondary can be used as another region.  Here I send a patch
to cut and copy secondary as if region (when region does not exist).

# Change log

2017-07-01  Tak Kunihiro  <tkk@misasa.okayama-u.ac.jp>

        Cut and copy secondary when region does not exist.

        * doc/emacs/killing.texi (Secondary Selection): Document support of cut and copy secondary.
        * lisp/simple.el (kill-secondary-flag): Use also secondary not only region to cut and copy.
        (kill-region): Set target to secondary not only region if kill-secondary-flag is non-nil.
        (kill-ring-save): Set target to secondary not only region if kill-secondary-flag is non-nil.
        * lisp/mouse.el (mouse-secondary-exists-p): Return location of secondary when it exists in current buffer.
        (mouse-set-mark-and-point-from-secondary): Set mark and point from secondary.
        (mouse-set-secondary-from-region): Set secondary to the text in region.

# NEWS

** Use can cut and copy secondary when region does not exist.
To cut and copy secondary using C-w and M-w, set 'kill-secondary-flag' to t.

# Code 1/2

diff --git a/mouse.260.el b/mouse.el
old mode 100644
new mode 100755
index 9b6b169..6ee368e
--- a/mouse.260.el
+++ b/mouse.el
@@ -1545,6 +1545,45 @@ CLICK position, kill the secondary selection."
 	 (> (length str) 0)
 	 (gui-set-selection 'SECONDARY str))))
 
+(defun mouse-secondary-exists-p ()
+  "Return location of mouse-secondary-overlay when exists in current buffer."
+  (let ((buf (overlay-buffer mouse-secondary-overlay))
+        (beg (overlay-start mouse-secondary-overlay))
+        (end (overlay-end mouse-secondary-overlay)))
+    (when (and buf beg end
+               (equal buf (current-buffer))
+               (/= beg end))
+      (list beg end))))
+
+(defun mouse-set-mark-and-point-from-secondary ()
+  "Set mark and point from mouse-secondary-overlay.
+This works when mouse-secondary-overlay exists and region does
+not exist.  The mouse-secondary-overlay will be deactivated."
+  (let ((secondary-to-kill (and (not (region-active-p))
+                                (mouse-secondary-exists-p))))
+    ;; delete overlay even on different buffer.
+    ;; this should be later than obtaining location.
+    (delete-overlay mouse-secondary-overlay)
+    (when secondary-to-kill
+      (push-mark (car secondary-to-kill) t t)
+      (goto-char (cadr secondary-to-kill)))))
+
+(defun mouse-set-secondary-from-region ()
+  "Set the secondary selection to the text in region.
+When region does not exists, set mouse-secondary-start to the point.
+When point is on mouse-secondary-overlay, do nothing."
+  (cond
+   ((region-active-p) ; create mouse-secondary-overlay from region
+    (delete-overlay mouse-secondary-overlay)
+    (move-overlay mouse-secondary-overlay (region-beginning) (region-end)))
+   ((member 'secondary-selection ; do nothing
+            (mapcar (lambda (xxx) (overlay-get xxx 'face))
+                    (overlays-at (point)))))
+   (t (delete-overlay mouse-secondary-overlay) ; create mouse-secondary-start from point
+      (push-mark (point))
+      (setq mouse-secondary-start (make-marker))
+      (move-marker mouse-secondary-start (point)))))
+
 \f
 (defcustom mouse-buffer-menu-maxlen 20
   "Number of buffers in one pane (submenu) of the buffer menu.

# Code 2/2

diff --git a/simple.252.el b/simple.el
index 5f70ade..e75743a 100644
--- a/simple.252.el
+++ b/simple.el
@@ -4287,11 +4287,19 @@ move the yanking point; just return the Nth kill forward."
   :type 'boolean
   :group 'killing)
 
+(defcustom kill-secondary-flag nil
+  "Kill mouse-secondary-overlay when it exists but region does not exists."
+  :type 'boolean
+  :group 'mouse
+  :version "26.1")
+
 (defun kill-region (beg end &optional region)
   "Kill (\"cut\") text between point and mark.
 This deletes the text from the buffer and saves it in the kill ring.
 The command \\[yank] can retrieve it from there.
 \(If you want to save the region without killing it, use \\[kill-ring-save].)
+If `kill-secondary-flag' is non-nil, kill
+mouse-secondary-overlay instead of the region.
 
 If you want to append the killed region to the last killed text,
 use \\[append-next-kill] before \\[kill-region].
@@ -4317,7 +4325,10 @@ Supply two arguments, character positions BEG and END indicating the
  region instead."
   ;; Pass mark first, then point, because the order matters when
   ;; calling `kill-append'.
-  (interactive (list (mark) (point) 'region))
+  (interactive
+   (progn (when kill-secondary-flag
+            (mouse-set-mark-and-point-from-secondary)) ; no region but secondary
+          (list (mark) (point) 'region)))
   (unless (and beg end)
     (user-error "The mark is not set now, so there is no region"))
   (condition-case nil
@@ -4387,6 +4398,8 @@ This command's old key binding has been given to `kill-ring-save'."
 In Transient Mark mode, deactivate the mark.
 If `interprogram-cut-function' is non-nil, also save the text for a window
 system cut and paste.
+If `kill-secondary-flag' is non-nil, save
+mouse-secondary-overlay instead of the region.
 
 If you want to append the killed line to the last killed text,
 use \\[append-next-kill] before \\[kill-ring-save].
@@ -4404,8 +4417,11 @@ This command is similar to `copy-region-as-kill', except that it gives
 visual feedback indicating the extent of the region being copied."
   ;; Pass mark first, then point, because the order matters when
   ;; calling `kill-append'.
-  (interactive (list (mark) (point)
-		     (prefix-numeric-value current-prefix-arg)))
+  (interactive
+   (progn (when kill-secondary-flag
+            (mouse-set-mark-and-point-from-secondary)) ; no region but secondary
+          (list (mark) (point)
+                (prefix-numeric-value current-prefix-arg))))
   (copy-region-as-kill beg end region)
   ;; This use of called-interactively-p is correct because the code it
   ;; controls just gives the user visual feedback.

# Info

diff --git a/killing.252.texi b/killing.texi
index 47de053..721b68e 100755
--- a/killing.252.texi
+++ b/killing.texi
@@ -624,6 +624,11 @@ end of the yanked text (@code{mouse-yank-secondary}).
 Double or triple clicking of @kbd{M-mouse-1} operates on words and
 lines, much like @kbd{mouse-1}.
 
+If @code{kill-secondary-flag} is non-@code{nil}, a command
+@kbd{C-w} (@code{kill-region}), and a command @kbd{M-w}
+(@code{kill-ring-save}) will target secondary selection when region
+does not exist.
+
 If @code{mouse-yank-at-point} is non-@code{nil}, @kbd{M-mouse-2} yanks
 at point.  Then it does not matter precisely where you click, or even
 which of the frame's windows you click on.  @xref{Mouse Commands}.





^ permalink raw reply related	[flat|nested] 26+ messages in thread

* bug#27530: patch to cut and copy secondary
  2017-06-29 12:43 bug#27530: patch to cut and copy secondary Tak Kunihiro
@ 2017-06-29 13:41 ` Drew Adams
  2017-07-01  0:45   ` Tak Kunihiro
  2017-09-05  3:11 ` Tak Kunihiro
  1 sibling, 1 reply; 26+ messages in thread
From: Drew Adams @ 2017-06-29 13:41 UTC (permalink / raw)
  To: Tak Kunihiro, 27530

> I found secondary can be used as another region.

Good initiative.

(But another "selection", not another region.)

And a selection that is (obviously) not affected by the
cursor position.  It persists even as you move the cursor.
That's the main difference from the region (advantages,
disadvantages).

> Here I send a patch to cut and copy secondary as if region
> (when region does not exist).

FWIW, I suggested similar things to Emacs devel long ago.
I use the secondary selection a *lot*.

See https://www.emacswiki.org/emacs/second-sel.el,
https://www.emacswiki.org/emacs/SecondarySelection#second-sel.el

You might want to consider incorporating some or all of
what is there.  I and others have been using it since 2008.

IMO, the first, and simplest, improvement to add to Emacs is
a way to create and yank the secondary selection using only
the keyboard, not the mouse.  My guess is that the reason
more users do not use the secondary selection is that there
are no keyboard keybindings for it.

> +(defun mouse-secondary-exists-p ()
> +  "Return location of mouse-secondary-overlay when exists in current
> buffer."

Name probably shouldn't end in `-p' if the return value is
mainly not a Boolean.  Non-nil here means overlay limits.

> +(defun mouse-set-mark-and-point-from-secondary ()

Cf. `secondary-to-primary'.

> +(defun mouse-set-secondary-from-region ()

Cf. `primary-to-secondary'.

`second-sel.el' also gives the secondary selection its own
history, `secondary-selection-ring', analogous to `kill-ring'.

HTH.





^ permalink raw reply	[flat|nested] 26+ messages in thread

* bug#27530: patch to cut and copy secondary
  2017-06-29 13:41 ` Drew Adams
@ 2017-07-01  0:45   ` Tak Kunihiro
  2017-08-01  1:35     ` Tak Kunihiro
  0 siblings, 1 reply; 26+ messages in thread
From: Tak Kunihiro @ 2017-07-01  0:45 UTC (permalink / raw)
  To: 27530; +Cc: tkk

I re-send a patch to cut and copy the secondary.

I saw https://www.emacswiki.org/emacs/second-sel.el and found it is a
super super-set of this patch.  As my submission, I try to maintain
this patch small and fit into `simple.el' and `mouse.el'.

> defun mouse-secondary-exists-p ()
> 
> Name probably shouldn't end in `-p' if the return value is
> mainly not a Boolean.  Non-nil here means overlay limits.

I changed docstring to match the name of function.

    Return if the secondary selection exists in current buffer.
    When exists, this returns start and end of the secondary selection.

> defun mouse-set-mark-and-point-from-secondary ()
> 
> Cf. `secondary-to-primary'.

I changed the name to mouse-set-primary-from-secondary.

> defun mouse-set-secondary-from-region ()
> 
> Cf. `primary-to-secondary'.

I changed the name to mouse-set-secondary-from-primary.

> IMO, the first, and simplest, improvement to add to Emacs is
> a way to create and yank the secondary selection using only
> the keyboard, not the mouse.  My guess is that the reason
> more users do not use the secondary selection is that there
> are no keyboard keybindings for it.

I made following the two functions to be interactive to be called from
keyboard.

    mouse-set-primary-from-secondary
    mouse-set-secondary-from-primary

My local plan is to set secondary by hook something like below.

    (add-hook 'view-mode-hook 'mouse-set-secondary-from-primary)


# Change log

2017-07-02  Tak Kunihiro  <tkk@misasa.okayama-u.ac.jp>

        Cut and copy the secondary selection when the region does not exist.

        * doc/emacs/killing.texi (Secondary Selection): Document support of cut and copy the secondary selection.
        * lisp/simple.el (kill-secondary-flag): Use also the secondary selection not only the region to cut and copy.
        (kill-region): Set target to the secondary selection not only the primary selection if kill-secondary-flag is non-nil.
        (kill-ring-save): Set target to the secondary selection not only the primary selection if kill-secondary-flag is non-nil.
        * lisp/mouse.el (mouse-secondary-exists-p): Return if the secondary selection exists in current buffer.
        (mouse-set-primary-from-secondary): Set the region to text in the secondary selection.
        (mouse-set-secondary-from-primary): Set the secondary selection to text in the region.

# NEWS

** Use can cut and copy secondary when region does not exist.
To cut and copy secondary using C-w and M-w, set 'kill-secondary-flag' to t.

# Code 1/2

diff --git a/mouse.260.el b/mouse.el
old mode 100644
new mode 100755
index 9b6b169..55357da
--- a/mouse.260.el
+++ b/mouse.el
@@ -1545,6 +1545,51 @@ CLICK position, kill the secondary selection."
 	 (> (length str) 0)
 	 (gui-set-selection 'SECONDARY str))))

+(defun mouse-secondary-exists-p ()
+  "Return if the secondary selection exists in current buffer.
+When exists, this returns start and end of the secondary selection."
+  (let ((buf (overlay-buffer mouse-secondary-overlay))
+        (beg (overlay-start mouse-secondary-overlay))
+        (end (overlay-end mouse-secondary-overlay)))
+    (when (and buf beg end
+               (equal buf (current-buffer))
+               (/= beg end))
+      (list beg end))))
+
+(defun mouse-set-primary-from-secondary ()
+  "Set the region to text in the secondary selection.
+This works when the secondary selection exists and the region
+does not exist in current buffer.  The mouse-secondary-overlay
+will be deleted."
+  (interactive)
+  (let ((secondary-to-kill (and (not (region-active-p))
+                                (mouse-secondary-exists-p))))
+    ;; Delete overlay even on different buffer.
+    ;; Deletion should be later than obtaining location.
+    (delete-overlay mouse-secondary-overlay)
+    (when secondary-to-kill
+      (push-mark (car secondary-to-kill) t t)
+      (goto-char (cadr secondary-to-kill)))))
+
+(defun mouse-set-secondary-from-primary ()
+  "Set the secondary selection to text in the region.
+When region does not exists, set mouse-secondary-start to the point.
+When point is in the secondary selection, do nothing."
+  (interactive)
+  (cond
+   ((region-active-p) ; Create mouse-secondary-overlay from region.
+    (delete-overlay mouse-secondary-overlay)
+    (move-overlay mouse-secondary-overlay (region-beginning) (region-end)))
+   ((member 'secondary-selection ; Do nothing.
+            (mapcar (lambda (xxx) (overlay-get xxx 'face))
+                    (overlays-at (point)))))
+   (t (delete-overlay mouse-secondary-overlay) ; Create mouse-secondary-start from point.
+      (push-mark (point))
+      (setq mouse-secondary-start (make-marker))
+      (move-marker mouse-secondary-start (point)))))
+
 \f
 (defcustom mouse-buffer-menu-maxlen 20
   "Number of buffers in one pane (submenu) of the buffer menu.

# Code 2/2

diff --git a/simple.252.el b/simple.el
index 5f70ade..a80953a 100644
--- a/simple.252.el
+++ b/simple.el
@@ -4287,11 +4287,21 @@ move the yanking point; just return the Nth kill forward."
   :type 'boolean
   :group 'killing)

+(defcustom kill-secondary-flag nil
+  "Kill the secondary selection when it exists but the region does not exist."
+  :type 'boolean
+  :group 'mouse
+  :version "26.1")
+
 (defun kill-region (beg end &optional region)
   "Kill (\"cut\") text between point and mark.
 This deletes the text from the buffer and saves it in the kill ring.
 The command \\[yank] can retrieve it from there.
 \(If you want to save the region without killing it, use \\[kill-ring-save].)
+If `kill-secondary-flag' is non-nil, kill
+mouse-secondary-overlay instead of the region.

 If you want to append the killed region to the last killed text,
 use \\[append-next-kill] before \\[kill-region].
@@ -4317,7 +4327,12 @@ Supply two arguments, character positions BEG and END indicating the
  region instead."
   ;; Pass mark first, then point, because the order matters when
   ;; calling `kill-append'.
-  (interactive (list (mark) (point) 'region))
+  (interactive
+   (progn (when kill-secondary-flag
+            (mouse-set-primary-from-secondary)) ; no region but secondary
+          (list (mark) (point) 'region)))
   (unless (and beg end)
     (user-error "The mark is not set now, so there is no region"))
   (condition-case nil
@@ -4387,6 +4402,8 @@ This command's old key binding has been given to `kill-ring-save'."
 In Transient Mark mode, deactivate the mark.
 If `interprogram-cut-function' is non-nil, also save the text for a window
 system cut and paste.
+If `kill-secondary-flag' is non-nil, save
+mouse-secondary-overlay instead of the region.

 If you want to append the killed line to the last killed text,
 use \\[append-next-kill] before \\[kill-ring-save].
@@ -4404,8 +4421,13 @@ This command is similar to `copy-region-as-kill', except that it gives
 visual feedback indicating the extent of the region being copied."
   ;; Pass mark first, then point, because the order matters when
   ;; calling `kill-append'.
-  (interactive (list (mark) (point)
-		     (prefix-numeric-value current-prefix-arg)))
+  (interactive
+   (progn (when kill-secondary-flag
+            (mouse-set-primary-from-secondary)) ; no region but secondary
+          (list (mark) (point)
+                (prefix-numeric-value current-prefix-arg))))
   (copy-region-as-kill beg end region)
   ;; This use of called-interactively-p is correct because the code it
   ;; controls just gives the user visual feedback.


# Info

diff --git a/killing.252.texi b/killing.texi
index 47de053..f554adb 100755
--- a/killing.252.texi
+++ b/killing.texi
@@ -624,6 +624,10 @@ end of the yanked text (@code{mouse-yank-secondary}).
 Double or triple clicking of @kbd{M-mouse-1} operates on words and
 lines, much like @kbd{mouse-1}.

+If @code{kill-secondary-flag} is non-@code{nil}, a command @kbd{C-w}
+(@code{kill-region}), and a command @kbd{M-w} (@code{kill-ring-save})
+will target the secondary selection when region does not exist.
+
 If @code{mouse-yank-at-point} is non-@code{nil}, @kbd{M-mouse-2} yanks
 at point.  Then it does not matter precisely where you click, or even
 which of the frame's windows you click on.  @xref{Mouse Commands}.





^ permalink raw reply related	[flat|nested] 26+ messages in thread

* bug#27530: patch to cut and copy secondary
  2017-07-01  0:45   ` Tak Kunihiro
@ 2017-08-01  1:35     ` Tak Kunihiro
  0 siblings, 0 replies; 26+ messages in thread
From: Tak Kunihiro @ 2017-08-01  1:35 UTC (permalink / raw)
  To: 27530; +Cc: Kunihiro Tak

Please do not forget the patch that I have sent 4 weeks ago.
I suppose everyone is busy.


On Jul 1, 2017, at 09:45 , Tak Kunihiro <tkk@misasa.okayama-u.ac.jp> wrote:

> I re-send a patch to cut and copy the secondary.
> 
> I saw https://www.emacswiki.org/emacs/second-sel.el and found it is a
> super super-set of this patch.  As my submission, I try to maintain
> this patch small and fit into `simple.el' and `mouse.el'.
> 
>> defun mouse-secondary-exists-p ()
>> 
>> Name probably shouldn't end in `-p' if the return value is
>> mainly not a Boolean.  Non-nil here means overlay limits.
> 
> I changed docstring to match the name of function.
> 
>    Return if the secondary selection exists in current buffer.
>    When exists, this returns start and end of the secondary selection.
> 
>> defun mouse-set-mark-and-point-from-secondary ()
>> 
>> Cf. `secondary-to-primary'.
> 
> I changed the name to mouse-set-primary-from-secondary.
> 
>> defun mouse-set-secondary-from-region ()
>> 
>> Cf. `primary-to-secondary'.
> 
> I changed the name to mouse-set-secondary-from-primary.
> 
>> IMO, the first, and simplest, improvement to add to Emacs is
>> a way to create and yank the secondary selection using only
>> the keyboard, not the mouse.  My guess is that the reason
>> more users do not use the secondary selection is that there
>> are no keyboard keybindings for it.
> 
> I made following the two functions to be interactive to be called from
> keyboard.
> 
>    mouse-set-primary-from-secondary
>    mouse-set-secondary-from-primary
> 
> My local plan is to set secondary by hook something like below.
> 
>    (add-hook 'view-mode-hook 'mouse-set-secondary-from-primary)
> 
> 
> # Change log
> 
> 2017-07-02  Tak Kunihiro  <tkk@misasa.okayama-u.ac.jp>
> 
>        Cut and copy the secondary selection when the region does not exist.
> 
>        * doc/emacs/killing.texi (Secondary Selection): Document support of cut and copy the secondary selection.
>        * lisp/simple.el (kill-secondary-flag): Use also the secondary selection not only the region to cut and copy.
>        (kill-region): Set target to the secondary selection not only the primary selection if kill-secondary-flag is non-nil.
>        (kill-ring-save): Set target to the secondary selection not only the primary selection if kill-secondary-flag is non-nil.
>        * lisp/mouse.el (mouse-secondary-exists-p): Return if the secondary selection exists in current buffer.
>        (mouse-set-primary-from-secondary): Set the region to text in the secondary selection.
>        (mouse-set-secondary-from-primary): Set the secondary selection to text in the region.
> 
> # NEWS
> 
> ** Use can cut and copy secondary when region does not exist.
> To cut and copy secondary using C-w and M-w, set 'kill-secondary-flag' to t.
> 
> # Code 1/2
> 
> diff --git a/mouse.260.el b/mouse.el
> old mode 100644
> new mode 100755
> index 9b6b169..55357da
> --- a/mouse.260.el
> +++ b/mouse.el
> @@ -1545,6 +1545,51 @@ CLICK position, kill the secondary selection."
> 	 (> (length str) 0)
> 	 (gui-set-selection 'SECONDARY str))))
> 
> +(defun mouse-secondary-exists-p ()
> +  "Return if the secondary selection exists in current buffer.
> +When exists, this returns start and end of the secondary selection."
> +  (let ((buf (overlay-buffer mouse-secondary-overlay))
> +        (beg (overlay-start mouse-secondary-overlay))
> +        (end (overlay-end mouse-secondary-overlay)))
> +    (when (and buf beg end
> +               (equal buf (current-buffer))
> +               (/= beg end))
> +      (list beg end))))
> +
> +(defun mouse-set-primary-from-secondary ()
> +  "Set the region to text in the secondary selection.
> +This works when the secondary selection exists and the region
> +does not exist in current buffer.  The mouse-secondary-overlay
> +will be deleted."
> +  (interactive)
> +  (let ((secondary-to-kill (and (not (region-active-p))
> +                                (mouse-secondary-exists-p))))
> +    ;; Delete overlay even on different buffer.
> +    ;; Deletion should be later than obtaining location.
> +    (delete-overlay mouse-secondary-overlay)
> +    (when secondary-to-kill
> +      (push-mark (car secondary-to-kill) t t)
> +      (goto-char (cadr secondary-to-kill)))))
> +
> +(defun mouse-set-secondary-from-primary ()
> +  "Set the secondary selection to text in the region.
> +When region does not exists, set mouse-secondary-start to the point.
> +When point is in the secondary selection, do nothing."
> +  (interactive)
> +  (cond
> +   ((region-active-p) ; Create mouse-secondary-overlay from region.
> +    (delete-overlay mouse-secondary-overlay)
> +    (move-overlay mouse-secondary-overlay (region-beginning) (region-end)))
> +   ((member 'secondary-selection ; Do nothing.
> +            (mapcar (lambda (xxx) (overlay-get xxx 'face))
> +                    (overlays-at (point)))))
> +   (t (delete-overlay mouse-secondary-overlay) ; Create mouse-secondary-start from point.
> +      (push-mark (point))
> +      (setq mouse-secondary-start (make-marker))
> +      (move-marker mouse-secondary-start (point)))))
> +
> 
> (defcustom mouse-buffer-menu-maxlen 20
>   "Number of buffers in one pane (submenu) of the buffer menu.
> 
> # Code 2/2
> 
> diff --git a/simple.252.el b/simple.el
> index 5f70ade..a80953a 100644
> --- a/simple.252.el
> +++ b/simple.el
> @@ -4287,11 +4287,21 @@ move the yanking point; just return the Nth kill forward."
>   :type 'boolean
>   :group 'killing)
> 
> +(defcustom kill-secondary-flag nil
> +  "Kill the secondary selection when it exists but the region does not exist."
> +  :type 'boolean
> +  :group 'mouse
> +  :version "26.1")
> +
> (defun kill-region (beg end &optional region)
>   "Kill (\"cut\") text between point and mark.
> This deletes the text from the buffer and saves it in the kill ring.
> The command \\[yank] can retrieve it from there.
> \(If you want to save the region without killing it, use \\[kill-ring-save].)
> +If `kill-secondary-flag' is non-nil, kill
> +mouse-secondary-overlay instead of the region.
> 
> If you want to append the killed region to the last killed text,
> use \\[append-next-kill] before \\[kill-region].
> @@ -4317,7 +4327,12 @@ Supply two arguments, character positions BEG and END indicating the
>  region instead."
>   ;; Pass mark first, then point, because the order matters when
>   ;; calling `kill-append'.
> -  (interactive (list (mark) (point) 'region))
> +  (interactive
> +   (progn (when kill-secondary-flag
> +            (mouse-set-primary-from-secondary)) ; no region but secondary
> +          (list (mark) (point) 'region)))
>   (unless (and beg end)
>     (user-error "The mark is not set now, so there is no region"))
>   (condition-case nil
> @@ -4387,6 +4402,8 @@ This command's old key binding has been given to `kill-ring-save'."
> In Transient Mark mode, deactivate the mark.
> If `interprogram-cut-function' is non-nil, also save the text for a window
> system cut and paste.
> +If `kill-secondary-flag' is non-nil, save
> +mouse-secondary-overlay instead of the region.
> 
> If you want to append the killed line to the last killed text,
> use \\[append-next-kill] before \\[kill-ring-save].
> @@ -4404,8 +4421,13 @@ This command is similar to `copy-region-as-kill', except that it gives
> visual feedback indicating the extent of the region being copied."
>   ;; Pass mark first, then point, because the order matters when
>   ;; calling `kill-append'.
> -  (interactive (list (mark) (point)
> -		     (prefix-numeric-value current-prefix-arg)))
> +  (interactive
> +   (progn (when kill-secondary-flag
> +            (mouse-set-primary-from-secondary)) ; no region but secondary
> +          (list (mark) (point)
> +                (prefix-numeric-value current-prefix-arg))))
>   (copy-region-as-kill beg end region)
>   ;; This use of called-interactively-p is correct because the code it
>   ;; controls just gives the user visual feedback.
> 
> 
> # Info
> 
> diff --git a/killing.252.texi b/killing.texi
> index 47de053..f554adb 100755
> --- a/killing.252.texi
> +++ b/killing.texi
> @@ -624,6 +624,10 @@ end of the yanked text (@code{mouse-yank-secondary}).
> Double or triple clicking of @kbd{M-mouse-1} operates on words and
> lines, much like @kbd{mouse-1}.
> 
> +If @code{kill-secondary-flag} is non-@code{nil}, a command @kbd{C-w}
> +(@code{kill-region}), and a command @kbd{M-w} (@code{kill-ring-save})
> +will target the secondary selection when region does not exist.
> +
> If @code{mouse-yank-at-point} is non-@code{nil}, @kbd{M-mouse-2} yanks
> at point.  Then it does not matter precisely where you click, or even
> which of the frame's windows you click on.  @xref{Mouse Commands}.






^ permalink raw reply	[flat|nested] 26+ messages in thread

* bug#27530: patch to cut and copy secondary
  2017-06-29 12:43 bug#27530: patch to cut and copy secondary Tak Kunihiro
  2017-06-29 13:41 ` Drew Adams
@ 2017-09-05  3:11 ` Tak Kunihiro
  2017-09-05  7:51   ` Robert Pluim
  2017-09-05 15:08   ` Eli Zaretskii
  1 sibling, 2 replies; 26+ messages in thread
From: Tak Kunihiro @ 2017-09-05  3:11 UTC (permalink / raw)
  To: 27530; +Cc: tkk

I found the secondary selection is very useful.  I sent a patch on
June 2017 and Drew inferred importance of commands to utilize the
secondary selection.

> IMO, the first, and simplest, improvement to add to Emacs is
> a way to create and yank the secondary selection using only
> the keyboard, not the mouse.  My guess is that the reason
> more users do not use the secondary selection is that there
> are no keyboard keybindings for it.

I found that the exchange of primary and secondary can be implemented
into C-x C-x as `mouse-exchange-point-and-mark-secondary'.

  (global-set-key [remap exchange-point-and-mark] 'mouse-exchange-point-and-mark-secondary)

The function `mouse-exchange-point-and-mark-secondary' exchanges `mark
and point' and secondary.  When there is neither primary nor
secondary, it behaves as `exchange-point-and-mark'.  By doing this, no
revision is necessary for functions that react to region.
 
Here I send a revised patch that only applied to lisp/mouse.el to
utilize the secondary selection more. Please consider this patch to be
applied.



# Change log

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

       Add a function to exchange the point and the mark, and the secondary selection.

       * lisp/mouse.el (mouse-exchange-point-and-mark-secondary): Exchange
        the point and the mark, and the secondary selection.
       (mouse-secondary-exists-p): Return if the secondary 
       selection exists in current buffer.
       (mouse-set-primary-from-secondary): Set the region to text in the 
       secondary selection.
       (mouse-set-secondary-from-primary): Set the secondary selection to 
       text in the region.


# Patch

diff --git a/mouse.260.el b/mouse.el
old mode 100644
new mode 100755
index 2fbaaad..505546f
--- a/mouse.260.el
+++ b/mouse.el
@@ -1916,6 +1916,71 @@ CLICK position, kill the secondary selection."
 	 (> (length str) 0)
 	 (gui-set-selection 'SECONDARY str))))
 
+(defun mouse-exchange-point-and-mark-secondary (&optional arg)
+  "Exchange the point and the mark, and the secondary selection.
+When the mark is active, this exchanges the point and the mark
+then creates the secondary selection from the primary selection.
+When the mark is not active but the secondary selection exists,
+this restores the primary selection from the secondary selection."
+  ;; (global-set-key [remap exchange-point-and-mark] 'mouse-exchange-point-and-mark-secondary)
+  (interactive "P")
+  (cond
+   ((region-active-p)            ; Do not care pre-existing secondary.
+    (mouse-set-secondary-from-primary))
+   ((mouse-secondary-exists-p)          ; When no primary exists.
+    (mouse-set-primary-from-secondary))
+   (t nil))                             ; No primary and no secondary.
+  (exchange-point-and-mark arg))
+
+(defun mouse-secondary-exists-p ()
+  "Return if the secondary selection exists in current buffer.
+When exists, this returns start and end of the secondary selection."
+  (let ((buf (overlay-buffer mouse-secondary-overlay))
+        (beg (overlay-start mouse-secondary-overlay))
+        (end (overlay-end mouse-secondary-overlay)))
+    (when (and buf beg end
+               (equal buf (current-buffer))
+               (/= beg end))
+      (list beg end))))
+
+(defun mouse-set-primary-from-secondary ()
+  "Set the region to text in the secondary selection.
+This works when the secondary selection exists and the region
+does not exist in current buffer.  The mouse-secondary-overlay
+will be deleted."
+  (interactive)
+  (let ((secondary-to-kill (and (not (region-active-p))
+                                (mouse-secondary-exists-p))))
+    ;; Delete overlay even on different buffer.
+    ;; Deletion should be later than obtaining location.
+    (delete-overlay mouse-secondary-overlay)
+    (when secondary-to-kill
+      (let* ((pos0 (car secondary-to-kill))
+             (pos1 (cadr secondary-to-kill))
+             ;; Restore point to closer position.
+             (is-point-front (< (point) (/ (+ pos0 pos1) 2))))
+        (push-mark (if is-point-front pos1 pos0) t t)
+        (goto-char (if is-point-front pos0 pos1))))))
+
+(defun mouse-set-secondary-from-primary ()
+  "Set the secondary selection to text in the region.
+When region does not exists, set mouse-secondary-start to the point.
+When point is in the secondary selection, do nothing."
+  (interactive)
+  (cond
+   ((region-active-p) ; Create mouse-secondary-overlay from region.
+    (delete-overlay mouse-secondary-overlay)
+    (move-overlay mouse-secondary-overlay (region-beginning) (region-end)))
+   ((member 'secondary-selection ; Do nothing.
+            (mapcar (lambda (xxx) (overlay-get xxx 'face))
+                    (overlays-at (point)))))
+   (t (delete-overlay mouse-secondary-overlay) ; Create mouse-secondary-start from point.
+      (push-mark (point))
+      (setq mouse-secondary-start (make-marker))
+      (move-marker mouse-secondary-start (point)))))
+
 \f
 (defcustom mouse-buffer-menu-maxlen 20
   "Number of buffers in one pane (submenu) of the buffer menu.





^ permalink raw reply related	[flat|nested] 26+ messages in thread

* bug#27530: patch to cut and copy secondary
  2017-09-05  3:11 ` Tak Kunihiro
@ 2017-09-05  7:51   ` Robert Pluim
  2017-09-05  9:25     ` Tak Kunihiro
  2017-09-05 15:08   ` Eli Zaretskii
  1 sibling, 1 reply; 26+ messages in thread
From: Robert Pluim @ 2017-09-05  7:51 UTC (permalink / raw)
  To: Tak Kunihiro; +Cc: 27530

Tak Kunihiro <tkk@misasa.okayama-u.ac.jp> writes:

> I found that the exchange of primary and secondary can be implemented
> into C-x C-x as `mouse-exchange-point-and-mark-secondary'.
>
>   (global-set-key [remap exchange-point-and-mark] 'mouse-exchange-point-and-mark-secondary)
>
> The function `mouse-exchange-point-and-mark-secondary' exchanges `mark
> and point' and secondary.  When there is neither primary nor
> secondary, it behaves as `exchange-point-and-mark'.  By doing this, no
> revision is necessary for functions that react to region.
>

This description seems to contradict the docstring:
>  
> +(defun mouse-exchange-point-and-mark-secondary (&optional arg)
> +  "Exchange the point and the mark, and the secondary selection.
> +When the mark is active, this exchanges the point and the mark
> +then creates the secondary selection from the primary selection.
> +When the mark is not active but the secondary selection exists,
> +this restores the primary selection from the secondary selection."
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Could you explain in more detail how this functions? The behaviour
seems useful, but I don't understand exactly what it does just from
the docstring.

Regards

Robert





^ permalink raw reply	[flat|nested] 26+ messages in thread

* bug#27530: patch to cut and copy secondary
  2017-09-05  7:51   ` Robert Pluim
@ 2017-09-05  9:25     ` Tak Kunihiro
  2017-09-05  9:32       ` Robert Pluim
  2017-09-05 13:53       ` Drew Adams
  0 siblings, 2 replies; 26+ messages in thread
From: Tak Kunihiro @ 2017-09-05  9:25 UTC (permalink / raw)
  To: rpluim; +Cc: tkk, 27530

>> The function `mouse-exchange-point-and-mark-secondary' exchanges `mark
>> and point' and secondary.  When there is neither primary nor
>> secondary, it behaves as `exchange-point-and-mark'.  By doing this, no
>> revision is necessary for functions that react to region.
> 
> This description seems to contradict the docstring:
>>  
>> +(defun mouse-exchange-point-and-mark-secondary (&optional arg)
>> +  "Exchange the point and the mark, and the secondary selection.
>> +When the mark is active, this exchanges the point and the mark
>> +then creates the secondary selection from the primary selection.
>> +When the mark is not active but the secondary selection exists,
>> +this restores the primary selection from the secondary selection."
>         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> 
> Could you explain in more detail how this functions? The behaviour
> seems useful, but I don't understand exactly what it does just from
> the docstring.

The function exchanges point and mark.
When there is region, this also creates secondary.
When there is secondary, this converts secondary to primary in advance.

As a consequence, an user sees the function exchanges
 - `point' and `mark'
 - `point and mark' (= primary) and secondary
at the same time.





^ permalink raw reply	[flat|nested] 26+ messages in thread

* bug#27530: patch to cut and copy secondary
  2017-09-05  9:25     ` Tak Kunihiro
@ 2017-09-05  9:32       ` Robert Pluim
  2017-09-05 12:22         ` Tak Kunihiro
  2017-09-05 13:53       ` Drew Adams
  1 sibling, 1 reply; 26+ messages in thread
From: Robert Pluim @ 2017-09-05  9:32 UTC (permalink / raw)
  To: Tak Kunihiro; +Cc: 27530

Tak Kunihiro <tkk@misasa.okayama-u.ac.jp> writes:

>>> The function `mouse-exchange-point-and-mark-secondary' exchanges `mark
>>> and point' and secondary.  When there is neither primary nor
>>> secondary, it behaves as `exchange-point-and-mark'.  By doing this, no
>>> revision is necessary for functions that react to region.
>> 
>> This description seems to contradict the docstring:
>>>  
>>> +(defun mouse-exchange-point-and-mark-secondary (&optional arg)
>>> +  "Exchange the point and the mark, and the secondary selection.
>>> +When the mark is active, this exchanges the point and the mark
>>> +then creates the secondary selection from the primary selection.
>>> +When the mark is not active but the secondary selection exists,
>>> +this restores the primary selection from the secondary selection."
>>         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>> 
>> Could you explain in more detail how this functions? The behaviour
>> seems useful, but I don't understand exactly what it does just from
>> the docstring.
>
> The function exchanges point and mark.
> When there is region, this also creates secondary.
> When there is secondary, this converts secondary to primary in advance.
>

OK. So if I've understood correctly, the user can then use C-y to yank
the primary (which was the secondary before)?

Regards

Robert





^ permalink raw reply	[flat|nested] 26+ messages in thread

* bug#27530: patch to cut and copy secondary
  2017-09-05  9:32       ` Robert Pluim
@ 2017-09-05 12:22         ` Tak Kunihiro
  0 siblings, 0 replies; 26+ messages in thread
From: Tak Kunihiro @ 2017-09-05 12:22 UTC (permalink / raw)
  To: rpluim; +Cc: tkk, 27530

>> The function exchanges point and mark.
>> When there is region, this also creates secondary.
>> When there is secondary, this converts secondary to primary in advance.
> 
> OK. So if I've understood correctly, the user can then use C-y to yank
> the primary (which was the secondary before)?

The function `mouse-exchange-point-and-mark-secondary' has nothing to
do with kill-ring.

I suppose you meant if the user can C-w to kill the primary (which was
the secondary before). Yes.





^ permalink raw reply	[flat|nested] 26+ messages in thread

* bug#27530: patch to cut and copy secondary
  2017-09-05  9:25     ` Tak Kunihiro
  2017-09-05  9:32       ` Robert Pluim
@ 2017-09-05 13:53       ` Drew Adams
  2017-09-05 23:17         ` Tak Kunihiro
  1 sibling, 1 reply; 26+ messages in thread
From: Drew Adams @ 2017-09-05 13:53 UTC (permalink / raw)
  To: Tak Kunihiro, rpluim; +Cc: 27530

> The function exchanges point and mark.
> When there is region, this also creates secondary.

Why?  What if I want to just exchange point and mark,
and not also copy the region to the secondary?

> When there is secondary, this converts secondary
> to primary in advance.

What if I don't want to do that?

I don't like the sound of this.  The point of having a
secondary selection is to keep it separate from the
region or primary selection.  `C-x C-x' should affect
only the region, not the secondary selection.

There is nothing wrong with having commands that do
the kinds of things you describe - I've long had similar,
as you know. What is not good, I think, is to confuse the
two wrt key bindings.  Please choose different bindings.

> As a consequence, an user sees the function exchanges
>  - `point' and `mark'
>  - `point and mark' (= primary) and secondary
> at the same time.

My suggestion is to please keep such functionality separate.

----

FWIW, I've been using secondary, swapping it with primary,
etc. for a long time.  I make sure, in second-sel.el, to
suggest key bindings that keep things separate.

(global-set-key (kbd "C-M-y") 'secondary-yank|select|move|swap)
(define-key esc-map "y" 'yank-pop-commands)
(global-set-key (kbd "C-x C-M-SPC") 'set-secondary-start)
(global-set-key (kbd "C-x C-M-<return>") 'secondary-save-then-kill)
(define-key isearch-mode-map (kbd "C-M-y") 'isearch-yank-secondary)

The single key `C-M-y' (just suggested, not done by second-sel.el)
does all of this:

Yank the secondary selection.  With a prefix arg, interact with
region.

 Prefix arg:

  None: Yank secondary.
  Zero: Select secondary as region.
  > 0:  Move secondary to region.
  < 0:  Swap region and secondary.

 Details:

 No prefix arg: Yank the secondary selection at point.  Move point
 to the end of the inserted text.  Leave mark where it was.

 Zero arg: Select the secondary selection and pop to its buffer.

 Non-zero arg: Move the secondary selection to this buffer's region.

 Negative arg: Also go to where the secondary selection was and
 select it as the region.  That is, swap the region and the
 secondary selection.

Yes, the command mixes behavior for the region and the secondary
selection.  But it does so only when you use a prefix arg.  And
it does so only on a new key binding (`C-M-y'), not on a binding
long associated with the mark and the region (`C-x C-x').  The
command and key are specifically for the secondary selection.





^ permalink raw reply	[flat|nested] 26+ messages in thread

* bug#27530: patch to cut and copy secondary
  2017-09-05  3:11 ` Tak Kunihiro
  2017-09-05  7:51   ` Robert Pluim
@ 2017-09-05 15:08   ` Eli Zaretskii
  2017-09-05 23:06     ` Tak Kunihiro
  1 sibling, 1 reply; 26+ messages in thread
From: Eli Zaretskii @ 2017-09-05 15:08 UTC (permalink / raw)
  To: Tak Kunihiro; +Cc: 27530

> Date: Tue, 05 Sep 2017 12:11:04 +0900 (JST)
> From: Tak Kunihiro <tkk@misasa.okayama-u.ac.jp>
> Cc: tkk@misasa.okayama-u.ac.jp
> 
> I found the secondary selection is very useful.  I sent a patch on
> June 2017 and Drew inferred importance of commands to utilize the
> secondary selection.
> 
> > IMO, the first, and simplest, improvement to add to Emacs is
> > a way to create and yank the secondary selection using only
> > the keyboard, not the mouse.  My guess is that the reason
> > more users do not use the secondary selection is that there
> > are no keyboard keybindings for it.
> 
> I found that the exchange of primary and secondary can be implemented
> into C-x C-x as `mouse-exchange-point-and-mark-secondary'.
> 
>   (global-set-key [remap exchange-point-and-mark] 'mouse-exchange-point-and-mark-secondary)

Hmm...  In Emacs 24, we have changed how selection works to conform
with other modern X applications, by having primary selection set only
via mouse gestures, whereas keyboard commands work with the clipboard.
Doesn't your proposal go in the opposite direction?

IOW, what is the logic of having keyboard commands set selections,
when all the rest of the X world does the exact opposite?  Or did the
trend got reversed yet again?

In any case, a command whose name starts with "mouse-" should have the
"e" interactive spec, and should react to mouse gestures, not to
keyboard keys.  I also don't like advising users to remap "C-x C-x" to
anything that smells a mouse.

Thanks.





^ permalink raw reply	[flat|nested] 26+ messages in thread

* bug#27530: patch to cut and copy secondary
  2017-09-05 15:08   ` Eli Zaretskii
@ 2017-09-05 23:06     ` Tak Kunihiro
  2017-09-06  2:33       ` Eli Zaretskii
  0 siblings, 1 reply; 26+ messages in thread
From: Tak Kunihiro @ 2017-09-05 23:06 UTC (permalink / raw)
  To: eliz; +Cc: tkk, 27530

>> I found that the exchange of primary and secondary can be implemented
>> into C-x C-x as `mouse-exchange-point-and-mark-secondary'.
>> 
>>   (global-set-key [remap exchange-point-and-mark] 'mouse-exchange-point-and-mark-secondary)
> 
> Hmm...  In Emacs 24, we have changed how selection works to conform
> with other modern X applications, by having primary selection set only
> via mouse gestures, whereas keyboard commands work with the clipboard.
> Doesn't your proposal go in the opposite direction?

I see.  I wonder if the direction lets the secondary selection react
with region-reacting functions such for comment-dwim.

> In any case, a command whose name starts with "mouse-" should have the
> "e" interactive spec, and should react to mouse gestures, not to
> keyboard keys.  I also don't like advising users to remap "C-x C-x" to
> anything that smells a mouse.

I see.  I will look for somewhere else to put in.





^ permalink raw reply	[flat|nested] 26+ messages in thread

* bug#27530: patch to cut and copy secondary
  2017-09-05 13:53       ` Drew Adams
@ 2017-09-05 23:17         ` Tak Kunihiro
  2017-09-06  0:29           ` Drew Adams
  0 siblings, 1 reply; 26+ messages in thread
From: Tak Kunihiro @ 2017-09-05 23:17 UTC (permalink / raw)
  To: drew.adams; +Cc: rpluim, tkk, 27530

>> The function exchanges point and mark.
>> When there is region, this also creates secondary.
> 
> Why?  What if I want to just exchange point and mark,
> and not also copy the region to the secondary?

I proposed to put a function in lisp/mouse.el that can be remapped to
C-x C-x by an user.  I did not propose to replace
exchange-point-and-mark.

I create the secondary selection every wheel scroll as memory of
region.  To me, C-x C-x works well to recall region.





^ permalink raw reply	[flat|nested] 26+ messages in thread

* bug#27530: patch to cut and copy secondary
  2017-09-05 23:17         ` Tak Kunihiro
@ 2017-09-06  0:29           ` Drew Adams
  0 siblings, 0 replies; 26+ messages in thread
From: Drew Adams @ 2017-09-06  0:29 UTC (permalink / raw)
  To: Tak Kunihiro; +Cc: rpluim, 27530

> >> The function exchanges point and mark.
> >> When there is region, this also creates secondary.
> >
> > Why?  What if I want to just exchange point and mark,
> > and not also copy the region to the secondary?
> 
> I proposed to put a function in lisp/mouse.el that can be remapped to
> C-x C-x by an user.  I did not propose to replace
> exchange-point-and-mark.
> 
> I create the secondary selection every wheel scroll as memory of
> region.  To me, C-x C-x works well to recall region.

I see.  I misunderstood.  I thought that you were proposing
to bind keys/mouse by default.  Adding useful commands can't
hurt.





^ permalink raw reply	[flat|nested] 26+ messages in thread

* bug#27530: patch to cut and copy secondary
  2017-09-05 23:06     ` Tak Kunihiro
@ 2017-09-06  2:33       ` Eli Zaretskii
  2017-09-06  3:42         ` Tak Kunihiro
  0 siblings, 1 reply; 26+ messages in thread
From: Eli Zaretskii @ 2017-09-06  2:33 UTC (permalink / raw)
  To: Tak Kunihiro; +Cc: 27530

> Date: Wed, 06 Sep 2017 08:06:49 +0900 (JST)
> Cc: 27530@debbugs.gnu.org, tkk@misasa.okayama-u.ac.jp
> From: Tak Kunihiro <tkk@misasa.okayama-u.ac.jp>
> 
> > Hmm...  In Emacs 24, we have changed how selection works to conform
> > with other modern X applications, by having primary selection set only
> > via mouse gestures, whereas keyboard commands work with the clipboard.
> > Doesn't your proposal go in the opposite direction?
> 
> I see.  I wonder if the direction lets the secondary selection react
> with region-reacting functions such for comment-dwim.

I'm not sure I understand this comment.  Can you elaborate?





^ permalink raw reply	[flat|nested] 26+ messages in thread

* bug#27530: patch to cut and copy secondary
  2017-09-06  2:33       ` Eli Zaretskii
@ 2017-09-06  3:42         ` Tak Kunihiro
  2017-09-06 16:04           ` Eli Zaretskii
  0 siblings, 1 reply; 26+ messages in thread
From: Tak Kunihiro @ 2017-09-06  3:42 UTC (permalink / raw)
  To: eliz; +Cc: tkk, 27530

>>> In Emacs 24, we have changed how selection works to conform with
>>> other modern X applications, by having primary selection set only
>>> via mouse gestures, whereas keyboard commands work with the
>>> clipboard.  Doesn't your proposal go in the opposite direction?
>>
>>  I see.  I wonder if the direction lets the secondary selection
>> react with region-reacting functions such for comment-dwim.
>
> I'm not sure I understand this comment.  Can you elaborate?

I often want to comment out text with mouse-secondary-overlay.

I meant if `mouse-secondary-overlay -> region' direction is not
supported, text with mouse-secondary-overlay cannot be commented out
until I select the text again as region.  I thought it is good to
avoid redundant operation if possible.

Probably I misunderstand two relationships.
 primary   -- region
 secondary -- mouse-secondary-overlay





^ permalink raw reply	[flat|nested] 26+ messages in thread

* bug#27530: patch to cut and copy secondary
  2017-09-06  3:42         ` Tak Kunihiro
@ 2017-09-06 16:04           ` Eli Zaretskii
  2017-09-07 12:35             ` Tak Kunihiro
  0 siblings, 1 reply; 26+ messages in thread
From: Eli Zaretskii @ 2017-09-06 16:04 UTC (permalink / raw)
  To: Tak Kunihiro; +Cc: 27530

> Date: Wed, 06 Sep 2017 12:42:52 +0900 (JST)
> Cc: 27530@debbugs.gnu.org, tkk@misasa.okayama-u.ac.jp
> From: Tak Kunihiro <tkk@misasa.okayama-u.ac.jp>
> 
> >>> In Emacs 24, we have changed how selection works to conform with
> >>> other modern X applications, by having primary selection set only
> >>> via mouse gestures, whereas keyboard commands work with the
> >>> clipboard.  Doesn't your proposal go in the opposite direction?
> >>
> >>  I see.  I wonder if the direction lets the secondary selection
> >> react with region-reacting functions such for comment-dwim.
> >
> > I'm not sure I understand this comment.  Can you elaborate?
> 
> I often want to comment out text with mouse-secondary-overlay.
> 
> I meant if `mouse-secondary-overlay -> region' direction is not
> supported, text with mouse-secondary-overlay cannot be commented out
> until I select the text again as region.  I thought it is good to
> avoid redundant operation if possible.

If we want a function that will put region around secondary selection,
why not write such a function, and let users who want to code commands
that use this functionality do that?  IOW, why do we have to come up
with a command to do something which we aren't sure is a frequent use
case?





^ permalink raw reply	[flat|nested] 26+ messages in thread

* bug#27530: patch to cut and copy secondary
  2017-09-06 16:04           ` Eli Zaretskii
@ 2017-09-07 12:35             ` Tak Kunihiro
  2017-09-07 19:11               ` Eli Zaretskii
  0 siblings, 1 reply; 26+ messages in thread
From: Tak Kunihiro @ 2017-09-07 12:35 UTC (permalink / raw)
  To: eliz; +Cc: tkk, 27530

>> I often want to comment out text with mouse-secondary-overlay.
>> 
>> I meant if `mouse-secondary-overlay -> region' direction is not
>> supported, text with mouse-secondary-overlay cannot be commented out
>> until I select the text again as region.  I thought it is good to
>> avoid redundant operation if possible.
> 
> If we want a function that will put region around secondary selection,
> why not write such a function, and let users who want to code commands
> that use this functionality do that?  IOW, why do we have to come up
> with a command to do something which we aren't sure is a frequent use
> case?

How about having those in subr.el?

 -- Function: overlay-exchange-region overlay
 -- Function: overlay-exists-p overlay
 -- Function: overlay-to-region overlay
 -- Function: overlay-from-region overlay





^ permalink raw reply	[flat|nested] 26+ messages in thread

* bug#27530: patch to cut and copy secondary
  2017-09-07 12:35             ` Tak Kunihiro
@ 2017-09-07 19:11               ` Eli Zaretskii
  2017-09-07 23:02                 ` Tak Kunihiro
  0 siblings, 1 reply; 26+ messages in thread
From: Eli Zaretskii @ 2017-09-07 19:11 UTC (permalink / raw)
  To: Tak Kunihiro; +Cc: 27530

> Date: Thu, 07 Sep 2017 21:35:20 +0900 (JST)
> Cc: 27530@debbugs.gnu.org, tkk@misasa.okayama-u.ac.jp
> From: Tak Kunihiro <tkk@misasa.okayama-u.ac.jp>
> 
> > If we want a function that will put region around secondary selection,
> > why not write such a function, and let users who want to code commands
> > that use this functionality do that?  IOW, why do we have to come up
> > with a command to do something which we aren't sure is a frequent use
> > case?
> 
> How about having those in subr.el?
> 
>  -- Function: overlay-exchange-region overlay
>  -- Function: overlay-exists-p overlay
>  -- Function: overlay-to-region overlay
>  -- Function: overlay-from-region overlay

Hard to answer that, without some details.  Can you tell in a few
words what each function is supposed to do?





^ permalink raw reply	[flat|nested] 26+ messages in thread

* bug#27530: patch to cut and copy secondary
  2017-09-07 19:11               ` Eli Zaretskii
@ 2017-09-07 23:02                 ` Tak Kunihiro
  2017-09-08  8:27                   ` Eli Zaretskii
  0 siblings, 1 reply; 26+ messages in thread
From: Tak Kunihiro @ 2017-09-07 23:02 UTC (permalink / raw)
  To: eliz; +Cc: tkk, 27530

> If we want a function that will put region around secondary selection,
> why not write such a function, and let users who want to code commands
> that use this functionality do that?  IOW, why do we have to come up
> with a command to do something which we aren't sure is a frequent use
> case?

Since the secondary selection is one of overlays, to have functions
that transform the region and an overlay is more general.

How about having those in lisp/subr.el?  An user can still manipulate the
secondary selection.  Sorry for shortage for words.

 -- Function: overlay-exchange-region overlay
     This function exchanges the region and OVERLAY.
     When the region is active, this sets OVERLAY from the region.
     When the region is not active but OVERLAY exists, this sets the
     region from OVERLAY.

-- Function: overlay-exists-p overlay
    This function returns if OVERLAY exists in current buffer.
    When OVERLAY exists, this returns list of start and end of
    OVERLAY.

-- Function: overlay-to-region overlay
    This function sets the region to text in OVERLAY.
    This works when OVERLAY exists and the region does not exist in
    current buffer.  The OVERLAY will be deleted.

-- Function: overlay-from-region overlay
    This function sets OVERLAY to text in the region.
    When the region does not exists, set OVERLAY to point.  When
    point is within OVERLAY, do nothing.





^ permalink raw reply	[flat|nested] 26+ messages in thread

* bug#27530: patch to cut and copy secondary
  2017-09-07 23:02                 ` Tak Kunihiro
@ 2017-09-08  8:27                   ` Eli Zaretskii
  2017-09-10  3:01                     ` Tak Kunihiro
  0 siblings, 1 reply; 26+ messages in thread
From: Eli Zaretskii @ 2017-09-08  8:27 UTC (permalink / raw)
  To: Tak Kunihiro; +Cc: 27530

> Date: Fri, 08 Sep 2017 08:02:08 +0900 (JST)
> Cc: 27530@debbugs.gnu.org, tkk@misasa.okayama-u.ac.jp
> From: Tak Kunihiro <tkk@misasa.okayama-u.ac.jp>
> 
> How about having those in lisp/subr.el?  An user can still manipulate the
> secondary selection.  Sorry for shortage for words.
> 
>  -- Function: overlay-exchange-region overlay
>      This function exchanges the region and OVERLAY.
>      When the region is active, this sets OVERLAY from the region.
>      When the region is not active but OVERLAY exists, this sets the
>      region from OVERLAY.

Does this do anything but call overlay-to-region and
overlay-from-region? 

> -- Function: overlay-exists-p overlay
>     This function returns if OVERLAY exists in current buffer.
>     When OVERLAY exists, this returns list of start and end of
>     OVERLAY.

This is just

  (memq OVERLAY (overlays-in (point-min) (point-max)))

Right?

> -- Function: overlay-to-region overlay
>     This function sets the region to text in OVERLAY.
>     This works when OVERLAY exists and the region does not exist in
>     current buffer.  The OVERLAY will be deleted.

I don't understand this one.  I guess "text in OVERLAY" is confusing;
did you mean OVERLAY's beginning and end?

> -- Function: overlay-from-region overlay
>     This function sets OVERLAY to text in the region.
>     When the region does not exists, set OVERLAY to point.  When
>     point is within OVERLAY, do nothing.

In sum, I think these are too general: they talk about OVERLAY in
general, whereas what you really mean is the special overlay used for
secondary selection.  So how about these instead:

  secondary-selection-exist-p
  secondary-selection-from-region
  secondary-selection-to-region

?  The advantage is that the caller will not have to pass OVERLAY,
which IMO is an unnecessary burden.

Thanks.





^ permalink raw reply	[flat|nested] 26+ messages in thread

* bug#27530: patch to cut and copy secondary
  2017-09-08  8:27                   ` Eli Zaretskii
@ 2017-09-10  3:01                     ` Tak Kunihiro
  2017-09-11  2:03                       ` Tak Kunihiro
  0 siblings, 1 reply; 26+ messages in thread
From: Tak Kunihiro @ 2017-09-10  3:01 UTC (permalink / raw)
  To: eliz; +Cc: tkk, 27530

Thank you for the response.

> In sum, I think these are too general: they talk about OVERLAY in
> general, whereas what you really mean is the special overlay used for
> secondary selection.  So how about these instead:
> 
>   secondary-selection-exist-p
>   secondary-selection-from-region
>   secondary-selection-to-region

OK. How about three functions like below?  I plan to send a patch
relative to lisp/mouse.el.

  (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 region.
      (delete-overlay mouse-secondary-overlay) ; Delete the secondary selection even on a different buffer.
      (move-overlay mouse-secondary-overlay (region-beginning) (region-end))))


Point-to-point responses are shown below.

>>  -- Function: overlay-exchange-region overlay
>>      This function exchanges the region and OVERLAY.
>>      When the region is active, this sets OVERLAY from the region.
>>      When the region is not active but OVERLAY exists, this sets the
>>      region from OVERLAY.
> 
> Does this do anything but call overlay-to-region and
> overlay-from-region? 

Yes.  I agree to exclude this.

>> -- Function: overlay-exists-p overlay
>>     This function returns if OVERLAY exists in current buffer.
>>     When OVERLAY exists, this returns list of start and end of
>>     OVERLAY.
> 
> This is just
> 
>   (memq OVERLAY (overlays-in (point-min) (point-max)))
> 
> Right?

Yes, you are correct.

>> -- Function: overlay-to-region overlay
>>     This function sets the region to text in OVERLAY.
>>     This works when OVERLAY exists and the region does not exist in
>>     current buffer.  The OVERLAY will be deleted.
> 
> I don't understand this one.  I guess "text in OVERLAY" is confusing;
> did you mean OVERLAY's beginning and end?

Yes, sentence was vague.  It should have said as below.

   -- Function: overlay-to-region overlay
       This function sets beginning and end of the region to those of
       OVERLAY.  This works when OVERLAY exists and the region does not
       exist in current buffer.  The OVERLAY will be deleted afterward.





^ permalink raw reply	[flat|nested] 26+ messages in thread

* bug#27530: patch to cut and copy secondary
  2017-09-10  3:01                     ` Tak Kunihiro
@ 2017-09-11  2:03                       ` Tak Kunihiro
  2017-09-20  7:55                         ` Eli Zaretskii
  0 siblings, 1 reply; 26+ messages in thread
From: Tak Kunihiro @ 2017-09-11  2:03 UTC (permalink / raw)
  To: eliz; +Cc: Kunihiro Tak, 27530

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))))
+
 \f
 (defcustom mouse-buffer-menu-maxlen 20
   "Number of buffers in one pane (submenu) of the buffer menu.






^ permalink raw reply related	[flat|nested] 26+ messages in thread

* bug#27530: patch to cut and copy secondary
  2017-09-11  2:03                       ` Tak Kunihiro
@ 2017-09-20  7:55                         ` Eli Zaretskii
  2017-09-20 12:39                           ` Tak Kunihiro
  0 siblings, 1 reply; 26+ messages in thread
From: Eli Zaretskii @ 2017-09-20  7:55 UTC (permalink / raw)
  To: Tak Kunihiro; +Cc: 27530

> From: Tak Kunihiro <tkk@misasa.okayama-u.ac.jp>
> Date: Mon, 11 Sep 2017 11:03:58 +0900
> Cc: Kunihiro Tak <tkk@misasa.okayama-u.ac.jp>,
>  27530@debbugs.gnu.org
> 
> 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!

Thanks.  A few minor comments below.

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

The doc string should describe where we put point and mark as result
of this.

> +  (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.

> +(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.

Please also add a NEWS entry.





^ permalink raw reply	[flat|nested] 26+ messages in thread

* bug#27530: patch to cut and copy secondary
  2017-09-20  7:55                         ` Eli Zaretskii
@ 2017-09-20 12:39                           ` Tak Kunihiro
  2017-09-21  8:32                             ` Eli Zaretskii
  0 siblings, 1 reply; 26+ messages in thread
From: Tak Kunihiro @ 2017-09-20 12:39 UTC (permalink / raw)
  To: eliz; +Cc: tkk, 27530

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  <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/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))))
+
 \f
 (defcustom mouse-buffer-menu-maxlen 20
   "Number of buffers in one pane (submenu) of the buffer menu.





^ permalink raw reply related	[flat|nested] 26+ messages in thread

* bug#27530: patch to cut and copy secondary
  2017-09-20 12:39                           ` Tak Kunihiro
@ 2017-09-21  8:32                             ` Eli Zaretskii
  0 siblings, 0 replies; 26+ messages in thread
From: Eli Zaretskii @ 2017-09-21  8:32 UTC (permalink / raw)
  To: Tak Kunihiro; +Cc: 27530-done

> Date: Wed, 20 Sep 2017 21:39:23 +0900 (JST)
> Cc: 27530@debbugs.gnu.org, tkk@misasa.okayama-u.ac.jp
> From: Tak Kunihiro <tkk@misasa.okayama-u.ac.jp>
> 
> Following is the revised NEWS, change log, news, and patch.

Thanks, pushed.  Two minor comments for the future:

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

NEWS changes should be submitted as diffs, like you do with other
changes.  (If you are uncertain in which part to make the change,
please ask; the rules are quite simple, and you will most probably
figure them out quickly.)

> 2017-09-20  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

The summary line should be just one line.





^ permalink raw reply	[flat|nested] 26+ messages in thread

end of thread, other threads:[~2017-09-21  8:32 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-29 12:43 bug#27530: patch to cut and copy secondary Tak Kunihiro
2017-06-29 13:41 ` Drew Adams
2017-07-01  0:45   ` Tak Kunihiro
2017-08-01  1:35     ` Tak Kunihiro
2017-09-05  3:11 ` Tak Kunihiro
2017-09-05  7:51   ` Robert Pluim
2017-09-05  9:25     ` Tak Kunihiro
2017-09-05  9:32       ` Robert Pluim
2017-09-05 12:22         ` Tak Kunihiro
2017-09-05 13:53       ` Drew Adams
2017-09-05 23:17         ` Tak Kunihiro
2017-09-06  0:29           ` Drew Adams
2017-09-05 15:08   ` Eli Zaretskii
2017-09-05 23:06     ` Tak Kunihiro
2017-09-06  2:33       ` Eli Zaretskii
2017-09-06  3:42         ` Tak Kunihiro
2017-09-06 16:04           ` Eli Zaretskii
2017-09-07 12:35             ` Tak Kunihiro
2017-09-07 19:11               ` Eli Zaretskii
2017-09-07 23:02                 ` Tak Kunihiro
2017-09-08  8:27                   ` Eli Zaretskii
2017-09-10  3:01                     ` Tak Kunihiro
2017-09-11  2:03                       ` Tak Kunihiro
2017-09-20  7:55                         ` Eli Zaretskii
2017-09-20 12:39                           ` Tak Kunihiro
2017-09-21  8:32                             ` Eli Zaretskii

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).