I am trying to add a hook which calls shr-render-buffer
after loading a file in html-mode
. This is what I came up with:
(add-hook 'html-mode-hook (lambda () (call-interactively #'shr-render-buffer)))
This works, except not quite as expected.
Calling M-x shr-render-buffer
in an html-mode
buffer splits the current frame vertically, and puts the rendered output in the bottom window with the html still visible in the top window. On the other hand, if I do find-file
and open an html file, my hook code splits the frame vertically, but buries the html buffer, so that I have the rendered buffer on the bottom, and whichever buffer I was visiting when I did find-file
at the top.
What is happening here? Seemingly, something with the timing is getting messed up from the way I am calling shr-render-buffer
, but I don't really know what/how.
(call-interactively #'she-render-buffer)
with a slight delay by usingrun-at-time
, e.g.,(run-at-time 0.1 nil (lambda () (call-interactively #'shr-render-buffer)))
, to simulate a manual invocation. – xuchunyang Jan 26 '16 at 5:35shr-render-buffer
, you'll see that it usespop-to-buffer
to show you a*html*
buffer. How exactly that happens depends on a number of unknowns as specified by the manydisplay-buffer
-related variables. – wasamasa Jan 26 '16 at 7:37shr-render-buffer
does when called interactively. However, I gather from @wasamasa 's comment that this is less straightforward than I thought. I will try @xuchunyang's solution to see if that helps. – elethan Jan 26 '16 at 12:58*html*
buffermy-shr-noselect-buf
-- without displaying it. Then, have your four (4) favorite functions on stand-by for just such an occasion. Decide which direction you want to display your buffer (left/right/up/down), and then create another function with just one line -- e.g.,my-html-display-buffer-left
which calls(my-display-buffer-left (my-shr-noselect-buf))
and and that to the hook. – lawlist Jan 26 '16 at 17:53