From 52d48f4375871624c14d5b38ed65cd37c9f7d145 Mon Sep 17 00:00:00 2001 From: coolneng Date: Mon, 31 Jul 2023 20:46:21 +0200 Subject: [PATCH] Improve compilation buffer closing implementation --- config.el | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/config.el b/config.el index d863194..5a9dad5 100644 --- a/config.el +++ b/config.el @@ -37,14 +37,21 @@ (add-hook! 'csv-mode-hook 'csv-align-mode) (add-hook! 'csv-mode-hook 'csv-header-line) ;; Close compilation buffer if successful -(setq compilation-finish-functions - (lambda (buf str) - (if (null (string-match ".*exited abnormally.*" str)) - (progn - (run-at-time - "0.5 sec" nil 'delete-windows-on - (get-buffer-create "*compilation*")) - (message "No Compilation Errors!"))))) +(defun close-compilation-buffer-if-successful (buffer string) + "Bury a compilation buffer if succeeded without warnings " + (when (and (eq major-mode 'compilation-mode) + (string-match "finished" string) + (not + (with-current-buffer buffer + (search-forward "warning" nil t)))) + (run-with-timer 1 nil + (lambda (buf) + (let ((window (get-buffer-window buf))) + (when (and (window-live-p window) + (eq buf (window-buffer window))) + (delete-window window)))) + buffer))) +(add-hook 'compilation-finish-functions #'close-compilation-buffer-if-successful) ;; Map leader key for major mode to , (setq evil-snipe-override-evil-repeat-keys nil) (setq doom-localleader-key ",")