summaryrefslogtreecommitdiff
path: root/.config/emacs/config.org
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2023-08-18 01:48:13 +0200
committerThomas Voss <mail@thomasvoss.com> 2023-08-18 01:48:13 +0200
commit992f28ad73d372a7dcb9737f0acba2f32b31e8cc (patch)
tree73415dbe777aa4fa6a978e9e006d1ec62ba333a7 /.config/emacs/config.org
parent9f72f040fbb2375ce484daf17a25feee40e530cc (diff)
emacs: Handle compilation buffers better
Diffstat (limited to '.config/emacs/config.org')
-rw-r--r--.config/emacs/config.org23
1 files changed, 17 insertions, 6 deletions
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