Skip to content
This repository has been archived by the owner on Jun 25, 2024. It is now read-only.

which-key-add-keymap-based-replacements with key sequences #275

Closed
JAremko opened this issue Dec 4, 2020 · 5 comments
Closed

which-key-add-keymap-based-replacements with key sequences #275

JAremko opened this issue Dec 4, 2020 · 5 comments

Comments

@JAremko
Copy link

JAremko commented Dec 4, 2020

It would be cool if which-key-add-keymap-based-replacements worked for key sequences, especially major mode specific ones since which-key stores the replacements in the single global variable and Spacemacs has a lot of them.

This actually works(surprisingly) but only visually:
(which-key-add-keymap-based-replacements emacs-lisp-mode-map "SPC mt" "test")

The problem is that it collides with "SPC" (or any other leading kbd) in Evil mode and prevents you from typing. And adding it "the usual way" results in bad prefix error.

Maybe it ca be fixed by adding unused key code that will serve as a root for all fake which-key keys in the map so it won't collide with anything user defined?

@JAremko
Copy link
Author

JAremko commented Dec 4, 2020

For example (define-key (current-global-map) [123456789] '(WHAT . (IS . (GOING . ON)))) binds fine.
This also works (message "%s" (lookup-key (current-global-map) [123456789]))

So can which-key choose a large random number and store key sequences under it?

@justbur
Copy link
Owner

justbur commented Dec 15, 2020

The problem is that it collides with "SPC" (or any other leading kbd) in Evil mode and prevents you from typing. And adding it "the usual way" results in bad prefix error.

That shouldn't happen I don't think. Can you give me a small non-spacemacs example to test?

@JAremko
Copy link
Author

JAremko commented Dec 18, 2020

Yeah it was my mistake. Sorry.

Btw it works fine for evil-leader

(setq inhibit-startup-screen t)
(require 'package)
(add-to-list 'package-archives
             '("melpa" . "https://melpa.org/packages/"))
(package-initialize)
(package-refresh-contents)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun testfun ()
  (interactive)
  (message "success!"))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(unless (package-installed-p 'evil)
  (package-install 'evil)
  (package-install 'evil-leader))

(unless (package-installed-p 'evil-leader)
  (package-install 'evil-leader))

(unless (package-installed-p 'which-key)
  (package-install 'which-key))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(require 'which-key)
(which-key-mode)
(which-key-setup-side-window-bottom)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(require 'evil)
(evil-mode 1)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(require 'evil-leader)
(global-evil-leader-mode)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(evil-leader/set-leader "SPC")
(evil-leader/set-key-for-mode 'emacs-lisp-mode "a b c" 'testfun)

(which-key-add-keymap-based-replacements
  evil-leader--default-map "a b" '("replacement"))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(emacs-lisp-mode)

Too bad making it mode specific would require digging into evil-leader--mode-maps - not related to Spacemacs, it uses different system.

@JAremko JAremko closed this as completed Dec 18, 2020
@justbur
Copy link
Owner

justbur commented Dec 18, 2020 via email

@JAremko
Copy link
Author

JAremko commented Dec 18, 2020

@justbur it's simpler to make it work for Spacemacs since it has a defvar for every mode map. But evil-leader can use some kind of integration yeah. It's not that straightforward.

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

No branches or pull requests

2 participants