gpt4 book ai didi

emacs - 在M-x编译中使用当前缓冲区的文件名

转载 作者:行者123 更新时间:2023-12-03 13:24:36 25 4
gpt4 key购买 nike

我希望emacs将当前缓冲区的文件名用作传递给M-x compile的命令的一部分。例如,如果我正在编辑〜/ foo.rb,我希望M-x compile执行ruby ~/foo.rb
我尝试将compilation-command设置为(list "ruby" buffer-file-name),但是显然您不能在此处传递s表达式。

最佳答案

1.阅读功能文档

C-hf compile 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.

现在我们已经找到了想要的东西,让我们……

2.……阅读变量的文档……

C-hv compile-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))))))

3.…最后使示例适应您的需求
(add-hook 'ruby-mode-hook
(lambda ()
(set (make-local-variable 'compile-command)
(concat "ruby " buffer-file-name))))

当然,您可以轻松地自定义它以使用 rake(如果有 Rakefile

关于emacs - 在M-x编译中使用当前缓冲区的文件名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12756531/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com