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

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

Hi there, just a quick message to say that v4.3 is now released which fixes the auto-indentation preference.

Have fun!

Thanks so much for remembering I asked about this and letting me know about the update. Very awesome of you! Have a great day!

1 Like