Arduino Forum

Development => Suggestions for the Arduino Project => Topic started by: ghlawrence2000 on Jan 01, 2016, 02:32 pm

Title: [Closed]IDE Suggestion :- Indented # statements
Post by: ghlawrence2000 on Jan 01, 2016, 02:32 pm
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
Title: Re: IDE Suggestion :- Indented # statements
Post by: PaulS on Jan 01, 2016, 08:44 pm
Quote
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?
Title: Re: IDE Suggestion :- Indented # statements
Post by: ghlawrence2000 on Jan 01, 2016, 09:58 pm
Ok, fair enough, was just a thought.

Regards,

Graham
Title: Re: [Closed]IDE Suggestion :- Indented # statements
Post by: pert on Jan 05, 2016, 10:28 am
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: http://astyle.sourceforge.net/astyle.html#_indent-preproc-block (http://astyle.sourceforge.net/astyle.html#_indent-preproc-block) There is actually already in formatter.conf:
Code: [Select]
# 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 (https://github.com/arduino/Arduino/blob/master/examples_formatter.conf) 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.
Title: Re: [Closed]IDE Suggestion :- Indented # statements
Post by: ghlawrence2000 on Jan 05, 2016, 02:11 pm
@pert,

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

+1

Regards,

Graham