smart-compile package inside Emacs.
add this into your
(setq compilation-last-buffer nil)
;; save all modified buffers without asking before compilation
(setq compilation-ask-about-save nil)
(defun compile-again (ARG)
"Run the same compile as the last time.
With a prefix argument or no last time, this acts like M-x compile,
and you can reconfigure the compile args."
;; the following two lines create bug: split a new window every time
;; (if (not (get-buffer-window "*compilation*"))
(if (and (eq ARG 1) compilation-last-buffer)
(bind-key* "C-x C-m" 'compile-again)
;; create a new small frame to show the compilation info
;; will be auto closed if no error
`(("*compilation*" . ((name . "*compilation*")
(left . (- 1))
(top . 0)))))
(lambda (buf str)
(if (null (string-match ".*exited abnormally.*" str))
;;no errors, make the compilation window go away in a few seconds
"1 sec" nil 'delete-windows-on
(message "No Compilation Errors!")))))
C-x C-m to compile your source code, If you are the first time to execute
C-x C-m, it will ask you to change the default command (which is usually enough), otherwise it will execute the command you just used to compile directly and you have to use
C-u C-x C-m to change the command if you want. If you got a
Makefile inside the current directory, it will notice and prompt to ask whether you want to use it.
Maybe this answer is too much for your question, but please try it.