The combination ctrl+' can be used to fold/unfold a selected group.

Is there a way to fold/unfold all cells at a given nesting level, and possibly also to fold/unfold all groups? I'm thinking something along the lines of ctrl+k ctrl+j, ctrl+k ctrl+1 and so on, that are used for these kinds of folding actions in Visual Studio Code, Atom, and possibly other editors.

Given that in a Mathematica notebook the "nesting" works different than in a regular code editor (no nesting inside code for one), by "nesting level" I here mean to fold/unfold all chapters, sections, subsections and so on.

Edit: I've just found this other post where Kuba gives a function to open/close all groups at a given level. It therefore only remains to find a way to bind this to the appropriate keyboard shortcuts.

I'm however not sure how to use the above mentioned bindings to do this.

  • $\begingroup$ You could iterate the folding process (via the appropriate front-end token) then put that iteration into your KeyEventTranslations.tr $\endgroup$ – b3m2a1 Aug 27 '17 at 16:53
  • $\begingroup$ @b3m2a1 possibly, but my first problem with that is that I cannot find the appropriate front-end token to use. Strangely enough, searching KeyEventTranslations.tr for ' or words related to grouping/folding doesn't give me anything $\endgroup$ – glS Aug 27 '17 at 16:55
  • 1
    $\begingroup$ That's in MenuSetup.tr (most of the key-events are). $\endgroup$ – b3m2a1 Aug 27 '17 at 16:56
  • $\begingroup$ thanks, found it. So the token seems to be OpenCloseGroup. Still I cannot seem to make it work from the front end. Something like FrontEndExecute@FrontEndToken[EvaluationNotebook[], "OpenCloseGroup"] does nothing $\endgroup$ – glS Aug 27 '17 at 17:03
  • 1
    $\begingroup$ Try this: SelectionMove[PreviousCell[], All, CellGroup]; FrontEndTokenExecute[ParentNotebook@PreviousCell[], "OpenCloseGroup"] $\endgroup$ – b3m2a1 Aug 27 '17 at 17:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.