all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#12204: 24.1.50; Binding mouse-movement interferes with "C-h c" for mouse clicks
@ 2012-08-14 19:07 Eli Zaretskii
  2017-06-12  0:18 ` npostavs
  0 siblings, 1 reply; 10+ messages in thread
From: Eli Zaretskii @ 2012-08-14 19:07 UTC (permalink / raw)
  To: 12204

This bug report will be sent to the Bug-GNU-Emacs mailing list
and the GNU bug tracker at debbugs.gnu.org.  Please check that
the From: line contains a valid email address.  After a delay of up
to one day, you should receive an acknowledgment at that address.

Please write in English if possible, as the Emacs maintainers
usually do not have translators for other languages.

Please describe exactly what actions triggered the bug, and
the precise symptoms of the bug.  If you can, give a recipe
starting from `emacs -Q':

    emacs -Q
    M-x gdb RET

 . Choose some executable, it doesn't matter which one, and type its file
   name followed by RET.

 . Wait for GDB to start up and show its prompt, then type:

    M-x gud-tooltip-mode RET

 . If your Emacs bzr revision is older than 109615, click the mouse
   once somewhere in the window.  (Revision 109615 fixed the bug which
   required that click.)

 . Type "C-h c", and then move the mouse to some tool-bar button or
   menu-bar menu item, and click on it.  Watch in disbelief as Emacs
   _executes_ the command bound to that click instead of showing its
   documentation.

 . Repeat the experiment, but this time, after "C-h c" slowly move the
   mouse a small ways and watch the echo area.  You will see a message
   there:

     <mouse-movement> runs the command gud-tooltip-mouse-motion

   The message will disappear after you move the mouse again.

This happens because gud-tooltip-mode binds the command
gud-tooltip-mouse-motion to mouse-movement event.  The echo area
display of "C-h c" about that is promptly erased by the next mouse
motion, so if you are going for a tool bar or menu bar, you won't
notice it.  Then you will be surprised by the execution of a command
for which you wanted to see help.

This is not a bug, strictly speaking: the help command works as
designed.  But I wonder whether we could somehow surprise the user
less in this situation.

If Emacs crashed, and you have the Emacs process in the gdb debugger,
please include the output from the following gdb commands:
    `bt full' and `xbacktrace'.
For information about debugging Emacs, please read the file
d:/gnu/bzr/emacs/trunk/etc/DEBUG.


In GNU Emacs 24.1.50.1 (i386-mingw-nt5.1.2600)
 of 2012-08-14 on HOME-C4E4A596F7
Bzr revision: 109616 eliz@gnu.org-20120814184839-4s25r2c06hsuazco
Windowing system distributor `Microsoft Corp.', version 5.1.2600
Configured using:
 `configure --with-gcc (3.4) --no-opt --enable-checking --cflags
 -Id:/usr/include/libxml2 -DGLYPH_DEBUG=1'

Important settings:
  value of $LANG: ENU
  locale-coding-system: cp1255
  default enable-multibyte-characters: t

Major mode: Lisp Interaction

Minor modes in effect:
  gud-tooltip-mode: t
  tooltip-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  line-number-mode: t
  transient-mark-mode: t

Recent input:
M-x g d b <return> <M-backspace> <M-backspace> . . 
/ s r <tab> o <tab> / i <tab> e m a c s SPC <backspace> 
. e x e <return> M-x g u d - g d b <tab> <backspace> 
<backspace> <backspace> t o o l <tab> m o d e <return> 
<mouse-movement> C-h c <mouse-movement> C-h c <mouse-movement> 
<mouse-movement> <help-echo> <help-echo> <mouse-movement> 
<menu-bar> <buffer> C-@ <help-echo> <mouse-movement> 
<help-echo> <mouse-movement> <mouse-movement> <mouse-movement> 
C-h c <mouse-movement> <mouse-movement> <mouse-movement> 
<help-echo> <menu-bar> <buffer> C-a <help-echo> M-x 
r e p o r t - e m <tab> <return>

Recent messages:
For information about GNU Emacs and the GNU system, type C-h C-a.
Target doesn't support non-stop mode.  Turning it off.
Gud-Tooltip mode enabled
<mouse-movement> runs the command gud-tooltip-mouse-motion [3 times]

Load-path shadows:
None found.

Features:
(shadow sort gnus-util mail-extr emacsbug message format-spec rfc822 mml
easymenu mml-sec mm-decode mm-bodies mm-encode mail-parse rfc2231
mailabbrev gmm-utils mailheader sendmail rfc2047 rfc2045 ietf-drums
mm-util mail-prsvr mail-utils cus-start cus-load gdb-mi bindat json gud
easy-mmode comint ansi-color ring time-date tooltip ediff-hook vc-hooks
lisp-float-type mwheel dos-w32 disp-table ls-lisp w32-win w32-vars
tool-bar dnd fontset image regexp-opt fringe tabulated-list newcomment
lisp-mode register page menu-bar rfn-eshadow timer select scroll-bar
mouse jit-lock font-lock syntax facemenu font-core frame cham georgian
utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao korean
japanese hebrew greek romanian slovak czech european ethiopic indian
cyrillic chinese case-table epa-hook jka-cmpr-hook help simple abbrev
minibuffer button faces cus-face files text-properties overlay sha1 md5
base64 format env code-pages mule custom widget hashtable-print-readable
backquote make-network-process multi-tty emacs)





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

* bug#12204: 24.1.50; Binding mouse-movement interferes with "C-h c" for mouse clicks
  2012-08-14 19:07 bug#12204: 24.1.50; Binding mouse-movement interferes with "C-h c" for mouse clicks Eli Zaretskii
@ 2017-06-12  0:18 ` npostavs
  2017-06-12 14:10   ` Eli Zaretskii
  0 siblings, 1 reply; 10+ messages in thread
From: npostavs @ 2017-06-12  0:18 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 12204

tags 12204 + confirmed
found 12204 25.2
severity 12204 minor
quit

Eli Zaretskii <eliz@gnu.org> writes:

>     emacs -Q
>     M-x gdb RET
>
>  . Choose some executable, it doesn't matter which one, and type its file
>    name followed by RET.
>
>  . Wait for GDB to start up and show its prompt, then type:
>
>     M-x gud-tooltip-mode RET
>
>  . If your Emacs bzr revision is older than 109615, click the mouse
>    once somewhere in the window.  (Revision 109615 fixed the bug which
>    required that click.)
>
>  . Type "C-h c", and then move the mouse to some tool-bar button or
>    menu-bar menu item, and click on it.  Watch in disbelief as Emacs
>    _executes_ the command bound to that click instead of showing its
>    documentation.
>
>  . Repeat the experiment, but this time, after "C-h c" slowly move the
>    mouse a small ways and watch the echo area.  You will see a message
>    there:
>
>      <mouse-movement> runs the command gud-tooltip-mouse-motion
>
>    The message will disappear after you move the mouse again.
>
> This happens because gud-tooltip-mode binds the command
> gud-tooltip-mouse-motion to mouse-movement event.  The echo area
> display of "C-h c" about that is promptly erased by the next mouse
> motion, so if you are going for a tool bar or menu bar, you won't
> notice it.  Then you will be surprised by the execution of a command
> for which you wanted to see help.
>
> This is not a bug, strictly speaking: the help command works as
> designed.  But I wonder whether we could somehow surprise the user
> less in this situation.

Perhaps describe-key could respect 'use-dialog-box' and popup a dialog
box when the "key" comes from the mouse?

Also, if I understand the gud.el code, it seems like it might be better
implemented if the 'help-echo' or 'mouse-face' text properties were
extended to support a value of 2 functions: a 'mouse-in' and a
'mouse-out' function.






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

* bug#12204: 24.1.50; Binding mouse-movement interferes with "C-h c" for mouse clicks
  2017-06-12  0:18 ` npostavs
@ 2017-06-12 14:10   ` Eli Zaretskii
  2017-06-12 16:58     ` Noam Postavsky
  0 siblings, 1 reply; 10+ messages in thread
From: Eli Zaretskii @ 2017-06-12 14:10 UTC (permalink / raw)
  To: npostavs; +Cc: 12204

> From: npostavs@users.sourceforge.net
> Cc: 12204@debbugs.gnu.org
> Date: Sun, 11 Jun 2017 20:18:54 -0400
> 
> > This happens because gud-tooltip-mode binds the command
> > gud-tooltip-mouse-motion to mouse-movement event.  The echo area
> > display of "C-h c" about that is promptly erased by the next mouse
> > motion, so if you are going for a tool bar or menu bar, you won't
> > notice it.  Then you will be surprised by the execution of a command
> > for which you wanted to see help.
> >
> > This is not a bug, strictly speaking: the help command works as
> > designed.  But I wonder whether we could somehow surprise the user
> > less in this situation.
> 
> Perhaps describe-key could respect 'use-dialog-box' and popup a dialog
> box when the "key" comes from the mouse?

What would be shown in the dialog box?





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

* bug#12204: 24.1.50; Binding mouse-movement interferes with "C-h c" for mouse clicks
  2017-06-12 14:10   ` Eli Zaretskii
@ 2017-06-12 16:58     ` Noam Postavsky
  2017-06-12 17:07       ` Eli Zaretskii
  0 siblings, 1 reply; 10+ messages in thread
From: Noam Postavsky @ 2017-06-12 16:58 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 12204

On Mon, Jun 12, 2017 at 10:10 AM, Eli Zaretskii <eliz@gnu.org> wrote:
>>
>> Perhaps describe-key could respect 'use-dialog-box' and popup a dialog
>> box when the "key" comes from the mouse?
>
> What would be shown in the dialog box?

The usual message: "<mouse-movement> runs the command gud-tooltip-mouse-motion"





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

* bug#12204: 24.1.50; Binding mouse-movement interferes with "C-h c" for mouse clicks
  2017-06-12 16:58     ` Noam Postavsky
@ 2017-06-12 17:07       ` Eli Zaretskii
  2017-06-12 17:15         ` Noam Postavsky
  0 siblings, 1 reply; 10+ messages in thread
From: Eli Zaretskii @ 2017-06-12 17:07 UTC (permalink / raw)
  To: Noam Postavsky; +Cc: 12204

> From: Noam Postavsky <npostavs@users.sourceforge.net>
> Date: Mon, 12 Jun 2017 12:58:07 -0400
> Cc: 12204@debbugs.gnu.org
> 
> On Mon, Jun 12, 2017 at 10:10 AM, Eli Zaretskii <eliz@gnu.org> wrote:
> >>
> >> Perhaps describe-key could respect 'use-dialog-box' and popup a dialog
> >> box when the "key" comes from the mouse?
> >
> > What would be shown in the dialog box?
> 
> The usual message: "<mouse-movement> runs the command gud-tooltip-mouse-motion"

That could look weird on systems that don't (yet) support dialog
boxes, and use menus to emulate them.  Like MS-Windows, for example,
or text-mode terminals with a mouse.

I was actually thinking seriously to not show the help message for
mouse-movement bindings.  Would that break something important?





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

* bug#12204: 24.1.50; Binding mouse-movement interferes with "C-h c" for mouse clicks
  2017-06-12 17:07       ` Eli Zaretskii
@ 2017-06-12 17:15         ` Noam Postavsky
  2017-06-12 17:20           ` Eli Zaretskii
  0 siblings, 1 reply; 10+ messages in thread
From: Noam Postavsky @ 2017-06-12 17:15 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 12204

On Mon, Jun 12, 2017 at 1:07 PM, Eli Zaretskii <eliz@gnu.org> wrote:
>> From: Noam Postavsky <npostavs@users.sourceforge.net>
>> Date: Mon, 12 Jun 2017 12:58:07 -0400
>> Cc: 12204@debbugs.gnu.org
>>
>> On Mon, Jun 12, 2017 at 10:10 AM, Eli Zaretskii <eliz@gnu.org> wrote:
>> >>
>> >> Perhaps describe-key could respect 'use-dialog-box' and popup a dialog
>> >> box when the "key" comes from the mouse?
>> >
>> > What would be shown in the dialog box?
>>
>> The usual message: "<mouse-movement> runs the command gud-tooltip-mouse-motion"
>
> That could look weird on systems that don't (yet) support dialog
> boxes, and use menus to emulate them.  Like MS-Windows, for example,
> or text-mode terminals with a mouse.
>
> I was actually thinking seriously to not show the help message for
> mouse-movement bindings.  Would that break something important?

It should only break discovery of what's bound to <mouse-movement> I
guess, and we could still leave "C-h k" for that so it shouldn't be
much of a problem.





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

* bug#12204: 24.1.50; Binding mouse-movement interferes with "C-h c" for mouse clicks
  2017-06-12 17:15         ` Noam Postavsky
@ 2017-06-12 17:20           ` Eli Zaretskii
  2017-06-25  3:18             ` npostavs
  0 siblings, 1 reply; 10+ messages in thread
From: Eli Zaretskii @ 2017-06-12 17:20 UTC (permalink / raw)
  To: Noam Postavsky; +Cc: 12204

> From: Noam Postavsky <npostavs@users.sourceforge.net>
> Date: Mon, 12 Jun 2017 13:15:24 -0400
> Cc: 12204@debbugs.gnu.org
> 
> > I was actually thinking seriously to not show the help message for
> > mouse-movement bindings.  Would that break something important?
> 
> It should only break discovery of what's bound to <mouse-movement> I
> guess, and we could still leave "C-h k" for that so it shouldn't be
> much of a problem.

Then I think this is what we should do, and perhaps leave some knob to
get back the old behavior.





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

* bug#12204: 24.1.50; Binding mouse-movement interferes with "C-h c" for mouse clicks
  2017-06-12 17:20           ` Eli Zaretskii
@ 2017-06-25  3:18             ` npostavs
  2017-06-25 13:49               ` Eli Zaretskii
  0 siblings, 1 reply; 10+ messages in thread
From: npostavs @ 2017-06-25  3:18 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 12204

[-- Attachment #1: Type: text/plain, Size: 989 bytes --]

tags 12204 + patch
quit

Eli Zaretskii <eliz@gnu.org> writes:

>> From: Noam Postavsky <npostavs@users.sourceforge.net>
>> Date: Mon, 12 Jun 2017 13:15:24 -0400
>> Cc: 12204@debbugs.gnu.org
>> 
>> > I was actually thinking seriously to not show the help message for
>> > mouse-movement bindings.  Would that break something important?
>> 
>> It should only break discovery of what's bound to <mouse-movement> I
>> guess, and we could still leave "C-h k" for that so it shouldn't be
>> much of a problem.
>
> Then I think this is what we should do, and perhaps leave some knob to
> get back the old behavior.

Here are some patches, the first deduplicates the code of describe-key
and describe-key-briefly since they had some almost-identical sections
that confused me when I started by accidentally modifying the wrong one.

The second patch just ignores mouse-movement for "C-h c", I don't think
it's worth an option to get the old behaviour, but it's easy enough to
add it if you want.


[-- Attachment #2: patch --]
[-- Type: text/plain, Size: 14379 bytes --]

From b973070650626de588fa64ffd08348c39de7be77 Mon Sep 17 00:00:00 2001
From: Noam Postavsky <npostavs@gmail.com>
Date: Sat, 17 Jun 2017 20:33:56 -0400
Subject: [PATCH 1/2] Refactor key describing commands

* lisp/help.el (help-read-key-sequence, help--analyze-key): New
functions, extracted from `describe-key' and `describe-key-briefly'.
(describe-key, describe-key-briefly): Use them.
---
 lisp/help.el | 251 ++++++++++++++++++++++++-----------------------------------
 1 file changed, 103 insertions(+), 148 deletions(-)

diff --git a/lisp/help.el b/lisp/help.el
index 4d98c1dc81..24e07662e8 100644
--- a/lisp/help.el
+++ b/lisp/help.el
@@ -593,6 +593,39 @@ (defun help-key-description (key untranslated)
 	    string
 	  (format "%s (translated from %s)" string otherstring))))))
 
+(defun help--analyze-key (key untranslated)
+  "Get information about KEY its corresponding UNTRANSLATED events.
+Returns a list of the form (BRIEF-DESC DEFN EVENT MOUSE-MSG)."
+  (if (numberp untranslated)
+      (setq untranslated (this-single-command-raw-keys)))
+  (let* ((event (aref key (if (and (symbolp (aref key 0))
+				   (> (length key) 1)
+				   (consp (aref key 1)))
+			      1
+			    0)))
+	 (modifiers (event-modifiers event))
+	 (mouse-msg (if (or (memq 'click modifiers) (memq 'down modifiers)
+			    (memq 'drag modifiers)) " at that spot" ""))
+	 (defn (key-binding key t)))
+    ;; Handle the case where we faked an entry in "Select and Paste" menu.
+    (when (and (eq defn nil)
+	       (stringp (aref key (1- (length key))))
+	       (eq (key-binding (substring key 0 -1)) 'yank-menu))
+      (setq defn 'menu-bar-select-yank))
+    ;; Don't bother user with strings from (e.g.) the select-paste menu.
+    (when (stringp (aref key (1- (length key))))
+      (aset key (1- (length key)) "(any string)"))
+    (when (and untranslated
+               (stringp (aref untranslated (1- (length untranslated)))))
+      (aset untranslated (1- (length untranslated)) "(any string)"))
+    (list
+     ;; Now describe the key, perhaps as changed.
+     (let ((key-desc (help-key-description key untranslated)))
+       (if (or (null defn) (integerp defn) (equal defn 'undefined))
+           (format "%s%s is undefined" key-desc mouse-msg)
+         (format "%s%s runs the command %S" key-desc mouse-msg defn)))
+     defn event mouse-msg)))
+
 (defun describe-key-briefly (&optional key insert untranslated)
   "Print the name of the function KEY invokes.  KEY is a string.
 If INSERT (the prefix arg) is non-nil, insert the message in the buffer.
@@ -603,73 +636,10 @@ (defun describe-key-briefly (&optional key insert untranslated)
 If KEY is a menu item or a tool-bar button that is disabled, this command
 temporarily enables it to allow getting help on disabled items and buttons."
   (interactive
-   (let ((enable-disabled-menus-and-buttons t)
-	 (cursor-in-echo-area t)
-	 saved-yank-menu)
-     (unwind-protect
-	 (let (key)
-	   ;; If yank-menu is empty, populate it temporarily, so that
-	   ;; "Select and Paste" menu can generate a complete event.
-	   (when (null (cdr yank-menu))
-	     (setq saved-yank-menu (copy-sequence yank-menu))
-	     (menu-bar-update-yank-menu "(any string)" nil))
-           (while
-               (progn
-                 (setq key (read-key-sequence "Describe the following key, mouse click, or menu item: "))
-                 (and (vectorp key)
-                      (consp (aref key 0))
-                      (symbolp (car (aref key 0)))
-                      (string-match "\\(mouse\\|down\\|click\\|drag\\)"
-                                    (symbol-name (car (aref key 0))))
-                      (not (sit-for (/ double-click-time 1000.0) t)))))
-	   ;; Clear the echo area message (Bug#7014).
-	   (message nil)
-	   ;; If KEY is a down-event, read and discard the
-	   ;; corresponding up-event.  Note that there are also
-	   ;; down-events on scroll bars and mode lines: the actual
-	   ;; event then is in the second element of the vector.
-	   (and (vectorp key)
-		(let ((last-idx (1- (length key))))
-		  (and (eventp (aref key last-idx))
-		       (memq 'down (event-modifiers (aref key last-idx)))))
-		(read-event))
-	   (list
-	    key
-	    (if current-prefix-arg (prefix-numeric-value current-prefix-arg))
-	    1))
-       ;; Put yank-menu back as it was, if we changed it.
-       (when saved-yank-menu
-	 (setq yank-menu (copy-sequence saved-yank-menu))
-	 (fset 'yank-menu (cons 'keymap yank-menu))))))
-  (if (numberp untranslated)
-      (setq untranslated (this-single-command-raw-keys)))
-  (let* ((event (if (and (symbolp (aref key 0))
-			 (> (length key) 1)
-			 (consp (aref key 1)))
-		    (aref key 1)
-		  (aref key 0)))
-	 (modifiers (event-modifiers event))
-	 (standard-output (if insert (current-buffer) standard-output))
-	 (mouse-msg (if (or (memq 'click modifiers) (memq 'down modifiers)
-			    (memq 'drag modifiers)) " at that spot" ""))
-	 (defn (key-binding key t))
-	 key-desc)
-    ;; Handle the case where we faked an entry in "Select and Paste" menu.
-    (if (and (eq defn nil)
-	     (stringp (aref key (1- (length key))))
-	     (eq (key-binding (substring key 0 -1)) 'yank-menu))
-	(setq defn 'menu-bar-select-yank))
-    ;; Don't bother user with strings from (e.g.) the select-paste menu.
-    (if (stringp (aref key (1- (length key))))
-	(aset key (1- (length key)) "(any string)"))
-    (if (and (> (length untranslated) 0)
-	     (stringp (aref untranslated (1- (length untranslated)))))
-	(aset untranslated (1- (length untranslated)) "(any string)"))
-    ;; Now describe the key, perhaps as changed.
-    (setq key-desc (help-key-description key untranslated))
-    (if (or (null defn) (integerp defn) (equal defn 'undefined))
-	(princ (format "%s%s is undefined" key-desc mouse-msg))
-      (princ (format "%s%s runs the command %S" key-desc mouse-msg defn)))))
+   (pcase-let ((`(,key ,_up-event) (help-read-key-sequence)))
+     `(,key ,current-prefix-arg 1)))
+  (princ (car (help--analyze-key key untranslated))
+         (if insert (current-buffer) standard-output)))
 
 (defun help--key-binding-keymap (key &optional accept-default no-remap position)
   "Return a keymap holding a binding for KEY within current keymaps.
@@ -734,6 +704,55 @@ (defun help--binding-locus (key position)
                (throw 'found x))))
           nil)))))
 
+(defun help-read-key-sequence ()
+  "Reads a key sequence from the user.
+Returns a list of the form (KEY UP-EVENT), where KEY is the key
+sequence, and UP-EVENT is the up-event that was discarded by
+reading KEY, or nil."
+  (let ((enable-disabled-menus-and-buttons t)
+        (cursor-in-echo-area t)
+        saved-yank-menu)
+    (unwind-protect
+        (let (key)
+          ;; If yank-menu is empty, populate it temporarily, so that
+          ;; "Select and Paste" menu can generate a complete event.
+          (when (null (cdr yank-menu))
+            (setq saved-yank-menu (copy-sequence yank-menu))
+            (menu-bar-update-yank-menu "(any string)" nil))
+          (while
+              (pcase (setq key (read-key-sequence "\
+Describe the following key, mouse click, or menu item: "))
+                ((and (pred vectorp) (let `(,key0 . ,_) (aref key 0))
+                      (guard (symbolp key0)) (let keyname (symbol-name key0)))
+                 (and (string-match "\\(mouse\\|down\\|click\\|drag\\)"
+                                    keyname)
+                      (not (sit-for (/ double-click-time 1000.0) t))))))
+          (list
+           key
+           ;; If KEY is a down-event, read and include the
+           ;; corresponding up-event.  Note that there are also
+           ;; down-events on scroll bars and mode lines: the actual
+           ;; event then is in the second element of the vector.
+           (and (vectorp key)
+                (let ((last-idx (1- (length key))))
+                  (and (eventp (aref key last-idx))
+                       (memq 'down (event-modifiers (aref key last-idx)))))
+                (or (and (eventp (aref key 0))
+                         (memq 'down (event-modifiers (aref key 0)))
+                         ;; However, for the C-down-mouse-2 popup
+                         ;; menu, there is no subsequent up-event.  In
+                         ;; this case, the up-event is the next
+                         ;; element in the supplied vector.
+                         (= (length key) 1))
+                    (and (> (length key) 1)
+                         (eventp (aref key 1))
+                         (memq 'down (event-modifiers (aref key 1)))))
+                (read-event))))
+      ;; Put yank-menu back as it was, if we changed it.
+      (when saved-yank-menu
+        (setq yank-menu (copy-sequence saved-yank-menu))
+        (fset 'yank-menu (cons 'keymap yank-menu))))))
+
 (defun describe-key (&optional key untranslated up-event)
   "Display documentation of the function invoked by KEY.
 KEY can be any kind of a key sequence; it can include keyboard events,
@@ -748,83 +767,20 @@ (defun describe-key (&optional key untranslated up-event)
 If KEY is a menu item or a tool-bar button that is disabled, this command
 temporarily enables it to allow getting help on disabled items and buttons."
   (interactive
-   (let ((enable-disabled-menus-and-buttons t)
-	 (cursor-in-echo-area t)
-	 saved-yank-menu)
-     (unwind-protect
-	 (let (key)
-	   ;; If yank-menu is empty, populate it temporarily, so that
-	   ;; "Select and Paste" menu can generate a complete event.
-	   (when (null (cdr yank-menu))
-	     (setq saved-yank-menu (copy-sequence yank-menu))
-	     (menu-bar-update-yank-menu "(any string)" nil))
-           (while
-               (progn
-                 (setq key (read-key-sequence "Describe the following key, mouse click, or menu item: "))
-                 (and (vectorp key)
-                      (consp (aref key 0))
-                      (symbolp (car (aref key 0)))
-                      (string-match "\\(mouse\\|down\\|click\\|drag\\)"
-                                    (symbol-name (car (aref key 0))))
-                      (not (sit-for (/ double-click-time 1000.0) t)))))
-	   (list
-	    key
-	    (prefix-numeric-value current-prefix-arg)
-	    ;; If KEY is a down-event, read and include the
-	    ;; corresponding up-event.  Note that there are also
-	    ;; down-events on scroll bars and mode lines: the actual
-	    ;; event then is in the second element of the vector.
-	    (and (vectorp key)
-		 (let ((last-idx (1- (length key))))
-		   (and (eventp (aref key last-idx))
-			(memq 'down (event-modifiers (aref key last-idx)))))
-		 (or (and (eventp (aref key 0))
-			  (memq 'down (event-modifiers (aref key 0)))
-			  ;; However, for the C-down-mouse-2 popup
-			  ;; menu, there is no subsequent up-event.  In
-			  ;; this case, the up-event is the next
-			  ;; element in the supplied vector.
-			  (= (length key) 1))
-		     (and (> (length key) 1)
-			  (eventp (aref key 1))
-			  (memq 'down (event-modifiers (aref key 1)))))
-		 (read-event))))
-       ;; Put yank-menu back as it was, if we changed it.
-       (when saved-yank-menu
-	 (setq yank-menu (copy-sequence saved-yank-menu))
-	 (fset 'yank-menu (cons 'keymap yank-menu))))))
-  (if (numberp untranslated)
-      (setq untranslated (this-single-command-raw-keys)))
-  (let* ((event (aref key (if (and (symbolp (aref key 0))
-				   (> (length key) 1)
-				   (consp (aref key 1)))
-			      1
-			    0)))
-	 (modifiers (event-modifiers event))
-	 (mouse-msg (if (or (memq 'click modifiers) (memq 'down modifiers)
-			    (memq 'drag modifiers)) " at that spot" ""))
-	 (defn (key-binding key t))
-         key-locus key-locus-up key-locus-up-tricky
-	 defn-up defn-up-tricky ev-type
-	 mouse-1-remapped mouse-1-tricky)
-
-    ;; Handle the case where we faked an entry in "Select and Paste" menu.
-    (when (and (eq defn nil)
-	       (stringp (aref key (1- (length key))))
-	       (eq (key-binding (substring key 0 -1)) 'yank-menu))
-      (setq defn 'menu-bar-select-yank))
-    (if (or (null defn) (integerp defn) (equal defn 'undefined))
-	(message "%s%s is undefined"
-		 (help-key-description key untranslated) mouse-msg)
+   (pcase-let ((`(,key ,up-event) (help-read-key-sequence)))
+     `(,key ,(prefix-numeric-value current-prefix-arg) ,up-event)))
+  (pcase-let ((`(,brief-desc ,defn ,event ,mouse-msg)
+               (help--analyze-key key untranslated))
+              (defn-up nil) (defn-up-tricky nil)
+              (key-locus-up nil) (key-locus-up-tricky nil)
+              (mouse-1-remapped nil) (mouse-1-tricky nil)
+              (ev-type nil))
+    (if (or (null defn)
+            (integerp defn)
+            (equal defn 'undefined))
+        (message "%s" brief-desc)
       (help-setup-xref (list #'describe-function defn)
 		       (called-interactively-p 'interactive))
-      ;; Don't bother user with strings from (e.g.) the select-paste menu.
-      (when (stringp (aref key (1- (length key))))
-	(aset key (1- (length key)) "(any string)"))
-      (when (and untranslated
-		 (stringp (aref untranslated (1- (length untranslated)))))
-	(aset untranslated (1- (length untranslated))
-	      "(any string)"))
       ;; Need to do this before erasing *Help* buffer in case event
       ;; is a mouse click in an existing *Help* buffer.
       (when up-event
@@ -849,13 +805,12 @@ (defun describe-key (&optional key untranslated up-event)
 	    (aset sequence 0 'mouse-1)
 	    (setq defn-up-tricky (key-binding sequence nil nil (event-start up-event)))
             (setq key-locus-up-tricky (help--binding-locus sequence (event-start up-event))))))
-      (setq key-locus (help--binding-locus key (event-start event)))
       (with-help-window (help-buffer)
-	(princ (help-key-description key untranslated))
-	(princ (format "%s runs the command %S%s, which is "
-		       mouse-msg defn (if key-locus
-                                          (format " (found in %s)" key-locus)
-                                        "")))
+        (princ brief-desc)
+        (let ((key-locus (help--binding-locus key (event-start event))))
+          (when key-locus
+            (princ (format " (found in %s)" key-locus))))
+        (princ ", which is ")
 	(describe-function-1 defn)
 	(when up-event
 	  (unless (or (null defn-up)
-- 
2.11.1


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: patch --]
[-- Type: text/x-diff, Size: 4113 bytes --]

From f44c0dfe8bd29374a980848db29890c1438fe3f3 Mon Sep 17 00:00:00 2001
From: Noam Postavsky <npostavs@gmail.com>
Date: Sun, 18 Jun 2017 00:39:05 -0400
Subject: [PATCH 2/2] Ignore mouse-movement for describe-key-briefly
 (Bug#12204)

* lisp/help.el (help-read-key-sequence): Add optional argument ot
ignore `mouse-movement' events.
(describe-key-briefly): Use it.
* doc/emacs/help.texi (Key Help):
* etc/NEWS: Mention that mouse movement is ignored.
---
 doc/emacs/help.texi |  7 ++++---
 etc/NEWS            |  3 +++
 lisp/help.el        | 18 ++++++++++++------
 3 files changed, 19 insertions(+), 9 deletions(-)

diff --git a/doc/emacs/help.texi b/doc/emacs/help.texi
index 548ca6a1b4..fd6df1c7e5 100644
--- a/doc/emacs/help.texi
+++ b/doc/emacs/help.texi
@@ -203,9 +203,10 @@ Key Help
 describes the command corresponding to @var{key}.
 
   @kbd{C-h c}, @kbd{C-h k} and @kbd{C-h K} work for any sort of key
-sequences, including function keys, menus, and mouse events.  For
-instance, after @kbd{C-h k} you can select a menu item from the menu
-bar, to view the documentation string of the command it runs.
+sequences, including function keys, menus, and mouse events (except
+that @kbd{C-h c} ignores mouse movement events).  For instance, after
+@kbd{C-h k} you can select a menu item from the menu bar, to view the
+documentation string of the command it runs.
 
 @kindex C-h w
 @findex where-is
diff --git a/etc/NEWS b/etc/NEWS
index 60c98a35c0..281bacffd0 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -373,6 +373,9 @@ use the local Emacs to edit remote files via Tramp.  See the node
 "emacsclient Options" in the user manual for the details.
 
 +++
+** 'describe-key-briefly' now ignores mouse movement events.
+
++++
 ** The new variable 'eval-expression-print-maximum-character' prevents
 large integers from being displayed as characters.
 
diff --git a/lisp/help.el b/lisp/help.el
index 24e07662e8..dc341b0635 100644
--- a/lisp/help.el
+++ b/lisp/help.el
@@ -636,7 +636,9 @@ (defun describe-key-briefly (&optional key insert untranslated)
 If KEY is a menu item or a tool-bar button that is disabled, this command
 temporarily enables it to allow getting help on disabled items and buttons."
   (interactive
-   (pcase-let ((`(,key ,_up-event) (help-read-key-sequence)))
+   ;; Ignore mouse movement events because it's too easy to miss the
+   ;; message while moving the mouse.
+   (pcase-let ((`(,key ,_up-event) (help-read-key-sequence 'no-mouse-movement)))
      `(,key ,current-prefix-arg 1)))
   (princ (car (help--analyze-key key untranslated))
          (if insert (current-buffer) standard-output)))
@@ -704,11 +706,13 @@ (defun help--binding-locus (key position)
                (throw 'found x))))
           nil)))))
 
-(defun help-read-key-sequence ()
+(defun help-read-key-sequence (&optional no-mouse-movement)
   "Reads a key sequence from the user.
 Returns a list of the form (KEY UP-EVENT), where KEY is the key
 sequence, and UP-EVENT is the up-event that was discarded by
-reading KEY, or nil."
+reading KEY, or nil.
+If NO-MOUSE-MOVEMENT is non-nil, ignore key sequences starting
+with `mouse-movement' events."
   (let ((enable-disabled-menus-and-buttons t)
         (cursor-in-echo-area t)
         saved-yank-menu)
@@ -724,9 +728,11 @@ (defun help-read-key-sequence ()
 Describe the following key, mouse click, or menu item: "))
                 ((and (pred vectorp) (let `(,key0 . ,_) (aref key 0))
                       (guard (symbolp key0)) (let keyname (symbol-name key0)))
-                 (and (string-match "\\(mouse\\|down\\|click\\|drag\\)"
-                                    keyname)
-                      (not (sit-for (/ double-click-time 1000.0) t))))))
+                 (if no-mouse-movement
+                     (string-match "mouse-movement" keyname)
+                   (and (string-match "\\(mouse\\|down\\|click\\|drag\\)"
+                                      keyname)
+                        (not (sit-for (/ double-click-time 1000.0) t)))))))
           (list
            key
            ;; If KEY is a down-event, read and include the
-- 
2.11.1


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

* bug#12204: 24.1.50; Binding mouse-movement interferes with "C-h c" for mouse clicks
  2017-06-25  3:18             ` npostavs
@ 2017-06-25 13:49               ` Eli Zaretskii
  2017-07-01 14:10                 ` npostavs
  0 siblings, 1 reply; 10+ messages in thread
From: Eli Zaretskii @ 2017-06-25 13:49 UTC (permalink / raw)
  To: npostavs; +Cc: 12204

> From: npostavs@users.sourceforge.net
> Cc: 12204@debbugs.gnu.org
> Date: Sat, 24 Jun 2017 23:18:03 -0400
> 
> >> > I was actually thinking seriously to not show the help message for
> >> > mouse-movement bindings.  Would that break something important?
> >> 
> >> It should only break discovery of what's bound to <mouse-movement> I
> >> guess, and we could still leave "C-h k" for that so it shouldn't be
> >> much of a problem.
> >
> > Then I think this is what we should do, and perhaps leave some knob to
> > get back the old behavior.
> 
> Here are some patches, the first deduplicates the code of describe-key
> and describe-key-briefly since they had some almost-identical sections
> that confused me when I started by accidentally modifying the wrong one.
> 
> The second patch just ignores mouse-movement for "C-h c", I don't think
> it's worth an option to get the old behaviour, but it's easy enough to
> add it if you want.

Thanks, please install if no objections come up in a few days, and
let's see if someone hollers.





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

* bug#12204: 24.1.50; Binding mouse-movement interferes with "C-h c" for mouse clicks
  2017-06-25 13:49               ` Eli Zaretskii
@ 2017-07-01 14:10                 ` npostavs
  0 siblings, 0 replies; 10+ messages in thread
From: npostavs @ 2017-07-01 14:10 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 12204

tags 12204 fixed
close 12204 26.1
quit

Eli Zaretskii <eliz@gnu.org> writes:

> Thanks, please install if no objections come up in a few days, and
> let's see if someone hollers.

Pushed to master.

[1: 2bd32ede1c]: 2017-07-01 09:40:29 -0400
  Refactor key describing commands
  http://git.savannah.gnu.org/cgit/emacs.git/commit/?id=2bd32ede1ce05b88278bab15f6cc603c97a1fb2f>

[2: e620bbe38e]: 2017-07-01 09:40:29 -0400
  Ignore mouse-movement for describe-key-briefly (Bug#12204)
  http://git.savannah.gnu.org/cgit/emacs.git/commit/?id=e620bbe38ed5e3e2a77f01eac2814c01dfa41c2d





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

end of thread, other threads:[~2017-07-01 14:10 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-08-14 19:07 bug#12204: 24.1.50; Binding mouse-movement interferes with "C-h c" for mouse clicks Eli Zaretskii
2017-06-12  0:18 ` npostavs
2017-06-12 14:10   ` Eli Zaretskii
2017-06-12 16:58     ` Noam Postavsky
2017-06-12 17:07       ` Eli Zaretskii
2017-06-12 17:15         ` Noam Postavsky
2017-06-12 17:20           ` Eli Zaretskii
2017-06-25  3:18             ` npostavs
2017-06-25 13:49               ` Eli Zaretskii
2017-07-01 14:10                 ` npostavs

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.