我试图让prettier在spacemacs中工作。
我(prettier-js :location (recipe :url "https://raw.githubusercontent.com/prettier/prettier/master/editors/emacs/prettier-js.el" :fetcher url))
有点工作,但是在消息中我看到了
Contacting host: raw.githubusercontent.com:443
Wrote /Users/travis/.emacs.d/.cache/quelpa/build/prettier-js/prettier-js.el
File: /Users/travis/.emacs.d/.cache/quelpa/build/prettier-js/prettier-js.stamp
Error getting PACKAGE-DESC: (search-failed ;;; prettier-js.el ends here)
Cannot load prettier-js
我不知道足够的emacs还知道PACKAGE-DESC的功能,或者我是否需要它来加载更漂亮。
我试图在私有层中执行此操作
文档说:
将此添加到您的init
(require 'prettier-js)
(add-hook 'js-mode-hook
(lambda ()
(add-hook 'before-save-hook 'prettier-before-save)))
我想我应该有类似的东西:
(defun myJS/post-init-prettier-js ()
"Initialize prettier-js"
(use-package prettier-js)
:defer t
:init
(progn
(add-hook 'before-save-hook 'prettier-before-save)
)
)
在我的图层
答案 0 :(得分:5)
从提交9d2a108开始,Spacemacs附带了一个添加对Prettier的支持的层。如果您正在使用Spacemacs的develop
分支,或者将来要阅读此书,并且正在使用版本0.300或更高版本,则可以今天使用它。
要使用它,只需将prettier
添加为dotspacemacs-configuration-layers
指定的层列表中的一层。此外,您应该为要使用Prettier的语言的层启用Prettier作为格式器。具体层中记录了如何执行此操作。对于JavaScript,您应将以下内容添加到dotspacemacs/user-init
中。
(setq javascript-fmt-tool 'prettier)
使用上述配置,JavaScript层将使用户更漂亮以格式化JavaScript文件。
答案 1 :(得分:3)
prettier-js包现在在melpa上安装它在你的spacemacs文件中添加更漂亮的js到dotspacemacs-additional-packages。
答案 2 :(得分:2)
要在 Spacemacs 中激活prettier
,我们需要执行一些步骤:
1。在Spacemacs中安装prettier
集成:
<SPC> <SPC>
(按两次空格键),这将触发 HELM ,允许我们搜索Emacs命令。
在按下<SPC> <SPC>
之后,在 HELM 缓冲区中键入package-install
,然后按下<RET>
(Return / Enter键)。
软件包列表将出现在 HELM软件包安装缓冲区中,在其中键入prettier-js
,然后按<RET>
。
2。在您的系统中安装prettier
:
没有prettier
本身,集成不会做任何事情。
假设您已经安装了node
和npm
,请转到终端并输入:npm install -g prettier
,然后按Enter。
3。 (可选)在保存时设置自动格式:
通过按.spacemacs
打开<SPC> <f> <e> <d>
配置文件。
找到它的dotspacemacs/user-config
部分,然后在其中键入以下代码段:
(defun dotspacemacs/user-config ()
(add-hook 'js2-mode-hook 'prettier-js-mode)
(add-hook 'web-mode-hook 'prettier-js-mode)
)
通过按<SPC> <f> <s>
通过按<SPC> <f> <e> <R>