Some brackets folding, some aren't

Some of my brackets are allowing me to fold, some aren't. Not sure why as they're formatted the same.

I've tried keyboard shortcuts and finding other forums but don't see anything

Any ideas? Could just be bug but thought I'd ask just in case.

Using Arduino 2.0.1-nightly-20221003

Pictures of code are a waste of time

Please post your code using code tags so that it can be copied

In my experience the easiest way to tidy up the code and add the code tags is as follows

Start by tidying up your code by using Tools/Auto Format in the IDE to make it easier to read. Then use Edit/Copy for Forum and paste what was copied in a new reply. Code tags will have been added to the code to make it easy to read in the forum thus making it easier to provide help.

Hi @caibaldwin. Arduino IDE 2.x uses a crude folding system that is based on code indentation level. The reason that block won't fold is because its code isn't indented.

Select Tools > Auto Format from the Arduino IDE menus to correctly format the code. After that, the folding should work as expected.

1 Like

Thank you both, auto format solved it.

Apologies for screenshot, been a while since i've posted and forgot

1 Like

I think that in this case it was useful to demonstrate the experienced issue. I do not think that there is a way to copy a folded function without it being unfolded when pasted.

1 Like

This was my initial thought, but I could have also just inserted code too.

Anyway, thank you all.

The picture illustrated the problem but gave no opportunity to test it for ourselves with the actual code that was being used

So it should have been a picture and the code as was :wink:

It would not have worked for me because the first thing I do after pasting code from the forum in the IDE is autoformat; just can't help it :smiley:

Me too. It is an automatic action to get the code in my preferred format

Sometimes I also absentmindedly do Ctrl+T on code in the forum. Needless to say it doesn't work, or to be precise it does what it is designed to do in Chrome which is to open a new tab :grinning:

As to the fact that the code posted did not exhibit the problem after formatting it, that would have lead to a discussion about what he/she was doing differently than you and I and we would have got there in the end