all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* run_window_configuration_change_hook
@ 2011-04-18 13:15 martin rudalics
  2011-04-18 13:21 ` run_window_configuration_change_hook martin rudalics
  2011-04-19 12:43 ` run_window_configuration_change_hook martin rudalics
  0 siblings, 2 replies; 4+ messages in thread
From: martin rudalics @ 2011-04-18 13:15 UTC (permalink / raw
  To: emacs-devel

With current trunk and emacs -Q evaluate the following code:

(let* ((old-window (selected-window))
        (new-frame (make-frame))
        (new-window (frame-root-window new-frame)))
   (set-window-buffer new-window (other-buffer))
   (select-window old-window)
   (let ((current-buffer (window-buffer new-window)))
     (split-window new-window)
     (cons current-buffer (current-buffer))))

 From the return value I can deduce that `split-window' changes the
current buffer.  This would be incorrect.  IIUC the behavior is due to
the fact that run_window_configuration_change_hook

   if (SELECTED_FRAME () != f)
     {
       record_unwind_protect (select_frame_norecord, Fselected_frame ());
       select_frame_norecord (frame);
     }

   /* Use the right buffer.  Matters when running the local hooks.  */
   if (current_buffer != XBUFFER (Fwindow_buffer (Qnil)))
     {
       record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
       Fset_buffer (Fwindow_buffer (Qnil));
     }

   ...

   unbind_to (count, Qnil);

first restores the current buffer and afterwards the selected frame
which can make another buffer current.  Inverting the order of the two
clauses resolves the problem for me.

martin



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

* Re: run_window_configuration_change_hook
  2011-04-18 13:15 run_window_configuration_change_hook martin rudalics
@ 2011-04-18 13:21 ` martin rudalics
  2011-04-19 12:43 ` run_window_configuration_change_hook martin rudalics
  1 sibling, 0 replies; 4+ messages in thread
From: martin rudalics @ 2011-04-18 13:21 UTC (permalink / raw
  To: emacs-devel

Please disregard this post.  My scenario was wrong.

martin




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

* Re: run_window_configuration_change_hook
  2011-04-18 13:15 run_window_configuration_change_hook martin rudalics
  2011-04-18 13:21 ` run_window_configuration_change_hook martin rudalics
@ 2011-04-19 12:43 ` martin rudalics
  2011-04-19 13:45   ` run_window_configuration_change_hook Stefan Monnier
  1 sibling, 1 reply; 4+ messages in thread
From: martin rudalics @ 2011-04-19 12:43 UTC (permalink / raw
  To: emacs-devel

A hopefully correct scenario for reproducing the bug goes as follows:
With the current trunk do emacs -Q and evaluate the following form:

(let ((frame (selected-frame))
       (window (frame-root-window (make-frame))))
   (set-window-buffer window "*Messages*")
   (split-window window)
   (select-frame frame)
   (with-current-buffer "*Messages*"
     (adjust-window-trailing-edge window 1 nil)
     (message "%s" (current-buffer))))

The call to `adjust-window-trailing-edge' changes the current buffer
from *Messages* to *scratch* here.

As stated before the reason is that run_window_configuration_change_hook
has this code

   if (SELECTED_FRAME () != f)
     {
       record_unwind_protect (select_frame_norecord, Fselected_frame ());
       Fselect_frame (frame, Qt);
     }

   /* Use the right buffer.  Matters when running the local hooks.  */
   if (current_buffer != XBUFFER (Fwindow_buffer (Qnil)))
     {
       record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
       Fset_buffer (Fwindow_buffer (Qnil));
     }

which implies to first restore the current buffer and afterwards the
selected frame which can make another buffer current.  Inverting the
order of the two clauses resolves the problem for me.  Since I hardly
ever use more than one frame, I'm not 100% sure whether reverting the
clauses can break existing code.  Comments welcome.

martin

Note: The bug cannot be reproduced by using `split-window' alone as I
tried earlier since that wraps run_window_configuration_change_hook in
set_window_buffer which takes some care to restore the current buffer.



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

* Re: run_window_configuration_change_hook
  2011-04-19 12:43 ` run_window_configuration_change_hook martin rudalics
@ 2011-04-19 13:45   ` Stefan Monnier
  0 siblings, 0 replies; 4+ messages in thread
From: Stefan Monnier @ 2011-04-19 13:45 UTC (permalink / raw
  To: martin rudalics; +Cc: emacs-devel

> As stated before the reason is that run_window_configuration_change_hook
> has this code

>   if (SELECTED_FRAME () != f)
>     {
>       record_unwind_protect (select_frame_norecord, Fselected_frame ());
>       Fselect_frame (frame, Qt);
>     }

>   /* Use the right buffer.  Matters when running the local hooks.  */
>   if (current_buffer != XBUFFER (Fwindow_buffer (Qnil)))
>     {
>       record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
>       Fset_buffer (Fwindow_buffer (Qnil));
>     }

> which implies to first restore the current buffer and afterwards the
> selected frame which can make another buffer current.

Indeed, that sounds wrong.

> Inverting the order of the two clauses resolves the problem for me.
> Since I hardly ever use more than one frame, I'm not 100% sure whether
> reverting the clauses can break existing code.  Comments welcome.

I think swapping the two is the right thing to do, yes.


        Stefan



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

end of thread, other threads:[~2011-04-19 13:45 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-04-18 13:15 run_window_configuration_change_hook martin rudalics
2011-04-18 13:21 ` run_window_configuration_change_hook martin rudalics
2011-04-19 12:43 ` run_window_configuration_change_hook martin rudalics
2011-04-19 13:45   ` run_window_configuration_change_hook Stefan Monnier

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.