-
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
add mode and meow state specific keymaps #126
Conversation
Thanks for the contribution, it seems to be both well implemented and well documented. It's clear to me that a lot users want this feature. Before accepting the PR, I want to have a explanation here. In an early version of Meow, it is possible to define a mode specific leader keymap in meow, at that moment I believe the leader keymap is for highly used commands. And which commands are highly used depends on current major mode. But I removed the functionality later because I realized that it's not a good idea to have custom keybindings only existing in meow's keymap. I want meow to be something that leverage your vanilla Emacs configuration, not the package that limits how you build your configuration. That is:
Additionally, these cases are what I'm trying to avoid:
So my recommendation is to bind keys in vanilla Emacs. For example: You want a consistent keybinding SPC t i to toggle images in both org-mode and markdown-mode. You should make a consistent keybinding in vanilla Emacs, and tell meow to use that. ;; assume C-x M-t the prefix for 'toggle'
;; global 'toggle' commands
(global-set-key (kbd "C-x M-t l") 'display-line-numbers-mode)
;; major mode specific 'toggle' commands
(define-key markdown-mode-map (kbd "C-x M-t i") #'markdown-toggle-inline-images)
(define-key org-mode-map (kbd "C-x M-t i") #'org-toggle-inline-images)
;; add entry for 'toggle' in leader
(meow-leader-define-key '("t" . "C-x M-t")) Then you have consistent keybinding SPC t i in leader and C-x M-t i in vanilla Emacs. Below configuration are not specific to meow, they are useful whether you use meow or not. I'd like to have a discussion here. If I can convince others, I'm still inclined to reject this feature. |
Thanks for the compliment and the detailed reply! You've made a compelling argument for sure. The keybind system is still one of the parts of emacs that I can never quite get fully sunk into by brain. I'm coming from the evil-mode side of emacs (and vim before that) and so was originally trying to replicate the way you can bind keys there (and with general.el being able to specific evil The other problem I'm looking to solve that the above doesn't work for is to have a command called under a specific emacs mode AND specific meow state. For example when in
That would be one situation where having a mode and state specific keymap would be handy. That being said I don't have very many insert state specific commands. Most are for normal state which can be handled in the manner you pointed out. So for those few commands I do want state specific functionality I suppose I can just inspect the meow minor mode. So the above could be rewritten as:
But I'm happy with only doing that for the few commands I feel need to be state aware and using your method for the bulk of my other keybinds. I can see where having the option to have meow state specific keybinds will lead people to tie their keybinds to meow and make it harder to remove it. I'm certainly finding that to be the case for evil-mode! So thanks again for the nudge in the right direction for organizing my keybinds "the emacs way". I'm happy to close the PR and look forward to whats next for meow! |
I also have some insert mode specific keybindings. I think my case is very similar to your case mentioned here. In clojure-mode, I want the semicolon key to insert a colon when the cursor is not at the 1) beginning of line 2) string 3) comment. Otherwise it should still insert the semicolon. In rust-mode, I want to the minus key to insert a underscore when the cursor is after a word. here is how I implement this in my configuration I just bind the command in clojure-mode-map and rust-mode-map. Meow normal state won't be affected in this case. In fact, if you look at my configuration, you can find
|
Thanks for this! It gave me the "ah ha" moment realizing that meow's normal state keymap is part of This is where I have trouble fully groking the way emacs looks up keybinds, but it's slowly starting to sink in. |
Hi, not sure if this is the right place to ask. I am trying to remap
Sadly, this does not work as it also maps the |
This is not supported. The normal state is a general state, there's no mode-specific normal state keymap. Here the reason and solution is explained: #126 (comment) |
@DogLooksGood Hello, I would like to switch to meow but I would like to switch back and forth I was reading your suggestion to use vanilla emacs to define keys but I'm not sure I'm not sure if a macro is the best way to go about this but it should:
Ideally I would like to do an This is would be great: (setq my/modal 'meow)
(my/define-key 'normal
(kbd "<leader>z z") (lambda ()(interactive) (message "hi"))
(kbd "<leader>z f") #'do-something) I suppose I could use (setq my/modal 'evil)
(defmacro my/define-key (state map &rest rest)
(pcase my/modal
('evil `(evil-define-key ,state ,map ,rest))
('meow `(meow-leader-define-key '(,key . ,func ) ))
(_ (display-warning :wrong-variable "Wrong variable set for my/modal"))))
(my/define-key 'normal global-map "zz" (lambda () (interactive)(message "hi zz")) ) The current problem I have is getting arguments out of a list then passing them to evil (evil-define-key 'normal global-map ("zz" (lambda nil (interactive) (message "hi zz")))) Would like this, then figure out how to implement it for meow. (evil-define-key 'normal global-map "zz" (lambda nil (interactive) (message "hi zz"))) Thanks |
@rickalex21 I think I completely got your idea, but it sounds to be against the concept of this package. Meow has only one leader, it doesn't matter it's in normal mode or motion mode. Use Personally, I have few leader key bindings. All rest are default, and invoked by keypad. |
It looks like I will create a bunch of |
@licht1stein Just bind them on |
Makes me feel stupid :) thank you! |
Hi I do a similar thing as here where I bind mode-specific key maps to be different functions than whats set in the global map. Everything works fine, the function I set gets run instead of the global one. However in the key pad the display name is still the global function, not the mode-local one that is actually going to be run. This is minor but was wondering if there was a fix? |
@zackattackz Can you show a snippet about what you have done? |
There is more in my configs that could possibly be affecting this but I shared only what I think is relevant. But if it can't be reproduced let me know and I can share full init.el. I don't expect you to go out of your way to solve my problem but I very much appreciate meow and I hope I can contribute back some day. |
@zackattackz Please check this
By this way, you can build your own mode specific keybindings all with builtins, and it's well supported by Meow. I also recommend you to keep all default keybindings unchanged, using |
Ok thanks for the advice with using C-c, makes sense will use it going forward. I attempted your suggestion and it seems that actually pressing However using the meow keypad ( I will paste what I did below in case it's an error on my end. Thanks
I cleared any related entries in |
@zackattackz Guess you are missing |
Yup, good call. Adding that fixes the functionality of the keypad so that the right command is running now, my bad. But the keypad still reads "b -> ivy-switch-buffer" rather than run-term. |
Interestingly the keypad does properly switch between "my-buffer-keymap" and "my-git-commit-mode-keymap" on the top level though |
Maybe I am going about using meow wrongly though. My original intention is to try to have consistent binds across different modes, as well as for the keypad to guide me in case I forgot the exact key mappings. Similarly to how spacemacs works, but I didn't want to use spacemacs itself or evil mode. Should I go about this a different way? |
I think it's a display bug, just had a fix with f6a1b48. There's nothing right or wrong, you can have this mode specific keymap without any external packages, it's a just how Meow reuses it in leader system. Instead of copy keymap, it's better use set-keymap-parent to extend.
|
Thank you, works great! |
I recently found a workaround to bind mode and meow-state specific keybinds, without hacking into meow. You may check this discussion |
I would like to propose adding meow state specific and mode specific keybinds. So keybinds that would only be active under a specified mode (major or minor) and when under a specific meow state. This would allow binds in any combination of mode and meow state to be active and play nicely with one another.
My thought was to use
emulation-mode-map-alists
(similar to meow state's minor modes) to accomplish this. For lack of a better name I chose to call these keymaps "overlay maps", let me copy and paste some documentation going over their implementation:An example:
Thoughts?