From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Drew Adams" Newsgroups: gmane.emacs.devel Subject: RE: how to test whether region is active during a mouse event? Date: Sun, 2 Aug 2009 13:50:56 -0700 Message-ID: References: <1907CCC7DE424D73AA8FD0E2F798DF49@us.oracle.com> <4A75F794.103@harpegolden.net> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1249246261 10446 80.91.229.12 (2 Aug 2009 20:51:01 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 2 Aug 2009 20:51:01 +0000 (UTC) Cc: emacs-devel@gnu.org To: "'David De La Harpe Golden'" Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Aug 02 22:50:54 2009 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1MXi17-00016a-K9 for ged-emacs-devel@m.gmane.org; Sun, 02 Aug 2009 22:50:53 +0200 Original-Received: from localhost ([127.0.0.1]:50900 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MXi17-0004zZ-60 for ged-emacs-devel@m.gmane.org; Sun, 02 Aug 2009 16:50:53 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MXi13-0004zO-1N for emacs-devel@gnu.org; Sun, 02 Aug 2009 16:50:49 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MXi0x-0004wp-Lg for emacs-devel@gnu.org; Sun, 02 Aug 2009 16:50:47 -0400 Original-Received: from [199.232.76.173] (port=54211 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MXi0x-0004wm-ER for emacs-devel@gnu.org; Sun, 02 Aug 2009 16:50:43 -0400 Original-Received: from acsinet11.oracle.com ([141.146.126.233]:57530) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1MXi0w-0006tL-Of for emacs-devel@gnu.org; Sun, 02 Aug 2009 16:50:43 -0400 Original-Received: from acsinet15.oracle.com (acsinet15.oracle.com [141.146.126.227]) by acsinet11.oracle.com (Switch-3.3.1/Switch-3.3.1) with ESMTP id n72Kp4Mw002313 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Sun, 2 Aug 2009 20:51:05 GMT Original-Received: from abhmt015.oracle.com (abhmt015.oracle.com [141.146.116.24]) by acsinet15.oracle.com (Switch-3.3.1/Switch-3.3.1) with ESMTP id n72KoxEt021216; Sun, 2 Aug 2009 20:50:59 GMT Original-Received: from dradamslap1 (/141.144.232.5) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Sun, 02 Aug 2009 13:50:37 -0700 X-Mailer: Microsoft Office Outlook 11 In-Reply-To: <4A75F794.103@harpegolden.net> Thread-Index: AcoTsFl8LfCkPQLrQ5Oy2zpmN5EpXgAAG1kQ X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5579 X-Source-IP: abhmt015.oracle.com [141.146.116.24] X-Auth-Type: Internal IP X-CT-RefId: str=0001.0A010209.4A75FC1E.0160:SCFSTAT5015188,ss=1,fgs=0 X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 1) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:113571 Archived-At: > 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.