SC-IDE does not indent the subsequent methods in longer method chans. How about other editors & formatter?

Hello,
According to the following guide,

the following block of code is the recommended style.

Button()
    .states_([["blorp", nil, nil]])
    .action_({
        "hey hey hey".postln
    });

However, SC-IDE indents this block as follows:

Button()
.states_([["blorp", nil, nil]])
.action_({
	"hey hey hey".postln
});

I have tried to find where the indentation feature is defined, but could not find it. Could anyone know? It would be nice if SC-IDE would indent the subsequent methods in longer method chains.

2 Likes

Perhaps this could work for operators too?

E.g.

x
   .foo
   + y
   bar: 4
      .foo
   - car;

I fail to grasp the logic there; it feels quite odd to me!

Your example is not easy to understand. Currently, operators such as + are not indented.
I do not think this is necessary, as I could not find a guideline regarding operators.

I could not find the corresponding part in the *.sc files of my SuperCollider installation. I think it is defined as primitives written in C++.

Indentation is an editor feature, not a language feature. It would be found under editors/sc-ide. I had a look at it once but my C++ isn’t good enough (and would also require familiarity with Qt interfaces).

hjh

but at a glance I think it is not a straightforward change because you probably also need to extend the tokenizing code:

Good luck!

1 Like

@VIRTUALDOG
Thank you for your help.

I did the followings:

[1] I edited the part starting at line 685. I thought this would replace . with \t. after adding \t or according to various parenthesis pairs when there is \n, \s or \t before .. I successfully built SuperCollider on Ubuntu after editing the file, but nothing happened:

QString ScCodeEditor::makeIndentationString(int level) {

 QRegExp rx("(\n|\t|\\s)(\\.)");

 if (level <= 0)
     return QString();

 if (mSpaceIndent) {
     const int spaces = mDoc->indentWidth() * level;
     QString indentationString(spaces, QChar(' '));
     indentationString.replace(rx, "$1 .");
     return indentationString;
 } else {
     const int tabs = level;
     QString indentationString(tabs, QChar('\t'));
     indentationString.replace(rx, "$1\t.");
     return indentationString;
 }
}

[2] I also tried to combine the following code into that section (before return indentationString), but it was not easy.

// #include <iostream>
// #include <string>
#include <regex>

int main() {
    std::string code = "SinOsc\n.ar\n\tSinOsc\n\t.ar\n\t\tSinOsc\n\t\t.ar\n";
    std::regex regexPattern("(^|\t|\\s+)(\\.)");

    std::string transformedCode = std::regex_replace(code, regexPattern, "$1\t.");

    std::cout << code + "\n";
    std::cout << transformedCode;

    return 0;
}

I find it a bit strange that SC-IDE indentation does not support this indentation, which is described in the recommended code style.

But, abandoned!
I am not at the level to implement this feature. I do not even have the introductory basics in C++ and Qt to do what I want.

Anyway, it was a good experience for me. Thanks again!

indentationString is just a string of tabs or spaces, so your regex wouldn’t do anything. Regex is not really the tool for this, you have to extend the lexer since it doesn’t currently understand method continuations.

Well, in open source to have features you need someone to implement them, unfortunately lots of people are requesting things but nobody is coding them, this leads to the current state.

2 Likes

Hm…,

Do other sclang-supporting editors support this indentation?

@john-d-murphy: How about your tree-sitter support for supercollider regarding this?

I think the code style guide should be changed if there is no sclang-supporting editor that supports it. How about your thoughts?

sclang-format is not a sclang-enabled editor, but it does support indentation for the followings:

  • .method’ starting on a new line with or without spaces or tabs.
  • operators starting on a new line, with or without spaces or tabs.

(caution: It does not format schelp files.)
Example:

from

(
{
	SinOsc
 .ar
* 0.1
}.play
)

to

(
{
	SinOsc
		.ar
		* 0.1
}.play
)

by

cat /Users/prko/Downloads/test.scd | ./sclang-format -t

in the folder where sclang-format exists.