From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.bugs Subject: bug#29478: [Patch] bug#29478: 26.0.90; `C-h k' followed by mouse clicks no longer shows down event Date: Sat, 23 Dec 2017 11:17:26 +0000 Message-ID: <20171223111726.GA6618@ACM> References: <1b3879d6-f14e-47b0-970f-baf09598fcfd@default> <871skjnpd8.fsf@users.sourceforge.net> <20171128221036.GC14868@ACM> <83o9ni3l3i.fsf@gnu.org> <83bmji2xye.fsf@gnu.org> <83tvwzubez.fsf@gnu.org> <20171222220549.GC8072@ACM> <833741lr0t.fsf@gnu.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: blaine.gmane.org 1514027899 18585 195.159.176.226 (23 Dec 2017 11:18:19 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 23 Dec 2017 11:18:19 +0000 (UTC) User-Agent: Mutt/1.7.2 (2016-11-26) Cc: 29478@debbugs.gnu.org, Stefan Monnier , npostavs@users.sourceforge.net To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat Dec 23 12:18:14 2017 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eShoi-0004C7-QU for geb-bug-gnu-emacs@m.gmane.org; Sat, 23 Dec 2017 12:18:13 +0100 Original-Received: from localhost ([::1]:41509 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eShqd-00087Z-TN for geb-bug-gnu-emacs@m.gmane.org; Sat, 23 Dec 2017 06:20:11 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:39466) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eShqY-00087D-4v for bug-gnu-emacs@gnu.org; Sat, 23 Dec 2017 06:20:07 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eShqU-0003nq-4Z for bug-gnu-emacs@gnu.org; Sat, 23 Dec 2017 06:20:06 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:40056) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eShqT-0003ni-Uw for bug-gnu-emacs@gnu.org; Sat, 23 Dec 2017 06:20:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1eShqT-0003va-LL for bug-gnu-emacs@gnu.org; Sat, 23 Dec 2017 06:20:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Alan Mackenzie Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 23 Dec 2017 11:20:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 29478 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: confirmed Original-Received: via spool by 29478-submit@debbugs.gnu.org id=B29478.151402797215058 (code B ref 29478); Sat, 23 Dec 2017 11:20:01 +0000 Original-Received: (at 29478) by debbugs.gnu.org; 23 Dec 2017 11:19:32 +0000 Original-Received: from localhost ([127.0.0.1]:48737 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eShpz-0003uo-QL for submit@debbugs.gnu.org; Sat, 23 Dec 2017 06:19:32 -0500 Original-Received: from colin.muc.de ([193.149.48.1]:20704 helo=mail.muc.de) by debbugs.gnu.org with smtp (Exim 4.84_2) (envelope-from ) id 1eShpy-0003uf-0d for 29478@debbugs.gnu.org; Sat, 23 Dec 2017 06:19:30 -0500 Original-Received: (qmail 10883 invoked by uid 3782); 23 Dec 2017 11:19:28 -0000 Original-Received: from acm.muc.de (p548C7AB5.dip0.t-ipconnect.de [84.140.122.181]) by colin.muc.de (tmda-ofmipd) with ESMTP; Sat, 23 Dec 2017 12:19:23 +0100 Original-Received: (qmail 6689 invoked by uid 1000); 23 Dec 2017 11:17:26 -0000 Content-Disposition: inline In-Reply-To: <833741lr0t.fsf@gnu.org> X-Delivery-Agent: TMDA/1.1.12 (Macallan) X-Primary-Address: acm@muc.de X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:141417 Archived-At: Hello, Eli. On Sat, Dec 23, 2017 at 11:42:10 +0200, Eli Zaretskii wrote: > > Date: Fri, 22 Dec 2017 22:05:49 +0000 > > Cc: drew.adams@oracle.com, 29478@debbugs.gnu.org, > > npostavs@users.sourceforge.net > > From: Alan Mackenzie > > (i) emacs-26 -Q > > (ii) M-: (read-key-sequence "prompt: ") > > (iii) -mouse-1 > > What happens now is the key sequence is displayed, a S-down-mouse-1 > > event, but immediately overwritten in the message area by > > is undefined > > . Why? I merely asked for the key sequence. I didn't ask for it to be > > looked up in any key maps. What is doing the translation from a > > shift-down-mouse event to a S-click event? What is looking up this > > down-mouse event in a key map? > read-key-sequence itself examines the possible remapping of the > sequence. And it seems reasonable, since how can it otherwise know > when the sequence is complete? > What is perhaps unexpected here (or might be a bug) is that for some > reason the sequence is left in unread-command-events (or somewhere > similar, perhaps in read_key_sequence_remapped?), because if I set a > breakpoint in Fding, the backtrace from the "is undefined" message > clearly shows it was the command loop that invoked 'undefined': [ .... ] Of course! read-key-sequence consumes all the events up to the S-down-mouse-1, leaving the following S-mouse-1 in the event buffer. This is read at the next iteration of the command loop. > CC'ing Stefan in the hope that he could have some insights. OK, I have a provisional fix. The problem was that the double-click-time loop in help-read-key-sequence was discarding all events but the last one. I have amended the loop so that _all_ these events are stored in a list, and we then discard the most recent events till we find one with a binding. This patch seems to work with GPM in a Linux tty, and also in X-Windows (I think). (It is based on the emacs-26 branch, of course.) diff --git a/lisp/help.el b/lisp/help.el index 212e3679da..dd1676adb0 100644 --- a/lisp/help.el +++ b/lisp/help.el @@ -717,7 +717,7 @@ help-read-key-sequence (cursor-in-echo-area t) saved-yank-menu) (unwind-protect - (let (key down-ev) + (let (key keys down-ev discarded-up) ;; If yank-menu is empty, populate it temporarily, so that ;; "Select and Paste" menu can generate a complete event. (when (null (cdr yank-menu)) @@ -731,6 +731,7 @@ help-read-key-sequence (or (and no-mouse-movement (string-match "mouse-movement" keyname)) + (progn (push key keys) nil) (and (string-match "\\(mouse\\|down\\|click\\|drag\\)" keyname) (progn @@ -739,13 +740,31 @@ help-read-key-sequence (sleep-for 0.01) (while (read-event nil nil 0.01)) (not (sit-for (/ double-click-time 1000.0) t)))))))) + ;; When we have a sequence of mouse events, discard the most + ;; recent ones till we find one with a binding. + (let ((keys-1 keys)) + (while (and keys-1 + (not (key-binding (car keys-1)))) + ;; If we discard the last event, and this was a mouse + ;; up, remember this. + (if (and (eq keys-1 keys) + (vectorp (car keys-1)) + (let* ((last-idx (1- (length (car keys-1)))) + (last (aref (car keys-1) last-idx))) + (and (eventp last) + (memq 'click (event-modifiers last))))) + (setq discarded-up t)) + (setq keys-1 (cdr keys-1))) + (if keys-1 + (setq key (car keys-1)))) (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) + (and (not discarded-up) ; Don't attempt to ignore the up-event twice. + (vectorp key) (let ((last-idx (1- (length key)))) (and (eventp (aref key last-idx)) (memq 'down (event-modifiers (aref key last-idx))))) -- Alan Mackenzie (Nuremberg, Germany).