# Emacs Tips — Close compilation buffer

Author

Dheepak Krishnamurthy

Published

July 19, 2015

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

## Citation

BibTeX citation:
@online{krishnamurthy2015,
author = {Krishnamurthy, Dheepak},
title = {Emacs {Tips} — {Close} Compilation Buffer},
date = {2015-07-19},
url = {https://kdheepak.com/blog/emacs-tips-close-compilation-buffer-if-successful},
langid = {en}
}