2010-04-03 76 views
14

我有以下行我~/.emacs.d/init.elEmacs的:討厭Flymake對話框

(custom-set-variables 
    '(flymake-allowed-file-name-masks 
    (quote 
     (
     ("\\.cc\\'" flymake-simple-make-init) 
     ("\\.cpp\\'" flymake-simple-make-init))))) 
(add-hook 'find-file-hook 'flymake-find-file-hook) 

當我打開一個C++文件,在同一個文件夾中有一個適當的Makefile中,我得到即時編譯和錯誤報告(Flymake將在代碼編輯過程中檢查語法並報告錯誤和警告)。

的Makefile有一個check-syntax目標:

.PHONY: check-syntax 
check-syntax: 
$(CXX) -Wall -Wextra -pedantic -fsyntax-only $(CHK_SOURCES) 

的問題是,當我打開一個沒有相應的Makefile一個.cc文件我得到警告我,flymake被禁用惱人的對話框。

所以,如果我用20 C++文件的文件夾中推出emacs *.cc我得到20個模式對話框說像沒有構建文件中找到[...]。 Flymake將關閉

是否有一些鉤子可以用來禁用該警告?你能提供樣本elisp代碼和解釋你如何找到正確的鉤子?

回答

14

完成此操作並仍然收到消息的最簡單方法是將定製變量設置爲true,然後重新定義flymake-display-warning函數。

;; Overwrite flymake-display-warning so that no annoying dialog box is 
;; used. 

;; This version uses lwarn instead of message-box in the original version. 
;; lwarn will open another window, and display the warning in there. 
(defun flymake-display-warning (warning) 
    "Display a warning to the user, using lwarn" 
    (lwarn 'flymake :warning warning)) 

;; Using lwarn might be kind of annoying on its own, popping up windows and 
;; what not. If you prefer to recieve the warnings in the mini-buffer, use: 
(defun flymake-display-warning (warning) 
    "Display a warning to the user, using lwarn" 
    (message warning)) 
+3

我會用'defadvice'而不是'defun'來覆蓋函數,因爲前者顯式聲明瞭你的意圖來覆蓋函數,即使稍後flymake被重新加載,它也可以工作。 – 2010-10-26 23:43:36

+0

,因爲那不會完全相同(即's/defun/defadvice /'不夠),你可以將它作爲答案張貼@RyanThompson – ocodo 2013-03-03 19:58:58

11

有一個可以定製的變量,我忽略了。

flymake-gui-warnings-enabled

這將禁用任何GUI的消息,但我會與它的罰款,如果沒有人將發佈一個更好的答案。

+2

看來這樣會禁用flymake的所有警告/錯誤消息。最好的方法是在minibuffer中顯示消息。 – RNA 2012-12-03 20:41:41