Intercept the SCIde:s block evaluation

Would it be possible to replace the surrounding parentheses of a code block with something else, e.g. empty line breaks in the SCIde? So that this:


"lines of code".postln;
"lines of code".postln;
"lines of code".postln;

Evaluates the whole block like this on cmd/ctrl+return:

(
"lines of code".postln;
"lines of code".postln;
"lines of code".postln;
)

I’m working a my own live coding system using preProcessor and want to keep it as minimal as possible. My guess is that this is impossible without hacking the actual IDE? I made a solution using Document that searches for empty lines, but it would be so much nicer to have this at the IDE level.

1 Like

I wouldn’t hold my breath on that… There are several feature requests for customizing IDE behavior, but not a lot of developers who are familiar enough with that part of the codebase to do it.

One concrete issue with using blank lines is, in normal SC, it’s fairly common for a block to have blank lines in it. How would you tell the difference between a blank line as a delimiter and a blank line as a pause in a block of code that needs to stay together?

It took quite some effort in my live coding system to be able to handle live coding and standard SC statements in the same block. It was worth it to support, but not easy :laughing:

hjh

1 Like

Here’s an idea: if you put one set of parens over your whole document, then cmd+enter will run it all. But, you still have a chance to intercept the full document string and only interpret a subset of it by using Interpreter:preProcess. In your preprocess function, you should be able to get the current cursor position and document string and simply walk forward and backward to find empty lines, and then return the substring you want to interpret. You won’t get a nice IDE flash for the smaller region, but otherwise it should work fine.

Another option would be to automatically add parens to separate code blocks as you type. It would be straightforward to intercept a subset (or all) keyboard actions on your Document, look for code blocks that are not already surrounded by parens and then add them. Alternatively, you could add parens every time you execute? Lots of possibilities…

1 Like

I see. Yes, i my system i’m not allowed to use blank lines casually or for readability. They have a syntactic meaning. At least that’s my intention.

Intercepting the Document string and checking for blank lines is what i’ve tried so far. It works, but i kind of miss the flashing… But your second suggestion made me think that i might be able to add invisible parentheses on the blank lines. A hack of course, but it might actually work the way i want.

1 Like

Sure, nothing wrong with that. What I was thinking about is, do you want your live coding preprocessor to replace standard SC syntax, or add to it?

If you’re totally overriding sclang syntax, then it will be illegal to have a block containing blank lines, so the desired editor behavior would be consistent with the syntax – ok.

If you expect to use normal SC blocks sometimes, then it would be strange to forbid blank lines in normal SC.

The preprocessor is global, not per code window, so I’d be cautious about totally overriding the SC compiler.

Another alternative btw is TextView (which I do use as a live coding editor). Use keyDownAction to catch the “execute” hotkey and then you can do as you like with the string.

hjh

Good points! Thanks! I want to be able to use normal SC syntax too sometimes i guess. I’ll have to think more about this.
I was also considering other text editors like vim for this.

I’d recommend nvim - there’s a great package SCNvim to interface. Easy to script your wish above

1 Like