diff options
| author | Mohsin Kaleem <mohkale@kisara.moe> | 2021-12-27 18:00:21 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-12-27 10:00:21 -0800 |
| commit | 2e9816513789c233acc79493523a7e1aa5b3eeb6 (patch) | |
| tree | 26f43ff2238443e4dfc0e2dfb7c85cecb6023d1e /README.md | |
| parent | e700c78a5db4ea9599b2d04bbc8e4c40ce822c37 (diff) | |
[#62] Support functions as formatters (#63)
* [#62] Support functions as formatters
Closes #62.
Lets you use a lisp function as a formatter. This gives apheleia a lot
more flexibility in regards to what constitutes a formatter. For example
you can now plug an external language server or another tool as a
formatter for use with apheleia.
Here's a very basic example of using indent-line-function with apheleia
after merging this commit. Note: this doesn't take into account any
special local variables in the original buffer such as lisp-body-indent.
It's really just for demonstration purposes and as a proof of concept.
```lisp
(defun apheleia-indent-region+ (orig scratch callback)
(with-current-buffer scratch
(setq-local indent-line-function
(buffer-local-value 'indent-line-function orig))
(indent-region (point-min)
(point-max))
(funcall callback scratch)))
(push '(indent-region . apheleia-indent-region+) apheleia-formatters)
(push '(elisp-mode . indent-region) apheleia-mode-alist)
(push '(lisp-interaction-mode . indent-region) apheleia-mode-alist)
```
* Fix misc-bugs + prevent race conditions
* Update docstring
* Reword a bit
* Add to README
Co-authored-by: Radon Rosborough <radon.neon@gmail.com>
Diffstat (limited to 'README.md')
| -rw-r--r-- | README.md | 5 |
1 files changed, 5 insertions, 0 deletions
@@ -119,6 +119,11 @@ variables: example a buffer called `*foo-bar.c*` that has no associated file will have an implicit file-name of `foo-bar.c` and any temporary files will be suffixed with a `.c` extension. + * You can implement formatters as arbitrary Elisp functions which + operate directly on a buffer, without needing to invoke an + external command. This can be useful to integrate with e.g. + language servers. See the docstring for more information on the + expected interface for Elisp formatters. * `apheleia-mode-alist`: Alist mapping major modes and filename regexps to names of formatters to use in those modes and files. See the docstring for more information. |
