From 992f28ad73d372a7dcb9737f0acba2f32b31e8cc Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Fri, 18 Aug 2023 01:48:13 +0200 Subject: emacs: Handle compilation buffers better --- .config/emacs/config.org | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to '.config') diff --git a/.config/emacs/config.org b/.config/emacs/config.org index 3a27717..3e14e99 100644 --- a/.config/emacs/config.org +++ b/.config/emacs/config.org @@ -721,12 +721,23 @@ every time. I would like to have this buffer, but only when things go wrong. #+BEGIN_SRC elisp - (add-hook 'compilation-finish-functions - (lambda (buffer _) - (with-current-buffer buffer - (when (= 0 compilation-num-errors-found - compilation-num-warnings-found) - (kill-buffer buffer))))) + (defun mango--compilation-make-window () + "Make a new vertical split for the compilation buffer if such a buffer doesn’t + already exist." + (unless (get-buffer "*compilation*") + (split-window-vertically))) + + (defun mango--compilation-exit-autoclose (status code msg) + "Automatically bury the compilation buffer and delete the compilation window + if compilation was successful." + (when (and (eq status 'exit) + (zerop code)) + (bury-buffer) + (delete-window (get-buffer-window "*compilation*"))) + (cons msg code)) + + (add-hook 'compilation-mode-hook #'mango--compilation-make-window) + (setq compilation-exit-message-function #'mango--compilation-exit-autoclose) #+END_SRC -- cgit v1.2.3