0

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.

glS
  • 7,623
  • 1
  • 21
  • 61
  • You could iterate the folding process (via the appropriate front-end token) then put that iteration into your KeyEventTranslations.tr – b3m2a1 Aug 27 '17 at 16:53
  • @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 – glS Aug 27 '17 at 16:55
  • 1
    That's in MenuSetup.tr (most of the key-events are). – b3m2a1 Aug 27 '17 at 16:56
  • 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 – glS Aug 27 '17 at 17:03
  • 1
    Try this: SelectionMove[PreviousCell[], All, CellGroup]; FrontEndTokenExecute[ParentNotebook@PreviousCell[], "OpenCloseGroup"] – b3m2a1 Aug 27 '17 at 17:04
  • Here's the answer to your update: https://mathematica.stackexchange.com/a/6227/38205 – b3m2a1 Aug 27 '17 at 17:35
  • @b3m2a1 do you know if thers is a way to use a sequence of characters for a command? Something like ... KeyEvent["k1", Modifiers -> {Control}] ... does not work. I'm trying to have a command execute when pressing two characters in succession while ctrl is down – glS Aug 27 '17 at 18:20
  • I don't think that's possible (I don't know if even tkinter in python supports that). But post a question about it and maybe you'll get a better answer. – b3m2a1 Aug 27 '17 at 18:23

0 Answers0