For C/C++, I have the following to be run when I do M-x compile
on a .c/.cpp file
(add-hook 'c++-mode-hook
(lambda ()
(set (make-local-variable 'compile-command)
(concat "g++ " buffer-file-name " && ./a.out" ) )))
Now, say I work on some other languages that do not have mode-hook, say R. I want to do something like this:
(add-hook 'r-mode-hook
(lambda ()
(set (make-local-variable 'compile-command)
(concat "Rscript " buffer-file-name ) )))
After putting above code in my init.el and reloading emacs, there are no errors on startup. I went ahead and open and .r file, but M-x compile
does not result in: Rscript . Instead, I got the default prompt from M-x compile
: make -k.
Is there a way to do this?