[Closed]IDE Suggestion :- Indented # statements

When we do a code format, it is immediately obvious which { } belong to each other by the indenting, would it be possible to indent #if #else #endif also?

In long sketches/libraries it is easy to make mistakes or if the code is not your own and you are looking through a library with multiple levels of #statements it is sometimes quite difficult to tell which #if #endif are pairs. If it is possible, I just think it would make life easier if this could be done.

Happy New Year to all.

Regards,

Graham

If it is possible, I just think it would make life easier if this could be done.

None of the versions of VisualStudio that I've used have ever done this. How hard is it to properly indent as you type?

Ok, fair enough, was just a thought.

Regards,

Graham

The problem with the manual indentation solution that PaulS recommended is that you will no longer be able to use Auto Format otherwise it will undo your manual indentation.

You can customize the action of Auto Format by editing the file lib/formatter.conf in your Arduino IDE installation folder. It is recommended that you copy the customized file to the same location as your preference.txt so that your changes won't be lost when you update to a new IDE version. By adding indent-preproc-define and/or indent-preproc-cond to the file you can achieve some automatic indentation according to preprocessor statements. For more information see the astyle documentation: Artistic Style There is actually already in formatter.conf:

# also indent macros
indent-preprocessor

But the indent-preprocessor option doesn't appear anywhere in the astyle documentation. I don't find it in a search of the patches for the version of astyle that the Arduino IDE uses and I don't see any effect from removing that line from the file. The astyle configuration file that Arduino uses to format their examples even has indent-preproc-define and indent-preproc-cond in it.

I like to use the default Auto Format style for consistency so I just comment my preprocessor conditional statements instead of trying to indent but it does get confusing when there are multiple nested conditionals spanning more than a page of code.

@pert,

PERFECT!! Thank you, that's exactly what I wanted. Works a charm.

+1

Regards,

Graham