配置Emacs Flymake直接调用g ++ [英] Configure Emacs Flymake to call g++ directly

查看:167
本文介绍了配置Emacs Flymake直接调用g ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

  g ++ -c a.cpp 

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



非常感谢

解决方案

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

 (require'flymake)

(defun flymake-cc-init()
(let *((temp-file -init-create-temp-buffer-copy
'flymake-create-temp-inplace))
(本地文件(file-relative-name
temp-file
file-name-directory buffer-file-name)))
(listg ++(list-Wall-Wextra-fsyntax-onlylocal-file)))

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

我得到了以下的sc调用 flymake-allowed-file-name-mask





以下是评论版本。

  ;;进口flymake 
(需要'flymake)

;;定义函数
(defun flymake-cc-init()
(let *(;;创建临时文件是当前文件的副本
(temp-file(flymake-init-create-temp -buffer-copy
'flymake-create-temp-inplace))
;;从当前目录获取临时文件的相对路径
(本地文件(文件相对名称
temp-file
(file-name-directory buffer-file-name))))

;;构造定义列表的编译命令
;;第一个元素是
;;第二个元素是选项列表
;;所以这意味着g ++ -Wall -Wextra -fsyntax-only tempfile-path
(列表g ++(列表-Wall-Wextra-fsyntax-onlylocal-file))))

;;启用上面的flymake设置为C ++文件(后缀为'.cpp')
(push'(\\.cpp $flymake-cc-init)flymake-allowed-file-name-masks)

;;为C ++文件启用flymake-mode。
(add-hook'c ++ - 模式挂钩'flymake模式)


When writing simple, one file, C++ code, I usually call g++ directly. By default, Flymake seems to assume the presence of a Makefile with a check-syntax target. How do I configure Flymake to simply call g++ directly, e.g:

g++ -c a.cpp

If the answer could be modified to include compiler flags, that would be even better

Many thanks

解决方案

You can call g++ directly with following flymake configuration.

(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)

I got following screenshot when I call flymake-allowed-file-name-masks

Following is comment version.

;; 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 Flymake直接调用g ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆