I have a key bound to some program which prepares a buffer, switches to it via
switch-to-buffer and afterwards calls some function which modifies the buffer (and can take a few seconds to execute).
When pressing the key, this modifying function is executed before the buffer is actually switched (noticeable by a considerable lag), although it appears after
Can somebody please explain why this is the case?
Here are full details, although I don't think these are relevant for my problem:
I'm using elfeed and have set
elfeed-entry-switch, which by default is just
(defun my-elfeed-entry-switch (buffer) (with-current-buffer buffer (switch-to-buffer buffer) (org-latex-preview)))
The computationally intensive function therefore is
org-latex-preview, which renders and displays inline latex code and, like I wrote, sometimes takes several seconds to complete.
When trying to switch to an entry which contains a lot of latex code, I have to wait for a second or so before the buffer becomes visible.
What I actually expect is that the buffer first becomes visible (with unrendered latex code) and then
org-latex-preview starts its work, which it does if called interactively.
UPDATE As suggested below, removing
with-current-buffer does not solve the problem, i.e.
(defun my-elfeed-entry-switch (buffer) (switch-to-buffer buffer) (org-latex-preview))
still does not show the buffer before
org-latex-preview has finished rendering.