From d246307f87d757c71b26d6db10ff2f4788f6cbf2 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Tue, 22 Oct 2019 19:55:50 -0400 Subject: [PATCH] config/default: bind SPC c {F,i,r} to LSP commands These are experimental keybinds. I'm looking for a way to integrate LSP's formatter commands (and lsp-organize-imports) into the :editor format module. And a way to unify refactoring commands (perhaps with emr or erefactor), including lsp-rename. - 'SPC c F' -> format region or buffer - 'SPC c i' -> organize imports - 'SPC c r' -> rename symbol at point Addresses #1417 --- modules/config/default/+evil-bindings.el | 4 +++- modules/config/default/autoload/default.el | 9 +++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/modules/config/default/+evil-bindings.el b/modules/config/default/+evil-bindings.el index 2fa8dc564..22ce02354 100644 --- a/modules/config/default/+evil-bindings.el +++ b/modules/config/default/+evil-bindings.el @@ -624,8 +624,10 @@ :desc "Evaluate buffer/region" "e" #'+eval/buffer-or-region :desc "Evaluate & replace region" "E" #'+eval:replace-region :desc "Format buffer/region" "f" #'+format/region-or-buffer + :desc "LSP Format buffer/region" "F" #'+default/lsp-format-region-or-buffer + :desc "LSP Organize imports" "i" #'lsp-organize-imports :desc "Jump to documentation" "k" #'+lookup/documentation - :desc "Open REPL" "r" #'+eval/open-repl-other-window + :desc "LSP Rename" "r" #'lsp-rename :desc "Delete trailing whitespace" "w" #'delete-trailing-whitespace :desc "Delete trailing newlines" "W" #'doom/delete-trailing-newlines (:when (featurep! :tools flycheck) diff --git a/modules/config/default/autoload/default.el b/modules/config/default/autoload/default.el index dede7a180..48883b14b 100644 --- a/modules/config/default/autoload/default.el +++ b/modules/config/default/autoload/default.el @@ -315,3 +315,12 @@ ARG is set, prompt for a known project to search from." (interactive) (doom-completing-read-org-headings "Jump to org headline: " org-agenda-files 3 t)) + +;;;###autoload +(defun +default/lsp-format-region-or-buffer () + "Format the buffer (or selection) with LSP." + (interactive) + (call-interactively + (if (use-region-p) + #'lsp-format-region + #'lsp-format-buffer)))