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: Wed, 20 Sep 2017 21:39:23 +0900 (JST) Message-ID: <20170920.213923.723510225184251711.tkk@misasa.okayama-u.ac.jp> References: <20170910.120143.946950380669459918.tkk@misasa.okayama-u.ac.jp> <63B07AE9-1836-4EC5-8913-2D03249B9847@misasa.okayama-u.ac.jp> <83o9q5g5xm.fsf@gnu.org> 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 1505916803 7119 195.159.176.226 (20 Sep 2017 14:13:23 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 20 Sep 2017 14:13:23 +0000 (UTC) Cc: tkk@misasa.okayama-u.ac.jp, 27530@debbugs.gnu.org To: eliz@gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Sep 20 16:13:16 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 1dufkY-0001Nx-Q3 for geb-bug-gnu-emacs@m.gmane.org; Wed, 20 Sep 2017 16:13:15 +0200 Original-Received: from localhost ([::1]:48346 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dufkf-0001ZG-Oq for geb-bug-gnu-emacs@m.gmane.org; Wed, 20 Sep 2017 10:13:21 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:38305) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1duf4a-0005Ny-Qm for bug-gnu-emacs@gnu.org; Wed, 20 Sep 2017 09:29:54 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1duf4U-0005tr-K5 for bug-gnu-emacs@gnu.org; Wed, 20 Sep 2017 09:29:52 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:40493) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1duf4U-0005q9-FS for bug-gnu-emacs@gnu.org; Wed, 20 Sep 2017 09:29:46 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1dueIL-00009o-KA for bug-gnu-emacs@gnu.org; Wed, 20 Sep 2017 08:40:03 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Tak Kunihiro Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 20 Sep 2017 12:40: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.1505911182573 (code B ref 27530); Wed, 20 Sep 2017 12:40:01 +0000 Original-Received: (at 27530) by debbugs.gnu.org; 20 Sep 2017 12:39:42 +0000 Original-Received: from localhost ([127.0.0.1]:49147 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dueI2-00009A-0G for submit@debbugs.gnu.org; Wed, 20 Sep 2017 08:39:42 -0400 Original-Received: from mxl069v66.mxlogic.net ([208.81.69.66]:15639 helo=s18p02o143.mxlogic.net) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dueHy-00008y-B0 for 27530@debbugs.gnu.org; Wed, 20 Sep 2017 08:39:40 -0400 Original-Received: from unknown [42.127.236.175] (EHLO mlsec.cc.okayama-u.ac.jp) by s18p02o143.mxlogic.net(mxl_mta-8.5.0-1834) over TLS secured channel with ESMTP id 48162c95.0.555550.00-377.1094421.s18p02o143.mxlogic.net (envelope-from ); Wed, 20 Sep 2017 06:39:34 -0600 (MDT) X-MXL-Hash: 59c26186640f447f-62b700664a07867dbf214d7cee998a9d859f8bb5 Original-Received: from alml002.ouadm.okayama-u.ac.jp (unknown [42.127.236.168]) by mlsec.cc.okayama-u.ac.jp with smtp id 47ec_3358_718f79fa_3c71_40e3_8959_55d9e481aa54; Wed, 20 Sep 2017 21:39:26 +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 B45E64C0A0E; Wed, 20 Sep 2017 21:39:26 +0900 (JST) In-Reply-To: <83o9q5g5xm.fsf@gnu.org> 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: 10.1 X-NAI-Spam-Rules: 6 Rules triggered TS_MSG_REP_80_512=10, RCVD_BAD_SIP=0.1, EDT_SA_AU_PASS=0, EDT_SA_DN_PASS=0, EDT_SA_TS_FAIL=0, RV6120=0 X-NAI-Spam-Version: 2.3.0.9418 : core <6120> : inlines <6078> : streams <1763825> : uri <2503575> X-AnalysisOut: [v=2.2 cv=E6K9neVl 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=uKw34HOxTCIHa1ldOIMA:9 a=7Zwj6sZBwVKJAoWSPK] X-AnalysisOut: [xL6X1jA+E=:19 a=KG8rLa7inIDdwcrl:21 a=pfb9nxcKP7AakggE:21 ] X-AnalysisOut: [a=CjuIK1q_8ugA:10] X-Spam: [F=0.5000000000; CM=0.500; MH=0.500(2017092007); 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:137165 Archived-At: 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 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)))) + (defcustom mouse-buffer-menu-maxlen 20 "Number of buffers in one pane (submenu) of the buffer menu.