prko
December 23, 2023, 5:42am
1
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
jordan
December 23, 2023, 12:42pm
2
Perhaps this could work for operators too?
E.g.
x
.foo
+ y
bar: 4
.foo
- car;
smoge
December 23, 2023, 12:48pm
3
I fail to grasp the logic there; it feels quite odd to me!
prko
December 24, 2023, 11:48pm
4
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.
prko
December 24, 2023, 11:51pm
5
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
QList<QTextEdit::ExtraSelection> selections;
selections.append(mBracketSelections);
selections.append(mSearchSelections);
setExtraSelections(selections);
}
void ScCodeEditor::indentCurrentRegion() { indent(currentRegion()); }
void ScCodeEditor::indent(EditBlockMode editBlockMode) { indent(textCursor(), editBlockMode); }
void ScCodeEditor::indent(const QTextCursor& selection, EditBlockMode editBlockMode) {
if (selection.isNull())
return;
QTextCursor cursor(selection);
if (editBlockMode == NewEditBlock)
cursor.beginEditBlock();
else
cursor.joinPreviousEditBlock();
but at a glance I think it is not a straightforward change because you probably also need to extend the tokenizing code:
/*
SuperCollider Qt IDE
Copyright (c) 2012 Jakob Leben & Tim Blechmann
http://www.audiosynth.com
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
This file has been truncated. show original
Good luck!
1 Like
prko
December 28, 2023, 5:14am
8
@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:
/*
SuperCollider Qt IDE
Copyright (c) 2012 Jakob Leben & Tim Blechmann
http://www.audiosynth.com
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
This file has been truncated. show original
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
prko
December 30, 2023, 4:07pm
10
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?
prko
January 5, 2024, 12:00pm
11
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.