I'm trying to map F5 to compile from a parent directory of the current buffer.
Emacs compile-command find makefile in superior directory provides an excellent answer to achieve this:
(defun compile-project ()
(interactive)
(let* ((make-directory (locate-dominating-file (buffer-file-name)
"Makefile"))
(command (concat "make -k -C "
(shell-quote-argument make-directory))))
(compile command)))
(global-set-key (kbd "<f5>") 'compile-project)
Besides, C/C++ Development Environment for Emacs describes a way such that F5 does not prompt for the compile command every time, but if a prefix argument C-u is provided, then compile
prompts for a compile command:
(global-set-key (kbd "<f5>") (lambda ()
(interactive)
(setq-local compilation-read-command nil)
(call-interactively 'compile)))
Question: How can I modify the compile-project
function, so that when a prefix command C-u is provided, it shows the compilation command in the mini-buffer, including a default command of make -k -C ...
generated by the body of let*
?