Go Down

Topic: [Closed]IDE Suggestion :- Indented # statements (Read 1 time) previous topic - next topic

ghlawrence2000

Jan 01, 2016, 02:32 pm Last Edit: Jan 02, 2016, 08:40 pm by ghlawrence2000
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
UTFT_SdRaw now included in library manager!! ;) High speed image drawing from SD card to UTFT displays for Mega & DUE.
UTFT_GHL - a VASTLY upgraded version of UTFT_CTE. Coming soon to a TFT near you! 8) Shipping April 1 2016!

PaulS

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?
The art of getting good answers lies in asking good questions.

ghlawrence2000

Ok, fair enough, was just a thought.

Regards,

Graham
UTFT_SdRaw now included in library manager!! ;) High speed image drawing from SD card to UTFT displays for Mega & DUE.
UTFT_GHL - a VASTLY upgraded version of UTFT_CTE. Coming soon to a TFT near you! 8) Shipping April 1 2016!

pert

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 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 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.

ghlawrence2000

@pert,

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

+1

Regards,

Graham
UTFT_SdRaw now included in library manager!! ;) High speed image drawing from SD card to UTFT displays for Mega & DUE.
UTFT_GHL - a VASTLY upgraded version of UTFT_CTE. Coming soon to a TFT near you! 8) Shipping April 1 2016!

Go Up