From 090a68ab8f3e64322159cdee29897663ba10f0e3 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Thu, 21 May 2020 01:20:00 -0400 Subject: [PATCH] Add +format-with-lsp variable To control whether or not to use LSP code formatter when it is available. --- modules/editor/format/autoload/format.el | 6 ++++-- modules/editor/format/config.el | 6 ++++++ 2 files changed, 10 insertions(+), 2 deletions(-) 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