From 54d6b097e406a614056f13dc56de9bd2f125f118 Mon Sep 17 00:00:00 2001 From: Lucien Cartier-Tilet Date: Mon, 23 Jan 2023 10:45:46 +0100 Subject: [PATCH] [Emacs] Better keybinds for LSP in major-modes --- org/config/emacs.org | 67 ++++++++++++++++++++++++++++++-------------- 1 file changed, 46 insertions(+), 21 deletions(-) diff --git a/org/config/emacs.org b/org/config/emacs.org index 4416002..6572a3d 100644 --- a/org/config/emacs.org +++ b/org/config/emacs.org @@ -1428,7 +1428,12 @@ Due to this, I absolutely need a mode for editing Dockerfiles. :hook (dockerfile-mode . lsp-deferred) :init (put 'docker-image-name 'safe-local-variable #'stringp) - :mode "Dockerfile\\'") + :mode "Dockerfile\\'" + :general + (phundrak/major-leader-key + :keymaps 'general-mode-map + :packages 'lsp-mode + "l" '(:keymap lsp-command-map :which-key "lsp"))) #+end_src The ~docker~ package also provides interactivity with Docker and @@ -4270,6 +4275,10 @@ enhances a couple of built-in functions from Emacs, namely: (add-hook 'TeX-mode-hook #'visual-line-mode) (add-hook 'TeX-update-style-hook #'rainbow-delimiters-mode) :general + (phundrak/major-leader-key + :packages 'lsp-mode + :keymaps '(latex-mode-map LaTeX-mode-map) + "l" '(:keymap lsp-command-map :which-key "lsp")) (phundrak/major-leader-key :packages 'auctex :keymaps '(latex-mode-map LaTeX-mode-map) @@ -6957,7 +6966,12 @@ configuration for StumpWM]]. #+begin_src emacs-lisp (use-package lsp-dart :straight (:build t) - :defer t) + :defer t + :general + (phundrak/major-leader-key + :keymaps 'dart-mode-map + :packages '(lsp-mode lsp-dart) + "l" '(:keymap lsp-command-map :which-key "lsp"))) #+end_src **** EmacsLisp @@ -7085,7 +7099,12 @@ org-babel supports. (setq python-indent-guess-indent-offset-verbose nil) (when (and (executable-find "python3") (string= python-shell-interpreter "python")) - (setq python-shell-interpreter "python3"))) + (setq python-shell-interpreter "python3")) + :general + (phundrak/major-leader-key + :keymaps 'python-mode-map + :packages 'lsp-mode + "l" '(:keymap lsp-command-map :which-key "lsp"))) #+end_src Now let’s add a package for [[https://docs.pytest.org/en/latest/][pytest]]. @@ -7335,6 +7354,10 @@ development. First, let’s install the most important package, :packages 'lsp "M-t" #'lsp-ui-imenu "M-?" #'lsp-find-references) + (phundrak/major-leader-key + :keymaps 'rustic-mode-map + :packages 'lsp-mode + "l" '(:keymap lsp-command-map :which-key "lsp")) (phundrak/major-leader-key :keymaps 'rustic-mode-map :packages 'rustic @@ -7348,12 +7371,6 @@ development. First, let’s install the most important package, "bn" #'rustic-cargo-new "bo" #'rustic-cargo-outdated "br" #'rustic-cargo-run - "l" '(:ignore t :which-key "lsp") - "la" #'lsp-execute-code-action - "lr" #'lsp-rename - "lq" #'lsp-workspace-restart - "lQ" #'lsp-workspace-shutdown - "ls" #'lsp-rust-analyzer-status "t" '(:ignore t :which-key "cargo test") "ta" #'rustic-cargo-test "tt" #'rustic-cargo-current-test) @@ -7489,6 +7506,10 @@ Let’s customize a bit the built-in CSS mode. :init (put 'css-indent-offset 'safe-local-variable #'integerp) :general + (phundrak/major-leader-key + :keymaps 'css-mode-map + :packages 'lsp-mode + "l" '(:keymap lsp-command-map :which-key "lsp")) (phundrak/major-leader-key :keymaps 'css-mode-map :packages 'css-mode @@ -7531,7 +7552,12 @@ activate when I open ~.less~ files by default. Let’s fix that. :mode "\\.less\\'" :hook (less-css-mode . smartparens-mode) :hook (less-css-mode . lsp-deferred) - :hook (less-css-mode . prettier-js-mode)) + :hook (less-css-mode . prettier-js-mode) + :general + (phundrak/major-leader-key + :keymaps 'less-css-mode-map + :packages 'lsp-mode + "l" '(:keymap lsp-command-map :which-key "lsp"))) #+end_src ***** Javascript @@ -7559,11 +7585,9 @@ Next.JS. 2 3 4)) :general (phundrak/major-leader-key - :keymaps 'rjsx-mode-map - :infix "a" - "" '(:keymap lsp-command-map :which-key "lsp") - "=" '(:ignore t :wk "format") - "a" '(:ignore t :which-key "actions")) + :keymaps 'rjsx-mode-map + :packages 'lsp-mode + "l" '(:keymap lsp-command-map :which-key "lsp")) :config (setq js-chain-indent t js2-basic-offset 2 @@ -7638,12 +7662,9 @@ Typescript is a safer alternative to Javascript. Let’s install its major mode (add-to-list 'auto-mode-alist '("\\.tsx\\'" . typescript-tsx-mode)) :general (phundrak/major-leader-key - :packages 'lsp - :keymaps '(typescript-mode-map typescript-tsx-mode-map) - :infix "a" - "" '(:keymap lsp-command-map :which-key "lsp") - "=" '(:ignore t :wk "format") - "a" '(:ignore t :which-key "actions")) + :keymaps '(typescript-mode-map typescript-tsx-mode-map) + :packages 'lsp-mode + "l" '(:keymap lsp-command-map :which-key "lsp")) (phundrak/major-leader-key :packages 'typescript-mode :keymaps '(typescript-mode-map typescript-tsx-mode-map) @@ -7707,6 +7728,10 @@ First, here is its major mode. :modes zig-mode) (add-to-list 'flycheck-checkers 'zig) :general + (phundrak/major-leader-key + :keymaps 'zip-mode-map + :packages 'lsp-mode + "l" '(:keymap lsp-command-map :which-key "lsp")) (phundrak/major-leader-key :packages 'zig-mode :keymaps 'zig-mode-map