unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#15960: 24.3.50; Provide a good way to tell when in `mouse-drag-track' (regression)
@ 2013-11-23 19:39 Drew Adams
  2013-11-23 22:04 ` Stefan Monnier
  0 siblings, 1 reply; 4+ messages in thread
From: Drew Adams @ 2013-11-23 19:39 UTC (permalink / raw)
  To: 15960

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'





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

end of thread, other threads:[~2013-11-24  0:42 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-11-23 19:39 bug#15960: 24.3.50; Provide a good way to tell when in `mouse-drag-track' (regression) Drew Adams
2013-11-23 22:04 ` Stefan Monnier
2013-11-23 23:21   ` Drew Adams
2013-11-24  0:42     ` Stefan Monnier

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