unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* how to test whether region is active during a mouse event?
@ 2009-08-02 18:55 Drew Adams
  2009-08-02 19:00 ` Drew Adams
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Drew Adams @ 2009-08-02 18:55 UTC (permalink / raw)
  To: emacs-devel

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.





^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2009-08-06 16:16 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-08-02 18:55 how to test whether region is active during a mouse event? Drew Adams
2009-08-02 19:00 ` Drew Adams
2009-08-02 20:31 ` David De La Harpe Golden
2009-08-02 20:50   ` Drew Adams
2009-08-02 22:13     ` David De La Harpe Golden
2009-08-02 22:32       ` Drew Adams
2009-08-03  0:13         ` David De La Harpe Golden
2009-08-06 15:47 ` Stefan Monnier
2009-08-06 16:16   ` Drew Adams

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).