Re: Routine folding: display and cursor movement issues
- Posted by Al Getz <Xaxo at aol.com> Aug 30, 2005
- 454 views
Pete Lomax wrote: > > > I've written some (experimental) code to implement folding. I just > wonder if I am "doing it right" and/or if there is "a better way". > > I can't seem to google proper on this either ;-((. > > To begin with, when, say, a routine from line 8 to 12 inclusive is > folded, I add an entry to the bookmark table (another goodie planned > for 0.2.2), of {FOLD,8,12}. Easy. I also have code to update this as > lines are inserted/deleted/etc. > > The "internal" struggle (as in conceptually) is how I display from > line 1 to line 30 normally, but line 1 to 34 with a fold mark against > line 8, and more critically how I cursor up/down from line 8 to line > 13 and vice versa, as well as paging up and down, and opening the > editor with eg the cursor on line 34 in the above described scenario > - so I need to start with line 1 of display as line 1of the file, not > line 4. (I plan to retain folds, btw). > > So my question is: how would you store the (run-time) info: > a) a really packed table that is small but costs alot to scan, > (in practice I probably have to keep that anyway), > b) a full-on 1..length(filetext[currfile]) flag array (or two) > that scans really easy but costs an arm and a leg to update, > c) an array 1..visible lines (by default 1..len(f[c]), with > significant overheads as per or perhaps even worse than b, > d) some other scheme? > > Hopefully, > Pete > > Hi there Pete, There are probably a ton of ways to do this right? One of the simplest is probably this: Assuming you hold the lines in a nested sequence like: { "line 1", "line 2", "......" } Let's say you want to show lines 1 to 30 normally, but lines 31 to 40 you wish to show 'folded'. Let's also assume you're satisfied with the marker "<->" to show a folded section. 1. Move lines 31 through 40 into a buffer with the same structure as the nested sequence above repeated n times. This is easy of course. Note bookmarks adjust={31,40-31+1} or whatever. You'll also have to keep a table of what goes where for later reconstruction for other operations such as file saves. 2. Insert a new line 31 as #FF&"<->" (first char=#FF). 3. Modify the display routine to look for 1st char=#FF. 4. Of course you also have to modify other routines that expect the full text, such as clipboard operations, file save, etc. 5. To reconstruct the text simply replace line 31 with the text saved to location [31] of the buffer. 6. While your at it, you may wish to modify the routines so that you can add other flags too as your program progresses. Some ideas. Take care, Al And, good luck with your Euphoria programming! My bumper sticker: "I brake for LED's"