From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: "Stefan Monnier" Newsgroups: gmane.emacs.devel Subject: Weird mishandling of bindings with mouse-autoselect-window Date: Fri, 11 Apr 2003 19:45:51 -0400 Sender: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Message-ID: <200304112345.h3BNjpc4012245@rum.cs.yale.edu> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: main.gmane.org 1050105206 6900 80.91.224.249 (11 Apr 2003 23:53:26 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Fri, 11 Apr 2003 23:53:26 +0000 (UTC) Original-X-From: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Sat Apr 12 01:53:24 2003 Return-path: Original-Received: from quimby.gnus.org ([80.91.224.244]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1948Ki-0001n7-00 for ; Sat, 12 Apr 2003 01:53:24 +0200 Original-Received: from monty-python.gnu.org ([199.232.76.173]) by quimby.gnus.org with esmtp (Exim 3.12 #1 (Debian)) id 1948QO-00023B-00 for ; Sat, 12 Apr 2003 01:59:16 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.10.13) id 1948FJ-00047S-08 for emacs-devel@quimby.gnus.org; Fri, 11 Apr 2003 19:47:49 -0400 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.10.13) id 1948Ec-0003qY-00 for emacs-devel@gnu.org; Fri, 11 Apr 2003 19:47:06 -0400 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.10.13) id 1948EJ-0003T7-00 for emacs-devel@gnu.org; Fri, 11 Apr 2003 19:46:49 -0400 Original-Received: from rum.cs.yale.edu ([128.36.229.169]) by monty-python.gnu.org with esmtp (Exim 4.10.13) id 1948DQ-0002jt-00 for emacs-devel@gnu.org; Fri, 11 Apr 2003 19:45:52 -0400 Original-Received: from rum.cs.yale.edu (localhost [127.0.0.1]) by rum.cs.yale.edu (8.12.8/8.12.8) with ESMTP id h3BNjqx6012247 for ; Fri, 11 Apr 2003 19:45:52 -0400 Original-Received: (from monnier@localhost) by rum.cs.yale.edu (8.12.8/8.12.8/Submit) id h3BNjpc4012245; Fri, 11 Apr 2003 19:45:51 -0400 X-Mailer: exmh version 2.4 06/23/2000 with nmh-1.0.4 Original-To: emacs-devel@gnu.org X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1b5 Precedence: list List-Id: Emacs development discussions. List-Help: List-Post: List-Subscribe: , List-Archive: List-Unsubscribe: , Errors-To: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Xref: main.gmane.org gmane.emacs.devel:13175 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:13175 I've been using mouse-autoselect-window for a while and has been bothered by a bug in it that makes it sometimes look up keys in the wrong buffer. More specifically, if I have buffer-A selected in window-A and I move the mouse to window-B showing buffer-B and then hit a key, the command will be executed in B but the key lookup is done using A's keymaps. Someone else already reported this problem. I think the patch below fixes the problem in the case where window-A and window-B are not on the same frame, but it still doesn't help when they are on the same frame. What it does is create a switch-frame event before the select-window event (in the case when the new window is on a different frame), such that select-window events only ever really switch between windows on the same frame. I think the problem is that the select-window event is bound to handle-select-window in special-event-map (whereas switch-frame is bound to handle-switch-frame in global-map). The use of special-event-map means that the event is processed directly in read_char and is thus never even seen by read_key_sequence. I.e. what happens is: - read_key_sequence calls read_char in buffer-A. Note: it has already collected the active keymaps. - you move the mouse - a select-window event is generated and handled directly in read_char - you hit a key - it is returned to read_key_sequence which has no clue that the current buffer has just been changed, so it uses the already collected active keymaps which correspond to buffer-A even though we've already switched to buffer-B. I think we need to either make GOBBLE_FIRST_EVENT work, or bind the select-window event in the global-map (rather than in the special-event-map), or both. ...[time passes]... Alright I think I got it. It's now handled very much like switch-frame. Please test. Stefan PS: The patch below is only of historical relevance. --- keyboard.c 24 Mar 2003 19:59:08 -0000 1.732 +++ keyboard.c 11 Apr 2003 21:42:37 -0000 @@ -4002,14 +4027,6 @@ internal_last_event_frame = frame; kbd_fetch_ptr = event + 1; } - else if (event->kind == SELECT_WINDOW_EVENT) - { - /* Make an event (select-window (WINDOW)). */ - obj = Fcons (event->frame_or_window, Qnil); - obj = Fcons (Qselect_window, Fcons (obj, Qnil)); - - kbd_fetch_ptr = event + 1; - } else { /* If this event is on a different frame, return a switch-frame this @@ -4037,6 +4054,13 @@ if (NILP (obj)) { + if (event->kind == SELECT_WINDOW_EVENT) + { + /* Make an event (select-window (WINDOW)). */ + obj = Fcons (event->frame_or_window, Qnil); + obj = Fcons (Qselect_window, Fcons (obj, Qnil)); + } + else obj = make_lispy_event (event); #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined(MAC_OS) \