emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

how to test whether region is active during a mouse event?


From: Drew Adams
Subject: how to test whether region is active during a mouse event?
Date: Sun, 2 Aug 2009 11:55:14 -0700

Suppose the region is active (I'm using transient-mark mode), and I click
mouse-1.

When I look at the events generated by the mouse-button click action, and
whether the region is active for each of those events, I see three events for a
single button click (press + release):

 down,  and the region is active
 down,  and the region is not active
 click, and the region is not active

I want to be able to check whether the region is active during the overall
button-click action. I tried (separately) checking for a `down' event and a
`click' event.

The code is on `post-command-hook'. I want it to check each event and react only
to mouse clicks. And I want it to react differently, depending on whether the
region is active at the time the button is pressed.

If I check only `click' events, I can never see the region as active, because a
previous `down' event inactivates the region.

If I check `down' events instead, the first `down' is treated fine, but the
second `down' is then treated, and for that event the region is inactive. (And
the effect of my code is such that treatment of the second `down' wipes out the
effect of treating the first `down'.)

Questions:

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

2. Given this state of affairs, how can I do what I want: have the code do
something different if the mouse is clicked with or without the region being
active?

The code in question is on `post-command-hook'. It checks whether the region is
active, and then it checks for the mouse event:

(and (string-match "mouse" (format "%S" (event-basic-type last-command-event)))
     (memq 'click (event-modifiers last-command-event)))

Changing `click' to `down' here doesn't help, as explained above: That works for
the first `down' event, but the second `down' event then sees no active region.

Thanks for explanations and suggestions.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]