Recent

Author Topic: How to add new code folding rules?  (Read 4061 times)

Areso

  • New Member
  • *
  • Posts: 21
    • My Github
How to add new code folding rules?
« on: April 18, 2016, 06:54:49 am »
Very interesting thing for me:
could I write my own code folding rules for Lazarus IDE? Or just add some my own rules to existing ones?
Lazarus 1.4.4, FPC 2.6.4, target platforms: Windows, Linux (both x86).

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 12386
  • Debugger - SynEdit - and more
    • wiki
Re: How to add new code folding rules?
« Reply #1 on: April 18, 2016, 05:37:52 pm »
Without knowing what you want to add, I can only give very basic pointers.

Folding is provided by the Highlighter, and the unit SynEditFoldedView.

The HL provides what can be folded (except for folding/hiding current selected text)

There is a tutorial on the HL, that also covers the very basic of folding.
http://wiki.lazarus.freepascal.org/SynEdit_Highlighter


Areso

  • New Member
  • *
  • Posts: 21
    • My Github
Re: How to add new code folding rules?
« Reply #2 on: April 25, 2016, 08:18:16 am »
Without knowing what you want to add, I can only give very basic pointers.

Folding is provided by the Highlighter, and the unit SynEditFoldedView.

The HL provides what can be folded (except for folding/hiding current selected text)

There is a tutorial on the HL, that also covers the very basic of folding.
http://wiki.lazarus.freepascal.org/SynEdit_Highlighter
Thank you. I have read provided material. As I understand, this library commonly used for creation new text-based Code Redactors.
As for my example. I often use global variables, and I'd like to fold Unit's var section, 'cause in some projects there are a lot of them.
As for another example, I'd like to fold Try-Except-Finally construction.
Lazarus 1.4.4, FPC 2.6.4, target platforms: Windows, Linux (both x86).

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 12386
  • Debugger - SynEdit - and more
    • wiki
Re: How to add new code folding rules?
« Reply #3 on: April 25, 2016, 01:08:17 pm »
global var and try except are already foldable. This is configurable.

Menu Tools > Options
Section Editor > Code Folding.

Areso

  • New Member
  • *
  • Posts: 21
    • My Github
Re: How to add new code folding rules?
« Reply #4 on: April 25, 2016, 04:36:48 pm »
global var and try except are already foldable. This is configurable.

Menu Tools > Options
Section Editor > Code Folding.
Thank you.
Lazarus 1.4.4, FPC 2.6.4, target platforms: Windows, Linux (both x86).

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 12386
  • Debugger - SynEdit - and more
    • wiki
Re: How to add new code folding rules?
« Reply #5 on: April 25, 2016, 04:58:46 pm »
You can also define fold able areas anywhere in the code by adding to the code:

Code: Pascal  [Select][+][-]
  1. {%region}
  2.   // can be folded
  3. {%endregion}
  4.  
  5. {%region /fold}
  6.   // can be folded / folds by default
  7. {%endregion}
  8.  

And you can also select text, and fold/hide the selected lines.
That however is not restored when the IDE is restarted.

 

TinyPortal © 2005-2018