Skip to content
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

Re-use keymap (for special modes) #231

Open
psionic-k opened this issue Jan 6, 2023 · 2 comments
Open

Re-use keymap (for special modes) #231

psionic-k opened this issue Jan 6, 2023 · 2 comments
Labels
enhancement New feature or request

Comments

@psionic-k
Copy link
Contributor

IIRC magit still binds the status buffer independently from the transient definition even though it's mostly the same.

I'm writing some code that goes like this:

(transient-define-prefix uni-dyn-dispatch
  "Control the uni-dyn render states."
  ["Dynaverse\n"
   ["Rendering"
    ("c" "create" undefined :transient t)
    ("p" "pause" undefined :transient t)
    ("k" "clear data" undefined :transient t)
    ("g" "refresh size" undefined :transient t) ; todo add to keymap
    ("f" "fullscreen" uni-dyn-fullscreen)
    ""
    ("q" "quit" undefined :transient t)]
   ["Update Dynamics\n"
    ("l" "iteration limit" uni-dyn--dispatch-set-limit)
    ("p" "sampling scale" uni-dyn--dispatch-set-sampling-scale)
    ""
    ("e" "render escapers only" undefined :transient t)
    ("r" "render repeaters only" undefined :transient t)]
   ["" ("h" "toggle help" transient-quit-all)]])

(defvar uni-dyn-render-mode-map
  (let ((map (make-composed-keymap button-buffer-map special-mode-map)))
    (define-key map "c" #'undefined)
    (define-key map "k" #'undefined)
    (define-key map "g" #'undefined)
    (define-key map "q" #'undefined)
    (define-key map "h" #'uni-dyn-dispatch)

    (define-key map "l" #'uni-dyn-set-limit)
    (define-key map "g" nil) ; there is no update.
    map))

And whenever making special modes like this, it would be beneficial to extract the prefix's map (which has a superset of keymap information) and then modify the keymap for any commands that shouldn't be bound.

What concerns should come up during the implementation? Since a regular keymap is usually not dynamic like transients are during each setup, I believe logic that deactivates keys situationally for the transient UI should be bypassed, meaning a special mode map derived from a transient always has the full set of keys bound and nothing hidden / inapt.

@tarsius
Copy link
Member

tarsius commented Jan 6, 2023

And whenever making special modes like this, it would be beneficial to extract the prefix's map (which has a superset of keymap information) and then modify the keymap for any commands that shouldn't be bound.

I am planing to eventually do something along those lines, but I would probably go the other way. I.e., add a :keymap argument to the prefix and allow suffixes to have no key defined. The key binding would then be looked up in the specified keymap.

One potential benefit of that approach could be that the binding could be changed using keymap-set/define-key instead of the less familiar transient-specific functions. However the main benefit I see and my motivation for adding such a feature, is that it would allow defining prefixes that just show information about the bindings that are available in the currently active keymaps, using transient's buffer. Think which-key but with the added benefit that related commands could be grouped instead of just showing an alphabetic list.

@tarsius tarsius added the enhancement New feature or request label Jan 9, 2023
@psionic-k
Copy link
Contributor Author

probably go the other way

Sounds good. The transient spec would just need to map commands to descriptions.

A modification mechanism for the transient's spec will need to exist. Something more high-level than transient-insert-suffix Would be nice if the modification expressions are very similar to the original declaration expressions, a merging declaration style.

Personally I would prefer certain keys sequences never to be bound. I think it's unlikely that people will want to use long sequences in a modal dialog, and that means transient might also have a need for reducing key sequences while also avoiding ones the user hates. Whether independent or not, I sense a need for mass keymap re-writing, automatic keymap munging.

I was going to work on an automated special mode adapter a while back but realized that automatically generating these mappings didn't seem viable for enough situations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants