I am a strong believer in not polluting hooks, especially something so fundamental like
special-mode that is used by countless other major-modes. As such, I would recommend not using the
special-mode-hook. The following example adds an entry to the
display-buffer-alist that will trigger a custom
display-buffer-... function when a matching regexp exists.
[The internal function
window--display-buffer has five (5) arguments in Emacs 25 and Emacs 26, but only four (4) arguments in Emacs 27. This example should work on all of the aforementioned versions of Emacs.]
(defun display-buffer-fn (buffer-or-name alist direction &optional size pixelwise)
"BUFFER: The buffer that will be displayed.
ALIST: See the doc-string of `display-buffer' for more information.
DIRECTION: Must use one of these symbols: 'left 'right 'below 'above
SIZE: See the doc-string for `split-window'.
PIXELWISE: See the doc-string for `split-window'.
There are three possibilities:
- (1) If a window on the frame already displays the target buffer,
then just reuse the same window.
- (2) If there is already a window in the specified direction in relation
to the selected window, then display the target buffer in said window.
- (3) If there is no window in the specified direction, then create one
in that direction and display the target buffer in said window."
(if (bufferp buffer-or-name)
((get-buffer-window buffer (selected-frame)))
(split-window (selected-window) size direction pixelwise)))))
(window--display-buffer buffer window 'window alist)
(defun display-buffer-right--select-window (buffer alist)
(select-window (display-buffer-fn buffer nil 'right)))
(add-to-list 'display-buffer-alist '("^[*]warnings[*]$" . (display-buffer-right--select-window)))
TEST: After evaluating the above code, test it by evaluating the following snippet:
(display-warning :warning "hello-world")