views:

111

answers:

3

Hi,

I am trying to use Pylint with Emacs on Windows XP. My Emacs version is EmacsW32 23.1, pylint is 0.21.3 with Python 2.5. After easy_install pylint, I added the following lines to Emacs init file, copied form Emacs Wiki.

When I invoke the flymake-mode on a .py file, I can see the flymake starting the syntax check, the mode status changed to flymake*, and then goes back to flymake after several seconds. But no error is reported, and no syntax error highlighting.

I tried to use pylint in command line, and it works with command "pylint test.py", reporting syntax errors on the same file.

I even tried to clear out my .emacs file, but it doesn't help.

Could someone help me on this? Thanks a lot.

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

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

Question Update: I tried the following at command line prompt with "pylint" and "epylint". Does this mean epylint has a problem?

C:\Projects>pylint test_lib.py
No config file found, using default configuration
************* Module test_lib
E: 13: invalid syntax

C:\Projects>epylint test_lib.py
'test_lib.py':1: [F] No module named 'test_lib.py'

C:\Projects>epylint
Traceback (most recent call last):
  File "C:\Python25\Scripts\epylint", line 5, in <module>
    pkg_resources.run_script('pylint==0.21.3', 'epylint')
  File "C:\Python25\Lib\site-packages\pkg_resources.py", line 489, in run_script

    self.require(requires)[0].run_script(script_name, ns)
  File "C:\Python25\Lib\site-packages\pkg_resources.py", line 1207, in run_script
    execfile(script_filename, namespace, namespace)
  File "c:\python25\lib\site-packages\pylint-0.21.3-py2.5.egg\EGG-INFO\scripts\epylint", line 3, in <module>
    epylint.Run()
  File "c:\python25\lib\site-packages\pylint-0.21.3-py2.5.egg\pylint\epylint.py", line 93, in Run
    lint(sys.argv[1])
IndexError: list index out of range
A: 

I use emacs22-nox on linux so you may need to google "font-lock-mode" to figure out how to do it on your computer. First enter the emacs command line by pressing Esc+x. Now you can type font-lock-mode and hit enter (the command line is at the bottom of the screen). I had the same problem on one my clients servers. Their emacs didn't turn font-lock-mode on by default. Hope that helps.

dustynachos
The font-lock-mode was turned on. If I enter "font-lock-mode" again, it will be disabled. My color-theme is working with either .el or .py files.
Jim
+2  A: 

The program called by flymake should return 0 errorlevel or else flymake thinks there have been problems calling subprocesses.

Reading this answer and those patches, I have managed to run flymake with pylint :

On Windows, but you could do the same kind of thing on Un*x, I have created a batch file pycheckers.bat (accessible in your PATH) :

pylint -f parseable -r n --disable=C,R,I %1 %2 %3 %4 %5 %6 %7 %8 %9
exit /b 0

In my .emacs, I have put those lines :

(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 "pycheckers"  (list local-file))))
  (add-to-list 'flymake-allowed-file-name-masks
               '("\\.py\\'" flymake-pyflakes-init)))

Now, when I open a .py file, I do a M-x flymake-mode to activate it. Flymake finds my python errors and warnings without problem.

Note that you can add other tools in the pycheckers.bat file.

Jérôme Radix
Thanks Jerome. It works. But I still don't understand why the installed epylint.bat and epylint does not work.
Jim
epylint.bat: python "%~dpn0" %*
Jim
epylint:#!C:\Python25\python.exe# EASY-INSTALL-SCRIPT: 'pylint==0.21.3','epylint'__requires__ = 'pylint==0.21.3'import pkg_resourcespkg_resources.run_script('pylint==0.21.3', 'epylint')
Jim
Also, all the Pylint output:warnings, errors, conventions are highlighted by the same color. customize-face RET flymake-warnline does not help.
Jim
A: 

I tried Jerome's answer on Ergoemacs and it works. The problem is as he said: Pylint returns non 0 errorlevel as it uses the errorlevel to give information about problems. I wanted to vote up Jerome's answer but I don't have any reputation.