{"id":13861911,"url":"https://github.com/purcell/emacs-reformatter","last_synced_at":"2025-05-16T14:04:27.205Z","repository":{"id":40635607,"uuid":"165345770","full_name":"purcell/emacs-reformatter","owner":"purcell","description":"Define commands which run reformatters on the current Emacs buffer","archived":false,"fork":false,"pushed_at":"2025-03-24T19:22:47.000Z","size":80,"stargazers_count":279,"open_issues_count":14,"forks_count":21,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-04-09T05:07:33.726Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/purcell.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","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":{"patreon":"sanityinc"}},"created_at":"2019-01-12T04:23:46.000Z","updated_at":"2025-04-06T14:29:40.000Z","dependencies_parsed_at":"2024-11-06T21:26:00.682Z","dependency_job_id":"2cd0cdff-fac0-4ae0-a069-248dcf23301a","html_url":"https://github.com/purcell/emacs-reformatter","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/purcell%2Femacs-reformatter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/purcell%2Femacs-reformatter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/purcell%2Femacs-reformatter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/purcell%2Femacs-reformatter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/purcell","download_url":"https://codeload.github.com/purcell/emacs-reformatter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254544146,"owners_count":22088807,"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:32.724Z","updated_at":"2025-05-16T14:04:27.153Z","avatar_url":"https://github.com/purcell.png","language":"Emacs Lisp","funding_links":["https://patreon.com/sanityinc","https://www.patreon.com/sanityinc"],"categories":["Emacs Lisp"],"sub_categories":[],"readme":"[![Melpa Status](http://melpa.org/packages/reformatter-badge.svg)](http://melpa.org/#/reformatter)\n[![Melpa Stable Status](http://stable.melpa.org/packages/reformatter-badge.svg)](http://stable.melpa.org/#/reformatter)\n[![NonGNU ELPA](https://elpa.nongnu.org/nongnu/reformatter.svg)](https://elpa.nongnu.org/nongnu/reformatter.html)\n[![Build Status](https://github.com/purcell/emacs-reformatter/actions/workflows/test.yml/badge.svg)](https://github.com/purcell/emacs-reformatter/actions/workflows/test.yml)\n\u003ca href=\"https://www.patreon.com/sanityinc\"\u003e\u003cimg alt=\"Support me\" src=\"https://img.shields.io/badge/Support%20Me-%F0%9F%92%97-ff69b4.svg\"\u003e\u003c/a\u003e\n\n# Define commands which run reformatters on the current Emacs buffer\n\nThis library lets elisp authors easily define an idiomatic command to\nreformat the current buffer using a command-line program, together\nwith an optional minor mode which can apply this command automatically\non save.\n\nBy default, reformatter.el expects programs to read from stdin and\nwrite to stdout, and you should prefer this mode of operation where\npossible.  If this isn't possible with your particular formatting\nprogram, refer to the options for `reformatter-define`, and see the\nexamples in the package's tests.\n\nIn its initial release it supports only reformatters which can read\nfrom stdin and write to stdout, but a more versatile interface will\nbe provided as development continues.\n\nAs an example, let's define a reformat command that applies the \"dhall\nformat\" command.  We'll assume here that we've already defined a\nvariable `dhall-command` which holds the string name or path of the\ndhall executable:\n\n```el\n(reformatter-define dhall-format\n  :program dhall-command\n  :args '(\"format\")\n  :lighter \" DF\")\n```\n\nThe `reformatter-define` macro expands to code which generates\n`dhall-format-buffer` and `dhall-format-region` interactive commands,\nand a local minor mode called `dhall-format-on-save-mode`. The `:args`\nand `:program` expressions will be evaluated at runtime, so they can\nrefer to variables that may (later) have a buffer-local value. A\ncustom variable will be generated for the mode lighter, with the\nsupplied value becoming the default.\n\nThe generated minor mode allows idiomatic per-directory or per-file\ncustomisation, via the \"modes\" support baked into Emacs' file-local\nand directory-local variables mechanisms.  For example, users of the\nabove example might add the following to a project-specific\n`.dir-locals.el` file:\n\n```el\n((dhall-mode\n   (mode . dhall-format-on-save)))\n```\n\nSee the documentation for `reformatter-define`, which provides a\nnumber of options for customising the generated code.\n\nLibrary authors might like to provide autoloads for the generated\ncode, e.g.:\n\n```el\n;;;###autoload (autoload 'dhall-format-buffer \"current-file\" nil t)\n;;;###autoload (autoload 'dhall-format-region \"current-file\" nil t)\n;;;###autoload (autoload 'dhall-format-on-save-mode \"current-file\" nil t)\n```\n\n## Examples of usage in the wild\n\nTo find reverse dependencies, look for \"Needed by\" on the [MELPA page\nfor reformatter](https://melpa.org/#/reformatter). Here are some\nspecific examples:\n\n* [dhall-mode.el](https://github.com/psibi/dhall-mode/blob/master/dhall-mode.el)\n* [elm-format.el](https://github.com/jcollard/elm-mode/blob/master/elm-format.el), in `elm-mode`\n* [sqlformat.el](https://github.com/purcell/sqlformat/blob/master/sqlformat.el)\n* [Here](https://github.com/purcell/emacs.d/blob/14f645a9bde04498ce2b60de268c2cbafa13604a/lisp/init-purescript.el#L18-L19) is the author defining a reformatter in his own configuration\n\n## Rationale\n\nI contribute to a number of Emacs programming language modes and\ntools, and increasingly use code reformatters in my daily work.  It's\nsurprisingly difficult to write robust, correct code to apply these\nreformatters, given that it must consider such issues as:\n\n* Missing programs\n* Buffers not yet saved to a file\n* Displaying error output\n* Colorising ANSI escape sequences in any error output\n* Handling file encodings correctly\n\nWith this library, I hope to help the community standardise on best\npractices, and make things easier for tool authors and end users\nalike.\n\n## FAQ\n\n### How is this different from [format-all.el](https://github.com/lassik/emacs-format-all-the-code)?\n\n`format-all` is a very different approach: it aims to provide a single\nminor mode which you then enable and configure to do the right thing\n(including nothing) for all the languages you use. It even tries to\ntell you how to install missing programs. It's an interesting project,\nbut IMO it's hard to design the configuration for such a grand unified\napproach, and it can get complex. For example, you'd have to be able\nto configure which of two possible reformatters you want to use for a\nspecific language, and to be able to do that on a per-project basis.\n\nIn contrast reformatter produces small, self-contained and separate\nformatters and minor modes which all work consistently and are\nindividually configured. It makes it possible to replace existing\nformatter code, and it's also very convenient for users to define\ntheir own ad-hoc reformatter wrappers\n\n## Installation\n\n### Manual\n\nEnsure `reformatter.el` is in a directory on your load-path, and add\nthe following to your `~/.emacs` or `~/.emacs.d/init.el`:\n\n```elisp\n(require 'reformatter)\n```\n\n### MELPA\n\nIf you're an Emacs 24 user or you have a recent version of\n`package.el` you can install `reformatter` from the\n[MELPA](http://melpa.org) repository. The version of\n`reformatter` there will always be up-to-date.\n\n## About\n\nAuthor: Steve Purcell \u003csteve at sanityinc dot com\u003e\n\nHomepage: https://github.com/purcell/emacs-reformatter\n\n\u003chr\u003e\n\n[💝 Support this project and my other Open Source work](https://www.patreon.com/sanityinc)\n\n[💼 LinkedIn profile](https://uk.linkedin.com/in/stevepurcell)\n\n[✍ sanityinc.com](https://www.sanityinc.com/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpurcell%2Femacs-reformatter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpurcell%2Femacs-reformatter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpurcell%2Femacs-reformatter/lists"}