Message Boards Message Boards

0
|
5060 Views
|
14 Replies
|
1 Total Likes
View groups...
Share
Share this post:

Is it possible to fold and unfold cells using keyboard shortcuts?

Posted 2 years ago

I would like to be able to 'fold' my functions so that only the first line appears, and then be able to unfold them again, all via the keyboard. Setting a cell to Open or not Open, sort of gives the effect I want, although I would prefer to be able to see the first line of the code.

I have seen reference to using ctrl + ' but using this on on MacOS with the latest V13 doesn't seem to do anything. Is there a setting I need to enable somewhere, or is there a totally different approach I should be using?

Cheers
Andy

POSTED BY: Andrew Burnett
14 Replies
Posted 2 years ago

I am not aware of any such setting for Cells, and I didn't find anything in the options inspector. But I also may be misunderstanding. How would you edit a cell that only showed the first line (assuming there was stuff in the cell below the fold)? Do you want to be folding/unfolding every time you edit? How should the width of the notebook influence what shows in a folded cell? Is there actually some further objective that you're trying to achieve that you haven't told us about?

Like maybe you want to know where a symbol is defined but you want to hide the definition. You could do this by putting a text cell just before the input cell where the definition is. The text cell could contain the symbol name and you could hide (close) the input cell. Or, better yet, use a cell type that has grouping rules (e.g. Section) instead of a text cell. Then, instead of hiding the input cell, you could just close the group.

POSTED BY: Eric Rimbey
Posted 2 years ago
POSTED BY: Andrew Burnett
Posted 2 years ago

Well, it can be done easily, just not automatically (as far as I know). Use Sections/Subsections/etc and expand/collapse the groups. This is pretty much identical to what IDEs do, but they can parse the text to determine where the blocks are, whereas you'll need to decide for yourself where the folding should happen and manually use the appropriate cell type. This is my standard practice when a notebook starts to feel unwieldy.

I believe there are plugins for Mathematica for other IDEs (e.g. IntelliJ or Atom I think--going on memory here). I suspect the trade-offs are extreme.

POSTED BY: Eric Rimbey
Posted 2 years ago

Just double-click the enclosing cell bracket?

enter image description here

Documentation link

POSTED BY: Hans Milton
Posted 2 years ago

Thank you both. I am looking for a mouse-less approach, so I will give the sections mechanism.

Cheers Andy

POSTED BY: Andrew Burnett
Posted 2 years ago
POSTED BY: Hans Milton
Posted 2 years ago

Yes, and Command ' on Mac also works, but what I am struggling with is: 1. It only seems to fold away the result of evaluating a cell 2. It seems as though I need to have the bracket selected for this to work. I.e. just having my cursor on the code doesn't result in the Command ' working. I am wondering if there is a notebook setting that I have to set somewhere. Did this just work out of the box for you?

POSTED BY: Andrew Burnett
Posted 2 years ago

Yes, it did. Cursor somewhere in the "header" cell. Then Ctrl + ' . Bracket selection not needed.

POSTED BY: Hans Milton
Posted 2 years ago
POSTED BY: Andrew Burnett
Posted 2 years ago
POSTED BY: Eric Rimbey
Posted 2 years ago

see the signatures of all my functions without having to scroll through a whole bunch of code

I know this isn't the same thing, but there is a function for seeing definitions associated with a symbol: Information. There is a special prefix form: ??. So you can evaluate this whenever/wherever you want:

??myFunction

Just using the groupings won't show you the signatures unless you manually keep your header text in sync with the function it relates to, but Information will tell you pretty much everything you want to know.

POSTED BY: Eric Rimbey
Posted 2 years ago

Perhaps you could explore an alternative. Do the coding in .wl files instead of .nb files. There you will have a popup menu showing the functions and their expected arguments.

enter image description here

Attachments:
POSTED BY: Hans Milton
Posted 2 years ago
POSTED BY: Andrew Burnett
Posted 2 years ago

Thanks Hans. I had never played with the .wl editor. That is actually an interesting approach. I will definitely try using that more. Being able to jump between functions is very helpful.

Cheers, Andy

POSTED BY: Andrew Burnett
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract