Open ttxtea opened 1 year ago
Same here. I'm always using the "Run cell and move down" command, but it only works if I highlight the code to be run. If I don't, I get the error @ttxtea mentions. Meanwhile, the "Run cell" command runs everything in the file, whereas it should really only run current line / block or what is highlighted.
Had the same issue and this bugged me a lot. I came up with a small workaround to restore original behavior of the hydrogen run command.
Add to the init.js script
atom.commands.add('atom-text-editor', 'custom:hydrogen-run', function () {
const editor = this.getModel();
atom.commands.dispatch(atom.views.getView(editor), 'editor:select-line');
atom.commands.dispatch(atom.views.getView(editor), 'hydrogen:run');
atom.commands.dispatch(atom.views.getView(editor), 'editor:move-to-end-of-line');
});
and map a key-binding to this function in the keymap, e.g.:
'atom-text-editor':
'shift-enter': 'custom:hydrogen-run'
EDIT:
If you want it to work with (python) indent-blocks, e.g. function definitions in python, you could do the following. This would allow you to put the cursor on the first line and the code will figure out the corresponding indent block.
atom.commands.add('atom-text-editor', 'custom:hydrogen-run', function () {
const editor = this.getModel();
atom.commands.dispatch(atom.views.getView(editor), 'editor:select-line');
const row = editor.getLastSelection().getBufferRange().start.row;
var k = 1;
while (/^\s+$/.test(editor.getTextInBufferRange([[row+k, 0], [row+k, 1]]))) {
atom.commands.dispatch(atom.views.getView(editor), 'core:select-down');
k = k + 1;
}
if (k != 1){
atom.commands.dispatch(atom.views.getView(editor), 'editor:select-to-end-of-line');
}
atom.commands.dispatch(atom.views.getView(editor), 'hydrogen:run');
atom.commands.dispatch(atom.views.getView(editor), 'editor:move-to-end-of-line');
});
@antonscharton this worked great! The second snippet is exactly what I needed.
Thanks @antonscharton ! This restores expected behaviour for me, but I still get the error pop-up everytime. Does it do that for anyone else?
Description
When running a cell the
TypeError: editor.languageMode.rowRangeForCodeFoldAtBufferRow is not a function
, see below happens.Prerequisites
Versions
Atom: 1.101.0-beta x64 Electron: 12.2.3 OS: Ubuntu 22.04.1 Thrown From: Hydrogen package 2.16.3
Stack Trace
Uncaught TypeError: editor.languageMode.rowRangeForCodeFoldAtBufferRow is not a function
Commands
Non-Core Packages