从命令行(emacs filename.py)运行时,flymake和pylint完美地协同工作.错误被正确突出显示. (虽然我无法工具提示悬停以获取错误详细信息,因为它是文本模式.)
当从GUI(Carbon Emacs)运行时,Flymake立即返回,并且文件中的第一行突出显示错误“in< module>”.第一行甚至在“Hello World”脚本上显示错误.)我想让它在GUI模式下正常工作,这样我就可以用鼠标导航(我知道,我知道)并使用工具提示来获取详细信息关于pylint报告的错误.
我用“easy_install pylint”安装了pylint,pylint和epylint脚本在“〜/ py / scripts”中.我将该目录添加到我的.bashrc中的PATH中:
export PATH=$PATH:~/py/scripts
(我的.profile是我的.bashrc的符号链接.)
我意识到Emacs-GUI没有从我的.bashrc加载路径,所以我创建了一个〜/ .MacOSX / environment.plist文件,用我在终端中看到的完整PATH设置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的回答:
* message *中的flymake的详细级别3输出:(这不会使问题的根源对我来说很明显.)
starting syntax check as new-line has been seenflymake is running: nilfile /Users/schof/pytest.py, init=flymake-pylint-init [3 times]create-temp-inplace: file=/Users/schof/pytest.py temp=/Users/schof/pytest_flymake.pysaved buffer pytest.py in file /Users/schof/pytest_flymake.pystarted process 3221, command=(epylint pytest_flymake.py), dir=/Users/schof/received 704 byte(s) of output from process 3221file /Users/schof/pytest.py, init=flymake-pylint-initparsed 'Traceback (most recent call last):', no line-err-infoparse 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/epylintparsed ' File "/Users/schof/py/scripts/epylint", line 4, in <module>', got line-err-infoparsed ' import pkg_resources', no line-err-infoparse 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.pyparsed ' File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/pkg_resources.py", line 2556, in <module>', got line-err-infoparsed ' working_set.require(__requires__)', no line-err-infoparse 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 requireget-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.pyparsed ' File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/pkg_resources.py", line 620, in require', got line-err-infoparsed ' needed = self.resolve(parse_requirements(requirements))', no line-err-infoparse 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 resolveget-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.pyparsed ' File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/pkg_resources.py", line 518, in resolve', got line-err-infoparsed ' raise DistributionNotFound(req) # XXX put more info here', no line-err-infoparsed 'pkg_resources.DistributionNotFound: pylint==0.23.0', no line-err-infofile /Users/schof/pytest.py, init=flymake-pylint-initprocess 3221 exited with code 1cleaning up using flymake-simple-cleanupdeleted file /Users/schof/pytest_flymake.pycreated an overlay at (1-18)pytest.py: 4 error(s), 0 warning(s) in 0.47 second(s)
为了比较,这是从emacs文本模式运行时flymake verbosity 3的输出. “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的日志级别,然后查看* messages *:
(setq flymake-log-level 3)
没有这些信息,我不会推测可能存在的问题.
有一个避免环境.plist方法,BTW的技巧;您可以让Emacs向您的常规shell询问您的首选路径:
(defun set-exec-path-from-shell-PATH () (let ((path-from-shell (replace-regexp-in-string "[ \t\n]*$" "" (shell-command-to-string "$SHELL --login -i -c 'echo $PATH'")))) (setenv "PATH" path-from-shell) (setq exec-path (split-string path-from-shell path-separator))))(when (and window-system (eq system-type 'darwin)) ;; When started from Emacs.app or similar, ensure $PATH ;; is the same the user would see in Terminal.app (set-exec-path-from-shell-PATH))
(这是从my Emacs config开始的,其中包含一堆flymake代码,包括使用pyflakes的python配置,所以你可能想看看.)
更新:既然你已经添加了详细输出,我看到你的〜/ py / epylint程序找不到pkg_resources,它指向PYTHONPATH错误.因此,使用上述技术的变体,试试这个:
(defun setenv-from-shell (varname) (setenv varname (replace-regexp-in-string "[ \t\n]*$" "" (shell-command-to-string (concat "$SHELL --login -i -c 'echo $" varname "'")))))(setenv-from-shell "PYTHONPATH")
来源:https://www.icode9.com/content-1-299801.html
联系客服