unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Drew Adams <drew.adams@oracle.com>
To: 15960@debbugs.gnu.org
Subject: bug#15960: 24.3.50; Provide a good way to tell when in `mouse-drag-track' (regression)
Date: Sat, 23 Nov 2013 11:39:43 -0800 (PST)	[thread overview]
Message-ID: <ed8eb56a-e02f-435b-9679-82c3853e0fd4@default> (raw)

I have code (library modeline-posn.el) that lets users optionally show
the active region size (highlighted) in the minibuffer, in place of the
buffer size.

My code did this, to test whether the region was active or the user
wants to allow an empty region to be highlighted:

(and transient-mark-mode  mark-active
       (or modelinepos-empty-region-flag
           (/= (region-beginning) (region-end))))

With `modelinepos-empty-region-flag' non-nil, this made it easy for a
user to see when the active region is empty.  (The mode-line size
indication is highlighted with face `region'.)

Emacs 24 changed things, so that this mode-line highlighting now
appeared immediately when you press `mouse-1', and did not wait until
you actually drag the mouse or release `mouse-1'.

This broke the user experience for this feature, because now each time
s?he clicked `mouse-1', without any dragging, a zero-size-region
indication showed in the mode line for as long as `mouse-1' was held
down during the click.  IOW, an annoying flash.

Obviously that is no good, so I updated my code to try to test whether
we are inside `mouse-drag-track'.  I found no clean and sure way to do
this, so I currently test `echo-keystrokes', which `mouse-drag-track'
binds to 0.  This seems to work fine, but it is obviously indirect and
fragile.

The bug report is to request some clearer, cleaner, and surer way to
tell whether we are in `mouse-drag-track'.

This is the code I use now for the test:

(defun modelinepos-empty-region-p ()
  "Return non-nil if region is active and empty.
But do not return non-nil if this is true but you are selecting with
the mouse.  This is to prevent highlighting in the mode line whenever
you press `mouse-1' without dragging at least one character."

  ;; Fragile hack: Starting with Emacs 24, the region is considered
  ;; empty as soon as you press `mouse-1' (`down-mouse-1').  That causes
  ;; modeline highlighting each time you just click `mouse-1', i.e.,
  ;; without dragging it.
  ;;
  ;; The hack is to check whether `echo-keystrokes' is 0.
  ;; `mouse-drag-track' binds `echo-keystrokes' to 0, and that seems to
  ;; be the only way to tell whether we are in `mouse-drag-track'.
  ;; If the Emacs code for that changes then this might break.
  (and transient-mark-mode  mark-active
       (or (if (> emacs-major-version 23)
               (and (not (eq 0 echo-keystrokes))
                    modelinepos-empty-region-flag)
             modelinepos-empty-region-flag)
           (/= (region-beginning) (region-end)))))


In GNU Emacs 24.3.50.1 (i686-pc-mingw32)
 of 2013-11-12 on LEG570
Windowing system distributor `Microsoft Corp.', version 6.1.7601
Configured using:
 `configure --enable-checking 'CFLAGS=-O0 -g3' CPPFLAGS=-DGLYPH_DEBUG=1'





             reply	other threads:[~2013-11-23 19:39 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-23 19:39 Drew Adams [this message]
2013-11-23 22:04 ` bug#15960: 24.3.50; Provide a good way to tell when in `mouse-drag-track' (regression) Stefan Monnier
2013-11-23 23:21   ` Drew Adams
2013-11-24  0:42     ` Stefan Monnier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ed8eb56a-e02f-435b-9679-82c3853e0fd4@default \
    --to=drew.adams@oracle.com \
    --cc=15960@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).