I would like emacs to use the current buffer's file name as part of the command passed to M-x compile
. For example, if I am editing ~/foo.rb, I would like M-x compile
to execute ruby ~/foo.rb
I tried setting compilation-command
to (list "ruby" buffer-file-name)
, but apparently you can't pass an s-expression here.
To execute a file of Emacs Lisp code, use M-x load-file . This command reads a file name using the minibuffer and then executes the contents of that file as Lisp code. It is not necessary to visit the file first; in any case, this command reads the file as found on disk, not text in an Emacs buffer.
To compile a program in Emacs, type Escape followed by x followed by compile, or use the pull down "tool" menu and select compile.
Start up Emacs and type the following sequence of keys: M-x (which means hold the "Alt" key and hit "x"). At the bottom of the emacs window "M-x" should appear. Type the command "run-scheme".
C-hfcompile
RET
compile is an interactive autoloaded compiled Lisp function in
`compile.el'.
[snip]
Interactively, prompts for the command if `compilation-read-command' is
non-nil; otherwise uses `compile-command'. With prefix arg, always prompts.
Additionally, with universal prefix arg, compilation buffer will be in
comint mode, i.e. interactive.
Now that we've found what we were looking for, let's …
C-hvcompile-command
RET
compile-command is a variable defined in `compile.el'.
Its value is "make -k "
[snip]
Sometimes it is useful for files to supply local values for this variable.
You might also use mode hooks to specify it in certain modes, like this:
(add-hook 'c-mode-hook
(lambda ()
(unless (or (file-exists-p "makefile")
(file-exists-p "Makefile"))
(set (make-local-variable 'compile-command)
(concat "make -k "
(file-name-sans-extension buffer-file-name))))))
(add-hook 'ruby-mode-hook
(lambda ()
(set (make-local-variable 'compile-command)
(concat "ruby " buffer-file-name))))
Of course you can easily customize it to use rake
if there is a
Rakefile
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With