How to disable Emacs-Flymake for html mode
Asked Answered
C

4

25

Here is my flymake setup in .emacs file:

 (when (load "flymake" t) 
         (defun flymake-pyflakes-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 "pyflakes" (list local-file)))) 

         (add-to-list 'flymake-allowed-file-name-masks 
                  '("\\.py\\'" flymake-pyflakes-init))) 

   (add-hook 'find-file-hook 'flymake-find-file-hook)
(load-library "flymake-cursor")

I want to use flymake only for .py files. and disable it for the rest. but It is always enabled. For example when I open an html file I always get following error Error (flymake): Flymake: Failed to launch syntax check process 'xml' with args (val /home/huseyin/vipsatis/templates/cancellation/base_flymake.html): Searching for program: no such file or directory, xml. Flymake will be switched OFF

So I want to turn it off for anything but py files. is it possible?

( For the people having the same problem, I want to explain the error message: Flymake uses xmlstarlet for xml and html validation. And it tries to call it as "xml val ......" but it has to call it as "xmlstarlet val...." to fix this you have to find flymake.el file and change the xml call with xmlstarlet. )

Chism answered 4/11, 2010 at 9:8 Comment(1)
I've followed all the suggestions below to no avail. Flymake mode is still active in my html buffers, which is really annoying when I'm using django tags. Any tips? I'm on Snow Leopard running emacs24.Rita
H
23

Remove the HTML entry from the list:

(delete '("\\.html?\\'" flymake-xml-init) flymake-allowed-file-name-masks)
Hippy answered 29/5, 2011 at 7:25 Comment(3)
When I try this, I get the error Symbol's value as variable is void: flymake-allowed-file-name-masksExpense
Although I don't know exactly why, putting the line at the end of .emacs won't have the error.Flavescent
@Flavescent It's probably because flymake-allowed-file-name-masks doesn't exist until loading the flymake package creates it. By putting the delete command at the end of your .emacs file, you're giving the package time to create the list.Reggi
C
6

OK I got it. here is what I did: first of all I found flymake.el file.(If you dont have it you probably have flymake.elc file under emacs installation.In that case just copy flymake.el file under your load path so it will be used instead of compiled version(.elc file) under insallation). than I found following function and commented .xml and .html bindings.

(defcustom flymake-allowed-file-name-masks
  '(("\\.\\(?:c\\(?:pp\\|xx\\|\\+\\+\\)?\\|CC\\)\\'" 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)
    )

Other comment outed lines was already there. Now flymake does not work for html and xml files

Chism answered 4/11, 2010 at 14:48 Comment(2)
you don't have to modify the .el file to make this happen. you can just set the variable in your own emacs.el (or equivalent).Sachi
so if I understand right, I have to put the code in the post in emacs.el file. so it will overwrite tthe one in flymake.el file. I will try that thank you. (If I am mistaking please correct me)Chism
C
3

In the error message you receive it's telling that it can't find the command-line XML validation tool xml. You can fix it by installing a compatible XML validation tool (xmllint is the right choice I guess).

But if you really just want to disable Flymake for HTML and XML files you don't have to copy whole the flymake.el file and change it. Simply add this line your init file:

(defun flymake-xml-init ())

This overrides the function that Flymake calls for HTML and XML files with an empty function.

Calcic answered 8/10, 2011 at 11:3 Comment(2)
+1 Not sure why you were downvoted, this seems normal for disabling other modes like java, even though it didn't work for me.Rita
I used (defun flymake-simple-make-init ()) to disable all the make-based flymake modes at once. Very handy.Rolf
C
3

Customize the variable named flymake-allowed-file-name-masks.

You can do it like this too:

M-x customize-variable RET

flymake-allowed-file-name-masks RET
Creighton answered 20/9, 2012 at 21:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.