14

I have the following lines in my ~/.emacs.d/init.el

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

When I open a C++ file that has a proper Makefile in the same folder, I get on-the-fly compilation and error reporting (Flymake will check the syntax and report errors and warnings during code editing).

The Makefile has a check-syntax target:

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

The problem is that when I open a .cc file that has no corresponding Makefile I get an annoying dialog box that warns me about flymake being disabled.

So if I launch emacs *.cc in a folder with 20 C++ files I get 20 modal dialog boxes saying something like No buildfile found for [...]. Flymake will be switched off.

Is there some hook I can use to disable that warning? Can you provide sample elisp code and explanation on how you found the proper hook?

SamB
  • 9,039
  • 5
  • 49
  • 56
baol
  • 4,362
  • 34
  • 44

2 Answers2

14

Easiest way to do this, and still recieve the messages, is to leave the customization variable set to true, and redefine the flymake-display-warning function.

;; 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))
SamB
  • 9,039
  • 5
  • 49
  • 56
arvidj
  • 775
  • 5
  • 25
  • 3
    I would override the function with `defadvice` rather than `defun`, since the former explicitly declares your intent to override the function, and it also works even if flymake is re-loaded later. – Ryan C. Thompson Oct 26 '10 at 23:43
  • since that wouldn't be exactly equivalent (ie. `s/defun/defadvice/` is not sufficent), can you post it as an answer @RyanThompson – ocodo Mar 03 '13 at 19:58
11

There is a variable that can be customized and that I overlooked.

flymake-gui-warnings-enabled

This will disable any GUI message, but I'll be fine with it if no one will post a better answer.

baol
  • 4,362
  • 34
  • 44
  • 2
    it seems this disables all the warnings/error messages from flymake. The best way would be to show the messages in minibuffer. – RNA Dec 03 '12 at 20:41