Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code folding for sections #212

Open
christophe-gouel opened this issue Apr 23, 2024 · 3 comments
Open

Code folding for sections #212

christophe-gouel opened this issue Apr 23, 2024 · 3 comments

Comments

@christophe-gouel
Copy link

It would be great to extend the code folding feature, which is limited to a very small set of code blocks for now, to work with whole sections.

This would allow quick navigation in big models by jumping to the proper section after folding everything.

One question is how to define code sections. One reasonable approach would be to follow RStudio approach, which would translate as defining a section by a line starting with a comment character and that contains at least four dashes:

* First level section ----

** Second level section ----

*** Third level section ----

This is compatible with the language and is easy to type and parse.

Here is an example of what it gives in emacs, where I have just implemented it:
section-folding

The icing on the cake would be to add a different syntax highlighting for section headings to distinguish them from simple comments, as I did in the emacs example.

I don't need this feature in GAMS Studio since I program in emacs, but having this in GAMS Studio would create a standard for code section and prevent me from fighting with co-authors who would not see the point of writing comments like this and would break my flow.

@LutzWestermann
Copy link
Member

Thank you for your suggestion! I agree that it can be very helpful to collapse defined sections. We actually introduced the $onFold / $offFold statements for this. They are just comments for GAMS but are understood by GAMS Studio. They can be nested and the first one can get an argument, that is still visible, when the section is collapsed. This could look like this with a modified version of the trnsport model:

image

More about the topic can be found here.

Can this work for you?

@christophe-gouel
Copy link
Author

Thanks for your quick answer.

Cool, I didn't know the $onFold/$offFold$ feature.

However, I don't think it really compares to what I suggest. The point is that GAMS models can lead to very big files that can be difficult to navigate. Basically, if you don't remember exactly the name of the equation you are looking for, it takes endless scrolling. So, the folding structure should be properly nested. OK, you can nest $onfold statements, but they have not a really hierarchy (they are not sections).

You cannot replicate the quick navigation I showed in my gif with your approach. Plus it takes two lines instead of one and visually when unfolded it does not look like separated sections.

In RStudio, code sections lead to a nice outline (see https://posit.co/blog/rstudio-v1-4-preview-little-things/). The outline is both in the text, when everything is folded and in an outline pane for quick navigation (cool but a bit redundant). When looking at the text, it is pretty clear the section level you are in. In RStudio, you can fold some code (like the body of a function) as in GAMS Studio, but also blocks of code through the sectioning system. The fact that the sectioning system is based on comments makes it transparent to the user (much more than $onFold) and allows quick navigation.

@LutzWestermann
Copy link
Member

OK, I see your point and we'll discuss how to proceed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants