Skip to content
kd
19 Jul 2015
Back to blog

Emacs tips — Close compilation buffer

When I work with markdown, $\LaTeX$ or code that requires compiling, I like to check often if everything looks okay. Emacs has a good description of everything you can do with the CompileCommand.

However, it does not have a description for auto-closing the buffer if the compilation was successful. StackOverflow to the rescue!

#!lisp
; from enberg on #emacs
(setq compilation-finish-function
(lambda (buf str)
    (if (null (string-match ".*exited abnormally.*" str))
        ;;no errors, make the compilation window go away in a few seconds
        (progn
            (run-at-time
            "1 sec" nil 'delete-windows-on
            (get-buffer-create "*compilation*"))
        (message "No Compilation Errors!")))))

Insert the above code into your .emacs file. You can change the time you wish the buffer to be available by changing the “1 sec” in the above code


Share this post on:

Emacs workflow — Using Emacs in the terminal
Create Emacsclient.app using AppleScript