fix(format): lsp-mode/eglot formatters
There seems to be context that eglot needs that isn't available in Apheleia's scratch buffer. Fix: #7962
This commit is contained in:
parent
879c0b06a4
commit
a0c901cca7
2 changed files with 45 additions and 45 deletions
|
@ -8,6 +8,9 @@
|
|||
|
||||
;;;###autoload (autoload 'apheleia--get-formatters "apheleia-formatters")
|
||||
|
||||
;;;###autoload
|
||||
(defvar +format--region-p nil)
|
||||
|
||||
;;;###autoload
|
||||
(defun +format-region (start end &optional callback)
|
||||
"Format from START to END with `apheleia'."
|
||||
|
@ -41,22 +44,21 @@
|
|||
(when (> indent 0)
|
||||
(indent-rigidly (point-min) (point-max) (- indent)))
|
||||
;;
|
||||
(apheleia-format-buffer
|
||||
command
|
||||
(lambda ()
|
||||
(with-current-buffer formatted-buffer
|
||||
(when (> indent 0)
|
||||
;; restore indentation without affecting new indentation
|
||||
(indent-rigidly (point-min) (point-max)
|
||||
(max 0 (- indent (+format--current-indentation)))))
|
||||
(set-buffer-modified-p nil))
|
||||
(with-current-buffer cur-buffer
|
||||
(delete-region start end)
|
||||
(goto-char start)
|
||||
(save-excursion
|
||||
(insert-buffer-substring-no-properties formatted-buffer)
|
||||
(when callback (funcall callback)))
|
||||
(kill-buffer formatted-buffer)))))
|
||||
(let ((+format--region-p (cons start end)))
|
||||
(apheleia-format-buffer
|
||||
command
|
||||
(lambda ()
|
||||
(with-current-buffer formatted-buffer
|
||||
(when (> indent 0)
|
||||
;; restore indentation without affecting new indentation
|
||||
(indent-rigidly (point-min) (point-max)
|
||||
(max 0 (- indent (+format--current-indentation)))))
|
||||
(set-buffer-modified-p nil))
|
||||
(with-current-buffer cur-buffer
|
||||
(with-silent-modifications
|
||||
(replace-region-contents start end (lambda () formatted-buffer) 5))
|
||||
(when callback (funcall callback))
|
||||
(kill-buffer formatted-buffer))))))
|
||||
(when (doom-region-active-p)
|
||||
(setq deactivate-mark t)))))
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue