本文介绍了在M-x编译中使用当前缓冲区的文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望emacs使用当前缓冲区的文件名作为传递给 M-x compile
的命令的一部分。例如,如果我正在编辑〜/ foo.rb,我希望 Mx编译
执行 ruby〜/ foo.rb
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
我尝试将 compilation-command
设置为(列表ruby文件名)
,但显然你不能在这里传递一个s表达式。
I tried setting compilation-command
to (list "ruby" buffer-file-name)
, but apparently you can't pass an s-expression here.
推荐答案
1。阅读函数的文档
compile
compile-command
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))))))
3。 ...最后适应你的需要
3. … and finally adapt the example to your needs
(add-hook 'ruby-mode-hook
(lambda ()
(set (make-local-variable 'compile-command)
(concat "ruby " buffer-file-name))))
当然,如果有
<$ c $,那么您当然可以轻松地自定义它,以使用 rake
c> Rakefile 。
Of course you can easily customize it to use rake
if there is aRakefile
.
这篇关于在M-x编译中使用当前缓冲区的文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!