From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Robert Weiner Newsgroups: gmane.emacs.devel Subject: Re: Emacs 26: Code that fixes mouse-drag-and-drop-region to work across frames Date: Mon, 16 Oct 2017 10:13:30 -0400 Message-ID: References: <86d15rjrpe.fsf@misasa.okayama-u.ac.jp> Reply-To: rswgnu@gmail.com NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="001a11404ff644f78b055baa9e58" X-Trace: blaine.gmane.org 1508163270 351 195.159.176.226 (16 Oct 2017 14:14:30 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 16 Oct 2017 14:14:30 +0000 (UTC) Cc: emacs-devel To: Tak Kunihiro Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Oct 16 16:14:24 2017 Return-path: Envelope-to: ged-emacs-devel@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 1e469g-0005wM-El for ged-emacs-devel@m.gmane.org; Mon, 16 Oct 2017 16:14:08 +0200 Original-Received: from localhost ([::1]:33208 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e469n-0006b6-Gq for ged-emacs-devel@m.gmane.org; Mon, 16 Oct 2017 10:14:15 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:44494) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e469e-0006aZ-HE for emacs-devel@gnu.org; Mon, 16 Oct 2017 10:14:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e469a-0005Wv-HF for emacs-devel@gnu.org; Mon, 16 Oct 2017 10:14:06 -0400 Original-Received: from fencepost.gnu.org ([2001:4830:134:3::e]:54628) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e469a-0005Wf-Cr for emacs-devel@gnu.org; Mon, 16 Oct 2017 10:14:02 -0400 Original-Received: from mail-qt0-f169.google.com ([209.85.216.169]:53197) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_128_CBC_SHA1:128) (Exim 4.82) (envelope-from ) id 1e469a-0000j7-0R for emacs-devel@gnu.org; Mon, 16 Oct 2017 10:14:02 -0400 Original-Received: by mail-qt0-f169.google.com with SMTP id 31so6418310qtz.9 for ; Mon, 16 Oct 2017 07:14:02 -0700 (PDT) X-Gm-Message-State: AMCzsaUIi84vs2U9Koqfdu+M8BhamooCfwicJ9bCFP00nVnf04Hftywv etqtLFdT06kcV9RrnOSPiq22b9+s+3ehRXF/dIY= X-Google-Smtp-Source: ABhQp+RdlsB+cZ29l3fZ3sv8FQ+vkXJPKIJqOdsXZPI2zVkRuvFNFy4dnVA70pY6UNScXjIj8u2QC/0U9666y5mJqOc= X-Received: by 10.200.34.167 with SMTP id f36mr12572202qta.173.1508163241439; Mon, 16 Oct 2017 07:14:01 -0700 (PDT) Original-Received: by 10.237.34.225 with HTTP; Mon, 16 Oct 2017 07:13:30 -0700 (PDT) In-Reply-To: X-Gmail-Original-Message-ID: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:4830:134:3::e X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:219577 Archived-At: --001a11404ff644f78b055baa9e58 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, Oct 16, 2017 at 9:45 AM, Robert Weiner wrote: > On Fri, Oct 13, 2017 at 5:57 AM, Tak Kunihiro > wrote: > >> I tried the revised `mouse-drag-and-drop-region' on Emacs -Q 26.0.90 on >> macOS 10.9.5. I can drag text within a frame but cannot do so among >> frames. I think I miss something. Do you have idea? >> > > =E2=80=8BThe yellow visual rectangle of the text being dragged seems to g= et stuck > at the source frame but if you continue your drag and release in another > frame with a non-read-only buffer, your text should be properly dropped > there. Is this what you did? Try it a couple different times to ensure > there is not some initialization warm up problem. > =E2=80=8BI see the issue now; the standard Emacs code does not handle cross= -frame drags well. Replace the mouse-set-point function from mouse.el with the version below and then the yellow rectangle of text will follow you to the drag release frame and your drag-and-drops should work as you expect (with the mouse-drag-and-drop-region changes from before). -- Bob=E2=80=8B (defun mouse-set-point (event &optional promote-to-region) "Move point to the position clicked on with the mouse. This should be bound to a mouse click event type. If PROMOTE-TO-REGION is non-nil and event is a multiple-click, select the corresponding element around point, with the resulting position of point determined by `mouse-select-region-move-to-beginning'." (interactive "e\np") (let ((start-w-or-f (posn-window (event-start event))) (end-w-or-f (posn-window (event-end event)))) (if (framep start-w-or-f) (with-selected-frame start-w-or-f (setq start-w-or-f (selected-window)))) (if (framep end-w-or-f) (with-selected-frame end-w-or-f (setq end-w-or-f (selected-window)))) (if (and (window-minibuffer-p start-w-or-f) (not (minibuffer-window-active-p start-w-or-f))) ;; Select the ending frame only, not the window pressed within. (select-frame (window-frame end-w-or-f)) ;; Give temporary modes such as isearch a chance to turn off. (run-hooks 'mouse-leave-buffer-hook) (if (and promote-to-region (> (event-click-count event) 1)) (progn (mouse-set-region event) (when (and (boundp 'mouse-select-region-move-to-beginning) mouse-select-region-move-to-beginning) (when (> (posn-point (event-start event)) (region-beginning)) (exchange-point-and-mark)))) ;; Use event-end in case called from mouse-drag-region. ;; If EVENT is a click, event-end and event-start give same value. (if (and (window-minibuffer-p end-w-or-f) (not (minibuffer-window-active-p end-w-or-f))) ;; Select the ending frame only, not the window pressed within. (select-frame (window-frame end-w-or-f)) (condition-case () (posn-set-point (event-end event)) (error (select-frame (window-frame end-w-or-f))))))))) --001a11404ff644f78b055baa9e58 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Mon, Oct 16, 2= 017 at 9:45 AM, Robert Weiner <rsw= @gnu.org> wrote:=
On Fri, Oct 13, 2017 at 5:57 AM, Tak Kuni= hiro <homeros.misasa@= gmail.com> wrote= :
I tried the revised `mouse-drag-and-drop-region' on Emacs = -Q 26.0.90 on
macOS 10.9.5.=C2=A0 I can drag text within a frame but cannot do so among frames.=C2=A0 I think I miss something.=C2=A0 Do you have idea?

=E2=80=8BThe yellow visual rectangle of the text being dragged seems to= get stuck at the source frame but if you continue your drag and release in= another frame with a non-read-only buffer, your text should be properly dr= opped there.=C2=A0 Is this what you did?=C2=A0 Try it a couple different ti= mes to ensure there is not some initialization warm up problem.
=

=E2=80=8BI see the issue now; the stan= dard Emacs code does not handle cross-frame drags well.=C2=A0 Replace the m= ouse-set-point function from mouse.el with the version below and then the y= ellow rectangle of text will follow you to the drag release frame and your = drag-and-drops should work as you expect (with the mouse-drag-and-drop-regi= on changes from before).=C2=A0 -- Bob=E2=80=8B

(defun mouse-set-point (event &a= mp;optional promote-to-region)
=C2=A0 "Move point to the position clicked on with the mouse.=
This should be bound = to a mouse click event type.
If PROMOTE-TO-REGION is non-nil and event is a multiple-click,
select the corresponding el= ement around point, with the resulting position of
point determined by `mouse-select-region-move-= to-beginning'."
=C2=A0 (interactive "e\np")
=C2=A0 (let ((start-w-or-f (posn-window (event-start eve= nt)))
(end-w-or-f=C2=A0 =C2=A0(posn-window (event-end eve= nt))))
=C2=A0 =C2=A0 (= if (framep start-w-or-f)
(with-selected-frame start-w-or-= f (setq start-w-or-f (selected-window))))
=C2=A0 =C2=A0 (if (framep end-w-or-f)
= (with-selected-frame end-w-or-f (setq end-w-or-f (selected-window))))
=C2=A0 =C2=A0 (if (and (wi= ndow-minibuffer-p start-w-or-f)
=C2=A0 =C2=A0 =C2=A0(not = (minibuffer-window-active-p start-w-or-f)))
;; Select the= ending frame only, not the window pressed within.
(selec= t-frame (window-frame end-w-or-f))
=C2=A0 =C2=A0 =C2=A0 ;; Give temporary modes such as isearch a= chance to turn off.
= =C2=A0 =C2=A0 =C2=A0 (run-hooks 'mouse-leave-buffer-hook)
<= div>=C2=A0 =C2=A0 =C2=A0 (if (and promo= te-to-region (> (event-click-count event) 1))
=C2=A0 (= progn (mouse-set-region event)
(when (and (boundp '= mouse-select-region-move-to-beginning)
=C2=A0 =C2=A0 mo= use-select-region-move-to-beginning)
=C2=A0 =C2=A0(when = (> (posn-point (event-start event)) (region-beginning))
=C2=A0 =C2=A0 =C2=A0(exchange-point-and-mark))))
;; Us= e event-end in case called from mouse-drag-region.
;; If = EVENT is a click, event-end and event-start give same value.
(if (and (window-minibuffer-p end-w-or-f)
(not (m= inibuffer-window-active-p end-w-or-f)))
=C2=A0 =C2=A0 ;; = Select the ending frame only, not the window pressed within.
=C2=A0 =C2=A0 (select-frame (window-frame end-w-or-f))
=C2=A0 (condition-case ()
=C2=A0 =C2=A0 =C2=A0 (posn-se= t-point (event-end event))
=C2=A0 =C2=A0 (error (select-f= rame (window-frame end-w-or-f)))))))))

--001a11404ff644f78b055baa9e58--