[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: display-buffer vs. current-buffer vs. post-command-hook
From: |
martin rudalics |
Subject: |
Re: display-buffer vs. current-buffer vs. post-command-hook |
Date: |
Tue, 04 Oct 2016 16:52:02 +0200 |
> The following snippet (saved in x.el), when loaded in 25.1.1 using
> [google-emacs -Q -l x.el], generates the message:
> *scratch* *scratch* *Help*
> demonstrating that (current-buffer) has a stale value after describe-key
> returns (I expect post to match the [run-at-time 0] value, not the pre
> value).
>
> (progn
> (setq display-buffer-alist '(("." (lambda (buffer alist)
> (switch-to-buffer buffer)))))
The preferred way to use the selected window for displaying a buffer is
the action function ‘display-buffer-same-window’.
> (setq pre (current-buffer))
> (describe-key (kbd "SPC"))
> (setq post (current-buffer))
> (run-at-time 0 nil (lambda () (message "%s %s %s" pre post
> (current-buffer)))))
‘describe-key’ is based on ‘with-temp-buffer-window’ which tries very
hard to restore the current buffer after doing its work. So what you
see here is not a stale value but one that has been correctly preserved.
Please tell us what you want to accomplish. Then we might be able to
tell you how to do that.
martin