prettier/prettier-emacs

Name: prettier-emacs

Owner: Prettier

Description: Minor mode to format JS code on file save

Created: 2017-05-29 15:56:34.0

Updated: 2018-01-15 12:33:21.0

Pushed: 2018-01-09 07:26:07.0

Homepage: http://jlongster.com/A-Prettier-Formatter

Size: 22

Language: Emacs Lisp

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Prettier-js for Emacs

MELPA

prettier-js is a function that formats the current buffer using prettier. The package also exports a minor mode that applies (prettier-js) on save.

Configuration
Requirements

Ensure that the prettier program is installed:

h prettier

If prettier is not installed already, you can install prettier using npm -g prettier or via your package manager.

Basic configuration

First require the package:

uire 'prettier-js)

Then you can hook to your favorite javascript mode:

-hook 'js2-mode-hook 'prettier-js-mode)
-hook 'web-mode-hook 'prettier-js-mode)

Prettier arguments

To adjust the CLI args used for the prettier command, you can customize the prettier-js-args variable:

q prettier-js-args '(
-trailing-comma" "all"
-bracket-spacing" "false"

Usage with web-mode

Web-mode is a popular mode for editing .js and .jsx files, but it is used to edit other template files too. If you want to hook prettier-js to web-mode for .js and .jsx files only, you can define a helper function like this:

un enable-minor-mode (my-pair)
nable minor mode if filename match the regexp.  MY-PAIR is a cons cell (regexp . minor-mode)."
f (buffer-file-name)
  (if (string-match (car my-pair) buffer-file-name)
  (funcall (cdr my-pair)))))

And then hook to web-mode like this:

-hook 'web-mode-hook #'(lambda ()
                        (enable-minor-mode
                         '("\\.jsx?\\'" . prettier-js-mode))))
Customization

This package is customizable via custom.el:

customize-group prettier-js

This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.