Creating functions- white space?

Hello! I’m having trouble creating white space for a function. When I go to define the function, if I add white space, when I go to add the next line of the function, it automatically puts my line of code back to the start of the line and deletes my white space. I’m unsure how to fix this?

In the Editor tab in the Preferences, there is an option for Auto-align that is enabled by default. I thought that disabling it would prevent this behaviour, but I just tried it and it didn’t make any difference for me (on version 4.2). I’m not sure if that’s because I’ve misunderstood what it does, or if it’s broken.

As a workaround, you could put a semicolon (;) at the start of the line, with spaces after it, like this:

define :myfunction do
  ;               play 60
end

It was unfortunately broken, but now fixed on GitHub, so will be in the next release. Thanks for spotting this!

@wfrj57 - one thing to note is that unlike Python, Sonic Pi does not require tabs/whitespace to structure code. In other words, you can have messy code and Sonic Pi won’t mind one bit. It also means you get to choose how to indent your own code, and in the next version, you’ll be able to disable the auto indentation system and do just that :slight_smile:

Got it!! Makes sense. Thank you @emlyn and @samaaron !!

1 Like