First of all, congrats to all who made and make Arduino IDE the awesome tool that it is. I am grateful for this powerful tool.
I've become hooked on code folding in IDE 1.8.x; I start my day with all folds of my 6000+ line program collapsed, then expand just the ones I want to work on. I would very much like to use IDE 2.x, but I am unable to locate a "Collapse All Folds" command. With a long program like mine, collapsing individual functions is tedious and time-consuming. Is there no way to 'collapse all' in 2.x? Absent this command, the new IDE does not support my (perhaps deeply flawed) work style.
Thanks for any tips to access this command, or work to make it available in the future.
~ Nancy
Nangeroni Design
I'll provide instructions you can follow to do this:
Press the F1 key, or if you prefer, the Ctrl+Shift+P keyboard shortcut (Command+Shift+P for macOS users) to open the "Command Palette".
A menu will appear on the editor toolbar:
Select the "Fold All" command from the menu. ⓘ You can scroll down through the list of commands to find it or type the name in the field.
The keyboard shortcut will be shown in the "Command Palette".
On Windows (keyboard shortcuts may be different from one operating system to another), the default keyboard shortcut for "Fold All" is Ctrl+KCtrl+0. This is a special kind of shortcut known as a "key sequence" (AKA "chord"). You press the first shortcut in the sequence (Ctrl+K), release, then press the second shortcut.
You can also customize the shortcut via the Keyboard Shortcuts configuration interface accessed by selecting File > Advanced > Keyboard Shortcuts from the Arduino IDE menus.
Yikes, I had tried F1 but didn't notice the scrollbar in the command listing. Then, I initially looked for "Collapse all folds", which wasn't there either. Then I looked at your message again and got it right.
I'd prefer that the trailing } be folded so that folded it ends up 1 line per function(), but I trust that whatever is most popular will carry the day and I will adapt.
After all, it's a pretty great tool for a freebie. Thanks to all who maintain it.
Nancy
6000 lines sounds a lot for a ... Have you heard of libraries or even breaking the code into smaller files. After some time you get an idea of the stability of the code - oldest would not have changed etc ... also GitHub is a useful tool to save your work with...
have fun
That's a good idea that also exposes the outer limits of my experience. I've mostly done low-level programming for microprocessors. My relationship with libraries is fraught, I'm always misplacing them. I guess that explains my dependence on the collapse function, which lets me easily partition my code.
GitHub is a good idea. My lack of experience again rears its head. I want to move my project towards open source, so that's now high on the list.
If you are interested in organizing a project into multiple files, but don't want to go so far as moving the reusable functions to a library, you can split your sketch code into multiple .ino files. Arduino IDE concatenates all the .ino files in the sketch into a single file before compiling it, so there is absolutely no difference between a single file of 6000 lines and two files with 3000 of those lines each.
The order of the concatenation is the .ino file that matches the sketch folder name first, followed by all the other .ino files in alphabetical order.
The files of the sketch are shown as tabs in the Arduino IDE editor, so you can quickly navigate to the file that contains the code you want to work on.
You can easily add additional files to a sketch by clicking the ●●● icon at the right side of the editor toolbar, then selecting "New Tab" from the menu.
Thank you for this thorough but clear and concise explanation of how to split my overlong file into more reasonably-sized files. I greatly appreciate your help here, and will begin breaking up my source code forthwith!