I have used both Carsten's and Eric's
solution, as well as
hideshow-org (
https://github.com/secelis/hideshow-org),
which works
rather well and deserves a mention.
Expanding a bit on Carsten's post: Tassilo Horn wrote some convenience
functions to set the outline minor mode regexps to correspond to the
current comment syntax. Thus, if I'm (for instance) in shell-script
mode, # * and # ** become the outline level 1 and 2 markers.
I have all this working and it's great. But... This is using
outline-minor-mode. Like Giovanni, who started this thread, I'm used
to orgmode, which is a little different although it uses outline mode. I
tried hacking the code to use orgstruct-mode, which is the minor mode
version of orgmode. I got a little figured out, but got lost. I would
think all of Tassilo's code to automatically set up outline-regexp would
still be valid, but I'm not doing something right. I saw Carsten's
message to look at the visibility cycling and understand that, but the
keymaps are not working right and the outline-regexp isn't being set
right. I've worked around the latter with a quick function I can call
from the file buffer. However, I don't know what's going on with the
keymap. It looks right. For example, c-h k TAB gives this: