Custom key bindings in SageMathCell CodeMirror blocks?

14 views
Skip to first unread message

Tevian Dray

unread,
Apr 16, 2018, 11:21:20 PM4/16/18
to sage-cell
Is there a way to load a custom key map into an embedded SageMathCell using CodeMirror blocks?  I am specifically interested in restoring my favorite emacs key bindings.  CodeMirror itself allows this; see:
(and take a look at the source code), essentially by loading
and then passing
    keyMap: "emacs"
in the CodeMirror call (at the end of the document).  But there doesn't appear to be a way to pass that setting as an option in the makeSagecell call, nor could I figure out a way to apply the CodeMirror JS directly to a sage block.

Is there some way to achieve this functionality using SageMathCell?  It's a bit frustrating to know that CodeMirror has a setting for this, which I don't (yet) know how to access.  To be clear, I am of course talking about SageMathCells embedded in my own webpages, where I have control over the options.

Andrey Novoseltsev

unread,
Apr 17, 2018, 11:24:15 PM4/17/18
to sage-cell

This is certainly not supported directly. In principle allowing arbitrary CodeMirror extensions and options could be useful, you can take a look at https://github.com/sagemath/sagecell/blob/master/js/editor.js and perhaps figure out a clean API with implementation for this ;-)

Tevian Dray

unread,
Apr 18, 2018, 1:12:23 PM4/18/18
to sage...@googlegroups.com
> This is certainly not supported directly. In principle allowing arbitrary
> CodeMirror extensions and options could be useful, you can take a look at
> https://github.com/sagemath/sagecell/blob/master/js/editor.js and perhaps
> figure out a clean API with implementation for this ;-)

Thanks for pointing out this file, but I don't speak JS well enough to
pursue a general solution. So I guess this becomes a feature request:

It would be nice if the options to makeSagecell included a keyMap
option, which, if present, could be included in the editorData
definition in this file. It would also be nice to automate the
subsequent loading of the appropriate keymap itself (e.g. emacs.js) from
codemirror.net, but authors of webpages with embedded SageMathCell
blocks could also be expected to do that manually so long as there were
documentation to that effect.
Reply all
Reply to author
Forward
0 new messages