emacsflymake

Flymake alternative that doesn't require altering the makefile


According to this question in order for Flymake to work you must add a special target to the makefile. I don't want to do this. Is there an alternative to Flymake that doesn'r require you to mess around with the makefiles?


Solution

  • Not true.

    You need not change the makefile in order to run flymake. As jtahlborn's comment said, flymake is a framework to run something when your buffer changes. It could be anything. You just need to tell flymake what to run.

    For example, there's a program called csslint. It checks a CSS file and flags any warnings or non-standard usages. Lint for CSS. When I edit a css file (in css-mode) I want flymake to run CSSlint and show me the problems. This is how I do it.

    (defun cheeso-flymake-css-init ()
      "the initialization fn for flymake for CSS"
      (let* ((temp-file (flymake-init-create-temp-buffer-copy
                           'cheeso-flymake-create-temp-intemp))
             (local-file (file-relative-name
                          temp-file
                          (file-name-directory buffer-file-name))))
        (list (concat (getenv "windir") "\\system32\\cscript.exe")
              (list "c:\\users\\cheeso\\bin\\csslint-wsh.js" "--format=compiler" local-file))))
    
    (defun cheeso-css-flymake-install ()
      "install flymake stuff for CSS files."
      (add-to-list
       'flymake-err-line-patterns
       (list css-csslint-error-pattern 1 2 3 4))
    
      (let* ((key "\\.css\\'")
             (cssentry (assoc key flymake-allowed-file-name-masks)))
        (if cssentry
            (setcdr cssentry '(cheeso-flymake-css-init))
          (add-to-list
           'flymake-allowed-file-name-masks
           (list key 'cheeso-flymake-css-init)))))
    
    
    (eval-after-load "flymake"
      '(progn
         (cheeso-css-flymake-install)))
    

    This runs a fn when flymake is loaded. The fn installs an entry in flymake's associative list for CSS files. The entry in that list tells flymake what command to run.

    There's a little bit more to tell flymake how to parse the CSS lint error messages. But that's the general idea.