Skip to main content

front end - Close subgroup of cells and keep them closed


Styles can be used to give your calculation a book-like structure; with chapters, sections and paragraphs. Closing those subgroups of cells you don't want to see is then very powerful to create visual order. I use this to keep oversight of my calculation. The cells containing the actual calculations I close, and only the titles and heads are visible.



This works well until I evaluate cells. Whenever a result or message is printed, the cells open automatically, and the notebook becomes a mess again. My question is: how can I prevent these cells from opening ?


I have some ideas, but I would like to hear if you have any (better) alternatives. This I what can think of:



  • Add a semicolon after each line.

  • Use Block[{Print}, Expression} to suppress Print statements


The side effect of these methods is that no results or messages are printed at all. I would like them to be printed though. At the same time I want to decide my self when to open a cell or not.



Answer



Adapting this answer, please try this:


autoFoldOutput[] := (If[$FrontEnd =!= $Failed, 

SelectionMove[EvaluationNotebook[], All, EvaluationCell];
FrontEndTokenExecute["SelectionCloseUnselectedCells"]])

And then in a new cell:


2 + 2
autoFoldOutput[]

Comments