Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot change lsp-keymap-prefix with setq #1532

Closed
tjtrabue opened this issue Mar 22, 2020 · 4 comments
Closed

Cannot change lsp-keymap-prefix with setq #1532

tjtrabue opened this issue Mar 22, 2020 · 4 comments

Comments

@tjtrabue
Copy link

tjtrabue commented Mar 22, 2020

Hey everyone! I hope I'm not terribly off-base here. This is my first time reporting a bug on GitHub. First of all, let me say that I love lsp-mode! It's fantastic. Great job, everyone. This is an incredible technical accomplishment.

Describe the bug
When I use (setq lsp-keymap-prefix "C-c l") to change the prefix for executing lsp-mode commands, I cannot use my new keymap. When I check C-h v to view the value of lsp-keymap-prefix I see that it is indeed my new keybinding "C-c l", but again, this new keybinding does nothing when I attempt to use it. In fact, Emac's echo area reports "C-c l is undefined".

I do have a workaround. Using (define-key lsp-mode-map (kbd "C-c l") lsp-command-map) does work. I got the idea from projectile's documentation detailing how to map their prefix sequence. Any idea why this method works for me while the official method seems to do nothing?

Thank you so much!

To Reproduce

  1. Minimalist init.el file:
(unless (package-installed-p 'use-package)
    (package-refresh-contents)
    (package-install 'use-package))
  (eval-when-compile
    (require 'use-package))

(use-package lsp-mode
  :ensure t
  :init (setq lsp-keymap-prefix "C-c l")
  ::hook
  (((sh-mode) . lsp)
    (lsp-mode . lsp-enable-which-key-integration))
  :commands lsp
  :config
  (require 'lsp-clients)
  (setq lsp-print-io t
    lsp-enable-snippet t
    lsp-enable-semantic-highlighting t))
  1. Open any file supported by a language server and client within lsp-mode (I used a Bash file with bash-language-server)

  2. Attempt to use the new keymapping "C-c l" to issue an LSP command.

Expected behavior
I expect to see a prompt for an LSP command appear in the echo area. However, I get "C-c l is undefined".

Which Language Server did you use
bash-language-server

OS
Arch Linux. Kernel version: 5.4.26-1-lts

Emacs version 28.0.50

Error callstack
The only error I get is that "C-c l is undefined." The lsp-mode functions appear to work just fine when I call them using M-x <function-name>. It's only the keymap that isn't working properly.

@kiennq
Copy link
Member

kiennq commented Mar 23, 2020

lsp-keymap-prefix is mostly for documentation of which-key integration only.
If you want to customize the key binding for lsp commands, you should key bind lsp-command-map.
For example:

(use-package lsp-mode
  :ensure t
  :defer t
  :hook (lsp-mode . (lambda ()
                      (let ((lsp-keymap-prefix "C-c l"))
                        (lsp-enable-which-key-integration))))
  :init
  (setq lsp-keep-workspace-alive nil
        lsp-signature-doc-lines 5
        lsp-idle-delay 0.5
        lsp-prefer-capf t
        lsp-client-packages nil)
  :config
  (define-key lsp-mode-map (kbd "C-c l") lsp-command-map))

@yyoncho
Copy link
Member

yyoncho commented Mar 23, 2020

You may use @kiennq suggestion or move setq on top-level as suggested by the updated docs.

@artemkovalyov
Copy link
Contributor

@tjtrabue , you can also use :bind-keymap from use-package to achieve that: https://github.com/jwiegley/use-package#binding-to-keymaps

  :bind-keymap ("s-SPC" . lsp-command-map)
  :bind (:map lsp-mode-map
              ("s-r"  . lsp-rename))

@xushijie
Copy link

lsp-keymap-prefix is mostly for documentation of which-key integration only. If you want to customize the key binding for lsp commands, you should key bind lsp-command-map. For example:

(use-package lsp-mode
  :ensure t
  :defer t
  :hook (lsp-mode . (lambda ()
                      (let ((lsp-keymap-prefix "C-c l"))
                        (lsp-enable-which-key-integration))))
  :init
  (setq lsp-keep-workspace-alive nil
        lsp-signature-doc-lines 5
        lsp-idle-delay 0.5
        lsp-prefer-capf t
        lsp-client-packages nil)
  :config
  (define-key lsp-mode-map (kbd "C-c l") lsp-command-map))

Since C-c l involves three keys, and my keyboard(thinkpad X1E) has a special key: Fn.
Is it possible to replace C-c l with Fn? I tried C-c l with Fn in your sample script, but fail...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants