简体   繁体   English

Emacs编译忽略编译命令变量

[英]Emacs compile ignoring compile-command variable

Initially, I had the following defined in my .emacs.d/init.el 最初,我在.emacs.d / init.el中定义了以下内容

(defun go-mode-setup ()
  (setq compile-command "go build -v && go test -v && go vet && golint")
  (define-key go-mode-map (kbd "C-c C-c") 'compile)
  )

While in go-mode, everything else seemed to work fine, but his did not seem to set or respect my Cc Cc command, instead producing 在进入模式时,其他所有内容似乎都可以正常工作,但是他似乎并没有设置或尊重我的Cc Cc命令,而是执行了

C-c C-c is undefined.

So, I added an explicit hook: 因此,我添加了一个明确的钩子:

(add-hook 'go-mode-hook (lambda () (define-key go-mode-map (kbd "C-c C-c") 'compile)))

This now respects my Cc Cc kbd shortcut, but still ignores the compile-command I set. 现在,这符合我的Cc Cc kbd快捷方式,但仍然忽略了我设置的编译命令。 Unfortunately, it seems to compile the entire folder rather than just the main.go file I am working on. 不幸的是,它似乎编译了整个文件夹,而不是我正在处理的main.go文件。

Compile command: make -k 

How can I set Cc Cc to use the compile-command I set? 如何设置抄送抄送以使用我设置的编译命令?

Your code works for me. 您的代码对我有用。 The only thing missing is an add-hook . 唯一缺少的是add-hook You probably want to set the compile-command to be buffer-local as well. 您可能还希望将compile-command设置为本地缓冲区。

Here's my code that definitely works: 这是我的绝对有效的代码:

(defun jpk/go-mode-hook ()
  (make-local-variable 'compile-command)
  (setq compile-command "go build -v")
  (define-key go-mode-map (kbd "C-c C-c") #'compile))
(add-hook 'go-mode-hook #'jpk/go-mode-hook)

I strongly recommend against redefining compile like in @jdc's answer. 我强烈建议不要像@jdc的答案那样重新定义compile If you must define your own command, do it with a different name. 如果必须定义自己的命令,请使用其他名称。

You may want to check out the multi-compile package, it allows you to set multiple compile commands (optionally major-mode specific). 您可能要签出多重编译包,它允许您设置多个编译命令(可选地,特定于主要模式)。

This should work: 这应该工作:

(add-hook 'go-mode-hook (lambda ()
  (defun compile ()
    (setq compile-command "go build -v && go test -v && go vet && golint"))
  (define-key go-mode-map (kbd "C-c C-c") 'compile)))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM