.emacs I have the following code:
(defun run-latexmk ()
(let ((TeX-save-query nil)
(TeX-command-expand "latexmk -pdf %t" 'TeX-master-file)
(if (plist-get TeX-error-report-switches (intern master-file))
(minibuffer-message "latexmk done"))))
(lambda () (local-set-key (kbd "C-0") #'run-latexmk))
C-0 to the defined function
run-latexmk which in turn saves all the files of the current document (based on the notion of
master file) and then runs
latexmk. If the compilation was successful then the compilation window closes. You can easily(?) change this code to your needs.
This answer is based on this one and this one.