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: Tue, 05 Sep 2017 12:11:04 +0900 (JST) Message-ID: <20170905.121104.688310267504171014.tkk@misasa.okayama-u.ac.jp> References: <20170629.214304.1822535652145654069.tkk@misasa.okayama-u.ac.jp> 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 1504581168 1392 195.159.176.226 (5 Sep 2017 03:12:48 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 5 Sep 2017 03:12:48 +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 Tue Sep 05 05:12:33 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 1dp4Ha-000706-Ax for geb-bug-gnu-emacs@m.gmane.org; Tue, 05 Sep 2017 05:12:10 +0200 Original-Received: from localhost ([::1]:56604 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dp4Hh-0007KD-Ay for geb-bug-gnu-emacs@m.gmane.org; Mon, 04 Sep 2017 23:12:17 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:58247) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dp4HX-0007JS-I4 for bug-gnu-emacs@gnu.org; Mon, 04 Sep 2017 23:12:12 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dp4HS-00068T-EO for bug-gnu-emacs@gnu.org; Mon, 04 Sep 2017 23:12:07 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:41132) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dp4HS-00067o-9x for bug-gnu-emacs@gnu.org; Mon, 04 Sep 2017 23:12:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1dp4HS-0005By-23 for bug-gnu-emacs@gnu.org; Mon, 04 Sep 2017 23:12:02 -0400 X-Loop: help-debbugs@gnu.org In-Reply-To: <20170629.214304.1822535652145654069.tkk@misasa.okayama-u.ac.jp> Resent-From: Tak Kunihiro Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 05 Sep 2017 03:12:02 +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.150458107619898 (code B ref 27530); Tue, 05 Sep 2017 03:12:02 +0000 Original-Received: (at 27530) by debbugs.gnu.org; 5 Sep 2017 03:11:16 +0000 Original-Received: from localhost ([127.0.0.1]:49813 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dp4Gi-0005As-3E for submit@debbugs.gnu.org; Mon, 04 Sep 2017 23:11:16 -0400 Original-Received: from mxl069v64.mxlogic.net ([208.81.69.64]:20045 helo=s18p02o141.mxlogic.net) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dp4Ge-0005Ag-ME for 27530@debbugs.gnu.org; Mon, 04 Sep 2017 23:11:14 -0400 Original-Received: from unknown [42.127.236.175] (EHLO mlsec.cc.okayama-u.ac.jp) by s18p02o141.mxlogic.net(mxl_mta-8.5.0-1834) over TLS secured channel with ESMTP id cc51ea95.0.344802.00-392.681426.s18p02o141.mxlogic.net (envelope-from ); Mon, 04 Sep 2017 21:11:09 -0600 (MDT) X-MXL-Hash: 59ae15cd75016f6b-1b9b63c726ace5c0a4a4b721e67cd8f64b853299 Original-Received: from alml002.ouadm.okayama-u.ac.jp (unknown [42.127.236.168]) by mlsec.cc.okayama-u.ac.jp with smtp id 5aa8_c683_e6a5c798_04c3_4185_bb41_824e18efaf13; Tue, 05 Sep 2017 12:11:04 +0900 Original-Received: from localhost (vesta.misasa.okayama-u.ac.jp [150.46.48.154]) by alml002.ouadm.okayama-u.ac.jp (Postfix) with ESMTPSA id 203314C0BF7; Tue, 5 Sep 2017 12:11:05 +0900 (JST) X-NAI-Spam-Flag: NO X-NAI-Spam-Level: X-NAI-Spam-Threshold: 11 X-NAI-Spam-Score: 0.3 X-NAI-Spam-Rules: 7 Rules triggered BEC_TRC1=0.1, BEC_TRC1_W_GEN_SPAM_FEATRE=0.1, GEN_SPAM_FEATRE=0.1, EDT_SA_AU_PASS=0, EDT_SA_DN_PASS=0, EDT_SA_TS_PASS=0, RV6108=0 X-NAI-Spam-Version: 2.3.0.9418 : core <6108> : inlines <6055> : streams <1761632> : uri <2495134> X-AnalysisOut: [v=2.2 cv=F90nTupN c=1 sm=1 tr=0 a=8LLPK8U+aGQ6qN8QlyMYtQ==] X-AnalysisOut: [:117 a=8LLPK8U+aGQ6qN8QlyMYtQ==:17 a=kj9zAlcOel0A:10 a=2JC] X-AnalysisOut: [JgTwv5E4A:10 a=JJDX7p_2Sk7LEiNq4HAA:9 a=7Zwj6sZBwVKJAoWSPK] X-AnalysisOut: [xL6X1jA+E=:19 a=LezEI7HeV1yJfvY4:21 a=rTr5cPty8xsBJLuB:21 ] X-AnalysisOut: [a=CjuIK1q_8ugA:10] X-Spam: [F=0.5000000000; CM=0.500; MH=0.500(2017090413); S=0.485(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:136590 Archived-At: 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 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))))) + (defcustom mouse-buffer-menu-maxlen 20 "Number of buffers in one pane (submenu) of the buffer menu.