Text documents of course come in many forms; this extension picks up on some common patterns for fold information. The default is to use the Wiki convention, where a line begining with a number of '=' characters means a heading:
=Main Heading ==Subheading 1 ==Subheading 2 ===Sub 2 1 ===Sub 2 2You can of course change the character used. For Emacs-style outline files, put this in your properties file:
text.outline.char=*You can specify which files are to be treated as text, and what font to use with the following properties. For example, I like editing text in the fixed system font (years of using Notepad do that to a person!):
text.ext=*.txt;*.doc text.font.name=FixedsysAnother common style is to use numbered sections, like 1.2.1. (A bureaucratic curse, perhaps, but some people like it). Here is how to set the folder to recognize this style:
View|Toggle All Foldscommand will now work on your document, and you can of course manually fold and unfold in the usual way. It's common for Wiki-style documents to start at '==', and not have a top-level caption. In that case, you can specify what the starting level is:
text.outline.start=1This will allow you to view the outline for the markup of this page properly.
Tools|Show Outline shows all fold lines.
Tools|Rescancommand to sort the document out if it gets confused; note that this happens automatically on a buffer switch.
These functions allow you to set the folding level of the Scintilla control, and then to extract it. The basic level must start at
SC_FOLDLEVELBASE, and any fold lines must in addition have
SC_FOLDLEVELHEADERFLAG. Please note that the fold information generated by real lexers is more complex, and one has to fake bit operations.
local function set_level(i,lev,fold) local foldlevel = lev + SC_FOLDLEVELBASE if fold then foldlevel = foldlevel + SC_FOLDLEVELHEADERFLAG editor.FoldExpanded[i] = true end editor.FoldLevel[i] = foldlevel end local function get_level(i) local fold = false local level_flags = editor.FoldLevel[i] - SC_FOLDLEVELBASE if level_flags - SC_FOLDLEVELHEADERFLAG >= 0 then fold = true level_flags = level_flags - SC_FOLDLEVELHEADERFLAG end return level_flags, fold endI've made this a SciteExtMan script, to handle the tedious stuff of setting up command handlers and (most importantly) the
OnEditorLineevent. That can get confused with the
OnOutputLineevent, so if you're using the Lua console extension, expect to get the occaisional odd error message in the output pane.
I've toyed with the idea of doing automatic level number generation, but it's not trivial to do properly; one has to renumber items when new items are inserted, etc. (MS Word gets confused about it). This is a start at defining a 'major' mode for text documents (to use Emacs terminology), and obviously there would be 'minor' modes as well, like Wiki markup. It would be cool, for instance, if it automatically detected expressions like
editor.FoldLevel[i] and put it in monospaced font markup.