[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: how to test whether region is active during a mouse event?
From: |
David De La Harpe Golden |
Subject: |
Re: how to test whether region is active during a mouse event? |
Date: |
Sun, 02 Aug 2009 21:31:16 +0100 |
User-agent: |
Mozilla-Thunderbird 2.0.0.22 (X11/20090701) |
Drew Adams wrote:
1. Is it normal that there are two `down' events for a simple mouse-button click
action? I assume so, since this is the case since at least Emacs 20. (I'm still
curious as to why.)
Are you defining the active region with the keyboard or mouse? Do
you see two down events even when you've, say, used shift-arrowkeys
to define the active region then mouse click? (no)
See, you don't see the old down event on the post-command-hook until the
the whole extended "mouse gesture" started by the old event is
considered a completed command, so you appear to get two down events in
rapid succession, at least if you were going by what you see in
a post-command-hook
i.e.
down...drag...up......down..up....
^ not a finished command1, possibly counterintuitively
^finished command1
You can easily see this behaviour by turning on hl-line mode
and selecting a region with the mouse - note the hl-line position
(a post command hook) isn't updated until you do something
else after the mouse-based region selection.
The code in question is on `post-command-hook'. It checks whether the region is
active, and then it checks for the mouse event:
It may be better to do it somewhere else, at least in part, and yes, you
may have to save the value depending on what it is you really want to do
with it:
One possibility might be the deactivate-mark called before the new
active region is defined by the new mouse-drag-track*.
So a deactivate-mark hook will capture the previous region on each new
mouse down (try putting the same thing on post-command-hook and note the
difference in delivery time)
(defun dtest ()
(message (format "event(%s:%s) region(activep: %s, contents: '%s')"
(event-basic-type last-command-event)
(event-modifiers last-command-event)
(region-active-p)
(buffer-substring (region-beginning) (region-end)))))
(add-hook 'deactivate-mark-hook 'dtest)
; (remove-hook 'deactivate-mark-hook 'dtest)
* The call was actually reordered recently, but that move only means you
get the correct region during the relevant mark deactivation rather than
a wierd mix of the old mark to the new point i.e. it's a bugfix (but
note that in turn means code depending on it will only work on CVS HEAD
at present).
Re: how to test whether region is active during a mouse event?, Stefan Monnier, 2009/08/06