diff --git a/modules/editor/format/autoload/format.el b/modules/editor/format/autoload/format.el index 3954cc652..467976388 100644 --- a/modules/editor/format/autoload/format.el +++ b/modules/editor/format/autoload/format.el @@ -198,7 +198,14 @@ See `+format/buffer' for the interactive version of this function, and ;;; Commands ;;;###autoload -(defalias '+format/buffer #'format-all-buffer) +(defun +format/buffer () + "Reformat the current buffer using LSP or `format-all-buffer'." + (interactive) + (call-interactively + (if (and (bound-and-true-p lsp-mode) + (lsp-feature? "textDocument/formatting")) + #'lsp-format-buffer + #'format-all-buffer))) ;;;###autoload (defun +format/region (beg end) @@ -208,10 +215,13 @@ WARNING: this may not work everywhere. It will throw errors if the region contains a syntax error in isolation. It is mostly useful for formatting snippets or single lines." (interactive "rP") - (save-restriction - (narrow-to-region beg end) - (let ((+format-region-p t)) - (+format/buffer)))) + (if (and (bound-and-true-p lsp-mode) + (lsp-feature? "textDocument/rangeFormatting")) + #'lsp-format-region + (save-restriction + (narrow-to-region beg end) + (let ((+format-region-p t)) + (+format/buffer))))) ;;;###autoload (defun +format/region-or-buffer () @@ -220,14 +230,8 @@ is selected)." (interactive) (call-interactively (if (doom-region-active-p) - (if (and (bound-and-true-p lsp-mode) - (lsp-feature? "textDocument/rangeFormatting")) - #'lsp-format-region - #'+format/region) - (if (and (bound-and-true-p lsp-mode) - (lsp-feature? "textDocument/formatting")) - #'lsp-format-buffer - #'+format/buffer)))) + #'+format/region + #'+format/buffer))) ;;