[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: |
Drew Adams |
Subject: |
RE: how to test whether region is active during a mouse event? |
Date: |
Sun, 2 Aug 2009 13:50:56 -0700 |
> Are you defining the active region with the keyboard or mouse?
The mouse - that's what I was testing with.
> Do you see two down events even when you've, say, used
> shift-arrowkeys to define the active region then mouse click? (no)
No. Likewise, if I use C-x C-x to activate the region. I see only one `down'
followed by a `click'.
Thanks. I didn't think to try that. Since I was testing mouse stuff, it was
simpler to just use the mouse to define the region.
> 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
> ^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.
Got it. Thanks.
> > 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)
Very good info, thanks. I didn't know there was a `deactivate-mark-hook'. I see
that it is new for Emacs 23.
Yes, what you suggest sounds good. I'm thinking over my original intention,
though, and I think I might not bother with the specificity wrt region
activeness after all.
But this is very good to know, whether I eventually use it here or elsewhere.
> * 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).
Also good to know, I guess. What was the bug (in practical, use-case terms) that
this is intended to fix?
Thx - clear & complete explanation for what I asked.
Re: how to test whether region is active during a mouse event?, Stefan Monnier, 2009/08/06