{"id":13862955,"url":"https://github.com/prettier/prettier-emacs","last_synced_at":"2025-04-05T03:11:51.853Z","repository":{"id":45359126,"uuid":"92754468","full_name":"prettier/prettier-emacs","owner":"prettier","description":"Minor mode to format JS code on file save","archived":false,"fork":false,"pushed_at":"2024-06-19T20:39:32.000Z","size":22,"stargazers_count":376,"open_issues_count":39,"forks_count":54,"subscribers_count":10,"default_branch":"master","last_synced_at":"2024-10-29T15:15:08.507Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://jlongster.com/A-Prettier-Formatter","language":"Emacs Lisp","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/prettier.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"prettier","open_collective":"prettier","tidelift":"npm/prettier"}},"created_at":"2017-05-29T15:56:34.000Z","updated_at":"2024-10-18T12:26:50.000Z","dependencies_parsed_at":"2023-12-14T20:06:17.173Z","dependency_job_id":"476648d9-5eef-4387-8737-c5f9818b5b7f","html_url":"https://github.com/prettier/prettier-emacs","commit_stats":{"total_commits":20,"total_committers":15,"mean_commits":"1.3333333333333333","dds":0.75,"last_synced_commit":"e9b73e81d3e1642aec682195f127a42dfb0b5774"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prettier%2Fprettier-emacs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prettier%2Fprettier-emacs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prettier%2Fprettier-emacs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prettier%2Fprettier-emacs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/prettier","download_url":"https://codeload.github.com/prettier/prettier-emacs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246726491,"owners_count":20823824,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-05T06:01:57.719Z","updated_at":"2025-04-05T03:11:51.836Z","avatar_url":"https://github.com/prettier.png","language":"Emacs Lisp","funding_links":["https://github.com/sponsors/prettier","https://opencollective.com/prettier","https://tidelift.com/funding/github/npm/prettier"],"categories":["Emacs Lisp","🔌 Editor Integrations"],"sub_categories":[],"readme":"# Prettier-js for Emacs\n[![MELPA](http://melpa.org/packages/prettier-js-badge.svg)](http://melpa.org/#/prettier-js)\n\nprettier-js is a function that formats the current buffer using [prettier](https://github.com/prettier/prettier). The\npackage also exports a minor mode that applies `(prettier-js)` on save.\n\n## Configuration\n\n### Requirements\n\nEnsure that the prettier program is installed:\n\n```bash\nwhich prettier\n```\n\nIf prettier is not installed already, you can install prettier using `npm install -g prettier` or via your package manager.\n\n\n### Basic configuration\n\nFirst require the package:\n\n```elisp\n(require 'prettier-js)\n```\n\nThen you can hook to your favorite javascript mode:\n\n```elisp\n(add-hook 'js2-mode-hook 'prettier-js-mode)\n(add-hook 'web-mode-hook 'prettier-js-mode)\n...\n```\n\n### Prettier arguments\n\nTo adjust the CLI args used for the prettier command, you can customize the `prettier-js-args` variable:\n\n```elisp\n(setq prettier-js-args '(\n  \"--trailing-comma\" \"all\"\n  \"--bracket-spacing\" \"false\"\n))\n```\n\n### Usage with web-mode\n\nWeb-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:\n\n```elisp\n(defun enable-minor-mode (my-pair)\n  \"Enable minor mode if filename match the regexp.  MY-PAIR is a cons cell (regexp . minor-mode).\"\n  (if (buffer-file-name)\n      (if (string-match (car my-pair) buffer-file-name)\n      (funcall (cdr my-pair)))))\n```\n\nAnd then hook to web-mode like this:\n\n```elisp\n(add-hook 'web-mode-hook #'(lambda ()\n                            (enable-minor-mode\n                             '(\"\\\\.jsx?\\\\'\" . prettier-js-mode))))\n```\n## Installing on Windows\n\nThis package requires the `diff` tool which is already included on Unix platforms. The simplest way to install `diff` on Windows is to use [Chocolatey](https://chocolatey.org/). The steps are as follows:\n\n1. Follow the Chocolatey install instructions: https://chocolatey.org/install\n2. Open an Admin Powershell session\n3. Install the `diff` program: `choco install diffutils`\n\nYou should now be able to open Emacs and successfully use this package.\n\n## Customization\n\nThis package is customizable via custom.el:\n\n```\nM-x customize-group prettier-js\n```\n\n* `prettier-js-command` is the prettier command\n* `prettier-js-args` are the args passed to the prettier command\n* `prettier-js-show-errors` customizes where to display the error output (buffer, echo or nil)\n* `prettier-js-width-mode` customizes the width when formatting buffer contents (window, fill or nil)\n\n## Using node_modules/.bin/prettier\n\nIf you want to use your project's prettier version you can rely on https://github.com/codesuki/add-node-modules-path\n\n```elisp\n(eval-after-load 'web-mode\n    '(progn\n       (add-hook 'web-mode-hook #'add-node-modules-path)\n       (add-hook 'web-mode-hook #'prettier-js-mode)))\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprettier%2Fprettier-emacs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fprettier%2Fprettier-emacs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprettier%2Fprettier-emacs/lists"}