Minor autoindent bugs

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Minor autoindent bugs

JordanBrown
In 2019.05...

The builtin editor gets some autoindent cases wrong.  (Yes, I use the built-in editor.)

Case A:

If you say
for (i=[1:10]) foo();
it thinks the next line should be indented.

Case B:

If you say
x = [
    for (i=[1:10]) i
];

the first of all it'll try to indent the close-bracket line by two tab stops (one more than the for()), but then it will try to indent everything after that by one.

That is, if I type:

x = [ <Enter>
<Tab> for (i=[1:10]) i <Enter>
]; <Enter>
hello <Enter>
world

I get

x = [
    for (i=[1:10]) i
        ];
    hello
    world

Worse, if I type

x = [ <Enter>
<Tab> for (i=[1:10]) i <Enter>
<Backtab><Backtab>]; <Enter>
hello <Enter>
world

then I get

x = [
    for (i=[1:10]) i
];
    hello
    world

There are plenty of reasonable indentation styles, but I don't think this aligns with any of them.

There's no urgency, but having discovered what looks like a bug I don't want to just drop it.

Should I file a github issue?



_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
tp3
Reply | Threaded
Open this post in threaded view
|

Re: Minor autoindent bugs

tp3
On 16.03.20 02:37, Jordan Brown wrote:
> Should I file a github issue?

Nope, more issues with the same topic will not help.

https://github.com/openscad/openscad/issues/2374
https://github.com/openscad/openscad/issues/1172
https://github.com/openscad/openscad/issues/1075

You could add the examples somewhere if they are not
covered yet. I don't know if there's much of a
chance to fix that though. Right now the editor is
using the existing C++ indentation which causes the
mismatch. Writing an OpenSCAD specific one is
probably not an easy topic. It certainly would be
nice to have of cause.

ciao,
  Torsten.


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
-- Torsten
tp3
Reply | Threaded
Open this post in threaded view
|

Re: Minor autoindent bugs

tp3
On 16.03.20 03:25, Jordan Brown wrote:
> It might not be *that* big a deal.

The problem is that the options to hook into the existing
CPP lexer are limited. Maybe there are some ways to tweak
things to get at least some improvements.

> I'll try to remember to look at it in my Copious Free
> Time, now that I have a working OpenSCAD build environment.

If you give it a shot, feel free to reach out on IRC too
for more interactive discussion :-).

ciao,
  Torsten.

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
-- Torsten
Reply | Threaded
Open this post in threaded view
|

Re: Minor autoindent bugs

JordanBrown
I took a quick stab at just moving the keywords from one list to another.

Indeed, it seemed to change the indentation behavior - in my mind, for the better.  (But I can't claim to have comprehensively tested it.)

It also changed the color of the keywords I moved from green to blue.

It's clear that I don't understand what's really going on, because (for instance) "module" is also in keywordSet[0], and it gets a different indentation behavior.  I just took a blind stab, saying "I want 'for' to behave like 'union' " and so moved it into the same list.  I didn't try to understand the lexer.

diff --git a/src/scadlexer.cpp b/src/scadlexer.cpp
index b5b1a54d..8c9187e6 100644
--- a/src/scadlexer.cpp
+++ b/src/scadlexer.cpp
@@ -6,7 +6,7 @@ ScadLexer::ScadLexer(QObject *parent) : QsciLexerCPP(parent)
 {
        // -> Style: Keyword (lexer.l)
        keywordSet[0] =
-               "if else let for each module function true false undef "
+               "let each module function true false undef "
                "include use assert";

        // -> Style: KeywordSet2 (func.cc)
@@ -24,6 +24,7 @@ ScadLexer::ScadLexer(QObject *parent) : QsciLexerCPP(parent)

        // -> Style: GlobalClass
        keywordSet[3] =
+               "for if else"
                "cube sphere cylinder polyhedron square circle polygon text "
                "minkowski hull resize child children echo union difference "
                "intersection linear_extrude rotate_extrude import group  "

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org