Recent

Author Topic: Synedit: folding without end statement?  (Read 7228 times)

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Synedit: folding without end statement?
« on: January 27, 2014, 02:22:23 pm »
Just read the wiki article on Synedit and fiddled with the highlighter example.... now looking at folding.

Suppose I have this text:
Code: [Select]
fpcup: debug: TFPCInstaller: initialising...
Executing : C:\development\fpcbootstrap\ppc386.exe "-h" (working dir: )
Free Pascal Compiler version 2.6.2 [2013/02/12] for i386
Copyright (c) 1993-2012 by Florian Klaempfl and others
C:\development\fpcbootstrap\ppc386.exe [options] <inputfile> [options]
Put + after a boolean switch option to enable it, - to disable it
fpcup: info: well it's a fine day out here
fpcup: debug: more stuff
fpcup: info: yet more stuff
fpcup: debug: TFPCInstaller: initialising AGAIN...
Executing : C:\development\fpcbootstrap\ppc386.exe "-h" (working dir: )
Free Pascal Compiler version 2.6.2 [2013/02/12] for i386
Copyright (c) 1993-2012 by Florian Klaempfl and others
C:\development\fpcbootstrap\ppc386.exe [options] <inputfile> [options]
Put + after a boolean switch option to enable it, - to disable it
fpcup: info: we're done here.

If I understand correctly, it won't be possible to implement folding that folds away the 2 compiler output parts (everything between fpcup: basically).

Correct?
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 5699
    • wiki
Re: Synedit: folding without end statement?
« Reply #1 on: January 27, 2014, 03:36:36 pm »
What you want, is basically what the IDE can do with "var" or "type" blocks.

Code: [Select]
     
      procedure foo;
[-]    var
 |       a: Integer;   
 |_      b: boolean;
     begin
       ...

So it is possible, but not that easy.

In theory you close the block, at the line, before the next keyword. (You can get a 0 line block).
But you are not allowed to modify this line. If you did scanning after text edit might fail.


In SynPasSyn, it is done in procedure EndPascalCodeFoldBlockLastLine;

It stores the info in the current line, as a separate field. (see LastLinePasFoldLevelFix)

The code for "function FoldBlockEndLevel" and related is overridden, and calculates the correct value.


Note: in SynPasSyn the "begin" will only do a close-last-line if it is the very first token of the line. So the var is always on a previous line. If the var was on the same line then it would have to do  a normal close.

Also you need your own range class:
http://forum.lazarus.freepascal.org/index.php/topic,21727.msg139354.html#msg139354 and


The code in SynEdit is more complicated, because it uses the foldblock for fold-able, and none-fold able blocks, and it must keep track of both.
See wiki IncreaseLevel in StartCodeFoldBlock


http://forum.lazarus.freepascal.org/index.php/topic,21727.msg139419.html#msg139419
« Last Edit: January 27, 2014, 03:39:25 pm by Martin_fr »

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Synedit: folding without end statement?
« Reply #2 on: January 27, 2014, 04:02:59 pm »
Great Martin, thanks a lot for the info!
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

Edson

  • Hero Member
  • *****
  • Posts: 1055
Re: Synedit: folding without end statement?
« Reply #3 on: January 27, 2014, 06:40:00 pm »
You could also, just close the current fold block, when finding the initial token of the next block, just before of open the new block. Don't forget to check the position of the token.

Visually, is strange and you could have problem on expanding a "One line block", but I don't know if this apply for you.

PD: I have seen you are updating the Wiki. Good Job  :).
Lazarus 1.6 - FPC 3.0.0 - x86_64-win64 on  Windows 7

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 5699
    • wiki
Re: Synedit: folding without end statement?
« Reply #4 on: January 27, 2014, 07:06:21 pm »
@Edson: That would not work for him.

He knows, the block ended (in the previous line) when he finds a line that starts with "fpcup".

If he closed the fold that line, then that line will be part of the fold, and be hidden. [1] He does not want that.

Of course he could have a peek on the next line, when he finishes scanning a line. But that would NOT work (or only if the text is never edited). Because if the next line was edited, the peeked info may become wrong, but would not be updated.

----------
[1]
At current there is a hack, that deals with
  end else begin
excluding the end.

Not sure where that is, but IIRC not where it should be.

----------------
Another way, that may work: the HL has a method to return the length in lines of a block.
It may be possible (but not tested) to close in the "fpcup" line, and adjust the fold length/line count....

Edson

  • Hero Member
  • *****
  • Posts: 1055
Re: Synedit: folding without end statement?
« Reply #5 on: January 27, 2014, 07:48:48 pm »
If he closed the fold that line, then that line will be part of the fold, and be hidden. [1] He does not want that.

Currently, if one line is part of a previous block, and the beginning of another block, this line is not hidden when the previous block is closed.

This is how it works now. At least in  my system and with differents tokens.

I think it's a good behaviour.
Lazarus 1.6 - FPC 3.0.0 - x86_64-win64 on  Windows 7

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 5699
    • wiki
Re: Synedit: folding without end statement?
« Reply #6 on: January 27, 2014, 08:11:18 pm »
It is a behaviour that makes sense in parts of pascal code. (Actually it is mostly there for "end else begin")
But not necessarily for all else.

Also it makes a different in how the line in the gutter is shown. It does not end above the line, even though the fold will do that.

It is on my todo, to change that, maybe as option, maybe in general (it can then be done by the HL returning the folds as closed "early")

And the block starting in that line must be multi-line (as I understand it the OT does not want to start a block there)

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Synedit: folding without end statement?
« Reply #7 on: January 27, 2014, 08:15:39 pm »
Thanks, guys. It'll likely be some time before I get back to this but I'll save this thread URL in my source code ;)
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified