Tags:
create new tag
, view all tags
I've been working more offline the last couple weeks — I'm still not finished with the Nm TWiki Fold Single Heading macro, but I've "learned" a fair amount and am at a place where I have good Internet access, so I'm going to record some things on WikiLearn today.

I've "reserved" the pages ...Dev1 thru ...Dev3 to copy some of the other development pages that I've created offline, partly as sort of a record as my thinking process as I developed these macros.

A current summary:

  • I haven't completed the single heading macros and, in fact, at this point, don't even have the logic correctly worked out. I have a few versions (that I may very well not preserve) that almost work.
  • I should distinguish between two major variants of these macros:
    • One that I'll call (for now, after some "learning") the Microsoft approach — in general, you put the cursor in a heading and click expand or collapse, and that particular heading expands or collapses in a sequence something like the following (or vice versa for expand) (I'm not 100% sure this sequence is correct, but I have the correct sequence in my notes) and, I believe I have the logic correctly worked out for this approach:
      • Collapse (any visible) text
      • Collapse the lowest level (visible) heading
      • ...
      • Collapse the highest level (visible) heading
    • The other (that is what I am striving toward) is one where you put the cursor anywhere in the text and press a shortcut key that specifies the desired fold level (like set_level_5), the macro determines the appropriate range (of text and headings) to be dealt with and expands or collapses that range to the specified level. We'll get back to this (more than once) so eventually we'll have a good explanation.

I believe I have the logic correctly worked out for for the first approach, but the second approach can get very complex (unless I'm overlooking some simplifications). Some of the reasons for the complexity include the following. (Some are obviously more significant than others, but I probably won't rank them in this first listing.):

  • Limitations of the Nedit macro language:
    • In a regular expression, you can't use a variable as a multiplier. I.e., it would help if I could do something along these lines: a=5, and then in the RE: ...\\+{1,a}..., but that does not work.
    • The looping constructs are somewhat limited, there is neither a goto or a case statement (yes, I've been well indoctrinated) in the evils of goto — still, sometimes it helps.
  • An outline can be very complex. I want to introduce three terms:
    • well-formed outline: An outline that meets certain rules (discussed on the linked page)
    • ill-formed outline: An outline that meets those certain rules (examples on the linked page)
    • outline: A "generic" outline that might be well- or ill-formed (or have regions of either).
  • Because of the possible complexity of outlines, my first few approaches were oversimplifed and did not work when I hit some of the more complex outlines. (Lesson learned (I hope): I avoided creating a wealth of examples (to include all the ill-formed outline possibilities) because it was hard to think through, nevertheless, I would have been better off if I had accomplished that sooner.)
  • Now that I realize some of the complexity possible in outlines, I: * realize why Microsoft (in Word's outlining features) limited some of the possible outlines they deal with, IIRC, if a document does not start with a heading matching the highest level heading found elsewhere in the document, that first section will not collapse
    • I may consider similar or slightly different restrictions on the types of outline these macros will properly handle. (This will be discussed more later, but I'll point out that doesn't bother me too much, because, if the individual heading macros create a strangely collapsed outline, the global macros (NmTWikiFold), can, almost certainly, restore the outline to a more "normalized" collapsed state.
  • Another point that adds to the complexity of creating these macros relates to the way terminology (and markup?) of headings — a Level 1 heading is marked up as "---+" while a Level 6 heading is marked up as "---++++++". But, a Level 1 heading is the highest level heading, and Level 6 is the lowest level heading, thus leading to situations in the code where you (I) talk about the lowest level heading but its numeric value (in some contexts) being 6, and the highest level heading with its numeric value being 1. Just another element of cognitive dissonance (iiuc).
  • I do believe that I've worked out the logic for the complex most ill formed case, and since I've done that, I'll record it (in "ugly" pseudocode) for one level (the logic is similar for all levels, but is not generic) on Nm TWiki Fold Single Heading Logic for Ill-formed Outlines. It is so complex that I'm not sure I want to bother coding it or creating the variations for the other 5 possible levels. I guess I'm hoping either I'll have a revelation and find some simplification, or Nedit, AbiWord, or some other editor with a macro language that might make it a little easier to code.

Some of the simplifications I might consider:

  • (Uncertain of the value of this): If cursor is anywhere on a line, assume it's at the front of that line.
  • Require the user to put the cursor on the line (or at front of the line) at the beginning of the region he wants to expand or collapse — in other words, require the user to do the complicated logic that is causing me so much trouble)
  • Disallow ill-formed outlines:
    • Require user to avoid?
    • Build logic to prevent? (Complicating factor, see Nm TWiki Fold Well Formed Outline for more information, but, to really enforce those rules, they would have to be added to TWiki. I don't foresee doing that, or attempting to enforce such rules on uninterested TWiki users.)

Aside: Am I reinventing the wheel? Should I be looking for the worked out logic to accomplish this folding somewhere in the literature? Maybe! Certainly if I thought it was available I'd be better off reusing it than recreating it. I'm sure I've done some looking (well, maybe just keeping my eyes open in case I ran across something to deal with this in my fairly extensive reading and web-surfing), but haven't noticed anything helpful for the current problem (fold single heading) -- I did a set of folding macros for Nedit that tipped me off to the \f trick. To a certain extent, Microsoft and other companies that have done collapsible editing or folding must have built (part of this wheel), but:

  • They aren't likely to share it with me wink (Hmm, I wonder if I'd find anything helpful in EMACS.)
  • I'm not aware of any product (not that I've made an exhaustive search) that implements the fold single heading approach that I'm trying to accomplish.

Aside: I wrestled a little with calling the ill-formed outline a degenerate outline, but ran into two problems — what to call a non-degenerate outline (a generate outline??) and/or what term to use generically for an outline that might be either. (One possibility, tongue-in-cheek, is outline, degenerate outline, and non-degenerate (or generate) outline.)

See:

Contents

Notes

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

  • %DATE% —

Page Ratings

Edit | Attach | Watch | Print version | History: r3 < r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r3 - 2005-04-06 - RandyKramer
 
  • Learn about TWiki  
  • Download TWiki
This site is powered by the TWiki collaboration platform Powered by PerlCopyright 1999-2017 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding WikiLearn? WebBottomBar">Send feedback
See TWiki's New Look