0

I am using flycheck for for Python. I want flycheck to detect any errors right away when any Python file is opened. Currently it can detect if there is a modification and save operation is performed.

Let's say I have following code in hello.py file:

#!/usr/bin/env python3

import os

print(os.getpid())

Than I have commented out print(os.getpid()) and close the file and reopened it. At this stage flycheck does not detect that 'os' imported but unused [F401]. I have to make some moditifications and save the file for it do detect it.


my setup:

(require 'flycheck)
(require 'flycheck-mypy)

(setq python-shell-interpreter "python3"
      python-shell-prompt-detect-failure-warning nil
      flycheck-python-pycompile-executable "python3"
      python-shell-completion-native-enable nil
      python-shell-completion-native-disabled-interpreters '("python3")
      elpy-shell-echo-output nil ; 
      )

(add-hook 'python-mode-hook
      (lambda ()
        ;; (setq flycheck-mypyrc "~/venv/bin/pylint")
        (setq flycheck-python-pylint-executable "~/venv/bin/pylint")
        (local-set-key (kbd "C-c C-b") 'break-point)
        (setq flycheck-pylintrc "~/.pylintrc")))

I am also using Getting flycheck “jump to next/previous error” to cycle, it won't also able to detect it till save is done.

1

You can try the following:

(setq flycheck-check-syntax-automatically '(save idle-buffer-switch idle-change new-line mode-enabled)
      flycheck-idle-buffer-switch-delay 0)

This tells flycheck to run immediately "after you switch to a buffer". The other choices like save, idle-change, new-line, and mode-enabled are already configured as the default choices. The second option reduces the delay before the check is triggered. There is also flycheck-idle-change-delay which you can reduce if you want.

2
  • What would be the smallest value I can reduce for flycheck-idle-change-delay ? or is there any recommended value for it?
    – alper
    Jan 28 at 10:12
  • The default value is 0.5, you can make it 0. Jan 29 at 4:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.