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: Thu, 29 Jun 2017 21:43:04 +0900 (JST) Message-ID: <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 1498741585 8710 195.159.176.226 (29 Jun 2017 13:06:25 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 29 Jun 2017 13:06:25 +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 Thu Jun 29 15:06: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 1dQZ9A-0001iA-KR for geb-bug-gnu-emacs@m.gmane.org; Thu, 29 Jun 2017 15:06:12 +0200 Original-Received: from localhost ([::1]:39129 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQZ9G-0008OL-0V for geb-bug-gnu-emacs@m.gmane.org; Thu, 29 Jun 2017 09:06:18 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:39867) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQZ93-0008Lf-V3 for bug-gnu-emacs@gnu.org; Thu, 29 Jun 2017 09:06:11 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dQZ90-00033x-Gd for bug-gnu-emacs@gnu.org; Thu, 29 Jun 2017 09:06:05 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:40888) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dQZ90-00033j-D9 for bug-gnu-emacs@gnu.org; Thu, 29 Jun 2017 09:06:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1dQZ90-0003rT-5K for bug-gnu-emacs@gnu.org; Thu, 29 Jun 2017 09:06: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: Thu, 29 Jun 2017 13:06:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 27530 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.149874153714800 (code B ref -1); Thu, 29 Jun 2017 13:06:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 29 Jun 2017 13:05:37 +0000 Original-Received: from localhost ([127.0.0.1]:43564 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dQZ8b-0003qc-8Z for submit@debbugs.gnu.org; Thu, 29 Jun 2017 09:05:37 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:48675) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dQZ8a-0003qP-4T for submit@debbugs.gnu.org; Thu, 29 Jun 2017 09:05:36 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dQZ8T-0002YT-L3 for submit@debbugs.gnu.org; Thu, 29 Jun 2017 09:05:31 -0400 Original-Received: from lists.gnu.org ([2001:4830:134:3::11]:36095) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dQZ8T-0002YJ-Hj for submit@debbugs.gnu.org; Thu, 29 Jun 2017 09:05:29 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:39622) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQZ8R-0007Y8-SW for bug-gnu-emacs@gnu.org; Thu, 29 Jun 2017 09:05:29 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dQZ8L-0002RN-Bd for bug-gnu-emacs@gnu.org; Thu, 29 Jun 2017 09:05:27 -0400 Original-Received: from mxl065v65.mxlogic.net ([208.81.65.65]:59480 helo=s14p02o142.mxlogic.net) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dQZ8K-0002L3-Qv for bug-gnu-emacs@gnu.org; Thu, 29 Jun 2017 09:05:21 -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-1821) with ESMTP id 01bf4595.7f1cbb5fe700.17831.00-566.42204.s14p02o142.mxlogic.net (envelope-from ); Thu, 29 Jun 2017 07:05:20 -0600 (MDT) X-MXL-Hash: 5954fb1066ee8c3d-87cf54beaba2c361bf93a5b33391b28ed18ec97f Original-Received: from unknown [42.127.236.175] (EHLO mlsec.cc.okayama-u.ac.jp) by s14p02o142.mxlogic.net(mxl_mta-8.5.0-1821) over TLS secured channel with ESMTP id 606f4595.0.17524.00-393.41507.s14p02o142.mxlogic.net (envelope-from ); Thu, 29 Jun 2017 06:43:50 -0600 (MDT) X-MXL-Hash: 5954f6067ca18a73-f522152c97ec32f2ef6f04c23153d060417b7397 Original-Received: from alml002.ouadm.okayama-u.ac.jp (unknown [42.127.236.168]) by mlsec.cc.okayama-u.ac.jp with smtp id 3410_5e68_8758fa3e_8cf4_4647_a641_38ec93cc18de; Thu, 29 Jun 2017 21:43:45 +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 AFC0A4C0B66; Thu, 29 Jun 2017 21:43:12 +0900 (JST) 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.1 X-NAI-Spam-Rules: 6 Rules triggered TS_MSG_REP_80_512=5, RCVD_BAD_SIP=0.1, EDT_SA_AU_PASS=0, EDT_SA_DN_PASS=0, EDT_SA_TS_FAIL=0, RV6059=0 X-NAI-Spam-Version: 2.3.0.9418 : core <6059> : inlines <5955> : streams <1752017> : uri <2452977> X-AnalysisOut: [v=2.2 cv=Qvku5R6d 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=QLkBCTRx3O07t_5MtakA:9 a=7Zwj6sZBwVKJAoWSPK] X-AnalysisOut: [xL6X1jA+E=:19 a=UoNMor40mNS7r8qG:21 a=9k0TJg0g2_rrva-P:21 ] X-AnalysisOut: [a=CjuIK1q_8ugA:10] X-Spam: [F=0.5100000000; CM=0.500; MH=0.510(2017062904); S=0.200(2015072901)] X-MAIL-FROM: X-SOURCE-IP: [42.127.236.175] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x 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:134022 Archived-At: I found secondary can be used as another region. Here I send a patch to cut and copy secondary as if region (when region does not exist). # Change log 2017-07-01 Tak Kunihiro Cut and copy secondary when region does not exist. * doc/emacs/killing.texi (Secondary Selection): Document support of cut and copy secondary. * lisp/simple.el (kill-secondary-flag): Use also secondary not only region to cut and copy. (kill-region): Set target to secondary not only region if kill-secondary-flag is non-nil. (kill-ring-save): Set target to secondary not only region if kill-secondary-flag is non-nil. * lisp/mouse.el (mouse-secondary-exists-p): Return location of secondary when it exists in current buffer. (mouse-set-mark-and-point-from-secondary): Set mark and point from secondary. (mouse-set-secondary-from-region): Set secondary to the text in 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..6ee368e --- a/mouse.260.el +++ b/mouse.el @@ -1545,6 +1545,45 @@ CLICK position, kill the secondary selection." (> (length str) 0) (gui-set-selection 'SECONDARY str)))) +(defun mouse-secondary-exists-p () + "Return location of mouse-secondary-overlay when exists in current buffer." + (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-mark-and-point-from-secondary () + "Set mark and point from mouse-secondary-overlay. +This works when mouse-secondary-overlay exists and region does +not exist. The mouse-secondary-overlay will be deactivated." + (let ((secondary-to-kill (and (not (region-active-p)) + (mouse-secondary-exists-p)))) + ;; delete overlay even on different buffer. + ;; this 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-region () + "Set the secondary selection to the text in region. +When region does not exists, set mouse-secondary-start to the point. +When point is on mouse-secondary-overlay, do nothing." + (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..e75743a 100644 --- a/simple.252.el +++ b/simple.el @@ -4287,11 +4287,19 @@ move the yanking point; just return the Nth kill forward." :type 'boolean :group 'killing) +(defcustom kill-secondary-flag nil + "Kill mouse-secondary-overlay when it exists but region does not exists." + :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 +4325,10 @@ 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-mark-and-point-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 +4398,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 +4417,11 @@ 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-mark-and-point-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..721b68e 100755 --- a/killing.252.texi +++ b/killing.texi @@ -624,6 +624,11 @@ 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 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}.