general.el icon indicating copy to clipboard operation
general.el copied to clipboard

Creating a toggle to activate/deactivate keybindings

Open fast-90 opened this issue 2 years ago • 3 comments

Hi all, I have the following snippet in my config.

  (general-create-definer local-leader-keys
    :states '(normal visual emacs motion) ; 
    :keymaps 'override 
    :prefix ",")

  (local-leader-keys
    :keymaps 'org-mode-map
    "jc"    '(jupyter-org-clone-block                   :wk "Clone blocks")
    "jm"    '(jupyter-org-merge-blocks                  :wk "Merge blocks")
    "js"    '(jupyter-org-split-src-block               :wk "Split blocks")
    "jj"    '(jupyter-org-jump-to-visible-block         :wk "Jump to block"))

Is there any way to create another keybinding which acts like a toggle to activate/deactivate these four keybindings? I have tried things with :predicate and :prefix-map but couldn't quite figure out how to use them properly (not sure if these are even the solutions for my problems).

Thanks in advance!

fast-90 avatar May 04 '23 09:05 fast-90

Not sure exactly what the purpose of toggling is (e.g. do you want these keybindings to do something else in some context or just go away), but here are some ideas:

  • Create a minor mode, bind the keys in it, and bind another key to toggle the minor mode
  • Use :predicate with a variable and bind a key to toggle that variable

May be able to provide a better solution if you describe the use case in detail.

noctuid avatar May 09 '23 00:05 noctuid

Thanks for your reply. The use case is as follows: I use org-mode for my exploratory data analysis using Python with emacs-jupyter. When I work in an org file that is used as such a notebook, I want to have keybindings for commands such as jupyter-org-execute-and-next-block. However, I don't want to have these keybindings nor do I want them to show up in the Which Key pop up if I work in a "normal" org file (e.g. journalling, org-roam etc.).

Hope this makes sense. Thanks for your insights!

fast-90 avatar May 09 '23 13:05 fast-90

I would have to look at the jupyter code in more depth. Do you just want jupyter-org-interaction-mode-map? If that doesn't work the best way would be to use :predicate with a check for whether the current buffer is being used as a notebook.

noctuid avatar May 12 '23 12:05 noctuid