Wednesday, October 8, 2014

Compilation under Emacs

;; prevent compiler opens a new frame (put output in current buffer)
(add-to-list 'same-window-buffer-names "*compilation*”)


;; auto scroll compilation output
(setq compilation-scroll-output t)


;; auto close if succeeded
(defun bury-compile-buffer-if-successful (buffer string)
  "Bury a compilation buffer if succeeded without warnings"
  (if (and
         (string-match "compilation" (buffer-name buffer))
         (string-match "finished" string)
         (not (with-current-buffer buffer
                (goto-char (point-min))
                (search-forward "warning" nil t))))
      (with-current-buffer buffer
        (goto-char (point-max))
        (run-with-timer 5 nil
          (lambda (buf)
            (bury-buffer buf)
            (switch-to-prev-buffer (get-buffer-window buf) 'kill))
             buffer))))
(add-hook 'compilation-finish-functions

          'bury-compile-buffer-if-successful)

No comments:

Post a Comment