emacs/var/elfeed/db/data/98/983cfc5a98961f0dfc4876d04b958bc90e1911dc
2022-01-03 12:49:32 -06:00

1 line
2.6 KiB
Plaintext

<!-- SC_OFF --><div class="md"><p>Taking inspiration from Doom, I&#39;m using a &quot;local leader&quot; setup to bind mode-relevant commands, like:</p> <pre><code>(general-create-definer local-leader-def :states &#39;(normal visual motion) :prefix &quot;SPC m&quot;) </code></pre> <p>This way, I can do stuff like <code>(local-leader-def :keymaps &#39;ledger-mode-map &quot;r&quot; &#39;ledger-report)</code>, making it super easy to access the report when I&#39;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 &#39;org-mode-map &quot;a&quot; &#39;(:ignore t :wk &quot;attachments&quot;) &quot;a a&quot; &#39;org-attach &quot;a d&quot; &#39;(:ignore t :wk &quot;deletion&quot;) &quot;a d d&quot; &#39;org-attach-delete-one &quot;a d G&quot; &#39;org-attach-delete-all &quot;r&quot; &#39;(:ignore t :wk &quot;refile&quot;) &quot;r r&quot; &#39;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 &quot;foo&quot;)</code> trick (as seen above).</p> <p>Second, (and more annoyingly, IMO) doing it this way &quot;shadows&quot; the which-key description for modes which share a prefix. That is, if I&#39;m in ledger mode and type &quot;SPC m&quot;, it yields the suggestion &quot;r -&gt; refile&quot; instead of &quot;r -&gt; ledger-report&quot; as it should.</p> <p>I&#39;ve been futzing around with general&#39;s &quot;:prefix-command&quot; and related facilities to try and figure out a way of avoiding this second issue, but so far I haven&#39;t been able to get anything to work. Since my current strategy is ad hoc and not based on any best practices I&#39;m aware of, I thought I&#39;d ask here if there&#39;s a canonical/idiomatic way of using general&#39;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 --> &#32; submitted by &#32; <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> &#32; <span><a href="https://www.reddit.com/r/emacs/comments/qxq0uh/idiomatic_way_of_defining_bindings_with_a_common/">[comments]</a></span>