Bad indentation with curly braces {}

Hi,

Here are two examples that are badly auto-indented because of curly braces (?). Besides, it looks like the ‘Auto-align’ preference is ignored, and auto-indentation always applied.

Example using hash

notemap = { do: 72, re: 74, mi: 76 }
              
              puts "bad indenting"

Example using one-line lambda

inc = lambda {|x| x + 1}
  puts inc(2)

What do you think?

Thanks. Best wishes, ~n

Hey @namin,

welcome to the forums and thanks for the questions :slight_smile:

With respect to your first example, I don’t believe that the issue is due to curly braces, rather it seems that the auto-indentation system is getting confused with the do: which I’m assuming it’s mistaking for a do keyword.

Looks like the error is here: sonic-pi/beautifier.rb at main · sonic-pi-net/sonic-pi (github.com) The regexp is looking for do followed by a boundary which I’m assuming : is being interpreted as. This should be pretty simple to fix :slight_smile:

Unfortunately I wasn’t able to replicate your second issue, that indented just fine for me here. Can anyone else replicate it?

Thanks, Sam!

Very strange, I can no longer replicate the second issue! That’s good… :slight_smile:

1 Like

Related to bad indentation this also happens with two while loops:

y = 1
x = 2
while y<10 do
    y+=1
    print y
    while x<20  do
        x+=y
        print x
      end
    end
    print y
    print x

I think the do on a while loop is optional in ruby. If you omit it, then things are indented correctly:

y = 1
x = 2
while y<10
  y+=1
  print y
  while x<20
    x+=y
    print x
  end
end
print y
print x

Although this is just a workaround, the do is still allowed, so it would be nice if it was indented correctly.

This is true, although I’ve now pushed fixes to both the indentation issues in this thread which will be available in the next beta release :slight_smile:

1 Like

Hi

What about add " around your French notes ?