From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Tak Kunihiro Newsgroups: gmane.emacs.bugs Subject: bug#27530: patch to cut and copy secondary Date: Sat, 01 Jul 2017 09:45:23 +0900 (JST) Message-ID: <20170701.094523.2119298960961529023.tkk@misasa.okayama-u.ac.jp> References: <20170629.214304.1822535652145654069.tkk@misasa.okayama-u.ac.jp> <9cdc1ecc-d9b2-46fa-a044-fccc27ab1696@default> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: blaine.gmane.org 1498870100 29008 195.159.176.226 (1 Jul 2017 00:48:20 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 1 Jul 2017 00:48:20 +0000 (UTC) Cc: tkk@misasa.okayama-u.ac.jp To: 27530@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat Jul 01 02:48:13 2017 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dR6a1-0006tl-NR for geb-bug-gnu-emacs@m.gmane.org; Sat, 01 Jul 2017 02:48:09 +0200 Original-Received: from localhost ([::1]:46441 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dR6a3-00062G-Ns for geb-bug-gnu-emacs@m.gmane.org; Fri, 30 Jun 2017 20:48:11 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:60755) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dR6Zx-00062B-Kr for bug-gnu-emacs@gnu.org; Fri, 30 Jun 2017 20:48:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dR6Zu-0000sm-GJ for bug-gnu-emacs@gnu.org; Fri, 30 Jun 2017 20:48:05 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:44136) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dR6Zu-0000sO-BH for bug-gnu-emacs@gnu.org; Fri, 30 Jun 2017 20:48:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1dR6Zt-0006Q7-Ul for bug-gnu-emacs@gnu.org; Fri, 30 Jun 2017 20:48:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Tak Kunihiro Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 01 Jul 2017 00:48:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 27530 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 27530-submit@debbugs.gnu.org id=B27530.149887007324663 (code B ref 27530); Sat, 01 Jul 2017 00:48:01 +0000 Original-Received: (at 27530) by debbugs.gnu.org; 1 Jul 2017 00:47:53 +0000 Original-Received: from localhost ([127.0.0.1]:46813 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dR6Zk-0006Pj-Q1 for submit@debbugs.gnu.org; Fri, 30 Jun 2017 20:47:53 -0400 Original-Received: from mxl065v67.mxlogic.net ([208.81.65.67]:46140 helo=s14p02o144.mxlogic.net) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dR6Zh-0006PY-MH for 27530@debbugs.gnu.org; Fri, 30 Jun 2017 20:47:51 -0400 Original-Received: from unknown [42.127.236.175] (EHLO mlsec.cc.okayama-u.ac.jp) by s14p02o144.mxlogic.net(mxl_mta-8.5.0-1821) over TLS secured channel with ESMTP id 231f6595.0.46920.00-389.104146.s14p02o144.mxlogic.net (envelope-from ); Fri, 30 Jun 2017 18:47:47 -0600 (MDT) X-MXL-Hash: 5956f13314d57a02-db56eb6a6019072bf1d7f1b92eae7cb0641f125c Original-Received: from alml002.ouadm.okayama-u.ac.jp (unknown [42.127.236.168]) by mlsec.cc.okayama-u.ac.jp with smtp id 189a_41c8_c1acf388_21cb_4339_bfd8_81b259c0952c; Sat, 01 Jul 2017 09:47:40 +0900 Original-Received: from localhost (p219225-ipngn200207tottori.tottori.ocn.ne.jp [153.182.218.225]) by alml002.ouadm.okayama-u.ac.jp (Postfix) with ESMTPSA id 345A64C0980; Sat, 1 Jul 2017 09:47:41 +0900 (JST) In-Reply-To: <9cdc1ecc-d9b2-46fa-a044-fccc27ab1696@default> X-Mailer: Mew version 6.7 on Emacs 25.2 / Mule 6.0 (HANACHIRUSATO) X-NAI-Spam-Flag: NO X-NAI-Spam-Level: ***** X-NAI-Spam-Threshold: 11 X-NAI-Spam-Score: 5.2 X-NAI-Spam-Rules: 7 Rules triggered TS_MSG_REP_80_512=5, RCVD_BAD_SIP=0.1, TRK_NCM1=0.1, EDT_SA_AU_PASS=0, EDT_SA_DN_PASS=0, EDT_SA_TS_FAIL=0, RV6060=0 X-NAI-Spam-Version: 2.3.0.9418 : core <6060> : inlines <5959> : streams <1752231> : uri <2453880> X-AnalysisOut: [v=2.2 cv=AcfBJzfG c=1 sm=1 tr=0 a=8LLPK8U+aGQ6qN8QlyMYtQ==] X-AnalysisOut: [:117 a=8LLPK8U+aGQ6qN8QlyMYtQ==:17 a=kj9zAlcOel0A:10 a=LWS] X-AnalysisOut: [FodeU3zMA:10 a=xY1_shhyAAAA:8 a=ToASWR6KpZ2qS5WdBFgA:9 a=7] X-AnalysisOut: [Zwj6sZBwVKJAoWSPKxL6X1jA+E=:19 a=B1HoiEnjsBI-i7lc:21 a=Hb0] X-AnalysisOut: [_EswZ49xbdbr8:21 a=CjuIK1q_8ugA:10 a=_qGpZPc723ggZ2AwnKam:] X-AnalysisOut: [22] X-Spam: [F=0.5100000000; CM=0.500; MH=0.510(2017063010); S=0.200(2015072901)] X-MAIL-FROM: X-SOURCE-IP: [42.127.236.175] X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:134063 Archived-At: 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 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}.