1

does anyone know how to fold code inside google app script editor ?

it's very hard to read/debug long code inside online editor.

I did some search on google and I couldn't find any result related to this matter.

Rubén
  • 34,714
  • 9
  • 70
  • 166
newbie
  • 128
  • 2
  • 15
  • 3
    You cannot. The alternative is local development using clasp. Consider also using multiple files and functions with a single responsibility. – tehhowch Oct 19 '19 at 11:54
  • thanks. It's hard to believe why google forgot to add such a feature – newbie Oct 19 '19 at 12:01
  • 3
    [There is a feature request for this under Google's issue tracker](https://issuetracker.google.com/issues/64307043). You can help to increase visibility for this issue by starring it. – TheAddonDepot Oct 19 '19 at 12:29

3 Answers3

0

The Google Apps Script editor compared with Visual Studio Code1 and other IDEs is very limited. Since Google added CLASP to Google Apps Script "family" it's very unlikely that it will be added as a built-in feature but maybe this could be added by using a web browser extension.

On the Chrome Webstore there are already some Chrome extensions that extends the Google Apps Script editor but I don't know if already exists one to add code folding.

Notes

  1. VSC is mentioned that is should be used for code auto-completion in https://developers.google.com/apps-script/guides/typescript

Related

References

Rubén
  • 34,714
  • 9
  • 70
  • 166
0

There are many options for folding/unfolding (AKA "collapsing and expanding") sections of code in the Google Apps Script editor without adding a browser extension nor using an external editor.

Simply use: Ctrl + Shift + [

To view other methods, open the Command Pallet by doing one of the following while in the editor:

  • F1 key and type fold
  • Right-click in the editor area and select "Command Pallet", then type fold

From there, you can either click on the command you'd like to execute, or finish typing the phrase followed by enter, or using your arrow keys to select the command followed by enter.

Apps Script Editor Command Pallet Dropdown Menu - fold

You may similarly unfold code by typing the word unfold instead or using Ctrl + Shift + ]

Apps Script Editor Command Pallet Dropdown Menu - unfold

Another option to quickly toggle folding/unfolding while in the editor is to:

  • go to an area/scope of code where you'd like to work
  • hover over the area where you'd fold/unfold that area of code
  • hold the alt/option key, and click.

enter image description here

That will toggle between folding/unfolding all other areas of code besides the one you are working on. GAS remembers the last action you took (fold vs unfold) so sometimes it may require a couple clicks to get the desired result.

One last point which is related to this: You can define regions in your code that you'd like to be foldable. Folding/Unfolding that area will affect all code within it.

//#region My Custom Region
function myFn1() {
  // Some code here.
}
function myFn2() {
  // Some code here.
}
//#endregion
Brandon
  • 3,572
  • 2
  • 12
  • 27
-1

in 2022 this has been added as a built in feature in google appscript editor (new version) , no additional things are required

newbie
  • 128
  • 2
  • 15
  • I didn't downvote this, but I did upvote the other answer that also says this. Look at that one and see how he included more information and how-tos so that the answer was more useful to others. Just for future reference. – Chris Strickland Jul 14 '23 at 07:16
  • @ChrisStrickland LOL more information does not mean it's the correct answers. other 2 answers suggest using vscode and how to add plugin to vscode to make appscript work inside VSCODE, not inside GOOGLE APP SCRIPT editor. my requirement was to fold/unfold code inside GOOGLE APP SCRIPT editor it self , not somewhere else. so this is the 100% correct answer even for future as well. – newbie Jul 14 '23 at 15:51
  • Brandon's answer occurred before yours, correctly references the Apps Script editor and provides detailed instructions on HOW to get the code to fold. It is the superior answer. – Chris Strickland Jul 16 '23 at 12:19