From 7e8f3727447b23251691dcb65837c4411498bce9 Mon Sep 17 00:00:00 2001 From: Lucas Sta Maria Date: Fri, 29 Dec 2023 04:44:07 -0500 Subject: [PATCH] fix(emacs): close compilation buffer on 0-status exit Signed-off-by: Lucas Sta Maria --- .emacs.d/include/general.el | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/.emacs.d/include/general.el b/.emacs.d/include/general.el index 1ebc878..dd580ca 100644 --- a/.emacs.d/include/general.el +++ b/.emacs.d/include/general.el @@ -115,5 +115,21 @@ (global-unset-key (kbd "C-z")) (global-unset-key (kbd "C-x C-z")) +;; From https://stackoverflow.com/questions/8309769/how-can-i-prevent-emacs-from-opening-new-window-for-compilation-output + +;; Helper for compilation. Close the compilation window if +;; there was no error at all. (emacs wiki) +(defun compilation-exit-autoclose (status code msg) + ;; If M-x compile exists with a 0 + (when (and (eq status 'exit) (zerop code)) + ;; then bury the *compilation* buffer, so that C-x b doesn't go there + (bury-buffer) + ;; and delete the *compilation* window + (delete-window (get-buffer-window (get-buffer "*compilation*")))) + ;; Always return the anticipated result of compilation-exit-message-function + (cons msg code)) +;; Specify my function (maybe I should have done a lambda function) +(setq compilation-exit-message-function 'compilation-exit-autoclose) + (provide 'general) ;;; general.el ends here