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

问题描述 投票:0回答:1

编辑过程在emacs中非常静音,这就是为什么我决定让它变得更快更方便,我只遇到这个程序(代码串)不能自我更新的问题,即compile-command(首次启动后)保持不变,如果没有干预就不会改变,我决定加上defin,但我对lisp的无知阻止了我,结果不成功。

问题:如何使我的功能正常工作,以便每个新的ALT-M点击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)

初始版本:

(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" 'recompile)
emacs compilation elisp
1个回答
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 compile-command RET查看值
  5. M-x编译RET或你绑定compile的任何东西
© www.soinside.com 2019 - 2024. All rights reserved.