From: Tak Kunihiro <tkk@misasa.okayama-u.ac.jp>
To: 27530@debbugs.gnu.org
Cc: tkk@misasa.okayama-u.ac.jp
Subject: bug#27530: patch to cut and copy secondary
Date: Sat, 01 Jul 2017 09:45:23 +0900 (JST) [thread overview]
Message-ID: <20170701.094523.2119298960961529023.tkk@misasa.okayama-u.ac.jp> (raw)
In-Reply-To: <9cdc1ecc-d9b2-46fa-a044-fccc27ab1696@default>
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}.
next prev parent reply other threads:[~2017-07-01 0:45 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170701.094523.2119298960961529023.tkk@misasa.okayama-u.ac.jp \
--to=tkk@misasa.okayama-u.ac.jp \
--cc=27530@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).