Add +format-with-lsp variable

To control whether or not to use LSP code formatter when it is
available.
This commit is contained in:
Henrik Lissner 2020-05-21 01:20:00 -04:00
parent 885197bd06
commit 090a68ab8f
No known key found for this signature in database
GPG Key ID: 5F6C0EA160557395
2 changed files with 10 additions and 2 deletions

View File

@ -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

View File

@ -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