Skip to content

Re-use keymap (for special modes) #231

Open
@psionic-k

Description

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions