Is there a robust way to automatically make this *interpretation*
buffer current after it pops up, instead of having to type C-xo (other-window
)?
There are several ways of varying degree of hackiness to achieve this, but here is my preferred method.
The *interpretation*
buffer is created by the command executable-interpret
, bound to C-cC-x by default in sh-mode
, whose docstring reads:
executable-interpret is an interactive autoloaded compiled Lisp
function in ‘executable.el’.
(executable-interpret COMMAND)
Run script with user-specified args, and collect output in a buffer.
While script runs asynchronously, you can use the C-x `
command to find the next error. The buffer is also in ‘comint-mode’ and
‘compilation-shell-minor-mode’, so that you can answer any prompts.
The key clue here is compilation-shell-minor-mode
, which suggests we can hook into settings of the compile
library. One such relevant setting is compilation-finish-functions
:
compilation-finish-functions is a variable defined in ‘compile.el’.
Its value is nil
This variable may be risky if used as a file-local variable.
Documentation:
Functions to call when a compilation process finishes.
Each function is called with two arguments: the compilation buffer,
and a string describing how the process finished.
This allows us to register a custom function which selects the *interpretation*
buffer when the script is done jogging:
(defun my-pop-to-interpretation-buffer (buffer _why)
"Pop to `*interpretation*' BUFFER.
Intended as an element of `compilation-finish-functions'."
(when (string-match-p "\\`\\*interpretation\\*\\'" (buffer-name buffer))
(pop-to-buffer buffer)))
(add-to-list 'compilation-finish-functions #'my-pop-to-interpretation-buffer)
You can, of course, modify my-pop-to-interpretation-buffer
to your heart's content.