I do not think there is a predefined command that you are looking for. You can implement it yourself.
If this is a one-time task, I would use the emacs macro:
You only show top-level headings. Then you go to the first heading and start the Cx ( macro Cx ( . You select the C-SPACE Cn and type Cu Mx prepend-to-register . Cu also deletes the line. You stop the Cx ) macro Cx ) .
Now you repeat the macro for all top-level headings M-0 Cx e .
And you insert the register Cx ri .
Oleg Pavliv
source share