Skip to content

Commit e008d1f

Browse files
committed
feat(format): add emacs-lisp formatter
Introduce a formatter function for emacs-lisp (tracked upstream here [1]) that tries to preserve as much of what the user wants as possible [1]: radian-software/apheleia#102
1 parent e3cdbbb commit e008d1f

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

modules/editor/format/config.el

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,19 @@ select buffers.")
5151

5252
(after! apheleia-mode
5353
;; TODO html-tidy
54-
)
54+
(cl-defun apheleia--indent-lisp-buffer
55+
(&key buffer scratch callback &allow-other-keys)
56+
"Format a Lisp BUFFER. Use SCRATCH as a temporary buffer and CALLBACK to
57+
apply the transformation. For more implementation detail, see
58+
`apheleia--run-formatter-function'."
59+
(with-current-buffer scratch
60+
(setq-local indent-line-function
61+
(buffer-local-value 'indent-line-function buffer))
62+
(setq-local lisp-indent-function
63+
(buffer-local-value 'lisp-indent-function buffer))
64+
(funcall (with-current-buffer buffer major-mode))
65+
(goto-char (point-min))
66+
(let ((inhibit-message t)
67+
(message-log-max nil))
68+
(indent-region (point-min) (point-max)))
69+
(funcall callback))))

modules/lang/emacs-lisp/config.el

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ employed so that flycheck still does *some* helpful linting.")
3535
:documentation #'+emacs-lisp-lookup-documentation)
3636
(set-docsets! '(emacs-lisp-mode lisp-interaction-mode) "Emacs Lisp")
3737
(set-ligatures! 'emacs-lisp-mode :lambda "lambda")
38+
(set-formatter! 'lisp-indent #'apheleia--indent-lisp-buffer :modes '(emacs-lisp-mode))
3839
(set-rotate-patterns! 'emacs-lisp-mode
3940
:symbols '(("t" "nil")
4041
("let" "let*")

0 commit comments

Comments
 (0)