79464705

Date: 2025-02-24 20:23:28
Score: 1
Natty:
Report link

@jpkotta's answer is fine for me, except that when I only have a single buffer, it keeps the opened compilation buffer. I check for this case and close the window:

(defun bury-compile-buffer-if-successful (buffer string)
    "Bury a compilation buffer if succeeded without warnings."
    (when (and
           (buffer-live-p buffer)
           (string-match "compilation" (buffer-name buffer))
           (string-match "finished" string)
           )
      (run-with-timer 1 nil
                      (lambda (buf)
                        (bury-buffer buf)
                        (switch-to-prev-buffer (get-buffer-window buf) 'kill)
                        ;; delete window if it was opened by the compilation process
                        ;; (have two windows with the same buffer)
                        (when
                            (and (equal 2 (length (window-list)))
                                 (eq (window-buffer (car (window-list))) (window-buffer (cadr (window-list)))))
                          (delete-window (selected-window))
                          )
                        )
                      buffer)))
  (add-hook 'compilation-finish-functions 'bury-compile-buffer-if-successful)
Reasons:
  • Long answer (-1):
  • Has code block (-0.5):
  • User mentioned (1): @jpkotta's
  • Looks like a comment (1):
  • Low reputation (0.5):
Posted by: Deadly Pointer