From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Drew Adams Newsgroups: gmane.emacs.devel Subject: RE: mouse-drag-and-drop-region Date: Mon, 20 Nov 2017 08:03:41 -0800 (PST) Message-ID: <105026f5-e161-4f9f-bfac-5db4f3018371@default> References: <5A0ABD41.5040402@gmx.at> <20171116.092825.1408561780440493246.tak.kunihiro@gmail.com> <5A0D562D.1010803@gmx.at> <20171120.222937.949251858246319152.tak.kunihiro@gmail.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1511193915 25392 195.159.176.226 (20 Nov 2017 16:05:15 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 20 Nov 2017 16:05:15 +0000 (UTC) Cc: emacs-devel@gnu.org To: Tak Kunihiro , rudalics@gmx.at, Eli Zaretskii , Alex Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Nov 20 17:04:51 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 1eGoYw-00058Y-AP for ged-emacs-devel@m.gmane.org; Mon, 20 Nov 2017 17:04:46 +0100 Original-Received: from localhost ([::1]:58049 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eGoZ3-0004lW-ES for ged-emacs-devel@m.gmane.org; Mon, 20 Nov 2017 11:04:53 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:35335) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eGoYE-0004hR-O9 for emacs-devel@gnu.org; Mon, 20 Nov 2017 11:04:13 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eGoYC-0002Q3-E6 for emacs-devel@gnu.org; Mon, 20 Nov 2017 11:04:02 -0500 Original-Received: from userp1040.oracle.com ([156.151.31.81]:25178) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eGoY5-0002Jp-9h; Mon, 20 Nov 2017 11:03:53 -0500 Original-Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id vAKG3hfM001425 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 20 Nov 2017 16:03:44 GMT Original-Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id vAKG3gQ0030635 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 20 Nov 2017 16:03:43 GMT Original-Received: from abhmp0008.oracle.com (abhmp0008.oracle.com [141.146.116.14]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id vAKG3fTn003998; Mon, 20 Nov 2017 16:03:42 GMT In-Reply-To: <20171120.222937.949251858246319152.tak.kunihiro@gmail.com> X-Priority: 3 X-Mailer: Oracle Beehive Extensions for Outlook 2.0.1.9.1 (1003210) [OL 16.0.4615.0 (x86)] X-Source-IP: aserv0021.oracle.com [141.146.126.233] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] [fuzzy] X-Received-From: 156.151.31.81 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:220294 Archived-At: FWIW, your mails are incomprehensible, to me. A long jumble, with (apparently) no newlines, just one long line. > -----Original Message----- > From: Tak Kunihiro [mailto:tak.kunihiro@gmail.com] > Sent: Monday, November 20, 2017 5:30 AM > To: rudalics@gmx.at; Eli Zaretskii ; Alex > > Cc: tak.kunihiro@gmail.com; emacs-devel@gnu.org > Subject: Re: mouse-drag-and-drop-region >=20 > I revised mouse-drag-and-drop-region. I'm sending replay > tohttps://urldefense.proofpoint.com/v2/url?u=3Dhttps- > 3A__lists.gnu.org_archive_html_emacs-2Ddevel_2017- > 2D11_msg00387.html&d=3DDwIGCQ&c=3DRoP1YumCXCgaWHvlZYR8PZh8Bv7qIrMUB65eapI= _JnE > &r=3DkI3P6ljGv6CTHIKju0jqInF6AOwMCYRDQUmqX22rJ98&m=3D7dAC1SXS16w1t_k03RCa= PT4y > x9Dj2w0sgzE9HrhKdH4&s=3Di_DYhSyvTHRfqzR6fFgh4X_gjdsRoGvmXF4Fq-z- > eEU&e=3D,ChangeLog, and patch.* ChangeLog2017-11-21 Tak Kunihiro > Improve comments and have two new > options * lisp/mouse.el (mouse-drag-and-drop-region): Make tooltip > preview to be an option. Have an option to make dragging cut among > buffers. (mouse-drag-and-drop-region-cut-among-buffer): New flag. > When t, text is cut instead of copy when dragged among buffers. > (mouse-drag-and-drop-region-show-tooltip): New flag. When t, text is > shown by a tooltip in a graphic display.* Replay> Did you ever consider > using the "r" interactive switch instead of the> "e" one?I suppose you > suggest something like below. I cannot make this work.Thus this > revision, I do not use "r" interactive switch.(defun mouse-drag-and-drop- > region (event start and) (interactive "e\nr") ...)>>> (2) Activating > the secondary overlay can be distracting and should>>> be made > optional (facultatively keeping the primary overlay in>>> place > provided (4) below is done).>>>> Region on the other window is not > visible. Thus original region>> should be hi-lighted somehow. Since > mouse-drag-and-drop-region is>> located on mouse.el, mouse-secondary- > overlay was used.>> You mean that you highlight the original region with > the secondary> overlay so that the overlay shows up on the target window > as well and> the user is informed that dropping there might lead to say > "dubious"> results?I think yes. Also, since value-selection would be > inserted before thepoint and mark, I thought it is handy to keep track > where was theregion by an overlay.> I mean something like>> (defcustom > mouse-drag-and-drop-region-show-secondary-overlay t ...)>> where setting > this to nil means to just not show any overlay. And> your code would > have to accept that there is no secondary overlay at> the time of the > drop.I found this takes significant time. I skip to get rid of usage > ofsecondary-overlay on this revision.>>> (3) Showing tooltips can be > distracting and should be optional.>>> Note also, that usurping > tooltips this way may prevent them from>>> showing interesting > properties of the drop area like whether the>>> text there is read > only. OTOH we might consider retaining>>> properties of the text in > (non-GTK) tooltips.>>> I would say>> (defcustom mouse-drag-and-drop- > region-show-tooltip t)>> and never show a tooltip on text-only terminals > even if this is t.OK.>>> (4) The (deactivate-mark) and (mouse-set-point > event) trick to allow>>> showing point the way ?mouse-drag-track? > does can be distracting>>> and should be made optional.>>>> I think > that this is very related to 2, 3, and 5 (as you inferred).>> Yes. It's > irritating to drag a block cursor with the mouse. Do you> know of any > other applications which do such a thing?I cannot think of a way to show > insert point besides (mouse-set-pointevent). Do you suggest overlay-put > "|" or change cursor-type to 'barduring drag? I thought who prefers bar > changes the default cursoranyway. I did not revise code in this > respect.>>> (5) The mouse pointer shape should take care of indicating > the exact>>> position where the drop occurs. We should probably also > signal>>> whenever the current drop position is invalid. This is > IIUC>>> usual practice on most window systems now.>>>> I think it is > a good idea.>> We probably need to define additional cursors for this so > it's not for> Emacs 26.I did not revise code in this aspect.>>> (7) IMO > either cutting should be the default too when the drop>>> occurs in a > different buffer or copying would be the default and>>> pressing the > modifier should produce a cut instead. The current>>> behavior wants > me to always keep in mind whether the target>>> buffer is the same as > the source buffer. At least, this>>> behavior should be made > optional.>>>> Default behavior followed that of file browser on `drag' a > file.>> Which file browser?Finder on macOS and File Explorer on Windows > 10 behave like that way.>> Between the same volume (buffer), `drag' does > `cut' instead of `copy'.>> I prefer current behavior as default but > have>> no objection to have option something like>> (defvar mouse-drag- > and-drop-region-cut-hungry t)>> I would be more radical with>> (defcustom > mouse-drag-and-drop-region-cut-or-copy t)>> where the values 'cut and > 'copy would always categorically cut or copy> (unless the value of > 'mouse-drag-and-drop-region' implies to copy> instead of cut) and t means > your original behavior.A new option was created. Now `cut' can be > default even amongbuffers.(defvar mouse-drag-and-drop-region-cut-among- > buffer nil "When t, text is cut instead of copy when dragged among > buffers.")>>> (8) Read-only text should be handled. An attempt to drop > text into>>> a read-only area should be signalled to the user. An > attempt to>>> cut text from a read-only text/buffer should be > signalled as>>> well.>>>>> For the latter, we copy text instead (cf > C-w in read-only text). So>>> I think this feature should behave > similarly, at least by default.>>>>> I just noticed that the code does > use ?kill-region? already. This>>> has the side-effect of putting the > text into the kill ring,>>> something which should be documented at > least. But I think the code>>> should rather use ?delete-region? instead > with the behavior you>>> proposed.>>>> I suppose that you suggest to tell > user more explicitly in echo area>> how he cannot change the text.>> The > echo area should be avoided during tracking. Think of users who> invoke > 'mouse-drag-and-drop-region' on a frame without a minibuffer.OK.> I think > that first of all you should use 'delete-region' instead of> 'kill- > region' to avoid the above-mentioned side effect. Then your> code should > silently swallow any bugs for cutting from read-only> text provided > 'kill-read-only-ok' is t. For that purpose, simply> peruse the > corresponding code from 'kill-region'.OK. Now `delete-region' is used.> > A final drop into read-only text should always give an error. We> should > be able to redeem that by providing a feedback in form of a> mouse cursor > when the mouse is either over read-only text or no> buffer text at all.I > revised only to give message. I could not tell how to bringcondition- > case to code.>> On an user perspective, operation `drag-and-drop-region' > is a>> combination of `cut' and `paste'. Thus text was killed instead > of>> deleted. How you think delete is more preferred? I have no>> > objection to document it.> IMO using 'kill-region' is an unexpected side > effect. If people> think differently, we could add yet another option > like>> (defucstom mouse-drag-and-drop-region-cut-does-kill-region t)Now > `delete-region' is used instead of `kill-region'.* Patchdiff --git > a/lisp/mouse.el b/lisp/mouse.elold mode 100644new mode 100755index > 17d1732..08f70d4--- a/lisp/mouse.el+++ b/lisp/mouse.el@@ -2361,6 +2361,12 > @@ text is copied instead of being cut." :version "26.1" :group > 'mouse) +(defvar mouse-drag-and-drop-region-cut-among-buffer nil+ "When > t, text is cut instead of copy when dragged among buffers.")++(defvar > mouse-drag-and-drop-region-show-tooltip t+ "When t, text is shown by a > tooltip in a graphic display.")+ (defun mouse-drag-and-drop-region > (event) "Move text in the region to point where mouse is dragged to. > The transportation of text is also referred as `drag and drop'.@@ - > 2369,64 +2375,98 @@ modifier key was pressed when dropping, and the value > of the variable `mouse-drag-and-drop-region' is that modifier, the text > is copied instead of being cut." (interactive "e")- (require > 'tooltip)- (let ((start (region-beginning))+ (let ((mouse-drag-and- > drop-region-show-tooltip+ (and mouse-drag-and-drop-region-show- > tooltip+ (display-multi-frame-p)+ (require > 'tooltip)))+ (start (region-beginning)) (end (region-end)) > (point (point)) (buffer (current-buffer)) (window > (selected-window))- value-selection)+ no-modifier-on-drop+ > value-selection) ; This remains nil when event was "click". > (track-mouse- ;; When event was click instead of drag, skip loop+ > ;; When event was "click" instead of "drag", skip loop. (while > (progn (setq event (read-event)) (or > (mouse-movement-p event) ;; Handle `mouse-autoselect- > window'. (eq (car-safe event) 'select-window)))- > (unless value-selection ; initialization+ ;; Obtain the text in > region. When the loop was skipped,+ ;; value-selection remains > nil.+ (unless value-selection (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 under mouse when "event was > click",- ;; "drag negligible", > or- ;; "drag to read-only".- > (if (or (equal (mouse-posn-property (event-end event) 'face) 'region) ; > "event was click"- (member 'secondary-selection ; "drag > negligible"- (mapcar (lambda (xxx) (overlay-get xxx > 'face))- (overlays-at (posn-point (event-end > event)))))- buffer-read-only)- ;; Do not modify buffer > under mouse.+ (ignore-errors+ (deactivate-mark) ; > Maintain region in other window.+ (mouse-set-point event)+ > (when mouse-drag-and-drop-region-show-tooltip+ (tooltip-show > value-selection))))+ ;; Check if modifier was pressed on drop.+ > (setq no-modifier-on-drop+ (not (member mouse-drag-and-drop- > region (event-modifiers event))))+ (when mouse-drag-and-drop-region- > show-tooltip (tooltip-hide)))+ ;; Do not modify buffer under mouse > when event is "click", "drag+ ;; but negligible", or "drag to read- > only". Operation "drag but+ ;; negligible" is defined as drag-and- > drop the text to+ ;; secondary-selection without modifier pressed. > When pressed,+ ;; the text will be inserted to inside of secondary- > selection.+ (if (or (equal (mouse-posn-property (event-end event) > 'face) 'region) ; "click"+ (and (member 'secondary-selection ; > "drag but negligible"+ (mapcar (lambda (xxx) > (overlay-get xxx 'face))+ (overlays-at > (posn-point (event-end event)))))+ no-modifier-on-drop)+ > buffer-read-only) ; "drag to read-only" (cond- > ;; "drag negligible" or "drag to read-only", restore region.+ ;; > Set back the original text as region on "drag but negligible"+ ;; > or "drag to read-only". (value-selection- (select- > window window) ; In case miss drag to other window+ (if buffer- > read-only (message "Buffer is read-only")) ; (barf-if-buffer-read-only)+ > (select-window window) ; Select the source windows back on miss-drag to > other window. (goto-char point) (setq deactivate-mark > nil) (activate-mark))- ;; "event was click"+ ;; > Move point within region on "click". (t (deactivate- > mark) (mouse-set-point event)))- ;; Modify buffer under > mouse by inserting text.+ ;; Intert the text to destination buffer > under mouse. (push-mark) (insert value-selection)- (when > (not (equal (mark) (point))) ; on success insert+ ;; On success, set > the text as region on destination buffer.+ (when (not (equal (mark) > (point))) (setq deactivate-mark nil)- (activate-mark)) ; > have region on destination- ;; Take care of initial region on > source.- (if (equal (current-buffer) buffer) ; when same buffer- > (let (deactivate-mark) ; remove text- (unless (member mouse- > drag-and-drop-region (event-modifiers event))- (kill-region > (overlay-start mouse-secondary-overlay)- > (overlay-end mouse-secondary-overlay))))- (let ((window1 > (selected-window))) ; when beyond buffer- (select-window > window)- (goto-char point) ; restore point on source window- > (activate-mark) ; restore region+ (activate-mark))+ ;; Set > back the original text as region or delete the original+ ;; text on > source buffer.+ (if (equal (current-buffer) buffer)+ ;; > When source buffer and destination buffer are the same,+ ;; > remove the original text.+ (let (deactivate-mark)+ > (if no-modifier-on-drop+ (delete-region (overlay-start > mouse-secondary-overlay)+ (overlay-end > mouse-secondary-overlay))))+ ;; When source buffer and destination > buffer are different,+ ;; keep (set back the original text as > region) or remove the+ ;; original text.+ (let ((window1 > (selected-window)))+ (select-window window) ; Select window > with source buffer.+ (goto-char point) ; Move point to the > original text on source buffer.+ (if (or (if no-modifier-on- > drop+ (not mouse-drag-and-drop-region-cut-among- > buffer)+ mouse-drag-and-drop-region-cut-among-buffer)+ > buffer-read-only)+ ;; Set back the original text as region > on source buffer+ ;; like operation `copy'.+ > (progn+ (if buffer-read-only (message "Source is read- > only")) ; (barf-if-buffer-read-only)+ (activate-mark))+ > ;; Remove the original text from source buffer like+ ;; > operation `cut'.+ (delete-region (overlay-start mouse- > secondary-overlay)+ (overlay-end mouse- > secondary-overlay))) (select-window window1)))) (delete- > overlay mouse-secondary-overlay)))