gpt4 book ai didi

emacs - 配置Emacs Flymake直接调用g++

转载 作者:行者123 更新时间:2023-12-04 23:57:55 26 4
gpt4 key购买 nike

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

g++ -c a.cpp

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

非常感谢

最佳答案

您可以使用以下 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)

关于emacs - 配置Emacs Flymake直接调用g++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14864511/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com