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

lsp-keymap-prefix not working #1672

Closed
haoyuan80s opened this issue May 9, 2020 · 9 comments
Closed

lsp-keymap-prefix not working #1672

haoyuan80s opened this issue May 9, 2020 · 9 comments

Comments

@haoyuan80s
Copy link

Hi, I set prefix for lsp-command-keymap by (setq lsp-keymap-prefix "C-S-l").
With describe variable i can see:
image
But all the lsp functions are still have s-l as prefix:
image
How set the prefix correctly?

@Lenbok
Copy link
Contributor

Lenbok commented May 10, 2020

It is counter-intuitive how that doesn't work. I think it depends on when you call the setq. In my init I have:

(use-package lsp-mode
  :commands lsp
  :init
  (setq lsp-keymap-prefix "C-c l")
  :config
  (define-key lsp-mode-map (kbd "C-c l") lsp-command-map)
  (require 'lsp-clients)
  :hook (lsp-mode . lsp-enable-which-key-integration))

The define-key gets the actual commands working with the desired prefix, and the setq ensures that the which-key integration is using the correct prefix.

The lsp-mode docs show customization of the prefix by putting the setq before (outside) the use-package so that probably works as well, although it seems wrong to have it outside of the use-package.

@yyoncho
Copy link
Member

yyoncho commented May 10, 2020

the issue is that you should set the prefix before lsp-mode has been loaded and I am not quite sure how to achieve that with use-package.

:config
(define-key lsp-mode-map (kbd "C-c l") lsp-command-map)

This works fine too.

I am closing the issue but it could be used for further discussions.

@haoyuan80s
Copy link
Author

Yes, the key is "set the prefix before lsp-mode has been loaded ".

My problem was that I loaded ccls before lsp-mode. Seems that ccls loaded lsp-mode (without set the prefix). I fixed it by adding ":after lsp" in when loading ccls package: (use-package ccls :after lsp). Then, I am able to set the prefix in the "natural way":

(use-package lsp-mode
    :init (setq lsp-keymap-prefix "C-c l")

@phillord
Copy link
Contributor

I know that this issue has been closed, but I wonder whether it was worth revisiting. I have just hit the same problem caused by loading lsp-ui before lsp. Moving (setq lsp-keymap-prefix "blah") to top-level doesn't solve this problem.

This could be implemented by having a lsp-remap-prefix function and documented this as the main mechanism. This could also be added to the lsp-keymap-prefix customize code also, as I guess this won't work in without a restart.

Happy to send a PR if this would seem to be reasonable.

@yyoncho
Copy link
Member

yyoncho commented Feb 12, 2021

@phillord what about using setter for the defcustom?

@phillord
Copy link
Contributor

@yyoncho Not sure I understand. It doesn't have one at the moment. As far as I can see, we'd just need to call

  (define-key map (kbd lsp-keymap-prefix) lsp-command-map)

and then re-run the which-key integration. So a simple function which wraps that lot up, updated documentation and updating the defcustom to use this as a set function. Is that enough, or am I missing something. Can change this into a PR if wanted.

@yyoncho
Copy link
Member

yyoncho commented Feb 14, 2021

I meant instead of having this as part of a separate function it seems like having it part of the setter might be more convenient.

(defcustom lsp-keymap-prefix "s-l"
  "lsp-mode keymap prefix."
  :group 'lsp-mode
  :type 'string
  :package-version '(lsp-mode . "6.3")
  :set (lambda (sym val)
         ;; unbind old value
         ;; bind new value, update which-key, etc.
         ))

@phillord
Copy link
Contributor

I'd go the other way. Have this as a function, then call that function as the :set from defcustom. That way it would also work for people not using custom. There isn't a convienient way to call defcustom settters that I know of.

@kflu
Copy link

kflu commented Aug 8, 2021

It is counter-intuitive how that doesn't work. I think it depends on when you call the setq. In my init I have:

(use-package lsp-mode
  :commands lsp
  :init
  (setq lsp-keymap-prefix "C-c l")
  :config
  (define-key lsp-mode-map (kbd "C-c l") lsp-command-map)
  (require 'lsp-clients)
  :hook (lsp-mode . lsp-enable-which-key-integration))

The define-key gets the actual commands working with the desired prefix, and the setq ensures that the which-key integration is using the correct prefix.

The lsp-mode docs show customization of the prefix by putting the setq before (outside) the use-package so that probably works as well, although it seems wrong to have it outside of the use-package.

Even if I do this, C-c l is still not registered as the binding. Only if I put

  (define-key lsp-mode-map (kbd "C-c l") lsp-command-map)

outside use-package after all the use-packages did it work.

I still prefer to put define-key inside use-package, so does that mean I have some other kind of conflicts going on in my init.el?

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