Emacs - 无法让 Flymake 与 JSHint 一起使用
我正在尝试让 JSHint 与 Flymake 一起使用。
jshint
确实安装在 /opt/bin
中并且可以工作。 /opt/bin
位于 Emacs 的 exec-path
中。
我已遵循 EmacsWiki 上的说明,并将其放入我的 init.el< /code>:
(defun flymake-jshint-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 "jshint" (list local-file))))
(setq flymake-err-line-patterns
(cons '("^ [[:digit:]]+ \\([[:digit:]]+\\),\\([[:digit:]]+\\): \\(.+\\)$"
nil 1 2 3)
flymake-err-line-patterns))
(add-to-list 'flymake-allowed-file-name-masks
'("\\.js\\'" flymake-jshint-init))
当我打开 JavaScript 文件时,我的模型行显示为:
[(Javascript Flymake* AC)]
这很奇怪,因为当我将 Flymake 与 C++ 或 Python 一起使用时,*
通常不会出现。根据 Flymake 文档,Flymake*
表示“Flymake 当前正在运行”。然而,Flymake 没有显示任何错误。
我已经检查了 *Messages* 缓冲区,但它只列出了几行 Fontifying foo.js... (regexps.............. ......)
。没有错误。
其他建议?
I'm trying to get JSHint to work with Flymake.
jshint
is indeed installed in /opt/bin
and works. /opt/bin
is in Emacs' exec-path
.
I've followed the directions on the EmacsWiki and have this in my init.el
:
(defun flymake-jshint-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 "jshint" (list local-file))))
(setq flymake-err-line-patterns
(cons '("^ [[:digit:]]+ \\([[:digit:]]+\\),\\([[:digit:]]+\\): \\(.+\\)$"
nil 1 2 3)
flymake-err-line-patterns))
(add-to-list 'flymake-allowed-file-name-masks
'("\\.js\\'" flymake-jshint-init))
When I open JavaScript files, my modeline appears as:
[(Javascript Flymake* AC)]
This is odd because the *
usually doesn't appear when I'm using Flymake with C++ or Python. According to the Flymake docs, Flymake*
means "Flymake is currently running." However, Flymake isn't showing any errors.
I've checked the *Messages*
buffer but it only lists a few lines of Fontifying foo.js... (regexps...................)
. No errors.
Other suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试使用
M-:
执行(setq Flymake-log-level 3)
,这将使 Flymake 将调试信息打印到*Messages*
。这是我如何将 Flymake 与 jslint 结合使用,效果很好对我来说——该代码可能会给你一些关于你出了什么问题的线索。
您还可以考虑
js2-mode
,它提供一些语言感知的类似 lint 的警告,而无需运行外部进程。Try using
M-:
to execute(setq flymake-log-level 3)
, which will cause flymake to print debug info into*Messages*
.Here's how I use flymake with jslint, which works nicely for me -- that code might give you a clue about what's going wrong for you.
You might also consider
js2-mode
, which provides some language-aware lint-like warnings without resorting to running an external process.我找到了一个名为 jshint-mode 的项目并进行了尝试。它创建了一个名为 *jshint-mode* 的缓冲区,它揭示了错误:JSHint 找不到强大的模块。
我在 Emacs 中运行 Mx setenv 来设置
NODE_PATH
,以便jshint
可以找到强大的库。我还在/etc/profile
中设置了NODE_PATH
。I found a project called jshint-mode and tried that. It created a buffer called
*jshint-mode*
which revealed the error: JSHint couldn't find the formidable module.I ran M-x setenv in Emacs to set
NODE_PATH
so thatjshint
could find the formidable library. I also setNODE_PATH
in/etc/profile
.jshint-mode 对我不起作用(我使用 Linux Mint 14 'Nadia')——我当运行
curl
与运行 jshint 脚本的 Node.js 实例对话时,“flymake 的配置”出现错误。这很令人困惑,而且我不熟悉 ELisp 来搞乱.el
文件。我通过直接访问 github 上的 Emacs flymake 项目 fork 解决了这个问题,该项目现在支持 jshint内置(它需要安装为
npm -g install jshint
,这反过来要求您安装npm
和 node.js(如果尚未安装)。这使得事情顺利进行。还要注意一点:在我的 Linux 机器上,
node
是一个已存在于/usr/sbin
中的可执行文件,我必须创建一个名为node
的符号链接> 在/usr/local/bin
中覆盖前者。这是必要的,因为 Linux Mint(也可能是 Ubuntu,我还没有检查)的 Node.js 二进制文件被命名为nodejs
,并且会导致许多脚本假设二进制名称为node失败。您可以通过输入
node
进行测试:如果它是预先存在的二进制文件,它通常会默默地返回到提示符,但如果它是 Node.js,它会用>
提示您code> (你可以按 Ctrl-D 退出)jshint-mode did not work for me (I use Linux Mint 14 'Nadia') -- I was getting errors with "flymake's configuration" when it runs
curl
to talk to the Node.js instance running the jshint script. This was perplexing, and I'm not familiar with ELisp to go around messing with the.el
files.I solved this by instead going straight to the Emacs flymake project fork on github which now has support for jshint built-in (it needs to be installed as
npm -g install jshint
which in turn requires you to installnpm
and node.js if you haven't already). This made things work.One more caveat: on my Linux box,
node
was an executable already existing in/usr/sbin
and I had to make a symbolic link namednode
in/usr/local/bin
to override the former. This was necessary as the Node.js binary for Linux Mint (possibly Ubuntu as well, I haven't checked) is namednodejs
instead and will cause many scripts written assuming a binary name ofnode
to fail. You can test this by typingnode
: if it is the pre-existing binary it generally returns to the prompt silently, but if it is Node.js it prompts you with a>
(you can Ctrl-D to quit out of there)