[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: save-window-excursion and window-configuration-change-hook interacti

From: martin rudalics
Subject: Re: save-window-excursion and window-configuration-change-hook interaction
Date: Tue, 18 May 2010 14:06:56 +0200
User-agent: Thunderbird (Windows/20090302)

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

reply via email to

[Prev in Thread] Current Thread [Next in Thread]