Closed flying-sheep closed 4 years ago
@ryanhomer - are you actively working on this still?
Hi Tiffany. I’m not currently working on this as I’ve been juggling priorities and wasn’t sure how much of a demand there was for it. I can take a look at what would be involved if this is something you need. I’m also willing to accept merge requests if others are interested in enhancing this plugin.
Thanks @ryanhomer - totally understandable and this is very helpful as is. I would be happy to further develop to do what @flying-sheep suggests, but I need a little direction as to how to specify the list of languages the shortcuts are enabled for. @flying-sheep any chance you can point me in that direction?
Ok, sounds good. I'll provide as much support as I can from my end.
When the plugin calls this insertText
function, it passes in a reference to the current notebook. You can then get the current session context (tracker.sessionContext
) according to the documentation here. I believe this will give you information about the current kernel. See this page for its properties such as name
and kernelDisplayName
.
We'll also need a way to label each shortcut with an associated language. I'm not sure if you can add extra meta data to the shortcuts JSON; something to investigate. This will give you something to compare the current kernel against to determine whether to use the shortcut or not.
This begs the question: will you be able to use the same shortcut key combo for different text strings based on the language/kernel and if this will not be possible, is it really worth the effort to restrict a shortcut based on language just for the convenience of not inadvertently activating a shortcut?
Addressing the main goal presented in this issue, which is to ship the plugin with default shortcuts, we'd need a way to add the appropriate JSON to the user settings 1) only upon installation of the plugin and 2) only if the shortcuts that are included with the plugin are not already configured for the user (though I guess it would be quite unlikely). Perhaps, the plugin could ask the user if to install a default set of shortcuts upon installation. Not quite sure how to asks this question during installation or initial setup of the plugin though.
Finally, for a UI interface, I believe @jupyterlab/shortcutui
may be helpful for viewing/editing the actual shortcuts, though if I remember correctly, I think I tried it out before and it was only marginally helpful.
@joelostblom @ttimbers I've figured out a way to enable the shortcuts for specific kernels. The user would need to add one extra parameter per shortcut configuration, e.g. "kernel": "ir"
as in:
{
"shortcuts": [
{
"command": "text-shortcuts:insert-text",
"args": {
"kernel": "ir",
"text": "%>%",
"autoPad": true
},
"keys": [
"Accel Shift M"
],
"selector": "body"
},
.
.
.
]
}
This would be an optional parameter that, if present, would restrict the shortcut to the named kernel, otherwise would continue to work for any kernel.
Give me a few more days to see if I can figure out how to add the JSON to the configuration automatically on installation of the plugin. If I succeed, I'll get it documented in the README and publish a new version.
Cool! nice work @ryanhomer 🎉 And I will eagerly await your next move (Re: add the JSON to the configuration automatically on installation of the plugin)!
Great, thank you so much @ryanhomer !
@ttimbers @joelostblom The extension plugin has been updated to include the two shortcuts by default. Additionally, they will only work in R notebooks. The README.md
file has been updated with the details.
If you had the earlier version installed, the user-defined shortcuts will override the default ones; you may now remove those.
This is amazing!!! We will use this in MDS this year and attribute & credit you! Thanks!! :tada:
Nice. Glad I could contribute in some small way. Happy MDS 2020/21!
And thanks to @flying-sheep for initiating the thread. I just noticed that the original request was to specify a list of languages per shortcut. I'll do that in a future update.
Thank you for implementing this so quickly @ryanhomer ! I added it to the setup and tried it on all three OSes and it works great :+1: A clear simplification of the installation instructions!
I added promotion to https://irkernel.github.io/installation/
Thanks @flying-sheep!
It would be useful to be able to optionally specify a list of languages the shortcuts are enabled for. Then we could ship the two example shortcuts by default because they’d only be enabled in R kernels.