-
Notifications
You must be signed in to change notification settings - Fork 45
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
Display/specify which-key for general-predicate-dispatch #79
Comments
Unlike |
Thanks for the info, I really like this feature especially since some plugins rely on the actual binding being to |
I am not familiar with the menu items, but found this related closed issue inside the which-key project: justbur/emacs-which-key#147 Perhaps that tells you something about the state? Or is it not really related? |
It's not really related. #39 spawned that issue. The idea of that pull request was to use the menu-item ITEM-NAME to clue which-key in about what to display as a replacement (and was rejected). In that case the only reason menu-item was used was to give which-key a replacement. In this case, menu-item is used for a predicate. I'd make a new which-key issue. It seems you can't even manually add a replacement for keys bound to a menu-item. |
@terlar and @noctuid. which-key can easily support this if It seems to me that this is something that could be fixed in For reasons that I outlined in the other attempts to change the way which-key found bindings, I'm not interested in writing a custom I provided another way to conditionally display a certain string for a bindings here, which is an alternative route. |
@noctuid This commit (justbur/emacs-which-key@f516b84) takes a partial step in that direction. If it works well, I can extend it. The idea is to pre-process arguments to |
It would be nice if it was possible to dynamically retrieve the description from a |
I was able to display keybindings to
(defun which-key--get-current-bindings (&optional prefix)
"Generate a list of current active bindings."
(let* ((ignore-bindings '(self-insert-command
ignore
ignore-event
company-ignore))
(buffer (current-buffer))
(active-maps (with-current-buffer buffer
(current-active-maps))))
(cl-loop for entry in (cl-remove-duplicates
(thread-last
(if prefix
(mapcar (lambda (map) (lookup-key map prefix))
active-maps)
active-maps)
(cl-remove-if-not #'keymapp)
(mapcar (lambda (map)
(when (eq map 'mode-specific-command-prefix)
(setq map (buffer-local-value 'mode-specific-map
buffer)))
(cl-etypecase map
(list (cdr map))
(symbol (symbol-value map)))))
(apply #'append))
:from-end t
;; Prevent an error (wrong-type-argument listp keymap)
:key #'car-safe
:test #'eql)
with bindings = nil
do (pcase entry
(`(,key menu-item . ,details)
(push (cons (key-description (cl-etypecase key
(number (vector key))
(vector key)))
(or (car-safe details)
"menu-item"))
bindings))
((and `(,key . ,def)
(guard (not (memq def ignore-bindings))))
(push (cons (key-description (cl-etypecase key
(vector key)
(otherwise (vector key))))
(cond
((keymapp def) "Prefix Command")
((symbolp def) (copy-sequence (symbol-name def)))
((eq 'lambda (car-safe def)) "lambda")
((eq 'menu-item (car-safe def)) "menu-item")
((stringp def) def)
((vectorp def) (key-description def))
(t "unknown")))
bindings)))
finally return bindings))) The problem was that which-key (in I am not sure if this is the right solution. There may be issues I am unaware of, so I want you to test if it produces expected results. You don't have to turn on |
Sorry, it seems to need a lot of workarounds to make it work, so my solution is unrealistic. @terlar was right. Please ignore my comment above. |
Not sure if there is any way around this, but when I define a keybinding with
general-predicate-dispatch
I don't see that key appearing at all withwhich-key
. Otherwise I really like how this one is working, my usage currently:The text was updated successfully, but these errors were encountered: