diff --git a/modules/editor/format/autoload/format.el b/modules/editor/format/autoload/format.el index d43f2a54e..8dad3b4ec 100644 --- a/modules/editor/format/autoload/format.el +++ b/modules/editor/format/autoload/format.el @@ -206,7 +206,8 @@ See `+format/buffer' for the interactive version of this function, and "Reformat the current buffer using LSP or `format-all-buffer'." (interactive) (call-interactively - (if (and (bound-and-true-p lsp-mode) + (if (and +format-with-lsp + (bound-and-true-p lsp-mode) (lsp-feature? "textDocument/formatting")) #'lsp-format-buffer #'format-all-buffer))) @@ -219,7 +220,8 @@ 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") - (if (and (bound-and-true-p lsp-mode) + (if (and +format-with-lsp + (bound-and-true-p lsp-mode) (lsp-feature? "textDocument/rangeFormatting")) #'lsp-format-region (save-restriction diff --git a/modules/editor/format/config.el b/modules/editor/format/config.el index 240f2269f..9ba0a0fed 100644 --- a/modules/editor/format/config.el +++ b/modules/editor/format/config.el @@ -23,6 +23,12 @@ Indentation is always preserved when formatting regions.") (defvar-local +format-with nil "Set this to explicitly use a certain formatter for the current buffer.") +(defvar +format-with-lsp t + "If non-nil, format with LSP formatter if it's available. + +This can be set buffer-locally with `setq-hook!' to disable LSP formatting in +select buffers.") + ;; ;;; Bootstrap