2013-02-13 1 views
3

간단한 하나의 파일, C++ 코드를 작성할 때 저는 보통 g ++를 직접 호출합니다. 기본적으로 Flymake는 check-syntax 타겟을 가진 Makefile이 있다고 가정합니다. 어떻게 Flymake 단순히 g가 직접 ++ 호출하는 구성해야합니까 예 :Emacs Flymake가 g ++를 직접 호출하도록 설정하십시오.

g++ -c a.cpp 

대답이 컴파일러 플래그를 포함하도록 수정 될 수 있다면, 그것은 더 나은 것

많은 감사

답변

6

당신은 호출 할 수 있습니다 g ++ 다음 플라이 메이크 구성으로 직접. 나는 다음 flymake-allowed-file-name-masks

flymake-c++

를 호출 할 때 나는 스크린 샷을 다음있어

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

코멘트 버전입니다.

;; 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) 
+0

도움 주셔서 대단히 감사합니다. 전에 lisp을 사용 해본 적이 없으므로 코드의 각 행이 무엇을하고 있는지 간단히 설명 할 수 있습니까? 많은 분들께 다시 한번 감사드립니다. – Arrakis

+0

코멘트를 참조하십시오. version code (미안 해요 영어가 가난합니다). 플라이 메이크 모드를 다른 프로그래밍 언어로 사용한다면 flycheck (https://github.com/lunaryorn/flycheck)를 참조하십시오. flycheck은 많은 언어를 지원하므로 약간의 구성으로 flymake-mode를 사용할 수 있습니다. 그러한 Lisp 함수를 작성할 필요가 없습니다. – syohex

+0

@syohex 플라이 메이크가 특정 지연 후 오류를 표시하도록 할 수 있습니까? – Tengis

관련 문제