![](/img/trans.png)
[英]How to integrate Prettier into a shareable ESLint configuration?
[英]How to Integrate prettier-js.el into spacemacs
我想在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)
)
)
在我的图层中
在提交9d2a108时, Spacemacs附带了一个增加对Prettier支持的图层。 如果您正在使用Spacemacs的develop
分支,或者如果您将来阅读此版本并使用0.300版本或更新版本,则可以立即使用它。
要使用它,只需在由dotspacemacs-configuration-layers
指定的图层列表中添加prettier
dotspacemacs-configuration-layers
。 此外,您应该启用Prettier作为要使用Prettier的语言的图层的格式化程序。 具体层中记录了如何执行此操作。 对于JavaScript,您应该将以下内容添加到dotspacemacs/user-init
。
(setq javascript-fmt-tool 'prettier)
通过上述配置,JavaScript层将使用Prettier来格式化JavaScript文件。
prettier-js包现在在melpa上安装它在你的spacemacs文件中添加更漂亮的js到dotspacemacs-additional-packages。
我们需要执行几个步骤才能在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.(可选)在保存时设置自动格式:
按<SPC> <f> <e> <d>
打开.spacemacs
配置文件。
找到它的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>
重新加载保存的设置
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.