【问题标题】:can I change emacs' default compile command?我可以更改 emacs 的默认编译命令吗?
【发布时间】:2011-01-05 20:06:44
【问题描述】:

当我运行compile 时,Emacs 默认使用命令make -k。但是,我几乎从不认为在出现错误后让make 继续很有用,所以我总是删除-k 标志。有没有办法将我的.emacs 中的默认值更改为make

【问题讨论】:

  • 对于 X 的所有值,“我可以在 Emacs 中更改 X”的答案都是“是”。
  • 阿雪莱,完全正确。唯一真正的问题是,“如何在 Emacs 中更改 X?”

标签: emacs dot-emacs


【解决方案1】:
(setq compile-command "make") 

或类似的 .emacs 就足够了。

更多信息,请输入

C-h f compile

它描述了调用 M-x compile 时使用了哪些变量。

在那里,你应该看到它调用了 compile-command 和一个

C-h v compile-command

告诉你这默认为“make -k”。以上都是简化,但如果您需要进一步挖掘,所有信息都应该在这些命令中。

【讨论】:

  • 为此,(setq compile-command ...)(setq-default compile-command ...) 之间是否存在有效区别?
  • 不知道 Steve - C-h f setq 和 C-h f setq-default 提供了更多信息,但无法真正破译。
  • @Steve, from the Elisp Reference manual on setq-default: "如果 SYMBOL 不是当前缓冲区的本地缓冲区,并且没有自动标记为缓冲区本地,setq-default 与 @987654329 具有相同的效果@。” compile-command 不会自动缓冲本地,在执行.emacs 的过程中它通常不会是缓冲本地,所以它通常不会产生影响。
【解决方案2】:

由于我需要针对不同模式使用不同的编译器,因此我使用了以下 sn-p(此处显示为 javascript):

(require 'compile)
(add-hook 'js-mode-hook
          (lambda ()
            (set (make-local-variable 'compile-command)
                 (format "jshint %s" (file-name-nondirectory buffer-file-name)))))

这会将“jshint”作为我的编译命令运行。然后我也可以将钩子添加到其他语言,并根据我的需要进行自定义。

【讨论】:

  • 请注意,您也可以使用(file-name-sans-extension buffer-file-name) 作为不带扩展名的文件名。例如,(format "rustc %s && %s" (file-name-nondirectory buffer-file-name) (file-name-sans-extension buffer-file-name))
猜你喜欢
  • 1970-01-01
  • 2019-06-15
  • 1970-01-01
  • 2015-05-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多