wakib-keys icon indicating copy to clipboard operation
wakib-keys copied to clipboard

How to overwrite wakib-key for 1 mode?

Open gety9 opened this issue 1 year ago • 1 comments

I want to use default wakib-key binding for all modes, except for when i do programming (in python), there i want to use different binding. Could you please tell how to do that?

I tried

(use-package eglot
  :bind (:map wakib-keys-overriding-map
    ("C-f" . xref-find-definitions))
  :hook (python-ts-mode . eglot-ensure))

I works, but it overrides C-f binding for all modes/buffers.

I also tried

(use-package eglot
  :bind (:map eglot-mode-map
    ("C-f" . xref-find-definitions))
  :hook (python-ts-mode . eglot-ensure))

it doesn't work

And i also tried

(use-package eglot
  :config
  (define-key eglot-mode-map (kbd "C-f") 'xref-find-definitions)
  :hook (python-ts-mode . eglot-ensure))

also doesn't work

gety9 avatar Feb 13 '24 15:02 gety9

Update:

1, Seems like key can't be rebind (cause emulation-mode-map-alists is higher in hierarchy then eglot-mode-map or py-ts-map), but suprisingly command can be remapped, so i solved it like this:

  (define-key eglot-mode-map [remap consult-outline] 'xref-find-definitions)
  (define-key eglot-mode-map [remap consult-ripgrep] 'xref-go-back)

2, But remap can be used only one time, so if key is already remapped (by cua mode like in case of M-s) then above didn't work, so i solved it with custom function with if major mode check: https://stackoverflow.com/a/41080009/23311868 https://emacs.stackexchange.com/a/47106/42471

Please tell me if there was better way to do it :)

Thx for great package, learned a lot from your code!

gety9 avatar Feb 16 '24 20:02 gety9