unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#2932: call-interactively wrongly calls mouse-leave-buffer-hook
@ 2009-04-08 21:15 Alan Mackenzie
  2011-07-10  0:00 ` Juanma Barranquero
  2021-07-19 14:42 ` Lars Ingebrigtsen
  0 siblings, 2 replies; 4+ messages in thread
From: Alan Mackenzie @ 2009-04-08 21:15 UTC (permalink / raw)
  To: bug-gnu-emacs

Hi, Emacs!

In call-interactively (callint.c L~449), whilst processing `@' ("switch
to the window the mouse was clicked in") in an interactive string, the
code runs the hook `mouse-leave-buffer-hook'.

The code HASN'T CHECKED that this new window is different from the
current window, and even if it is, whether the new window is displaying
a different buffer.  Hence the hook is wrongly invoked when the mouse is
clicked in the current window.

Here is a fragment of the guilty code:

      else if (*string == '@')
        {
          Lisp_Object event, tem;

          event = (next_event < key_count
                   ? AREF (keys, next_event)
                   : Qnil);
          if (EVENT_HAS_PARAMETERS (event)
              && (tem = XCDR (event), CONSP (tem))
              && (tem = XCAR (tem), CONSP (tem))
              && (tem = XCAR (tem), WINDOWP (tem)))
            {                    /* <======================= Check for different window missing here. */
              if (MINI_WINDOW_P (XWINDOW (tem))
                  && ! (minibuf_level > 0 && EQ (tem, minibuf_window)))
                error ("Attempt to select inactive minibuffer window");

              /* If the current buffer wants to clean up, let it.  */
              if (!NILP (Vmouse_leave_buffer_hook))
                call1 (Vrun_hooks, Qmouse_leave_buffer_hook);   /* <============== Possibly spurious call */

              Fselect_window (tem, Qnil);
            }
          string++;
        }

######################################################

Similarly, DEFUN ("handle-switch-frame" (in frame.c L922) calls the same
hook without checking the new buffer is different.  This is _probably_
also a bug (I haven't checked whether handle-switch-frame's callers
perform this check).

######################################################

Similarly, there are several runnings of this hook from Lisp code, that
don't check the new buffer is different from the old. 


This probably isn't important enough to delay a release.


-- 
Alan Mackenzie (Nuremberg, Germany).







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

* bug#2932: call-interactively wrongly calls mouse-leave-buffer-hook
  2009-04-08 21:15 bug#2932: call-interactively wrongly calls mouse-leave-buffer-hook Alan Mackenzie
@ 2011-07-10  0:00 ` Juanma Barranquero
  2011-09-18  8:17   ` Lars Magne Ingebrigtsen
  2021-07-19 14:42 ` Lars Ingebrigtsen
  1 sibling, 1 reply; 4+ messages in thread
From: Juanma Barranquero @ 2011-07-10  0:00 UTC (permalink / raw)
  To: Alan Mackenzie; +Cc: 2932

On Wed, Apr 8, 2009 at 23:15, Alan Mackenzie <acm@muc.de> wrote:

> In call-interactively (callint.c L~449), whilst processing `@' ("switch
> to the window the mouse was clicked in") in an interactive string, the
> code runs the hook `mouse-leave-buffer-hook'.
>
> The code HASN'T CHECKED that this new window is different from the
> current window, and even if it is, whether the new window is displaying
> a different buffer.  Hence the hook is wrongly invoked when the mouse is
> clicked in the current window.

The trunk still behaves as you describe.

As a first pass, we should fix the docstring of
`mouse-leave-buffer-hook'. It seems wrong for the docstring of a hook
with "leave-buffer" in its name to talk about windows and not say a
word about buffers...

    Juanma





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

* bug#2932: call-interactively wrongly calls mouse-leave-buffer-hook
  2011-07-10  0:00 ` Juanma Barranquero
@ 2011-09-18  8:17   ` Lars Magne Ingebrigtsen
  0 siblings, 0 replies; 4+ messages in thread
From: Lars Magne Ingebrigtsen @ 2011-09-18  8:17 UTC (permalink / raw)
  To: Juanma Barranquero; +Cc: Alan Mackenzie, 2932

Juanma Barranquero <lekktu@gmail.com> writes:

> The trunk still behaves as you describe.
>
> As a first pass, we should fix the docstring of
> `mouse-leave-buffer-hook'. It seems wrong for the docstring of a hook
> with "leave-buffer" in its name to talk about windows and not say a
> word about buffers...

Yes, that's a somewhat confusing doc string.

-- 
(domestic pets only, the antidote for overdose, milk.)
  bloggy blog http://lars.ingebrigtsen.no/





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

* bug#2932: call-interactively wrongly calls mouse-leave-buffer-hook
  2009-04-08 21:15 bug#2932: call-interactively wrongly calls mouse-leave-buffer-hook Alan Mackenzie
  2011-07-10  0:00 ` Juanma Barranquero
@ 2021-07-19 14:42 ` Lars Ingebrigtsen
  1 sibling, 0 replies; 4+ messages in thread
From: Lars Ingebrigtsen @ 2021-07-19 14:42 UTC (permalink / raw)
  To: Alan Mackenzie; +Cc: 2932

Alan Mackenzie <acm@muc.de> writes:

> In call-interactively (callint.c L~449), whilst processing `@' ("switch
> to the window the mouse was clicked in") in an interactive string, the
> code runs the hook `mouse-leave-buffer-hook'.
>
> The code HASN'T CHECKED that this new window is different from the
> current window, and even if it is, whether the new window is displaying
> a different buffer.  Hence the hook is wrongly invoked when the mouse is
> clicked in the current window.

Test code:

(setq mouse-leave-buffer-hook '((lambda ()
				  (message "Leaving %s" (current-buffer)))))

And then mouse-click.  And, indeed, it's run even when not changing a
window.

... Uhm, OK, that was a slightly different thing.  Try this:

(setq mouse-leave-buffer-hook '((lambda ()
				  (message "Leaving %s" (selected-window)))))

The hook is run three times in the selected window, and then it's run
once in the new buffer:

Leaving #<window 110 on sel.el> [3 times]
Leaving #<window 114 on *Messages*>

So the problem isn't just in call-interactively -- the hook is called a
lot -- on any mouse click, and whether we switch windows or not, and
both before and after the switch.

I'm guessing we can't change this at this point, so I'll just adjust the
doc string to reflect the current state of affairs instead.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





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

end of thread, other threads:[~2021-07-19 14:42 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-04-08 21:15 bug#2932: call-interactively wrongly calls mouse-leave-buffer-hook Alan Mackenzie
2011-07-10  0:00 ` Juanma Barranquero
2011-09-18  8:17   ` Lars Magne Ingebrigtsen
2021-07-19 14:42 ` Lars Ingebrigtsen

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