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

Creating a toggle to activate/deactivate keybindings #548

Open
fast-90 opened this issue May 4, 2023 · 3 comments
Open

Creating a toggle to activate/deactivate keybindings #548

fast-90 opened this issue May 4, 2023 · 3 comments
Labels

Comments

@fast-90
Copy link

fast-90 commented May 4, 2023

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!

@noctuid
Copy link
Owner

noctuid commented May 9, 2023

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.

@fast-90
Copy link
Author

fast-90 commented May 9, 2023

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!

@noctuid
Copy link
Owner

noctuid commented May 12, 2023

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.

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

No branches or pull requests

2 participants