From 4ca742a28181b88723fd380d86d31fd4fea8e364 Mon Sep 17 00:00:00 2001 From: Fabian Schweinfurth Date: Fri, 23 May 2025 10:29:19 +0200 Subject: [PATCH] fix(format): lsp format scratch buffer Apheleia wants the formatters to act on the `scratch` buffer complains if `buffer` was modified. Fix: #8182 --- modules/editor/format/autoload/lsp.el | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/modules/editor/format/autoload/lsp.el b/modules/editor/format/autoload/lsp.el index f5cfe5246..4c01306a6 100644 --- a/modules/editor/format/autoload/lsp.el +++ b/modules/editor/format/autoload/lsp.el @@ -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)