* save-window-excursion and window-configuration-change-hook interaction
@ 2010-05-17 19:55 Jay Belanger
2010-05-18 12:06 ` martin rudalics
0 siblings, 1 reply; 4+ messages in thread
From: Jay Belanger @ 2010-05-17 19:55 UTC (permalink / raw
To: emacs-devel; +Cc: jay.p.belanger
I'm wondering if the following behavior is expected.
Suppose I have two windows; say the top window is active
and the bottom window (window WIN, buffer BUF) has
===
a
b
c
===
in it, with point before the "a".
If I run the command aaa:
(defun aaa ()
(interactive)
(with-current-buffer BUF
(save-window-excursion
(select-window WIN)
(search-forward "b"))
(set-window-point WIN (point))))
then the point in the bottom window moves to after the "b", which is
what I would expect. However, if the bottom window (with point again
before the "a") has a non-nil window-configuration-change-hook,
then running aaa does not move the point in the bottom window. I would
expected the point in the bottom window to move as before.
(To add the hook, with the bottom window active I did
M-: (add-hook 'window-configuration-change-hook (lambda () ()) nil t)
)
Thanks,
Jay
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: save-window-excursion and window-configuration-change-hook interaction
2010-05-17 19:55 save-window-excursion and window-configuration-change-hook interaction Jay Belanger
@ 2010-05-18 12:06 ` martin rudalics
2010-05-18 18:59 ` Jay Belanger
0 siblings, 1 reply; 4+ messages in thread
From: martin rudalics @ 2010-05-18 12:06 UTC (permalink / raw
To: jay.p.belanger; +Cc: emacs-devel
> Suppose I have two windows; say the top window is active
> and the bottom window (window WIN, buffer BUF) has
> ===
> a
> b
> c
> ===
> in it, with point before the "a".
> If I run the command aaa:
>
> (defun aaa ()
> (interactive)
> (with-current-buffer BUF
> (save-window-excursion
> (select-window WIN)
> (search-forward "b"))
> (set-window-point WIN (point))))
>
> then the point in the bottom window moves to after the "b", which is
> what I would expect. However, if the bottom window (with point again
> before the "a") has a non-nil window-configuration-change-hook,
> then running aaa does not move the point in the bottom window. I would
> expected the point in the bottom window to move as before.
> (To add the hook, with the bottom window active I did
> M-: (add-hook 'window-configuration-change-hook (lambda () ()) nil t)
> )
IIUC this happens for the following reason:
(1) When you quit the excursion, `set-window-configuration' sets
`window-point' of WIN to the value it had before since WIN is _not_
the selected window.
(2) When you now run the buffer local `window-configuration-change-hook'
it selects WIN to run the hook with WIN selected and BUF current.
Selecting WIN sets the `point' of BUF to the `window-point' recorded
for WIN which, however, was reset in step (1) to the value it had
before entering the excursion.
So the only reasonable solution in your case is to save the the position
after the search and do a `set-window-point' with that saved position.
martin, who never liked the idea of running
`window-configuration-change-hook' locally.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: save-window-excursion and window-configuration-change-hook interaction
2010-05-18 12:06 ` martin rudalics
@ 2010-05-18 18:59 ` Jay Belanger
2010-05-20 9:44 ` martin rudalics
0 siblings, 1 reply; 4+ messages in thread
From: Jay Belanger @ 2010-05-18 18:59 UTC (permalink / raw
To: martin rudalics; +Cc: jay.p.belanger, emacs-devel
martin rudalics <rudalics@gmx.at> writes:
...
> IIUC this happens for the following reason:
...
> So the only reasonable solution in your case is to save the the position
> after the search and do a `set-window-point' with that saved position.
Thanks for the information.
> martin, who never liked the idea of running
> `window-configuration-change-hook' locally.
I assure you, right now I like it less than you do.
Jay
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: save-window-excursion and window-configuration-change-hook interaction
2010-05-18 18:59 ` Jay Belanger
@ 2010-05-20 9:44 ` martin rudalics
0 siblings, 0 replies; 4+ messages in thread
From: martin rudalics @ 2010-05-20 9:44 UTC (permalink / raw
To: jay.p.belanger; +Cc: emacs-devel
> I assure you, right now I like it less than you do.
It's next to impossible to get this right. If we don't move `point' to
the window's point we get non-standard semantics for the code run in the
hook. That is, we'd violate a basic invariant that with a window
selected and its buffer current, the window's point and the buffer's
point refer to the same position.
If we do move `point' we have two choices: If we restore `point' to its
previous value (using some sort of `save-excursion'), any `point'
changing operations run in the hook are lost and any calculations based
on `point' run in the hook are moot. If we don't restore `point' to its
previous value we get the current behavior.
martin
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2010-05-20 9:44 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-05-17 19:55 save-window-excursion and window-configuration-change-hook interaction Jay Belanger
2010-05-18 12:06 ` martin rudalics
2010-05-18 18:59 ` Jay Belanger
2010-05-20 9:44 ` martin rudalics
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.