outshine
outshine copied to clipboard
[enhancement] treat class and function headings as outline headings
It would be great if there was an option to treat function headings, class headings etc (as matched by regexps) as outline subheadings under the nearest preceding outline, so they can be included in outline cycling. One can of course manually add outline lines before each function and each class, but this adds clutter and duplication, especially for short functions.
Related functionality is found in http://www.emacswiki.org/emacs/HideShow.
This is probably the most popular feature request for outshine, but at the same time a complete conceptual mismatch with the basic idea of outshine -> Org-mode outside Org-mode.
In Org-mode a headline is a headline, and functions are hidden in source-blocks. Defining function headers as outshine subheaders would totally wreck havoc with outshine and org-mode. Its impossible, even more on a conceptual than on a technical level.
But thats not a big problem really, because there is navi-mode.el. Simply typing 'f' in the Navi buffer shows you all the function headlines in the associated outshine buffer. You can type 'v' to see all variable definitions, 1 to 8 to see the headlines up to this level, and C-2 f to combine both searches (all headlines up to level 2 and all function headers).
And there is much more possible with navi-mode, I use it all the time. Most of all it allows you to have the overview and the details of a buffer side-by-side at the same time.
navi-mode is certainly useful, but doesn't replace Org's ability to drill down to just one part of the outline, and to move around using 2-3 uniform commands without switching buffers.
Might Org's plain lists be a better conceptual model? They can be cycled, including together with the outline; but, as the manual says, "Items are always subordinate to real headlines, however; the hierarchies remain completely separated.".
Or, maybe just outline-cycle could treat language headings as outline headings, by temporarily let-binding outline-regexp and outline-level for the duration of outline-cycle call?
Does Org-mode fold function headlines? Or plain lists? Could you give concrete examples of navigation,visibility cycling and structure editing functionality that is in Org-mode but missing in Outshine? Some Org-mode stuff might be (way) too complex for Outshine, but as long as it is in Org-mode, it should at least conceptually fit into Outshine too.
It folds plain lists (see doc of org-cycle-include-plain-lists for details). It also folds drawers and code blocks (though the end of those is simpler to find that the end of a function / class).
Conceptually, it might help to think of an implicit headline being added right before each function/class declaration, with level one greater than the nearest previous "standard" headline.
Ok, then I have to take a deeper look on how it is done in Org-mode. The big difference is of course that Org-mode always deals with Org syntax, e.g. with source-blocks, no matter what language is used in them. Outshine on the other hand is a minor-mode that should work with all kinds of programming language major modes - each having its own syntax.
Outshine right now should work out of the box with a G# major-mode that is written in 5 years for a new language, as long as this major mode defines a comment-syntax. But how could one fold functions, classes, methods, structs etc of that language if the are not surrounded by source-blocks? Just blank lines or white space is not really suited for an outline regexp. I can't see a solution for this problem without giving each language its specialized treatment - but Outshine should be major-mode agnostic as far as possible.
Any ideas?
What about just using navi-keywords? It's not much work to define a regexp that matches class/function headlines in a given major mode. You then OR that regexp with the current outline-regexp, with each wrapped in a match group; so you know which one matched. outline-level looks at which group matched and, if it's the user-defined regexp, keeps calling outline-back-to-heading until it gets to a "standard" headline, then adds 1 to the level of that headline.
For outorg you'd just use the standard outline-regexp. For structure editing also. Really it would be enough (I think) if outline-cycle cycled language headings.
That sounds good, I like the idea of reusing navi-keywords for this, since then each user can define his own set of regexps for his favorite language (and possibly send it to me for inclusion into navi-mode). So its not me who has to do all the work (possibly for languages I never use), but the result is a clearly defined alist that can even be used in two modes - navi-mode and outshine. And if there is no entry for a language in that alist, outshine falls back to its standard headline folding behaviour. Nice.
@notestaff There are a couple of things that might do this for you:
-
https://github.com/emacs-helm/helm-navi It uses
navi-keywords
and makes it easy to quickly jump to both headings anddef
s. -
I have this in my
el-mode-hook
:
(setq outline-level 'adp/el-outline-level)
(setq outline-regexp "\\(;;[;]\\{1,8\\} \\|\\((defun\\)\\)")
That lets me collapse defun
s with outline-minor-mode
, and other def
s could easily be added.
Other than those, I'm inclined to agree with Thorsten that this feels slightly out-of-scope for Outshine itself, but maybe I'm just not understanding the idea. :)