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?
r-mode
does not have a mode hook? Do you have a link to the source code forr-mode
so that we can have a look for ourselves to see whether that is accurate, and/or to make specific suggestions based upon our review of that source code?define-derived-mode
have a mode hook (foo-mode-hook
if the mode is namedfoo-mode
), and any major modes defined without that macro are expected to do the same thing. As such, the problem probably isn't what you think it is. I don't have anr-mode
so, as @lawlist says, please show us the source for that.after-change-major-mode-hook
and(when (derived-mode-p 'r-mode) ...)
in your hook function.C-h v major-mode
in one of your.r
file buffers.