简体   繁体   English

使用emacs上的flycheck即时与PEP8进行通信

[英]Conform on-the-fly to PEP8 using flycheck on emacs

I unpack flycheck to ~/. 我将flycheck解压缩到~/. and put the following lines in ~/.emacs : 并将以下行放在~/.emacs

;; (package-initialize)
(setq load-path (cons "~/flycheck-20170415.1006" load-path))
(require 'flycheck)
(add-hook 'after-init-hook #'global-flycheck-mode)

Starting Emacs 24.5.1 I get: 启动Emacs 24.5.1我得到:

File error: Cannot open load file, no such file or directory, let-alist

With Emacs 25.1.1 I get: 使用Emacs 25.1.1,我得到:

File error: Cannot open load file, No such file or directory, dash

(These errors do not change if I uncomment (package-initialize) . Emacs 25 now inserts (package-initialize) , nudging those of us with a long setup to adapt.) (如果我取消注释(package-initialize)这些错误不会改变。现在Emacs 25插入(package-initialize) ,通过长时间的设置轻推我们这些错误。)

My (subsequent) aim is to conform Python code on-the-fly to PEP8. 我(后续)的目标是使Python代码即时符合PEP8。 Once the problem above is resolved, I'll add 一旦上面的问题得到解决,我就会补充一下

(setq exec-path (append exec-path '("/opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin")))

to this brief ~/.emacs ( /opt/..2.7/bin is where MacPorts put flake8 ), but there is apparently an issue before I even specify the programming language. 这个简短的~/.emacs~/.emacs /opt/..2.7/bin ~/.emacs /opt/..2.7/bin ~/.emacs /opt/..2.7/bin是MacPorts放置flake8 ),但在我指定编程语言之前显然存在问题。

Update 更新

This is far more painful than I expected. 这比我想象的要痛苦得多。 Flycheck is heavy-handed about being installed through packages, and incorporating the steps described here to my usual ~/.emacs leads to the notorious Flycheck对于通过包装安装非常苛刻,并将这里描述的步骤结合到我常用的~/.emacs导致臭名昭着

load-with-code-conversion: Symbol’s value as variable is void: <!DOCTYPE

error. 错误。 (I'm pretty sure I have no HTML files hiding under a .el extension.) (我很确定我没有隐藏在.el扩展名下的HTML文件。)

Update2 UPDATE2

Uh.. I stand corrected! 呃..我的立场得到了纠正! Some dash.el made its way to my usual elisp directory, and flycheck depends on it, but it was indeed an HTML file. 一些dash.el进入我常用的elisp目录,而flycheck依赖于它,但它确实是一个HTML文件。

Flycheck depends on dash , let-alist , and seq . Flycheck依赖于dashlet-alistseq

Download the files 下载文件

  84766  dash.el
 381142  flycheck.el
   6136  let-alist.el
  17589  seq-24.el
  17684  seq-25.el
   1540  seq.el

and put them in ~/.concise-elisp . 并把它们放在~/.concise-elisp You need three files for seq because it has alternative implementations for Emacs 24 & 25. seq需要三个文件,因为它有Emacs 24和25的替代实现。

Put the following lines in your ~/.emacs : ~/.emacs以下行:

;; Even if you are not using packages, you need the following
;; commented-out line, or else Emacs 25 will insert one for you.
;; (package-initialize)

(setq load-path (cons "~/.concise-elisp" load-path))
(require 'flycheck)
(add-hook 'after-init-hook #'global-flycheck-mode)
(setq exec-path (append exec-path '("/opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin")))

The last line points to where MacPorts would have put flake8 . 最后一行指向MacPorts放置flake8 Flake8 is one of the programs to which flycheck delegates PEP8 checking. Flake8是flycheck委托PEP8检查的程序之一。

Next exercise: Hook flycheck just for Python (and perhaps C/C++/Java/JS/..). 下一个练习:Hook flycheck仅适用于Python(也许是C / C ++ / Java / JS / ..)。 In particular, don't worry about making elisp files kosher. 特别是,不要担心使elisp文件犹太洁食。 Selectively activate flycheck for languages as needed. 根据需要有选择地激活语言的flycheck

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM