org-roam / org-roam-bibtex

Org Roam integration with bibliography management software
GNU General Public License v3.0
568 stars 47 forks source link

(fix) Make org-roam-bibtex-mode buffer-local #182

Closed roshanshariff closed 3 years ago

roshanshariff commented 3 years ago

Avoids make the keymap active globally, since C-c ) conflicts with RefTeX, for example.

Update the README to hook into org-roam-file-setup-hook, so org-roam-bibtex-mode is activated only for org-roam files.

myshevchuk commented 3 years ago

Hi,

Conceptually, org-roam-bibtex-mode is a global mode because it modifies the global state. Namely, it changes the behaviour of ivy-bibtex, helm-bibtex and org-ref to make them use org-roam for note management instead of their built-in facilities. These commands are meant to be used anywhere in Emacs, so it would make little sense if, for example, helm-bibtex will open org-roam notes only when called from an org-roam buffer, and would not work anywhere else.

Thank you, however, for bringing the keymap conflict to my attention. If this is the only issue with org-roam-bibtex-mode being a global mode, then it would be better to assign a different key or keys. I did not check for such conflicts thoroughly when making the keybindings and would not mind if they are changed to other key sequences.

roshanshariff commented 3 years ago

Yes, you're right. I was thinking that three of the four commands currently bound in the C-c ) map are mostly useful while editing org-roam notes (i.e. all but orb-find-non-ref-file). Perhaps you could have an additional org-roam-bibtex-local-mode that just activates this keymap? Then the org-roam-bibtex-mode would have no keybindings. The orb-find-non-ref-file function can be left without a binding, but a user can bind it instead of org-roam-find-file if they prefer. What do you think?

myshevchuk commented 3 years ago

orb-note-actions is indeed a local command because it reads the value of #+ROAM_KEY: in the current buffer. It is a candidate for a local keymap. Three others can in principle be used in other buffers. orb-insert and orb-insert-non-ref make only sense when used in Org-mode buffers (not necessarily Org-roam buffers though), while orb-find-file-non-ref can be used in other modes too. The orb-insert commands are therefore candidates for org-mode-map, while orb-find-file-non-ref is a candidate for the global keymap.

I'm not sure if a single command justifies introducing another mode that wouldn't do anything useful apart from setting the keybinding. On the other hand, the current situation with orb-note-actions being bound in org-roam-bibtex-mode-map can be considered a bug, because it implies that this command may be used anywhere as long as the mode is active, which is not the case. Maybe for now just refrain from defining keys and let the user decide?

I have recently learned that some users would prefer binding Orb note actions to actual key sequences rather than calling them through the orb-note-actions dispatcher. So a local org-roam-bibtex mode can be introduced to support direct keybindings for these commands. I'll have to look whether any changes to the code are needed to decouple these commands from the dispatcher.

roshanshariff commented 3 years ago

Thanks for fixing the keybinding issue! I'm closing this pull request.

myshevchuk commented 3 years ago

Sure, thank you for letting me know about the issue. If you'd like a local org-roam-bitex-mode or a local keymap, which is another possible option, please open a new feature request.