Use lsp-format-region-or-buffer if available

Currently the user has to select `SPC c F` for lsp format. But if
lsp-mode is enabled, the user will always want to use the LSP formatter.
So this changes the default `SPC c f` to use lsp formatter if available.
This simplifies the interface a bit so the user doesn't have to worry
about selecting the "right" format, just like how other commands get
auto bound to LSP functions.
This commit is contained in:
James Ravn 2020-05-04 10:23:13 +01:00
parent 35591cfc4c
commit 300bc65918
No known key found for this signature in database
GPG key ID: 52C372C72159D6EE
3 changed files with 5 additions and 5 deletions

View file

@ -43,7 +43,6 @@
:desc "List errors" "x" #'flycheck-list-errors) :desc "List errors" "x" #'flycheck-list-errors)
(:when (featurep! :tools lsp) (:when (featurep! :tools lsp)
:desc "LSP Code actions" "a" #'lsp-execute-code-action :desc "LSP Code actions" "a" #'lsp-execute-code-action
:desc "LSP Format buffer/region" "F" #'+default/lsp-format-region-or-buffer
:desc "LSP Organize imports" "i" #'lsp-organize-imports :desc "LSP Organize imports" "i" #'lsp-organize-imports
:desc "LSP Rename" "r" #'lsp-rename :desc "LSP Rename" "r" #'lsp-rename
(:after lsp-mode (:after lsp-mode

View file

@ -360,7 +360,6 @@
:desc "Jump to documentation" "k" #'+lookup/documentation :desc "Jump to documentation" "k" #'+lookup/documentation
(:when (featurep! :tools lsp) (:when (featurep! :tools lsp)
:desc "LSP Execute code action" "a" #'lsp-execute-code-action :desc "LSP Execute code action" "a" #'lsp-execute-code-action
:desc "LSP Format buffer/region" "F" #'+default/lsp-format-region-or-buffer
:desc "LSP Organize imports" "i" #'lsp-organize-imports :desc "LSP Organize imports" "i" #'lsp-organize-imports
:desc "LSP Rename" "r" #'lsp-rename :desc "LSP Rename" "r" #'lsp-rename
(:after lsp-mode (:after lsp-mode

View file

@ -219,9 +219,11 @@ snippets or single lines."
is selected)." is selected)."
(interactive) (interactive)
(call-interactively (call-interactively
(if (use-region-p) (if (bound-and-true-p lsp-mode)
#'+format/region #'+default/lsp-format-region-or-buffer
#'+format/buffer))) (if (use-region-p)
#'+format/region
#'+format/buffer))))
;; ;;