如何通过ALT-M在emacs中进行编译?

时间:2019-02-28 19:42:06

标签: emacs compilation elisp

在emacs中,编译过程非常安静,这就是为什么我决定使其更快,更方便的原因,而我仅得到这个程序(代码字符串)不能自我更新的问题,即{{1 }}(在首次启动后),保持不变,并且无需干预就不会更改,因此我决定添加compile-command,但由于对Lisp的无知阻止了我,结果失败了。

问题:如何使我的功能正常运行,以便在每个新的ALT-M上都单击defin

我试图做的事情

compile-command

初始版本:

(defun x-recompile (compile-command)
(setq compile-command '(concat "/usr/local/Cellar/gcc/8.3.0/bin/gcc-8 -O2 -Wall -o "
                   (if (file-name-sans-extension buffer-file-name)
                  (shell-quote-argument
                   (file-name-sans-extension buffer-file-name)))
                   " "
                    (if buffer-file-name
                    (shell-quote-argument (buffer-file-name))))))

(define-key global-map "\eM" 'compile)
(define-key global-map "\em" 'x-recompile)

1 个答案:

答案 0 :(得分:2)

我认为最简单的方法是使用模式挂钩:

(add-hook 'c-mode-hook
  (lambda ()
    (set (make-local-variable 'compile-command)
         (concat "/usr/local/Cellar/gcc/8.3.0/bin/gcc-8 -O2 -Wall -o "
                 (if (file-name-sans-extension buffer-file-name)
                     (shell-quote-argument
                      (file-name-sans-extension buffer-file-name)))
                 " "
                 (if buffer-file-name
                     (shell-quote-argument (buffer-file-name)))))))

这将在您访问文件时设置compile-command,然后compilerecompile将正常工作。

  1. 将以上代码添加到.emacs
  2. 评估表格
  3. 重新访问文件(杀死缓冲区并再次打开文件)
  4. C-h v编译命令RET 查看值
  5. M-x编译RET 或将compile绑定到的任何内容