-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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 spacemacs/set-keys #2731
Add spacemacs/set-keys #2731
Conversation
@syl20bnr I know you're busy, but I was curious what you thought of this idea |
This is a sensitive subject that requires a lot of thought, I'm sure of one thing though, the proposal here is hard to read and understand without looking at the documentation of the function. This function may be the most called function in the distribution, it has to be understandable without requiring to read the doc. |
I understand. I just wanted to get started on a better solution.
|
These macros are better versions of `evil-leader/set-key` and `evil-leader/set-key-for-mode`. The difference is the ability to specify a prefix with a name that will automatically be declared.
Ok, this is implementation number two. I think it's pretty self-explanatory. (defun test1 () (interactive) (message "test 1"))
(defun test2 () (interactive) (message "test 2"))
;; equivalent to evil-leader/set-key
(spacemacs/set-keys
"[" 'test1)
;; binds "][" and "]]", and declares name of "]" prefix
(spacemacs/set-keys
"[" 'test1
"]" 'test2
:prefix-keys "]"
:prefix-name "backwards-bracket")
;; similar to the previous one, but only binds in emacs-lisp-mode
(spacemacs/set-keys
"[" 'test1
"]" 'test2
:major-mode 'emacs-lisp-mode
:prefix-keys "m["
:prefix-name "forward-bracket")
Adding an example from the spacemacs layer (spacemacs/set-keys
"b" 'spacemacs/helm-buffers-smart-do-search
"B" 'spacemacs/helm-buffers-smart-do-search-region-or-symbol
:prefix-keys "s"
:prefix-name "search/symbol")
(spacemacs/set-keys
"b" 'helm-do-ag-buffers
"B" 'spacemacs/helm-buffers-do-ag-region-or-symbol
"a" 'helm-ag-this-file
"A" 'spacemacs/helm-file-do-ag-region-or-symbol
"f" 'helm-do-ag
"F" 'spacemacs/helm-files-do-ag-region-or-symbol
"p" 'spacemacs/helm-project-do-ag
"P" 'spacemacs/helm-project-do-ag-region-or-symbol
:prefix-keys "sa"
:prefix-name "search-ag") EDIT: the keyword arguments are allowed to come before or after the bindings. |
Specifically the keyword arguments can come before or after the list of bindings.
@syl20bnr I'm going to unify all the stuff related to declaring prefixes in which-key and update this function to use it. Then we will have one interface to defining keys that incorporates the ability to simultaneously declare prefixes. |
I'm not sure that unifying prefix and bindings is a good thing, I'm not sure I want to hide such core emacs lisp functions. I want users to use them. |
Let use the raw emacs way to define key bindings and let just migrate the prefix stuff to which-key. I prefer them to be separated calls. This way key bindings definition are still raw compatible stock emacs and more portable. |
What I like with your which-key solution is that we don't even bother to define prefix names, that's really cool. This is all only which-key config. Since which-key is a bootstrap package it can be used anywhere. |
Ok fair enough. Most of the key bindings are made using evil-leader and I I'll forget this function and work on migrating the prefix declarations to For the bootstrap thing does it still make sense to have the config in the
|
Good question, it should stay in spacemacs layer but the loading |
Closing in favor of #2876 |
These functions are better versions of
evil-leader/set-key
andevil-leader/set-key-for-mode
. The difference is the ability to specifya prefix with a name that will automatically be declared.
Here's an illustration of how it is meant to be used, which will simultaneously declare "p" and "pp" as prefixes with names "prefix-name" and "sub-prefix-name" as well as the corresponding bindings. More string-command or string-list pairs can be used, and they can also be nested. I think this makes for a nicely structured and cleaner way to define bindings, avoiding the need to declare prefixes.
EDIT: This post only applies to the implementation in the first commit