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, 1 Aug 2017 10:35:35 +0900 Message-ID: <32F61636-00B7-4AE8-AA8B-2B2802F574F0@misasa.okayama-u.ac.jp> References: <20170629.214304.1822535652145654069.tkk@misasa.okayama-u.ac.jp> <9cdc1ecc-d9b2-46fa-a044-fccc27ab1696@default> <20170701.094523.2119298960961529023.tkk@misasa.okayama-u.ac.jp> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 (Mac OS X Mail 7.3 \(1878.6\)) Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1501551445 12485 195.159.176.226 (1 Aug 2017 01:37:25 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 1 Aug 2017 01:37:25 +0000 (UTC) Cc: Kunihiro Tak To: 27530@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Aug 01 03:37:18 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 1dcM7Z-0002mS-DN for geb-bug-gnu-emacs@m.gmane.org; Tue, 01 Aug 2017 03:37:17 +0200 Original-Received: from localhost ([::1]:34035 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dcM7d-0001NE-R6 for geb-bug-gnu-emacs@m.gmane.org; Mon, 31 Jul 2017 21:37:21 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:57759) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dcM7O-0001L7-0u for bug-gnu-emacs@gnu.org; Mon, 31 Jul 2017 21:37:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dcM7K-00021t-OL for bug-gnu-emacs@gnu.org; Mon, 31 Jul 2017 21:37:06 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:33268) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dcM7K-00021c-Kr for bug-gnu-emacs@gnu.org; Mon, 31 Jul 2017 21:37:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1dcM7K-0003yw-Ej for bug-gnu-emacs@gnu.org; Mon, 31 Jul 2017 21:37:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Tak Kunihiro Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 01 Aug 2017 01:37: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.150155138715251 (code B ref 27530); Tue, 01 Aug 2017 01:37:02 +0000 Original-Received: (at 27530) by debbugs.gnu.org; 1 Aug 2017 01:36:27 +0000 Original-Received: from localhost ([127.0.0.1]:35943 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dcM6k-0003xv-H0 for submit@debbugs.gnu.org; Mon, 31 Jul 2017 21:36:26 -0400 Original-Received: from mxl065v65.mxlogic.net ([208.81.65.65]:33804 helo=s14p02o142.mxlogic.net) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dcM6i-0003xk-Ea for 27530@debbugs.gnu.org; Mon, 31 Jul 2017 21:36:26 -0400 Original-Received: from unknown [42.127.236.175] (EHLO mlsec.cc.okayama-u.ac.jp) by s14p02o142.mxlogic.net(mxl_mta-8.5.0-1834) over TLS secured channel with ESMTP id 51bdf795.0.588045.00-311.1340088.s14p02o142.mxlogic.net (envelope-from ); Mon, 31 Jul 2017 19:36:21 -0600 (MDT) X-MXL-Hash: 597fdb155fe0c0a3-8d17ab537c7499dd5b2badc44d419ccbb4c7556d Original-Received: from alml002.ouadm.okayama-u.ac.jp (unknown [42.127.236.168]) by mlsec.cc.okayama-u.ac.jp with smtp id 1397_de54_2a5b16da_748a_4474_a6fb_70a26670c2a6; Tue, 01 Aug 2017 10:36:20 +0900 Original-Received: from [192.168.1.50] (vesta.misasa.okayama-u.ac.jp [150.46.48.154]) by alml002.ouadm.okayama-u.ac.jp (Postfix) with ESMTPSA id 57F9D4C0C0B; Tue, 1 Aug 2017 10:36:20 +0900 (JST) In-Reply-To: <20170701.094523.2119298960961529023.tkk@misasa.okayama-u.ac.jp> X-Mailer: Apple Mail (2.1878.6) X-NAI-Spam-Flag: NO X-NAI-Spam-Level: X-NAI-Spam-Threshold: 11 X-NAI-Spam-Score: 0.1 X-NAI-Spam-Rules: 5 Rules triggered TRK_NCM1=0.1, EDT_SA_AU_PASS=0, EDT_SA_DN_PASS=0, EDT_SA_TS_PASS=0, RV6083=0 X-NAI-Spam-Version: 2.3.0.9418 : core <6083> : inlines <5999> : streams <1756636> : uri <2473803> X-AnalysisOut: [v=2.2 cv=ebZNR/MH c=1 sm=1 tr=0 a=8LLPK8U+aGQ6qN8QlyMYtQ==] X-AnalysisOut: [:117 a=8LLPK8U+aGQ6qN8QlyMYtQ==:17 a=kj9zAlcOel0A:10 a=G3g] X-AnalysisOut: [G6ho9WtcA:10 a=xY1_shhyAAAA:8 a=caj15bac1sQNupzNW7QA:9 a=7] X-AnalysisOut: [Zwj6sZBwVKJAoWSPKxL6X1jA+E=:19 a=Ra9ED86FjxtbNGh0:21 a=Kpl] X-AnalysisOut: [TgWvN8rlMPqtn:21 a=CjuIK1q_8ugA:10 a=_qGpZPc723ggZ2AwnKam:] X-AnalysisOut: [22] X-Spam: [F=0.5100000000; CM=0.500; MH=0.510(2017073111); 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:135201 Archived-At: 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 = wrote: > I re-send a patch to cut and copy the secondary. >=20 > 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'. >=20 >> defun mouse-secondary-exists-p () >>=20 >> Name probably shouldn't end in `-p' if the return value is >> mainly not a Boolean. Non-nil here means overlay limits. >=20 > I changed docstring to match the name of function. >=20 > Return if the secondary selection exists in current buffer. > When exists, this returns start and end of the secondary selection. >=20 >> defun mouse-set-mark-and-point-from-secondary () >>=20 >> Cf. `secondary-to-primary'. >=20 > I changed the name to mouse-set-primary-from-secondary. >=20 >> defun mouse-set-secondary-from-region () >>=20 >> Cf. `primary-to-secondary'. >=20 > I changed the name to mouse-set-secondary-from-primary. >=20 >> 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. >=20 > I made following the two functions to be interactive to be called from > keyboard. >=20 > mouse-set-primary-from-secondary > mouse-set-secondary-from-primary >=20 > My local plan is to set secondary by hook something like below. >=20 > (add-hook 'view-mode-hook 'mouse-set-secondary-from-primary) >=20 >=20 > # Change log >=20 > 2017-07-02 Tak Kunihiro >=20 > Cut and copy the secondary selection when the region does not = exist. >=20 > * 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. >=20 > # NEWS >=20 > ** 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. >=20 > # Code 1/2 >=20 > 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)))) >=20 > +(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)) > + (/=3D 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))))) > + >=20 > (defcustom mouse-buffer-menu-maxlen 20 > "Number of buffers in one pane (submenu) of the buffer menu. >=20 > # Code 2/2 >=20 > 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) >=20 > +(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. >=20 > 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. >=20 > 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. >=20 >=20 > # Info >=20 > 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}. >=20 > +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}.