fix(format): lsp format scratch buffer

Apheleia wants the formatters to act on the `scratch` buffer
complains if `buffer` was modified.

Fix: #8182
This commit is contained in:
Fabian Schweinfurth
2025-05-23 10:29:19 +02:00
committed by Henrik Lissner
parent f71cbb9f5c
commit 4ca742a281

View File

@ -52,7 +52,7 @@ mode unconditionally, call `+format-with-lsp-mode' instead."
(funcall callback)
(funcall callback "LSP server doesn't support formatting")))
(cl-defun +format--with-lsp-mode (beg end &key buffer callback &allow-other-keys)
(cl-defun +format--with-lsp-mode (beg end &key buffer scratch callback &allow-other-keys)
"Format the current buffer or region with any available lsp-mode formatter.
Won't forward the buffer to chained formatters if successful."
@ -68,7 +68,8 @@ Won't forward the buffer to chained formatters if successful."
;; try next chained formatter(s)
((cl-return (ignore (funcall callback)))))))
(unless (seq-empty-p edits)
(lsp--apply-text-edits edits 'format))
(with-current-buffer scratch
(lsp--apply-text-edits edits 'format)))
t)))
(cl-defun +format--with-eglot (beg end &key buffer callback &allow-other-keys)