1 line
2.6 KiB
Plaintext
1 line
2.6 KiB
Plaintext
<!-- SC_OFF --><div class="md"><p>Taking inspiration from Doom, I'm using a "local leader" setup to bind mode-relevant commands, like:</p> <pre><code>(general-create-definer local-leader-def :states '(normal visual motion) :prefix "SPC m") </code></pre> <p>This way, I can do stuff like <code>(local-leader-def :keymaps 'ledger-mode-map "r" 'ledger-report)</code>, making it super easy to access the report when I'm in ledger mode with a quick <code>SPC m r</code>. However, this approach starts to break down in more complicated scenarios, such as:</p> <pre><code>(local-leader-def :keymaps 'org-mode-map "a" '(:ignore t :wk "attachments") "a a" 'org-attach "a d" '(:ignore t :wk "deletion") "a d d" 'org-attach-delete-one "a d G" 'org-attach-delete-all "r" '(:ignore t :wk "refile") "r r" 'org-refile) </code></pre> <p>First, this is kind of ugly - Org has a ton of features, and I try to use a lot of them, so some of my key sequences can get pretty long. I end up retyping the same prefix many, many times, sometimes with multiple layers of the <code>(:ignore t :wk "foo")</code> trick (as seen above).</p> <p>Second, (and more annoyingly, IMO) doing it this way "shadows" the which-key description for modes which share a prefix. That is, if I'm in ledger mode and type "SPC m", it yields the suggestion "r -> refile" instead of "r -> ledger-report" as it should.</p> <p>I've been futzing around with general's ":prefix-command" and related facilities to try and figure out a way of avoiding this second issue, but so far I haven't been able to get anything to work. Since my current strategy is ad hoc and not based on any best practices I'm aware of, I thought I'd ask here if there's a canonical/idiomatic way of using general's capabilities to define groups of similarly-prefixed commands without breaking which-key.</p> <p>(Also, why is there a distinction between :prefix-command and :prefix-map? When do you need to store a keymap as the value of a function instead of as variable or vice versa?)</p> </div><!-- SC_ON -->   submitted by   <a href="https://www.reddit.com/user/summetria"> /u/summetria </a> <br/> <span><a href="https://www.reddit.com/r/emacs/comments/qxq0uh/idiomatic_way_of_defining_bindings_with_a_common/">[link]</a></span>   <span><a href="https://www.reddit.com/r/emacs/comments/qxq0uh/idiomatic_way_of_defining_bindings_with_a_common/">[comments]</a></span> |