Emacs version 25
I have a short piece of elisp to create a few buffers and split my frame into multiple windows that are displayed the way I like. This code creates a *compilation*
buffer and dedicates it using this code:
;; https://stackoverflow.com/questions/5151620/how-do-i-make-this-emacs-frame-keep-its-buffer-and-not-get-resized
;; Toggle window dedication
(defun toggle-window-dedicated ()
"Toggle whether the current active window is dedicated or not"
(interactive)
(message
(if (let (window (get-buffer-window (current-buffer)))
(set-window-dedicated-p window
(not (window-dedicated-p window))))
"Window '%s' is dedicated"
"Window '%s' is normal")
(current-buffer)))
(switch-to-buffer (get-buffer-create "*compilation*"))
(toggle-window-dedicated)
My issue is that when running a compilation, even if the compiler output goes to the correct buffer, the *compilation*
buffer doesn't scroll automatically to always display the most recent text.
My configuration is (setq compilation-scroll-output 'first-error)
The normal scrolling behavior seems to only be enabled when the *compilation*
buffer is created by the compile
command and not by hand. Even if I make the window with this buffer dedicated latter.
Is there a correct way to create the *compilation*
buffer without running the compile
command but keeping the compilation-scroll-output
configuration behavior?
EDIT: a more detailed procedure:
How to trigger the problem:
- put
mybuffer.el
andMakefile
in one directory (/tmp/emacs_problem
for example) - open file
mybuffer.el
- go to end of the
create-my-buffers
function and execute the code (C-x C-e) - execute the
create-my-buffers
function withM-x create-my-buffers
- execute
M-x compile RET RET
How to see the expected behavior:
- open file
mybuffer.el
- execute
M-x compile RET RET
The Makefile:
default:
ls -1 /bin
mybuffer.el:
(defun create-my-buffers ()
(interactive)
(delete-other-windows)
(setq total-window-size (window-width (frame-selected-window)))
(setq total-window-height (window-height (frame-selected-window)))
(split-window-vertically)
(other-window 1)
(switch-to-buffer (get-buffer-create "*compilation*"))
(setq second-window-height (window-height (frame-selected-window)))
(setq expected-window-height (* 0.10 total-window-height))
(setq expand-window-height (- expected-window-height second-window-height))
(enlarge-window (round expand-window-height))
(other-window 1)
)
The result with the "bad" behavior, the window with the compilation buffer has not scrolled to the bottom:
The result with the good behavior, the cursor is at the end of the content and the window has scrolled correctly:
The output for M-x describe-mode
after calling M-x compile
is:
Enabled minor modes: Auto-Composition Auto-Compression Auto-Encryption
Autopair-Global Column-Number Company Company-Quickhelp
Company-Quickhelp-Local Delete-Selection Display-Time Electric-Indent
Evil-Matchit File-Name-Shadow Font-Lock Global-Auto-Revert
Global-Company Global-Eldoc Global-Evil-Matchit Global-Font-Lock
Global-Git-Gutter Global-Linum Global-Undo-Tree Global-Visual-Line
Global-Whitespace Hl-Line Line-Number Mouse-Wheel Save-Place
Shell-Dirtrack Show-Paren Tooltip Transient-Mark Undo-Tree Visual-Line
(Information about these minor modes follows the major mode info.)
Compilation mode defined in ‘compile.el’:
Major mode for compilation log buffers.
To visit the source for a line-numbered error,
move point to the error message line and type RET.
To kill the compilation, type C-c C-k.
Runs ‘compilation-mode-hook’ with ‘run-mode-hooks’ (which see).
EDIT 2: It seems that the scrolling is done correctly if I launch M-x compile
from the window containing *compilation*
rather than from the window containing mybuffer.el
.
(compilation-mode)
just after theswitch-to-buffer
. Also, the compilation mode will be set automatically if I don't set it by hand when I launch the first compilation. I took screenshots of the two buffers: imgur.com/gallery/muHuuM-x compile
doesn't setup the window you're using (maybe it sets up another window which displays the same buffer?).