Disable flymake for specific file types

Flymake uses external applications to validate buffers. But sometimes, You don't have those external apps installed. For instance, HTML validation with flymake on Ubuntu is really problematic for this reason. Flymake uses xmlstarlet for HTML validation. It does it by calling xmlstarlet by command 'xml val file name.html'. But when xmlstarlet is installed in Ubuntu, it is installed by name 'xmlstarlet' instead of 'xml'. That name change causes emacs to raise exception every time an HTML file if opened. Since I don't really need XML/HTML validation in emacs, I thought I could just disable flymake for those types of files. Here is how I did it:

In order to disable flymake for certain file types, open flymake.el file and find following section (flymake.el file should be somewhere in your ~/.emacs.d folder)

(defcustom flymake-allowed-file-name-masks
  '(("\\.c\\'" flymake-simple-make-init)
    ("\\.cpp\\'" flymake-simple-make-init) 
;   ("\\.xml\\'" flymake-xml-init)
;   ("\\.html?\\'" flymake-xml-init)
    ("\\.cs\\'" flymake-simple-make-init)
    ("\\.p[ml]\\'" flymake-perl-init)
    ("\\.php[345]?\\'" flymake-php-init)
    ("\\.h\\'" flymake-master-make-header-init flymake-master-cleanup)
("\\.java\\'" flymake-simple-make-java-init flymake-simple-java-cleanup)
("[0-9]+\\.tex\\'" flymake-master-tex-init flymake-master-cleanup)
("\\.tex\\'" flymake-simple-tex-init)
("\\.idl\\'" flymake-simple-make-init)
;; ("\\.cpp\\'" 1)
;; ("\\.java\\'" 3)
;; ("\\.h\\'" 2 ("\\.cpp\\'" "\\.c\\'")
;; ("[ \t]*#[ \t]*include[ \t]*\"\\([\w0-9/\\_\.]*[/\\]*\\)\\(%s\\)\"" 1 2))
;; ("\\.idl\\'" 1)
;; ("\\.odl\\'" 1)
;; ("[0-9]+\\.tex\\'" 2 ("\\.tex\\'")
;; ("[ \t]*\\input[ \t]*{\\(.*\\)\\(%s\\)}" 1 2 ))
;; ("\\.tex\\'" 1)
)
  "*Files syntax checking is allowed for."
  :group 'flymake
  :type '(repeat (string symbol symbol symbol)))

Comment out lines you need to disable.(In my case XML and HTML).

NOTE: I just could change command xml to xmlstarlet and it would work too. Command for HTML validation is in the same file in following section:

(defun flymake-xml-init ()
  (list "xml" (list "val" (flymake-init-create-temp-buffer-copy 'flymake-create-temp-inplace))))

Date 10 May 2011 Categories: Tags:
blog comments powered by Disqus