-
Notifications
You must be signed in to change notification settings - Fork 137
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
Helper function to create prefix keys for leader commands #131
Helper function to create prefix keys for leader commands #131
Conversation
Hi, thanks for the contribution! It seems like My thought is we just create a keymap, alias it, then have a simple binding in meow. Users may not be aware of this solution, but that is just a problem for documentation. How do you think? |
What you suggest makes perfect sense. I'll close my PR and see if I can find a good place in documentation to add this. Thank you for taking time to respond. I suppose this is how I'd accomplish what you're suggesting: (defvar spook-git-keymap (make-sparse-keymap)
"My custom keymap for easily accessing git stuff")
(defalias 'spook-git spook-git-keymap)
(define-key spook-git-keymap (kbd "s") #'magit-status)
(global-set-key (kbd "C-c g") 'spook-git)
(meow-leader-define-key
'("g" . "C-c g")) Small problem here is, even though on doing Is it possible to somehow get a good help text for |
I figure I can just do (meow-leader-define-key
'("p" . projectile-command-map)) |
Yes, you can bind a key to a keymap. If you bind like this
The command/keymap for |
I've found that if I do the following, sometimes the keybindings clash(?) and don't do what I expect/want. (meow-leader-define-key
'("g" . "C-c g")) E.g "C-c g g", assigned to So I figured I'll just add keymaps directly. When I add (defvar spook-buffer-keymap (make-sparse-keymap))
(defalias 'spook-buffer spook-buffer-keymap)
(global-set-key (kbd "C-c b") spook-buffer-keymap)
(define-key spook-buffer-keymap (kbd "b") #'ivy-switch-buffer)
(define-key spook-buffer-keymap (kbd "d") #'kill-current-buffer)
(define-key spook-buffer-keymap (kbd "s") #'startup--get-buffer-create-scratch) |
I figured it out. I have to use the alias i.e Here's how I am configuring my stuff now. I've create a macro to help me: (defmacro spook-defkeymap (name prefix &rest bindings)
"Create a new NAME-keymap bound to PREFIX, with BINDINGS.
Usage:
(spook-defkeymap \"spook-git\" \"C-c g\"
'(\"s\" . magit-status))
"
(let* ((keymap-name (intern (concat name "-keymap")))
(keymap-alias (intern name))
(keymap-bindings (mapcar
(lambda (binding)
(let ((binding (eval binding)))
`(define-key ,keymap-name (kbd ,(car binding)) #',(cdr binding))))
bindings)))
`(progn
(defvar ,keymap-name (make-sparse-keymap))
(defalias ',keymap-alias ,keymap-name)
(global-set-key (kbd ,prefix) ',keymap-alias)
,@keymap-bindings))) I define my keymap like this: (spook-defkeymap
"spook-buffers" "C-c b"
'("b" . ivy-switch-buffer)
'("d" . kill-current-buffer)) Then assign them to meow-leader-key (meow-leader-define-key
'("p" . projectile-command-map)
'("w" . spook-windows)
'("b" . spook-buffers)
'("g" . spook-git)) and keys don't clash either. Sorry for the spam, I thought I should put it out here in case someone else might stumble here. |
Firstly, I'm just typing, and found you figured it out. :) The way you just shown is what I considered the best way. Building your keymap in your own way, not bound to meow, looks pretty. |
I am kinda new to Emacs lisp, and I had a hard time figuring out how to add new prefixes to the leader key.
(error "Key sequence z s starts with non-prefix key z")
didn't help much, but enough that I could find my way to write a helper function.I think it can be useful for others as well. Please take a look. If you think it can be an acceptable addition to the repo and want me to make some changes, I'll be very happy to do that.
Thank you for your work on this project.