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#26725: patch for mouse.el Date: Mon, 01 May 2017 14:43:08 +0900 (JST) Message-ID: <20170501.144308.327409523.tkk@misasa.okayama-u.ac.jp> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: Multipart/Mixed; boundary="--Next_Part(Mon_May__1_14_43_08_2017_295)--" Content-Transfer-Encoding: 7bit X-Trace: blaine.gmane.org 1493617454 15754 195.159.176.226 (1 May 2017 05:44:14 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 1 May 2017 05:44:14 +0000 (UTC) Cc: tkk@misasa.okayama-u.ac.jp To: 26725@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon May 01 07:44:10 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 1d5481-0003zM-Nj for geb-bug-gnu-emacs@m.gmane.org; Mon, 01 May 2017 07:44:09 +0200 Original-Received: from localhost ([::1]:46936 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d5485-0003zv-Kd for geb-bug-gnu-emacs@m.gmane.org; Mon, 01 May 2017 01:44:13 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:44459) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d547x-0003zq-KK for bug-gnu-emacs@gnu.org; Mon, 01 May 2017 01:44:06 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d547u-0007B9-En for bug-gnu-emacs@gnu.org; Mon, 01 May 2017 01:44:05 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:50212) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1d547u-0007Ax-BA for bug-gnu-emacs@gnu.org; Mon, 01 May 2017 01:44:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1d547u-0000BJ-2R for bug-gnu-emacs@gnu.org; Mon, 01 May 2017 01:44: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: Mon, 01 May 2017 05:44:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 26725 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.1493617426654 (code B ref -1); Mon, 01 May 2017 05:44:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 1 May 2017 05:43:46 +0000 Original-Received: from localhost ([127.0.0.1]:48411 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d547d-0000AS-CJ for submit@debbugs.gnu.org; Mon, 01 May 2017 01:43:45 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:53451) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d547b-0000A9-1r for submit@debbugs.gnu.org; Mon, 01 May 2017 01:43:43 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d547U-00071c-By for submit@debbugs.gnu.org; Mon, 01 May 2017 01:43:37 -0400 Original-Received: from lists.gnu.org ([2001:4830:134:3::11]:53379) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d547U-00071X-86 for submit@debbugs.gnu.org; Mon, 01 May 2017 01:43:36 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:44419) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d547S-0003zN-P1 for bug-gnu-emacs@gnu.org; Mon, 01 May 2017 01:43:36 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d547P-00070l-Lh for bug-gnu-emacs@gnu.org; Mon, 01 May 2017 01:43:34 -0400 Original-Received: from mxl069v65.mxlogic.net ([208.81.69.65]:51855 helo=s18p02o142.mxlogic.net) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d547P-0006zm-2O for bug-gnu-emacs@gnu.org; Mon, 01 May 2017 01:43:31 -0400 Original-Received: from unknown [42.127.236.175] (EHLO mlsec.cc.okayama-u.ac.jp) by s18p02o142.mxlogic.net(mxl_mta-8.5.0-1675) over TLS secured channel with ESMTP id 7fac6095.0.516819.00-390.1147852.s18p02o142.mxlogic.net (envelope-from ); Sun, 30 Apr 2017 23:43:20 -0600 (MDT) X-MXL-Hash: 5906caf82829eb78-8831da9404eac7781ae2e4e6981c9ad7276fb1ab Original-Received: from alml002.ouadm.okayama-u.ac.jp (unknown [42.127.236.168]) by mlsec.cc.okayama-u.ac.jp with smtp id 21f4_101d_0c1853b6_fd63_4103_912e_02e6df966265; Mon, 01 May 2017 14:43:13 +0900 Original-Received: from localhost (unknown [172.24.1.79]) by alml002.ouadm.okayama-u.ac.jp (Postfix) with ESMTPSA id E2EC64C09C9; Mon, 1 May 2017 14:43:13 +0900 (JST) X-Mailer: Mew version 6.7 on Emacs 25.2 / Mule 6.0 (HANACHIRUSATO) X-NAI-Spam-Flag: NO X-NAI-Spam-Threshold: 11 X-NAI-Spam-Score: 0 X-NAI-Spam-Rules: 4 Rules triggered EDT_SA_AU_PASS=0, EDT_SA_DN_PASS=0, EDT_SA_TS_PASS=0, RV6012=0 X-NAI-Spam-Version: 2.3.0.9418 : core <6012> : inlines <5828> : streams <1743548> : uri <2419250> X-AnalysisOut: [v=2.2 cv=Cr/PSjwD c=1 sm=1 tr=0 a=8LLPK8U+aGQ6qN8QlyMYtQ==] X-AnalysisOut: [:117 a=8LLPK8U+aGQ6qN8QlyMYtQ==:17 a=AzvcPWV-tVgA:10 a=XfO] X-AnalysisOut: [3D5wU82Q9Hj0EyNUA:9 a=CjuIK1q_8ugA:10 a=hjlGXw3i1xpCsdrjrh] X-AnalysisOut: [UA:9 a=7Zwj6sZBwVKJAoWSPKxL6X1jA+E=:19] X-Spam: [F=0.5000000000; CM=0.500; MH=0.500(2017043007); 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:132151 Archived-At: ----Next_Part(Mon_May__1_14_43_08_2017_295)-- Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Drag and drop a file is already supported by Emacs. This patch extends drag and drop to region (text). In other word, this patch lets you `cut and paste' in a buffer only using mouse. When destination is other windows, drag and drop a region will be `copy and paste'. ----Next_Part(Mon_May__1_14_43_08_2017_295)-- Content-Type: Text/X-Patch; charset=us-ascii Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="mouse.el.patch" --- mouse.252.el 2017-05-01 13:45:39.735936700 +0900 +++ mouse.el 2017-05-01 13:59:11.102725500 +0900 @@ -688,12 +688,19 @@ Highlight the drag area as you move the mouse. This must be bound to a button-down mouse event. In Transient Mark mode, the highlighting remains as long as the mark -remains active. Otherwise, it remains until the next input event." - (interactive "e") - ;; Give temporary modes such as isearch a chance to turn off. - (run-hooks 'mouse-leave-buffer-hook) - (mouse-drag-track start-event)) +remains active. Otherwise, it remains until the next input event. +When the region already exists and `mouse-drag-and-drop-region' +is non-nil, this moves text on a region to point where mouse is +dragged over to." + (interactive "e") + (if (and mouse-drag-and-drop-region + (not (member 'triple (event-modifiers start-event))) + (mouse-on-region-p (event-start start-event))) + (mouse-drag-region-pasting start-event) + ;; Give temporary modes such as isearch a chance to turn off. + (run-hooks 'mouse-leave-buffer-hook) + (mouse-drag-track start-event))) (defun mouse-posn-property (pos property) "Look for a property at click position. @@ -1911,6 +1918,94 @@ t (called-interactively-p 'interactive))))))))) +;; Drag and drop support. +(defcustom mouse-drag-and-drop-region nil + "If non-nil, dragging mouse of the region moves text." + :type 'boolean + :version "26.1" + :group 'mouse) + +(defun mouse-on-region-p (position &optional start end) + "Return if POSITION is in between START and END in the current buffer. +When START and END are nil but there is active region, those of +active region is fed." + (when (region-active-p) + (setq start (or start (region-beginning))) + (setq end (or end (region-end)))) + (let ((point (posn-point position))) + (and + (numberp start) + (numberp end) + (numberp point) + (<= start point) + (<= point end)))) + +(defun mouse-drag-region-pasting (event) + "Move text on a region to point where mouse is dragged over to. +The transportation of text is also referred as `drag and drop'. +When text is dragged over to different buffer, the text is copied +instead of cut. This works similar to +`mouse-drag-secondary-moving' but expects region on launch and +specifies point later, by mouse. + +To try this function, evaluate the following line. + (global-set-key [down-mouse-3] \\='mouse-drag-region-pasting) +Then have a region and grab-and-drag it by mouse to point to move +to." + (interactive "e") + (require 'tooltip) + (let ((start (region-beginning)) + (end (region-end)) + (point (point)) + (buffer (current-buffer)) + (window (selected-window)) + value-selection) + (track-mouse + ;; when event was click instead of drag, skip loop + (while (progn + (setq event (read-event)) + (mouse-movement-p event)) + (unless value-selection ; initialization + (delete-overlay mouse-secondary-overlay) + (setq value-selection (buffer-substring start end)) + (move-overlay mouse-secondary-overlay start end)) ; (deactivate-mark) + (ignore-errors (deactivate-mark) ; care existing region in other window + (mouse-set-point event) + (tooltip-show value-selection))) + (tooltip-hide)) + ;; Do not modify buffer when "event was click", + ;; "drag negligible", or "drag to read-only". + (if (or (mouse-on-region-p (event-end event) start end) + buffer-read-only) + (cond + ;; drag negligible or drag to read-only, restore region + (value-selection + (select-window window) ; case miss drag to other window + (goto-char point) + (setq deactivate-mark nil) + (activate-mark)) + ;; event was click + (t + (deactivate-mark) + (mouse-set-point event))) + ;; insert text + (push-mark) + (insert value-selection) ; revise buffer + (when (not (equal (mark) (point))) ; on success + (setq deactivate-mark nil) + (activate-mark)) ; activate region on new place + ;; take out initial region + (if (equal (current-buffer) buffer) ; same buffer + (let (deactivate-mark) + (kill-region (overlay-start mouse-secondary-overlay) + (overlay-end mouse-secondary-overlay))) + (let ((window1 (selected-window))) ; beyond buffer + (select-window window) + (goto-char point) ; restore point to where it was + (select-window window1)))) + (delete-overlay mouse-secondary-overlay))) + + ;;; Bindings for mouse commands. (global-set-key [down-mouse-1] 'mouse-drag-region) ----Next_Part(Mon_May__1_14_43_08_2017_295)----