I know that we can start compile
interactively using C-u M-x compile
. Is there a way to start this whenever I run M-x compile
? If that cannot be done, how do I create a shortcut to C-u M-x compile
?
My current shortcut for M-x compile
is:
(global-set-key (kbd "<f5>") 'compile)
This would execute normal compile (not interactive). Ideally, I would like to create a separate shortcut for interactive compile (for program that requires a lot of user inputs).
Please let me know and thanks for your help
Edit: I forgot the mention that my compile command is also customized based on mode hook. For example, below is how I customize it for C++ mode hook and Fortran mode hook:
(add-hook 'c++-mode-hook
(lambda ()
(set (make-local-variable 'compile-command)
(concat "g++ -g -Wall -lm " buffer-file-name " && ./a.out" ) )))
(add-hook 'fortran-mode-hook
(lambda ()
(set (make-local-variable 'compile-command)
(concat "gfortran " buffer-file-name " && ./a.out" ) )))
ls -la
. This compilation window is not in comint mode, because if I doC-u M-x compile
, then the compilation window would have something like "Comint mode started at....". I also customize my compile command base on mode-hook, will update that in the question asap. – mle0312 May 20 '20 at 21:48(global-set-key [f5] (lambda () (interactive) (let ((current-prefix-arg '(4))) (call-interactively 'compile))))
I see that the functioncall-interactively
has optional arguments, one of them being KEYS -- it may be possible to use that argument as an alternative to setting thecurrent-prefix-arg
as I have done in the example of this comment. – lawlist May 20 '20 at 21:50