From c56afcfe01689eb6a13d45fa90b28b5983cc21ac Mon Sep 17 00:00:00 2001 From: James Ravn Date: Tue, 21 Apr 2020 20:24:13 +0100 Subject: [PATCH 1/2] Add lsp-command-map to SPC-c-l The default lsp-mode bindings are bound to `s-l` which is impractical for anyone using keybindings in their window manager. It also conflicts w/ the doom approach of using leader keys. This change makes all the default lsp bindings (see https://github.com/emacs-lsp/lsp-mode#commands) available on SPC-c-l. So for example, restarting the lsp server can be done with `SPC c l s r`. --- modules/config/default/+emacs-bindings.el | 22 ++++++++++++---------- modules/config/default/+evil-bindings.el | 11 +++++++---- modules/tools/lsp/config.el | 6 ++++++ 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/modules/config/default/+emacs-bindings.el b/modules/config/default/+emacs-bindings.el index 25391b39c..f6099d74d 100644 --- a/modules/config/default/+emacs-bindings.el +++ b/modules/config/default/+emacs-bindings.el @@ -42,16 +42,18 @@ (:when (featurep! :tools flycheck) :desc "List errors" "x" #'flycheck-list-errors) (:when (featurep! :tools lsp) - :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 Rename" "r" #'lsp-rename - (:when (featurep! :completion ivy) - :desc "Jump to symbol in current workspace" "j" #'lsp-ivy-workspace-symbol - :desc "Jump to symbol in any workspace" "J" #'lsp-ivy-global-workspace-symbol) - (:when (featurep! :completion helm) - :desc "Jump to symbol in current workspace" "j" #'helm-lsp-workspace-symbol - :desc "Jump to symbol in any workspace" "J" #'helm-lsp-global-workspace-symbol))) + :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 Rename" "r" #'lsp-rename + (:after lsp-mode + :desc "LSP" "l" lsp-command-map) + (:when (featurep! :completion ivy) + :desc "Jump to symbol in current workspace" "j" #'lsp-ivy-workspace-symbol + :desc "Jump to symbol in any workspace" "J" #'lsp-ivy-global-workspace-symbol) + (:when (featurep! :completion helm) + :desc "Jump to symbol in current workspace" "j" #'helm-lsp-workspace-symbol + :desc "Jump to symbol in any workspace" "J" #'helm-lsp-global-workspace-symbol))) ;;; f --- file (:prefix-map ("f" . "file") diff --git a/modules/config/default/+evil-bindings.el b/modules/config/default/+evil-bindings.el index ce615bb6f..4b1c155e2 100644 --- a/modules/config/default/+evil-bindings.el +++ b/modules/config/default/+evil-bindings.el @@ -337,7 +337,6 @@ ;;; c --- code (:prefix-map ("c" . "code") - :desc "LSP Execute code action" "a" #'lsp-execute-code-action :desc "Compile" "c" #'compile :desc "Recompile" "C" #'recompile :desc "Jump to definition" "d" #'+lookup/definition @@ -345,8 +344,6 @@ :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 (:when (featurep! :completion ivy) :desc "Jump to symbol in current workspace" "j" #'lsp-ivy-workspace-symbol :desc "Jump to symbol in any workspace" "J" #'lsp-ivy-global-workspace-symbol) @@ -354,7 +351,13 @@ :desc "Jump to symbol in current workspace" "j" #'helm-lsp-workspace-symbol :desc "Jump to symbol in any workspace" "J" #'helm-lsp-global-workspace-symbol) :desc "Jump to documentation" "k" #'+lookup/documentation - :desc "LSP Rename" "r" #'lsp-rename + (:when (featurep! :tools lsp) + :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 Rename" "r" #'lsp-rename + (:after lsp-mode + :desc "LSP" "l" lsp-command-map)) :desc "Send to repl" "s" #'+eval/send-region-to-repl :desc "Delete trailing whitespace" "w" #'delete-trailing-whitespace :desc "Delete trailing newlines" "W" #'doom/delete-trailing-newlines diff --git a/modules/tools/lsp/config.el b/modules/tools/lsp/config.el index 888c9c6fe..fcc3e1e37 100644 --- a/modules/tools/lsp/config.el +++ b/modules/tools/lsp/config.el @@ -42,6 +42,8 @@ working on that project after closing the last buffer.") (setq lsp-server-install-dir (concat doom-etc-dir "lsp/") lsp-groovy-server-install-dir (concat lsp-server-install-dir "lsp-groovy/") lsp-intelephense-storage-path (concat doom-cache-dir "lsp-intelephense/")) + ;; Let doom bind the LSP keymap. + (setq lsp-keymap-prefix nil) ;; Disable LSP's superfluous, expensive and/or debatably unnecessary features. ;; Some servers implement these poorly. Better to just rely on Emacs' native @@ -114,6 +116,10 @@ This also logs the resolved project root, if found, so we know where we are." (lambda (it) (format "[%s]" (lsp--workspace-print it))) lsp--buffer-workspaces)))))) + (dolist (leader-key (list doom-leader-key doom-leader-alt-key)) + (let ((lsp-keymap-prefix (concat leader-key " c l"))) + (lsp-enable-which-key-integration))) + (add-hook! 'lsp-mode-hook (defun +lsp-init-company-h () (if (not (bound-and-true-p company-mode)) From 4f3cf24afb4bf553ec049b1f4e3f11376e644b09 Mon Sep 17 00:00:00 2001 From: James Ravn Date: Mon, 4 May 2020 10:12:17 +0100 Subject: [PATCH 2/2] Only enable lsp keymap binding when +bindings --- modules/tools/lsp/config.el | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/modules/tools/lsp/config.el b/modules/tools/lsp/config.el index b7d7f5a1e..51f18346e 100644 --- a/modules/tools/lsp/config.el +++ b/modules/tools/lsp/config.el @@ -25,8 +25,10 @@ working on that project after closing the last buffer.") ;; For `lsp-clients' (setq lsp-server-install-dir (concat doom-etc-dir "lsp/") lsp-intelephense-storage-path (concat doom-cache-dir "lsp-intelephense/")) - ;; Let doom bind the LSP keymap. - (setq lsp-keymap-prefix nil) + + (when (featurep! :config default +bindings) + ;; Let doom bind the lsp keymap. + (setq lsp-keymap-prefix nil)) ;; Disable LSP's superfluous, expensive and/or debatably unnecessary features. ;; Some servers implement these poorly. Better to just rely on Emacs' native @@ -101,9 +103,10 @@ This also logs the resolved project root, if found, so we know where we are." (lambda (it) (format "[%s]" (lsp--workspace-print it))) lsp--buffer-workspaces)))))) - (dolist (leader-key (list doom-leader-key doom-leader-alt-key)) - (let ((lsp-keymap-prefix (concat leader-key " c l"))) - (lsp-enable-which-key-integration))) + (when (featurep! :config default +bindings) + (dolist (leader-key (list doom-leader-key doom-leader-alt-key)) + (let ((lsp-keymap-prefix (concat leader-key " c l"))) + (lsp-enable-which-key-integration)))) (add-hook! 'lsp-mode-hook (defun +lsp-init-company-h ()