From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Alex Newsgroups: gmane.emacs.bugs Subject: bug#14793: 23.4; Cannot bind a function to a sequence of two mouse keys Date: Wed, 04 Oct 2017 21:58:41 -0600 Message-ID: <87vajuutxq.fsf@gmail.com> References: <878twa94c5.fsf@users.sourceforge.net> <878tgvy3dq.fsf@gmail.com> <83tvzi3lh8.fsf@gnu.org> <87h8virbzn.fsf@gmail.com> <83poa63es2.fsf@gnu.org> <8760bwridy.fsf@gmail.com> <83r2uk1eu5.fsf@gnu.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: blaine.gmane.org 1507175953 1715 195.159.176.226 (5 Oct 2017 03:59:13 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 5 Oct 2017 03:59:13 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) Cc: 14793@debbugs.gnu.org, regularclockwork@gmail.com, npostavs@users.sourceforge.net To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Oct 05 05:59:08 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 1dzxJT-000861-5m for geb-bug-gnu-emacs@m.gmane.org; Thu, 05 Oct 2017 05:59:07 +0200 Original-Received: from localhost ([::1]:37677 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dzxJa-0001yB-DF for geb-bug-gnu-emacs@m.gmane.org; Wed, 04 Oct 2017 23:59:14 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:45057) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dzxJU-0001y5-GR for bug-gnu-emacs@gnu.org; Wed, 04 Oct 2017 23:59:10 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dzxJP-0004Hh-0T for bug-gnu-emacs@gnu.org; Wed, 04 Oct 2017 23:59:08 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:40872) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dzxJO-0004Hc-S7 for bug-gnu-emacs@gnu.org; Wed, 04 Oct 2017 23:59:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1dzxJO-000089-Ip for bug-gnu-emacs@gnu.org; Wed, 04 Oct 2017 23:59:02 -0400 X-Loop: help-debbugs@gnu.org In-Reply-To: Resent-From: Alex Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 05 Oct 2017 03:59:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 14793 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: confirmed Original-Received: via spool by 14793-submit@debbugs.gnu.org id=B14793.1507175937486 (code B ref 14793); Thu, 05 Oct 2017 03:59:02 +0000 Original-Received: (at 14793) by debbugs.gnu.org; 5 Oct 2017 03:58:57 +0000 Original-Received: from localhost ([127.0.0.1]:49553 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dzxJI-00007m-Hb for submit@debbugs.gnu.org; Wed, 04 Oct 2017 23:58:56 -0400 Original-Received: from mail-it0-f51.google.com ([209.85.214.51]:51692) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dzxJG-00007U-9D for 14793@debbugs.gnu.org; Wed, 04 Oct 2017 23:58:54 -0400 Original-Received: by mail-it0-f51.google.com with SMTP id w1so8841294itd.0 for <14793@debbugs.gnu.org>; Wed, 04 Oct 2017 20:58:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:message-id:user-agent :mime-version; bh=7JPkuS7Sx34cEsrE3AliOaECQacCZT3/xcSEAS2ITB8=; b=s/27nzGFFi6af7EvkuwGeozjk9nmDIIkJlNhzpjj+24CWxiRupH1EHBi+OcjQshtOf G5owkT+KSgevpN8AV7AMCW5+Q60WO47KQ77yIy/oy8+SRoNOUgZModxIGdyLoG9rxHQh tra1sr7MgoRS7eX78Q0LT6Fnuz7lRy7rpeinxVnOjptkkQeg15Q3HO6zLcllNFkU2wdW clqI36KbjeXV3UL6DoRQJ3PmkU4S/vqXOl11OAnkUNJYiU/vDwVF6MfLr5rL/gBWmt0I X/IY+mg2xXucYKUPFdLmpFYAp52WN/IKDA+KReQQLdH0oq4A7GhpiADmKTmkKn9jtBcW 4ihA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:message-id :user-agent:mime-version; bh=7JPkuS7Sx34cEsrE3AliOaECQacCZT3/xcSEAS2ITB8=; b=r+YgrIyuq/pVY3xhDbAaL367NZxi/AEl6wcUfpyR6kyLwHGkX2TAhUZHOedel8HxgW yDOPFQ/fDW90UtON8yvAFi9ndgq/PW1m/LH9f7AyqdYoNCuybrTZg365H0hvca4fWGmH IndCc39K1ZMkc4FCuEdsCQY7gjL6H0OcAh2UJO6QlfcW8EcWTyphYKYK4673uQUlKhV9 85a89dvVrZHpCPi0v0HAQSg++6C2/w17O5guLLefXS2+558uNmGliPPftrX517WNLmEC rigp+HGbN95gGlxBo9dfHS5Ie55vH1k+g7PbMAj8L+ztypQ1mLaDevHchSrSvqi3wHGn AIzQ== X-Gm-Message-State: AHPjjUjWei3osZeS9QCecQVtpIBZgi4IsPntOyv5RjMD4gXTNL7pWK5O DbhIPyiUSOwBEZ0JWSSZt6c= X-Google-Smtp-Source: AOwi7QCIJpNg/Hd4N+O2fCNiqojLDmwTYgNH6PD8rF7thQ8LiOu+FR9VJ9mgPDqeviY8J1E5IH7HgQ== X-Received: by 10.36.238.6 with SMTP id b6mr32042071iti.70.1507175928657; Wed, 04 Oct 2017 20:58:48 -0700 (PDT) Original-Received: from lylat (S010664777d9cebe3.ss.shawcable.net. [70.64.85.59]) by smtp.gmail.com with ESMTPSA id h81sm616767itb.18.2017.10.04.20.58.46 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 04 Oct 2017 20:58:47 -0700 (PDT) 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:137933 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Eli Zaretskii writes: >> From: Alex >> Cc: 14793@debbugs.gnu.org, npostavs@users.sourceforge.net, regularcloc= kwork@gmail.com >> Date: Mon, 02 Oct 2017 21:59:37 -0600 >>=20 >> > I just asked that question because my reading of the code is that this >> > is not supported. Maybe I'm misreading: keyboard.c:read_char is not >> > for the faint at heart. >>=20 >> Yeah, I'm having trouble going through it. Is there a way to make it >> supported, though? For example, what about catching the error around >> read_char_x_menu_prompt (keyboard.c:L2683) and not exiting if an error >> was thrown? > > That's hardly a clean solution. A clean solution would avoid calling > Fx_popup_menu when it detects the situation we are talking about. Right, I just figured it was the easiest way to check if the rest of the code supported prefix mouse clicks, but maybe it isn't for C. In any case, I have a possible solution below. >> >> Also, "(emacs) Mouse Buttons" states that "You can put more than one >> >> mouse button in a key sequence, but it isn=E2=80=99t usual to do so.". >> >>=20 >> >> How would one do this if a mouse click can't be a prefix key? >> > >> > By making a menu, I presume. >>=20 >> Do you mean those mentioned in "(emacs) Menu Mouse Clicks"? Does >> clicking in those menus count as key sequences? > > Yes, of course. You can see that with "C-h l", for example. Also, > every non-leaf menu item is a keymap. Ah, I see it now. It seems that it depends on the menu (the binding for C-down-mouse-1 isn't a keymap, but C-down-mouse-2's is, which is important for below). Anyway, I tried out the following diff, which is based on the condition at xmenu.c:L1460. The problem is that it uses the global variable `menu_items_used', which is incremented during the execution of Fx_popup_menu (keymap_panes). So the diff uses the value of `menu_items_used' of the previously called menu. With the diff, you can see that pressing C-down-mouse-2 right after startup leads to an undefined key message instead of opening a menu; after pressing C-down-mouse-1, though, pressing C-down-mouse-2 opens its menu properly. --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=mouse.diff Content-Description: simple diff diff --git a/src/keyboard.c b/src/keyboard.c index e8701b8870..5f92807087 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -2678,7 +2678,8 @@ read_char (int commandflag, Lisp_Object map, && !EQ (XCAR (prev_event), Qmenu_bar) && !EQ (XCAR (prev_event), Qtool_bar) /* Don't bring up a menu if we already have another event. */ - && !CONSP (Vunread_command_events)) + && !CONSP (Vunread_command_events) + && menu_items_used > MENU_ITEMS_PANE_LENGTH) { c = read_char_x_menu_prompt (map, prev_event, used_mouse_menu); -- 2.14.2 --=-=-= Content-Type: text/plain I've attached a patch that seems to work for single clicks. I had to move Fx_popup_menu's implementation outside of DEFUN so I could use used_mouse_menu in it. What do you think? --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-Allow-mouse-clicks-to-be-prefix-keys-Bug-14793.patch Content-Description: mouse prefix >From d001740b0f59cdc2165d62e05c7f2cb5ff8ab6b4 Mon Sep 17 00:00:00 2001 From: Alexander Gramiak Date: Tue, 3 Oct 2017 17:11:08 -0600 Subject: [PATCH] Allow mouse clicks to be prefix keys (Bug#14793) * src/keyboard.c (read_char): Check used_mouse_menu after calling read_char_x_menu_prompt. (read_char_x_menu_prompt): Pass used_mouse_menu to x_popup_menu and return nil if it wasn't set to true. * src/menu.c (Fx_popup_menu): Extract into a new function. (x_popup_menu): New function. Don't error if used_mouse_menu is null, and set used_mouse_menu if there was no error. * src/keyboard.h: Declare x_popup_menu. --- src/keyboard.c | 21 +++++++++++++-------- src/keyboard.h | 3 +++ src/menu.c | 11 ++++++++++- 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/src/keyboard.c b/src/keyboard.c index e8701b8870..5912f89115 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -2682,11 +2682,15 @@ read_char (int commandflag, Lisp_Object map, { c = read_char_x_menu_prompt (map, prev_event, used_mouse_menu); - /* Now that we have read an event, Emacs is not idle. */ - if (!end_time) - timer_stop_idle (); + /* Only exit if a mouse menu was actually used successfully. */ + if (*used_mouse_menu) + { + /* Now that we have read an event, Emacs is not idle. */ + if (!end_time) + timer_stop_idle (); - goto exit; + goto exit; + } } /* Maybe autosave and/or garbage collect due to idleness. */ @@ -8457,8 +8461,11 @@ read_char_x_menu_prompt (Lisp_Object map, /* Display the menu and get the selection. */ Lisp_Object value; - value = Fx_popup_menu (prev_event, get_keymap (map, 0, 1)); - if (CONSP (value)) + value = x_popup_menu (prev_event, get_keymap (map, 0, 1), used_mouse_menu); + + if (!*used_mouse_menu) + value = Qnil; + else if (CONSP (value)) { Lisp_Object tem; @@ -8489,8 +8496,6 @@ read_char_x_menu_prompt (Lisp_Object map, } else if (NILP (value)) value = Qt; - if (used_mouse_menu) - *used_mouse_menu = true; return value; } return Qnil ; diff --git a/src/keyboard.h b/src/keyboard.h index a2a5f8f21d..954485c78b 100644 --- a/src/keyboard.h +++ b/src/keyboard.h @@ -360,6 +360,9 @@ enum menu_item_idx extern void unuse_menu_items (void); +extern Lisp_Object +x_popup_menu (Lisp_Object position, Lisp_Object menu, bool *used_mouse_menu); + /* This is how to deal with multibyte text if HAVE_MULTILINGUAL_MENU isn't defined. The use of HAVE_MULTILINGUAL_MENU could probably be confined to an extended version of this with sections of code below diff --git a/src/menu.c b/src/menu.c index d569b4b29b..257c67f6a4 100644 --- a/src/menu.c +++ b/src/menu.c @@ -1157,6 +1157,12 @@ keyboard input, then this normally results in a quit and event (indicating that the user invoked the menu with the mouse) then no quit occurs and `x-popup-menu' returns nil. */) (Lisp_Object position, Lisp_Object menu) +{ + return x_popup_menu (position, menu, NULL); +} + +Lisp_Object +x_popup_menu (Lisp_Object position, Lisp_Object menu, bool *used_mouse_menu) { Lisp_Object keymap, tem, tem2; int xpos = 0, ypos = 0; @@ -1439,7 +1445,10 @@ no quit occurs and `x-popup-menu' returns nil. */) FRAME_DISPLAY_INFO (f)->grabbed = 0; #endif - if (error_name) error ("%s", error_name); + if (error_name && !used_mouse_menu) + error ("%s", error_name); + else if (!error_name && used_mouse_menu) + *used_mouse_menu = true; return selection; } -- 2.14.2 --=-=-= Content-Type: text/plain There are a couple issues that I can see though, regarding double/triple clicks. First, evaluate the following: (define-prefix-command 'test) (global-set-key [mouse-3] #'test) (global-set-key [mouse-3 mouse-1] #'forward-word) 1. Triple clicking mouse-3 results in a popup menu that seems like it shouldn't appear, but this is also case when triple clicking C-mouse-3 even without my patch. I'm not sure what it's doing there. 2. Double clicking mouse-3 usually results in a mouse-3 double-mouse-3 sequence, instead of double-mouse-3. You can tell by also evaluating: (global-set-key [mouse-3 double-mouse-3] #'forward-line) (global-set-key [double-mouse-3] #'goto-line) With the above key set, double clicking mouse-3 calls `forward-line', and oddly enough _triple_ clicking mouse-3 calls `goto-line'. Here's what `describe-key' has to say about triple clicking mouse-3: (translated from ) runs the command goto-line I have no idea why that translation exists. Do you have any ideas on how to solve these issues (especially getting double click to issue double-mouse-#)? If not, maybe I'll fiddle around with read_key_sequence later. --=-=-=--