5

Following are the snippets in my init.el relevant to Flymake:

(add-hook 'python-mode-hook 
      (lambda () 
        (unless (eq buffer-file-name nil) (flymake-mode 1)) ;dont invoke flymake on temporary buffers for the interpreter
        (local-set-key [f2] 'flymake-goto-prev-error)
        (local-set-key [f3] 'flymake-goto-next-error)
        (local-set-key [f4] 'flymake-display-err-menu-for-current-line)
        (hs-minor-mode)
        (orgtbl-mode)
        (outline-minor-mode -1)))

...

;;===== PyFlakes
;; code checking via pyflakes+flymake
(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 "pychecker" (list local-file))))

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

(mapcar (lambda (hook) (add-hook 'find-file-hook hook))
    (list 'flymake-find-file-hook))

(unload-feature 'flymake) ; unloaded in an attempt to get rid of the error

But everytime I find-file or revert-buffer (extensions .xml, .php, .html) I get the following error (not with .py):

Flymake: Failed to launch syntax check process 'php' with args (-f _posteddata_flymake.php -l): Searching for program: permission denied, php. Flymake will be switch OFF

or

Flymake: Failed to launch syntax check process 'xml' with args (val //path/to/file/config/prod-conf_flymake.xml): Searching for program: permission denied, xml. Flymake will be switch OFF

I've also tried doing (load "flymake" nil) but it didn't work either.

A big time sink when opening or reloading a big hunk of files.

How can I fix it?

Bleeding Fingers
  • 6,993
  • 7
  • 46
  • 74
  • 1
    Not really a solution, but give [flycheck](http://flycheck.github.io/) a try. It's a flymake that works out of the box with most languages and configurations and doesn't suck. – Ron Dec 26 '13 at 19:08
  • By the way, `(load "flymake" nil)` doesn't do, what you thought it would, namely unloading a library. That'd be `unload-feature`, but a library needs to explicitly support unloading, and Flymake doesn't. –  Dec 27 '13 at 10:47
  • Ran into this today: ridding your `.emacs` of any and all references to `flymake` might not suffice, if you are using some kind of session management package e.g. `desktop.el`. Be sure to kill that state as well, e.g. reload your buffers – DomQ Aug 14 '19 at 07:01

2 Answers2

3

Just don't add Flymake to find-file-hook. Instead only add it to the hooks of major modes, you'd like to use it in.

You may also want to look at the alternative Flycheck package, which is safer to enable globally, supports more languages, and needs much less customization. Disclaimer: I'm the author of this package.

  • Now that the hook is in place how do I get rid of it? – Bleeding Fingers Dec 26 '13 at 18:52
  • Uhm, well, just remove the corresponding line in hour configuration snippet. –  Dec 26 '13 at 20:21
  • On a running Emacs? ;) – Bleeding Fingers Dec 26 '13 at 20:42
  • In a running Emacs, just do `M-x flymake-mode` in buffers, which already have Flymake, and customize `find-file-hook` to remove Flymake. –  Dec 26 '13 at 20:45
  • Or just restart Emacs after removing the offending line. I wonder why you even added it in the first place, if it causes so much trouble? –  Dec 26 '13 at 20:47
  • Just in case I might need it my Python buffers. Restarting/killing Emacs is the last thing I do (sacrosanct). Record Emacs up-time 34 days. Hope you get the drift. – Bleeding Fingers Dec 26 '13 at 20:51
  • If Emacs uptime is what you are after, I'm probably the wrong person to help you. –  Dec 26 '13 at 21:31
  • Of course not, just that I, as far as possible, refrain from restarting my Emacs. – Bleeding Fingers Dec 27 '13 at 05:21
  • 1
    You do not need to add `flymake-mode` to `visit-file-hook`. In fact, actually you should **never** do that, even many places in the internet tell you so. Flymake doesn't fail gracefully, and thus is not suitable for being enabled globally. Don't copy anything from the Emacs Wiki, and if you've copied harmful customizations, removing them and restarting Emacs is often the easiest way of un-doing these. –  Dec 27 '13 at 10:45
3

I ended up in this question trying to disable flymake inside the python-mode / elpy which was called by default. It ain't perfect, but it worked, so I'm just posting it in case it's of help to someone else who ends up here with the same problem.

Assuming you use "use-package" in your config, and you want to replace flymake with flycheck, to enable flycheck you just need to add the following to your config:

(use-package flycheck
  :ensure t
  :init
  (global-flycheck-mode t))

Then to add elpy and python mode, the code would be:

(use-package python
  :mode ("\\.py" . python-mode)
  :ensure t
  :config
  (flymake-mode) ;; <- This line makes the trick of disabling flymake in python mode!
  (use-package elpy
    :ensure t
    :init
    (add-to-list 'auto-mode-alist '("\\.py$" . python-mode))
    :config
    (remove-hook 'elpy-modules 'elpy-module-flymake) ;; <- This removes flymake from elpy
    (setq elpy-rpc-backend "jedi")
    :bind (:map elpy-mode-map
              ("M-." . elpy-goto-definition)
              ("M-," . pop-tag-mark))
  )
  (elpy-enable)
)

The above code would enable elpy mode every time you are in the python-mode / editing python files. The problem was that python mode was automatically enabling flymake when it was being loaded, and then elpy was loading flycheck. So you'd have both checkers running.

The solution I came up was calling flymake-mode one more time after loading the python mode, thus disabling it. This should probably work on other modes / cases too.

I know that a "proper" solution would be to find a way to not load flymake at all when loading the python-mode, but until I manage to do that, this should suffice.

gekaklam
  • 331
  • 2
  • 5
  • 6
    `M-x customize-variable elpy-modules` then uncheck `Highlight syntax errors (Flymake)`. And then `Apply and Save`. Saves altering the `use-package` configuration for python. – ayman Feb 20 '19 at 23:59
  • @ayman your method worked for me, but I wonder where does it write the change to? I didn't find that in my `init.el`. – Jason Feb 19 '20 at 08:33
  • Answer myself: I got it, it deletes `elpy-module-flymake` from the `elpy-modules` list so I didn't find any `flymake` thing. I thought it wrote a line to explicitly disable `flymake`. – Jason Feb 19 '20 at 08:41