Just a tracking post for refactor(format): replace with apheleia by elken · Pull Request #6369 · doomemacs/doomemacs · GitHub atm which intends to replace format-all
with the much more up-to-date apheleia
.
State of set-formatter!
Currently in the PR I mark it as obsolete and replace it with a no-op that advises users to use apheleia vars for formatter customisations as it handles more use cases and is already very capable than a wrapper macro.
There’s nothing we could really add that it doesn’t do already.
Per a comment from Henrik, set-formatter!
is still intended to be included.
Planned summary of changes
Remove the tests included
apheleia
already includes a comprehensive test suite and any new formatter is required to include tests to be considered. If it looks like we’re going to implement lots of our own rather than upstreaming, this can maybe be revisited.
Replace format-all
with apheleia
format-all
has been pinned and listed on do-not-pr for some time now while a replacement has been investigated. apheleia
seems like a very viable candidate, formatting even very large buffers almost instantly.
Much like some of the complex advise included in the current module, apheleia
uses an RCS patching system to only apply what changed to the buffer after it’s been saved (so as not to contest with other tools/hooks). Replacing it means the module becomes greatly simplified.
Refactor the autoloaded functions
apheleia
does not yet support formatting regions, so this will either have to be implemented via refactoring the existing functions or upstream into apheleia
.
Replace all in-doom invocations
As we have full control of the code, this should be reasonably simple. Defining a formatter per-mode or even per-buffer is extremely simple:
(setf (alist-get 'isort apheleia-formatters) '("isort" "--stdout" "-"))
(setf (alist-get 'python-mode apheleia-mode-alist) '(isort black))
The above example creates a new formatter called isort
and sets it to run before black
during python-mode
only. Simpler and more complex configurations also exist.
Per a comment from Henrik, these will be incorporated into set-formatter!
still.
Refactor docs
apheleia
also has very good documentation (as is expected from raxod), so this should mostly just be stealing borrowing snippets to go here
Default formatters/cmdline
If applicable, the default formatter/cmdline for each module. Ideally filled out by either the module maintainer or Henrik.
:lang agda
:lang agda
Doesn’t seem like there is a linter available.
:lang beancount
Supported upstream (PR)
:lang cc
Using clang-format for this with -assume-filename
making a guess on the name of the file or the mode
:lang clojure
Using zprint to handle stdin and return stdout
:lang common-lisp
Using the same format function as emacs-lisp wrapped with sly’s indent function. There is probably an argument for us to suggest a default style but it’s also very subjective…
:lang coq
:lang coq
I tried coqindent and the below function to no avail. If anyone is able to PR a working version, they’re welcome!
(cl-defun +coq-formatter (&key buffer scratch callback &allow-other-keys)
(with-current-buffer scratch
(funcall (with-current-buffer buffer major-mode))
(goto-char (point-min))
(let ((inhibit-message t)
(message-log-max nil))
(indent-region (point-min) (point-max)))
(funcall callback)))
:lang crystal
Using the builtin crystal tool format
:lang csharp
Using csharpier installed as a local tool (some extra troubleshooting steps RE: libicu need to be documented)
:lang dart
Included upstream, uses dart format
:lang data
Using xmllint included with libxml2
for XML, and nothing for CSVs which can only really be validated (if one is requested then this can be amended
:lang dhall
Using either the included dhall-mode
auto-format via +dhall-format
or by default using apheleia to call dhall lint
:lang elixir
Included upstream using mix-format
:lang elm
Supported upstream (PR)
:lang emacs-lisp
Supported upstream (PR)
:lang erlang
Using efmt
:lang ess
Needs a domain expert
:lang factor
:lang factor
Could not find one
:lang faust
:lang faust
Could not find one
:lang fortran
Using fprettify
:lang fsharp
Included upstream via this PR Seems the PR has gone stale, so fantomas will be included here.
:lang fstar
:lang fstar
Could not find one
:lang gdscript
Using gdscript-toolkit
:lang go
Included upstream
:lang graphql
Included upstream
:lang haskell
Included upstream
:lang hy
Same function as emacs-lisp uses
:lang idris
:lang idris
Couldn’t find one
:lang java
Included upstream
:lang javascript
- JS included upstream
- TS included upstream
:lang json
Included upstream
:lang julia
:lang julia
:lang kotlin
Included upstream and overridden locally.
Optionally include 'android-mode
if it is bound and loaded, otherwise everything else should be up to the user
("ktlint" "--stdin" "-F"
(when (and (boundp 'android-mode)
android-mode)
"-a"))
:lang latex
Included upstream
:lang lean
:lang lean
Couldn’t find one
:lang ledger
:lang ledger
Couldn’t find one
:lang lua
Included upstream
:lang markdown
Included upstream
:lang nim
Using nimfmt)
:lang nix
Included upstream
:lang ocaml
Included upstream
:lang org
:lang org
AFAIK one does not exist, I would love to be proven wrong though
:lang php
Included upstream
:lang plantuml
:lang plantuml
Couldn’t find one
:lang purescript
Using purs-tidy
:lang python
Included upstream
:lang qt
:lang qt
Exists via qmllint | Qt Quick 6.5.0 but I struggled to get this working
:lang racket
Using racofmt
:lang raku
:lang raku
Found an old repo but couldn’t get it working
:lang rest
:lang rest
Doesn’t make sense
:lang rst
Using rstfmt
:lang ruby
Included upstream
:lang rust
Included upstream
:lang scala
Using scalafmt
:lang scheme
Using the same function for lisps, but it doesn’t quite seem to format them
:lang sh
- Fish included upstream
- sh included upstream and overriden locally
:lang sml
Using smlformat
:lang solidity
Using prettier
:lang swift
Using swiftformat
:lang terra
Included upstream
:lang web
- CSS included upstream
- HTML included upstream
- General web-mode included upstream
:lang yaml
Included upstream
:lang zig
Using the built-in zig fmt
:tools docker
Using dockfmt
Final
This is all WIP, and anything can/will change. Any other improvements/recommendations are welcome here.
Note that this is not the place to report issues unless during active development. After this is merged and live, issues should go to the relevant areas.