all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: martin rudalics <rudalics@gmx.at>
To: Tak Kunihiro <tak.kunihiro@gmail.com>,
	Eli Zaretskii <eliz@gnu.org>,  Alex <agrambot@gmail.com>
Cc: emacs-devel@gnu.org
Subject: Re: mouse-drag-and-drop-region
Date: Tue, 21 Nov 2017 10:24:26 +0100	[thread overview]
Message-ID: <5A13F0CA.2030605@gmx.at> (raw)
In-Reply-To: <20171120.222937.949251858246319152.tak.kunihiro@gmail.com>

 >> 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")
 >    ...)

We would probably have to change 'mouse-drag-region' for that to work.

 >> 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 of
 > secondary-overlay on this revision.

What takes significant time?  Please elaborate.

 > I cannot think of a way to show insert point besides (mouse-set-point
 > event).  Do you suggest overlay-put "|" or change cursor-type to 'bar
 > during drag?  I thought who prefers bar changes the default cursor
 > anyway.  I did not revise code in this respect.

I think that using 'mouse-set-point' as we do for 'mouse-drag-track' is
not necessarily a good idea.  The idea with 'mouse-drag-track' is that
its user usually wants point to go where the mouse moves.  The idea with
'mouse-drag-and-drop-region' is that the user wants to drop text where
the mouse goes but not necessarily also move point there.  If we want
'mouse-drag-and-drop-region' to do additional things (like killing the
region or moving point) we should make these customizable at least.

 >>>> (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.

Do you mean that they move a file when the target directories differ and
copy it when they are the same?  Isn't that then the opposite of

 >>> Between the same volume (buffer), `drag' does `cut' instead of `copy'.

In either case I fail to see the volume/buffer connection relationship.
But maybe that's just me.

 >> 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.

As mentioned, we can always add an option to kill the region instead.

 > I revised only to give message.  I could not tell how to bring
 > condition-case to code.

IMO this is one of the two major things to fix before the release.
Think of someone using this function in a way you didn't anticipate (for
example, take the bug mentioned by Alex that someone hits some other key
while dragging).  If mouse tracking then throws an error and you changed
point or the region or leave the secondary overlay around, this can be
very irritating.  After all, we want people to have a smooth experience
especially when using a new function.

Obviously, if you do not move point, do not create a secondary overlay
or do not change the region, these are not needed.  Otherwise, the
function should restore the entire configuration (selected window,
point, region, overlays at least) that existed before dragging started
so that the user can restart from there.

More precisely, you should wrap 'track-mouse' and whatever you do after
it terminates in a 'condition-case' form and in the error part restore
everything to the saved values.  Like so:

(... ; save the state here
  (condition-case nil
      (progn
        (track-mouse
	 )
        )
    (error ... ; restore the state here
	  )))

If you have any problems coding that, please ask.

 > +(defvar mouse-drag-and-drop-region-cut-among-buffer nil
 > +  "When t, text is cut instead of copy when dragged among buffers.")

This should be a 'defcustom'.  I would write instead

(defcustom mouse-drag-and-drop-region-cut-when-buffers-differ nil
   "If non-nil, cut text also when source and destination buffers differ.
If this option is nil, `mouse-drag-and-drop-region' will leave
the text in the source buffer alone when dropping it in a
different buffer.  If this is non-nil, it will cut the text just
as it does when dropping text in the source buffer."
   :type 'boolean
   :version "27.1"
   :group 'mouse)

and likewise for 'mouse-drag-and-drop-region-show-tooltip' (note also
the use of active voice and non-nil instead of t).

 > +          (when mouse-drag-and-drop-region-show-tooltip
 > +            (tooltip-show value-selection))))

Still not quite right: Never show a tooltip on text-only frames.  Think
of people who want to show tooltips but occasionally work on TTYs.

 > +          (if buffer-read-only (message "Buffer is read-only")) ; (barf-if-buffer-read-only)

'buffer-read-only' is not sufficient.  Please handle read-only
text properties at this position.

 > +      ;; Intert the text to destination buffer under mouse.
               ^

 > +        (let ((window1 (selected-window)))
 > +          (select-window window)   ; Select window with source buffer.
 > +          (goto-char point) ; Move point to the original text on source buffer.
[...]
 >             (select-window window1))))

I think

(set-window-point window point)

instead of the above should suffice.

And if I'm not mistaken you still disallow to copy text into itself.

martin



  parent reply	other threads:[~2017-11-21  9:24 UTC|newest]

Thread overview: 89+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-14  9:54 mouse-drag-and-drop-region martin rudalics
2017-11-14 17:01 ` mouse-drag-and-drop-region Eli Zaretskii
2017-11-14 18:29   ` mouse-drag-and-drop-region martin rudalics
2017-11-14 20:17 ` mouse-drag-and-drop-region Alex
2017-11-15  9:22   ` mouse-drag-and-drop-region martin rudalics
2017-11-15 18:22     ` mouse-drag-and-drop-region Eli Zaretskii
2017-11-15 18:50       ` mouse-drag-and-drop-region martin rudalics
2017-11-15 20:01         ` mouse-drag-and-drop-region Eli Zaretskii
2017-11-16  9:04           ` mouse-drag-and-drop-region martin rudalics
2017-11-15 19:46     ` mouse-drag-and-drop-region Alex
2017-11-15 20:15       ` mouse-drag-and-drop-region Eli Zaretskii
2017-11-15 22:03         ` mouse-drag-and-drop-region Alex
2017-11-16 15:54           ` mouse-drag-and-drop-region Eli Zaretskii
2017-11-17  6:33             ` mouse-drag-and-drop-region Alex
2017-11-17  7:33               ` mouse-drag-and-drop-region Eli Zaretskii
2017-11-17 15:58                 ` mouse-drag-and-drop-region Stefan Monnier
2017-11-17 16:39                   ` mouse-drag-and-drop-region Eli Zaretskii
2017-11-17 22:44                     ` mouse-drag-and-drop-region Stefan Monnier
2017-11-18  7:54                       ` mouse-drag-and-drop-region Eli Zaretskii
2017-11-18 14:36                         ` mouse-drag-and-drop-region Stefan Monnier
2017-11-18 15:04                           ` mouse-drag-and-drop-region Eli Zaretskii
2017-11-18 15:49                             ` mouse-drag-and-drop-region Stefan Monnier
2017-11-18  6:48                 ` mouse-drag-and-drop-region Alex
2017-11-18  9:07                   ` mouse-drag-and-drop-region Eli Zaretskii
2017-11-18 21:58                     ` mouse-drag-and-drop-region Alex
2017-11-19 15:27                       ` mouse-drag-and-drop-region Eli Zaretskii
2017-11-17  8:53               ` mouse-drag-and-drop-region martin rudalics
2017-11-18  6:49                 ` mouse-drag-and-drop-region Alex
2017-11-16  9:04       ` mouse-drag-and-drop-region martin rudalics
2017-11-17  6:02         ` mouse-drag-and-drop-region Alex
2017-11-17  8:53           ` mouse-drag-and-drop-region martin rudalics
2017-11-15 20:22   ` mouse-drag-and-drop-region Eli Zaretskii
2017-11-16  0:28 ` mouse-drag-and-drop-region Tak Kunihiro
2017-11-16  9:11   ` mouse-drag-and-drop-region martin rudalics
2017-11-20 13:29     ` mouse-drag-and-drop-region Tak Kunihiro
2017-11-20 16:03       ` mouse-drag-and-drop-region Drew Adams
2017-11-20 16:09         ` mouse-drag-and-drop-region Alan Schmitt
2017-11-20 17:34         ` mouse-drag-and-drop-region Eli Zaretskii
2017-11-20 18:17         ` mouse-drag-and-drop-region Paul Eggert
2017-11-21  9:24       ` martin rudalics [this message]
2017-11-21 13:09         ` mouse-drag-and-drop-region Stefan Monnier
2017-11-21 14:05           ` mouse-drag-and-drop-region martin rudalics
2017-11-21 19:07             ` mouse-drag-and-drop-region Stefan Monnier
2017-11-22  8:26               ` mouse-drag-and-drop-region martin rudalics
2017-11-22 21:20                 ` mouse-drag-and-drop-region Stefan Monnier
2017-11-23  7:46                   ` mouse-drag-and-drop-region martin rudalics
2017-11-23 14:00                     ` mouse-drag-and-drop-region Stefan Monnier
2017-11-23 16:09                     ` mouse-drag-and-drop-region Eli Zaretskii
2017-11-24  9:02                       ` mouse-drag-and-drop-region martin rudalics
2017-11-24  9:19                         ` mouse-drag-and-drop-region Eli Zaretskii
2017-11-24  9:41                           ` mouse-drag-and-drop-region martin rudalics
2017-11-24 13:25                             ` mouse-drag-and-drop-region Stefan Monnier
2017-11-26 10:24                               ` mouse-drag-and-drop-region martin rudalics
2017-11-24 13:45                             ` mouse-drag-and-drop-region Eli Zaretskii
2017-11-26 10:24                               ` mouse-drag-and-drop-region martin rudalics
2017-11-26 15:54                                 ` mouse-drag-and-drop-region Eli Zaretskii
2017-11-27  8:48                                   ` mouse-drag-and-drop-region martin rudalics
2017-11-27 15:59                                     ` mouse-drag-and-drop-region Eli Zaretskii
2017-11-21 15:45         ` mouse-drag-and-drop-region Eli Zaretskii
2017-11-22  8:22           ` mouse-drag-and-drop-region martin rudalics
2017-11-21 18:52         ` mouse-drag-and-drop-region Robert Weiner
2017-11-22  8:22           ` mouse-drag-and-drop-region martin rudalics
2017-11-23 23:28         ` mouse-drag-and-drop-region Tak Kunihiro
2017-11-24  9:02           ` mouse-drag-and-drop-region martin rudalics
2017-11-27 13:11             ` mouse-drag-and-drop-region Tak Kunihiro
2017-11-28  8:50               ` mouse-drag-and-drop-region martin rudalics
2017-12-01 14:16                 ` mouse-drag-and-drop-region Tak Kunihiro
2017-12-02 10:16                   ` mouse-drag-and-drop-region martin rudalics
2017-12-03 10:06                     ` mouse-drag-and-drop-region martin rudalics
2017-12-03 13:36                       ` mouse-drag-and-drop-region martin rudalics
2017-12-05  4:57                       ` mouse-drag-and-drop-region Tak Kunihiro
2017-12-05  8:53                         ` mouse-drag-and-drop-region martin rudalics
2017-12-06  9:29                           ` mouse-drag-and-drop-region Tak Kunihiro
2017-12-07  9:26                             ` mouse-drag-and-drop-region martin rudalics
2017-12-07 21:45                               ` mouse-drag-and-drop-region Tak Kunihiro
2017-12-08 10:12                                 ` mouse-drag-and-drop-region martin rudalics
2017-12-08 16:14                                   ` mouse-drag-and-drop-region Robert Weiner
2017-12-09 10:35                                     ` mouse-drag-and-drop-region martin rudalics
2017-12-14 23:14                                       ` mouse-drag-and-drop-region Tak Kunihiro
2017-12-15  8:50                                         ` mouse-drag-and-drop-region martin rudalics
2017-12-15 13:25                                           ` mouse-drag-and-drop-region martin rudalics
2017-12-16  2:07                                             ` mouse-drag-and-drop-region Tak Kunihiro
2017-12-16  9:42                                               ` mouse-drag-and-drop-region martin rudalics
2017-12-17  4:40                                                 ` mouse-drag-and-drop-region Tak Kunihiro
2017-12-17 10:44                                                   ` mouse-drag-and-drop-region martin rudalics
2017-12-21  1:36                                                     ` mouse-drag-and-drop-region Tak Kunihiro
2017-12-22  8:43                                                       ` mouse-drag-and-drop-region martin rudalics
2017-12-22  9:25                                                       ` mouse-drag-and-drop-region Eli Zaretskii
2017-12-22 17:57                                                         ` mouse-drag-and-drop-region martin rudalics

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5A13F0CA.2030605@gmx.at \
    --to=rudalics@gmx.at \
    --cc=agrambot@gmail.com \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=tak.kunihiro@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.