4

在写简单的,一个文件,C++代码的时候,我一般直接调用g++。默认情况下,Flymake 似乎假设存在带有检查语法目标的 Makefile。如何将 Flymake 配置为直接调用 g++,例如:

g++ -c a.cpp

如果可以修改答案以包含编译器标志,那就更好了

非常感谢

4

1 回答 1

7

您可以使用以下 flymake 配置直接调用 g++。

(require 'flymake)

(defun flymake-cc-init ()
  (let* ((temp-file   (flymake-init-create-temp-buffer-copy
                       'flymake-create-temp-inplace))
         (local-file  (file-relative-name
                       temp-file
                       (file-name-directory buffer-file-name))))
    (list "g++" (list "-Wall" "-Wextra" "-fsyntax-only" local-file))))

(push '("\\.cpp$" flymake-cc-init) flymake-allowed-file-name-masks)
(add-hook 'c++-mode-hook 'flymake-mode)

我打电话时收到以下屏幕截图flymake-allowed-file-name-masks

flymake-c++

以下为评论版。

;; Import flymake
(require 'flymake)

;; Define function
(defun flymake-cc-init ()
  (let* (;; Create temp file which is copy of current file
         (temp-file   (flymake-init-create-temp-buffer-copy
                       'flymake-create-temp-inplace))
         ;; Get relative path of temp file from current directory
         (local-file  (file-relative-name
                       temp-file
                       (file-name-directory buffer-file-name))))

    ;; Construct compile command which is defined list.
    ;; First element is program name, "g++" in this case.
    ;; Second element is list of options.
    ;; So this means "g++ -Wall -Wextra -fsyntax-only tempfile-path"
    (list "g++" (list "-Wall" "-Wextra" "-fsyntax-only" local-file))))

;; Enable above flymake setting for C++ files(suffix is '.cpp')
(push '("\\.cpp$" flymake-cc-init) flymake-allowed-file-name-masks)

;; Enable flymake-mode for C++ files.
(add-hook 'c++-mode-hook 'flymake-mode)
于 2013-02-14T01:15:27.843 回答