[Lazarus] automatic code unfolding, on edit (inside fold)

Mattias Gaertner nc-gaertnma at netcologne.de
Thu Jul 31 23:58:49 CEST 2008

On Thu, 31 Jul 2008 14:21:03 +0100
Martin Friebe <lazarus at mfriebe.de> wrote:

> While working on http://bugs.freepascal.org/view.php?id=7773, there a
> a few behavioural decisions:.
> The basic of the bug is (| = cursor):
> [ some comment is not needed,, but refers to later, to point out
> special situations ]
>   [+]  If a=b then begin {some comment} |
>          //Line after  end of above block
> The code is folded as above. If you press return a new line is
> inserted. It is inserted into the block, not after the block.
> Currently this leads to a (partial) unfold of the block.
> Similar issues can arise if:
> - a multi line text is inserted from clipboard
> - a multi line pattern replace occurs inside a fold
> - text is inserted elsewhere in a block (using other bugs, such as 
> move-cursor-word-left does jump into folds)
> The fact that the code unfolds at all, seems more result of a bug,
> than intention (so that can be seen either way) => The same code
> unfolds are valid folded block, if you insert a new "begin" in the
> text above it.
> ----
> In any case, I need to define a new valid behaviour. May intentions 
> would be:
> - inserting a new "begin" above a valid, unchanged folded block, will 
> keep this block folded
> - doing changes in the middle of a folded block, will keep it folded.
>   This should only occur with "replace-all".

And many codetools. For example rename identifier or class completion.

>   Any other operation needs to be fixed, and prevented to go into a 
> folded block. Or additional behaviour needs/can be defined later

Can you explain how?

>    ( I am thinking of a temporarily (maybe even intended partial)
> unfold during search/replace inside a folded block. => this would
> automatically fold again. However this is not part of the current
> work-item)
> - There should be no other "in folded block changes" So there is no
> need to provide "open-fold" behaviour for them (As long as the fold
> either opens correct (completely) or does not open at all)
> - ===> The only operation that will require to open a folded block is
> a return at the end or in the middle of the fold-start line
> (fcCollapsed / the line with the begin).
>  Alternatively this could insert  the new line after the block => I 
> don't think that would be intuitive, especially if the cursor was 
> between the "begin" and {comment} => then the comment would have to
> stay in the block, and an unfold was needed.


>  If the cursor was in front of the begin, the fold could be
> preserved. But I do not know if I will do that now. (since a/many new
> line(s) could also be inserted from clipboard or replace.
> I may base the condition as follow. If a line is inserted exclty
> below the cfCollapsed line, then an unfold occurs.


More information about the Lazarus mailing list