當從命令行運行(emacs filename.py
)時,flymake和pylint可以很好地協同工作。錯誤被正確突出顯示。 (雖然我無法提示懸停以獲取錯誤細節,因爲它是文本模式。)Pylint不能在OS X上使用Emacs GUI;從命令行運行
從GUI(Carbon Emacs)運行時,Flymake立即返回,並且文件中的第一行突出顯示錯誤「in <module>
」。第一行顯示錯誤,即使在「Hello World」腳本中。)我想在GUI模式下正常工作,以便我可以用鼠標導航(我知道,我知道)並使用工具提示獲取詳細信息在pylint上報告錯誤。
我用「easy_install pylint
」安裝了pylint,並且pylint和epylint腳本位於「~/py/scripts
」中。我添加了目錄,是我路上在我的.bashrc:
export PATH=$PATH:~/py/scripts
(我的.profile文件是一個符號鏈接到我的.bashrc)
我意識到,Emacs的圖形用戶界面並沒有從我的加載路徑。因此我創建了一個〜/ .MacOSX/environment.plist文件,並使用我在終端中看到的完整路徑設置PATH變量。
在Emacs的GUI現在 「(getenv "PATH")
」 則輸出正確的:
"/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin:/usr/X11/bin:/Users/schof/py/scripts:/usr/X11R6/bin"
同樣, 「C-h v exec-path
」 則輸出正確的:
("/usr/bin" "/bin" "/usr/sbin" "/sbin" "/usr/local/bin" "/usr/local/git/bin" "/usr/X11/bin" "/Users/schof/py/scripts" "/Applications/Emacs.app/Contents/MacOS/libexec" "/Applications/Emacs.app/Contents/MacOS/bin" "/usr/X11R6/bin")
這使我沒有進一步的想法我該如何解決這個問題。我絕不是emacs大師,所以我可能在這裏錯過了一些明顯的東西;隨時索取更多細節。
OS X 10.6.7;碳Emacs 22.3.1; pylint 0.23.0。從的.emacs
Flymake/pylint的代碼:
(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)))
;; Auto-start flymake-mode when you go into python-mode
(add-hook 'python-mode-hook
'(lambda()
(setq python-indent 4)
(flymake-mode)))
更新2011-04-05響應@ sanityinc的回答是:
詳細級別3輸出flymake的*messages*
:(這確實沒有使問題的根源對我來說是顯而易見的。)
starting syntax check as new-line has been seen
flymake is running: nil
file /Users/schof/pytest.py, init=flymake-pylint-init [3 times]
create-temp-inplace: file=/Users/schof/pytest.py temp=/Users/schof/pytest_flymake.py
saved buffer pytest.py in file /Users/schof/pytest_flymake.py
started process 3221, command=(epylint pytest_flymake.py), dir=/Users/schof/
received 704 byte(s) of output from process 3221
file /Users/schof/pytest.py, init=flymake-pylint-init
parsed 'Traceback (most recent call last):', no line-err-info
parse line: file-idx=2 line-idx=3 file=/Users/schof/py/scripts/epylint line=4 text=in <module>
get-real-file-name: file-name=/Users/schof/py/scripts/epylint real-name=~/py/scripts/epylint
parsed ' File "/Users/schof/py/scripts/epylint", line 4, in <module>', got line-err-info
parsed ' import pkg_resources', no line-err-info
parse line: file-idx=2 line-idx=3 file=/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/pkg_resources.py line=2556 text=in <module>
get-real-file-name: file-name=/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/pkg_resources.py real-name=/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/pkg_resources.py
parsed ' File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/pkg_resources.py", line 2556, in <module>', got line-err-info
parsed ' working_set.require(__requires__)', no line-err-info
parse line: file-idx=2 line-idx=3 file=/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/pkg_resources.py line=620 text=in require
get-real-file-name: file-name=/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/pkg_resources.py real-name=/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/pkg_resources.py
parsed ' File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/pkg_resources.py", line 620, in require', got line-err-info
parsed ' needed = self.resolve(parse_requirements(requirements))', no line-err-info
parse line: file-idx=2 line-idx=3 file=/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/pkg_resources.py line=518 text=in resolve
get-real-file-name: file-name=/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/pkg_resources.py real-name=/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/pkg_resources.py
parsed ' File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/pkg_resources.py", line 518, in resolve', got line-err-info
parsed ' raise DistributionNotFound(req) # XXX put more info here', no line-err-info
parsed 'pkg_resources.DistributionNotFound: pylint==0.23.0', no line-err-info
file /Users/schof/pytest.py, init=flymake-pylint-init
process 3221 exited with code 1
cleaning up using flymake-simple-cleanup
deleted file /Users/schof/pytest_flymake.py
created an overlay at (1-18)
pytest.py: 4 error(s), 0 warning(s) in 0.47 second(s)
爲了比較,這裏是flymake verbosit的輸出y 3從emacs運行時文本模式。 「hello world」文件通過了所有的pylint測試。
starting syntax check as new-line has been seen
flymake is running: nil
file /Users/schof/pytest.py, init=flymake-pylint-init [3 times]
create-temp-inplace: file=/Users/schof/pytest.py temp=/Users/schof/pytest_flymake.py
saved buffer pytest.py in file /Users/schof/pytest_flymake.py
started process 3395, command=(epylint pytest_flymake.py), dir=/Users/schof/
file /Users/schof/pytest.py, init=flymake-pylint-init
process 3395 exited with code 0
cleaning up using flymake-simple-cleanup
deleted file /Users/schof/pytest_flymake.py
pytest.py: 0 error(s), 0 warning(s) in 0.30 second(s)
完整的錯誤會有所幫助。它看起來像flymake *正在運行,否則你可能不會得到一個「在」錯誤。我的猜測是你的'PYTHONPATH'在終端和GUI上是不同的。我也很驚訝'.MacOSX /環境'技巧的作品。你在運行雪豹嗎? –
milkypostman
2011-04-05 18:37:58
是的,雪豹10.6.7。 – Schof 2011-04-06 03:24:16
離開城市而無法上網(沒想到這需要很長時間才能解決)。將於4月11日回覆並回復其他問題/測試建議。 – Schof 2011-04-06 07:03:31