下記参考サイトのようにやっても、PEP8のチェックがうまく動かなかったのでメモ。
- yamakk blog » Blog Archive » PEP8 and pyflakes for emacs
- PEP8をEmacsで - きちめも
- emacs の python 開発環境を整える - フリーフォーム フリークアウト
- Charlie's Second Blog: Check python coding style on the fly with emacs
(環境: MacOSX10.7, Emacs23.3.1, Python2.7)
EmacsWikiに載ってたものをちょいといじってみた
lintrunner.py を使ってやってみた。
Newest version of this code from the original author here.
EmacsWiki: Python Programming In Emacs
下準備、インストールなど
MacPortsでインストール
- python27
- py27-pyflakes
- command = pyflakes-2.7
- py27-pip
- command = pip-2.7
pipでインストール
- pep8
- command = pep8.py
『lintrunner.py』をダウンロードして若干いじる
『/opt/local/bin/』あたりに置いて。実行権限を与える。
line:12
PEP8_COMMAND = "pep8.py" PYFLAKES_COMMAND = "pyflakes-2.7"
line:241
Pep8とPyflakesだけ使うので(CompilerRunnerはいるのか?)
for runnerclass in (# PylintRunner, # PycheckerRunner, Pep8Runner, PyflakesRunner, CompilerRunner):
class Pep8Runner*1
日本語とか1文字=2文字とカウントするらしく、コメント書いたりするとすぐ『E501: line too long』と1行80文字オーバーのエラーが出る。
なのでE501は無視する。
class Pep8Runner(LintRunner): : sane_default_ignore_codes = set([ "E501", #line too long ]) : @property def run_flags(self): # return '--repeat', '--ignore=' + ','.join(self.ignore_codes) return '--repeat', '--ignore=' + ','.join(self.operative_ignore_codes)
init.el
(when (load "flymake" t) ;; FlymakePython (defun flymake-pyflakes-init () (when (not (subsetp (list (current-buffer)) (tramp-list-remote-buffers))) (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 "lintrunner.py" (list local-file))))) (add-to-list 'flymake-allowed-file-name-masks '("\\.py\\'" flymake-pyflakes-init)) (add-hook 'python-mode-hook (lambda () (flymake-mode t))) )
動作確認
hoge.pyを開くとこのエントリー始めの画像のような感じになる。
pyflakesのチェックは赤色、PEP8のチェックは青紫色。
*1:追記:20120118