0

EmacsWiki, among other sources, gives this sort of recipe to add Python checking to Flymake:

(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)))

Why is the use of local-file as a relative filename useful or desirable? I instead use:

(defun flymake-flake8-init ()
  (unless (file-remote-p default-directory)
    (let ((temp-file (flymake-init-create-temp-buffer-copy
                      'flymake-create-temp-with-folder-structure)))
      `("flake8" ("--max-complexity=10" ,temp-file)))))

It seems to work fine with the absolute temp-file.

Michael Hoffman
  • 32,526
  • 7
  • 64
  • 86
  • Who knows… probably `epylint` does something special when given a relative file name, probably it's just over-engineering. Code from the EmacsWiki should generally be treated with caution. –  May 23 '13 at 18:54
  • I've seen it in all sorts of flymake init functions, so it probably didn't originate with `epylint`. I assume it is just cargo cult Elisp. – Michael Hoffman May 23 '13 at 23:56
  • Yeah, likely. Probably most Flymake recipes were just copied and adapted from others, without real thinking. Btw, shameless plug, but you may want to take a look at [Flycheck](https://github.com/lunaryorn/flycheck), which is a Flymake alternative with a built-in syntax checker for flake8. Disclaimer: I am the author of this project. –  May 24 '13 at 08:26
  • It was already on my todo list :) – Michael Hoffman May 24 '13 at 14:03
  • Cool :) Please tell me how you like it and what could be improved. –  May 24 '13 at 17:31

1 Answers1

1

I am also confused this code snippet. But at least it is buggy and causes errors in the case that the working directory is represented by a symlink pathname. In such case, elisp function buffer-file-name simply returns symlink pathname of current buffer, rather than the real pathname. temp-file, however, is the real pathname of the flymake temporary file. So temp-file and the value of (file-name-directory buffer-file-name) are actually inconsistent. This discrepancy makes the relative pathname incorrect.

Yue Zhu
  • 301
  • 2
  • 6