[comp.emacs] Hierarchical program editing

eero@MEDIA-LAB.MEDIA.MIT.EDU (Eero Simoncelli) (05/06/87)

I am a new Gnu user and after reading the manual (5th edition,
December, 1986), I have a question/suggestion.  It seems to 
me that the worst aspect of Emacs is that it doesn't take 
advantage of the hierarchical directory structure of Unix
in Dired mode, or the hierarchical structure of source code
files themselves.  I am suggesting a sort of Dired Outline mode
in which one could Dired a subdirectory and have its contents
appear in the same buffer under the line containing the 
subdirectory name, indented.  In code files, there could
also be an outline mode.  Upon first entering the file, only 
top level lines (ie defuns and defvars for LISP, typedefs and
functions for C, etc.) would be visible.  The subforms of any 
function could be expanded hierarchically.  An option to hide
all comments would also be useful.  Such a mode would only require
8 functions:

	move-to-next-visible-heading
	move-to-prev-visible-heading
	move-to-parent-heading
	move-to-first-child-heading  (expand current heading if necessary)
	
	move-up-on-same-level
	move-down-on-same-level

	hide-subtree
	show-children

It doesn't seem like it would take much time to modify the
present Emacs Outline mode to do this.

Replies to eero@media-lab.mit.edu  (I'm not on any Emacs mailing lists).

p_e@obelix.UUCP (05/07/87)

eero%cadillac@MEDIA-LAB.MEDIA.MIT.EDU (Eero Simoncelli) writes:
> ...
>I am suggesting a sort of Dired Outline mode
>in which one could Dired a subdirectory and have its contents
>appear in the same buffer under the line containing the 
>subdirectory name, indented.  In code files, there could
>also be an outline mode.  Upon first entering the file, only 
>top level lines (ie defuns and defvars for LISP, typedefs and
>functions for C, etc.) would be visible.  The subforms of any 
>function could be expanded hierarchically.  An option to hide
>all comments would also be useful.
> ...
>Replies to eero@media-lab.mit.edu  (I'm not on any Emacs mailing lists).

This is a great idea. The concept of hierarchical editing of files
has been implemented in a number of different editors. I always wished
Emacs would have something similar. If someone is going to hack it up,
then maybe I can suggest something.

I don't really see the advantage in presenting one level of C code at
a time. No, the distinction should be logically based, not physically.
This also implies that Emacs must store hierarchical information in
the source code. This is normally done in special comments which are
hidden from the user. Preferrably, there should also be some character
at the end of a line, indicating that it has descendants.
To make this really useful, it should be possible to write pseudo code
and have Emacs strip this off before compilation. Emacs could make a
file out of every leaf and this should be pure C code. Everything else
is pseudo code.
On the top level it could look like:

Includes                                                                      >
Declarations                                                                  >
main(argc, argv)
  Declarations                                                                >
  Take care of args                                                           >
...

Moving the cursor to the 'Includes' line and giving an 'OPEN' command 
would yield:

Includes                                                                      >
#include <stdio.h>
#include <dir.h>
Declarations                                                                  >
main(argc, argv)
  Declarations                                                                >
  Take care of args                                                           >
...

The line is "expanded" and the underlying nodes become visible. Of course,
these could also have descendants. It would be nice if it was possible
to have the "opened" line highlighted, or something.

I can foresee some difficulty to implement this in Emacs, but with all
the thousands of hackers out there...
-- 
"Be sure brain is in gear before engaging mouth."

Dept of Comp and Info Science	(seismo!mcvax!enea!liuida!obelix!p_e)
Univ of Linkoping, Sweden	(p_e@obelix.liu.se , p_e@obelix.UUCP)