Recording what I hope is the correct logic (in pseudocode) to handle the "set heading to Level 5" macro even for an
ill-formed outline.
I'm home again, which means it's more convenient to edit "off-line" so that's what's happening.
See:
Contents
Notes
Need to add a collapsed example.
Assumptions
- Consider a very degenerate example, very degenerate case
- The goal is to set the area around the current location of the cursor to "Level 5 collapse" whether it needs to be collapsed or expanded to do so (or some combination of both?)
The Pseudocode
(I will not finish this before I have to leave, will get back to it later.)
- Find the first heading previous to (or at) the current location of the cursor, call it Current_Heading_Position, or CHP as a temporary acronym), and its level (call it Current_Heading_Level, or CHL).
- If there is none (search returns -1): we are at the beginning of the file and there is no heading (oops, modify the degeneate example to include this possibility) — nothing to do
- If "\n Level 5 Heading \f" or "\n Level 5 Heading \n"
- find the end of the Level 5 region, collapse it, done
- Find the Next_Previous_Heading (NPH) at a higher level (Next_Previous_Level, NPL):
-
- If none (-1) — nothing to do
-
- If "\n Level 5 Heading \f" or "\n Level 5 Heading \n"
- find the end of the Level 5 region, collapse it, done
Example to Consider
Expanded Form
text
---++++++ Level 6
text
---+++++ Level 5
text
---++++ Level 4
text
---+++ Level 3
text
---++ Level 2
text
---+ Level 1
text
---++++++ Level 6
text
---+++++ Level 5
text
---++++ Level 4
text
---+++ Level 3
text
---++ Level 2
text
---+ Level 1
text
---++++++ Level 6
text
---+++++ Level 5
text
---++++ Level 4
text
---+++ Level 3
text
---++ Level 2
text
---+ Level 1
text
Collapsed Form (Degenerate Case)
I've labeled this "degenerate" because, for example Microsoft (IIRC), would not collapse the headings into the text.
Note also:
- This is a "total" collapse, there can be all manner of intermediate levels of collapse.
- I may work on a better way to show the collapse on TWiki. In Nedit (and with the switch from continuous wrap to none), the following would show up as one long unwrapped line (stretching way to the right), with a <np> in place of each \f. I may replace the \f's with the ASCII sequence "<np>" just to make the condition more visible. Note that (for me) having the long wrapped line (instead of unwrapped) is not a major negative, hmm, but wait, enclosed in the <pre> tags, it may indeed show up as one long unwrapped line.
text ---++++++ Level 6 text ---+++++ Level 5 text ---++++ Level 4 text ---+++ Level 3 text ---++ Level 2 text
---+ Level 1 text ---++++++ Level 6 text ---+++++ Level 5 text ---++++ Level 4 text ---+++ Level 3 text ---++ Level 2 text
---+ Level 1 text ---++++++ Level 6 text ---+++++ Level 5 text ---++++ Level 4 text ---+++ Level 3 text ---++ Level 2 text
---+ Level 1 text
Contributors
- () RandyKramer - 05 Nov 2003
- If you edit this page: add your name here; move this to the next line; and if you've used a comment marker (your initials in parenthesis), include it before your WikiName.
Revision Comment
Page Ratings