Author Topic: HowTo fold your code with code folding  (Read 7985 times)

Offline Stefan

  • Administrator
  • Hero Member
  • *****
  • Posts: 775
  • Karma: +6/-0
HowTo fold your code with code folding
« on: July 28, 2009, 12:32:53 PM »
HippoEDIT has the option to fold your text or code
by specified chars like { and }  or f.ex. begin and end

This specified chars are defined in {syntax}_def.xml files in HippoEDIT data\syntax-folder.

For example for Pascal syntax there are definition for begin and end like this:
     <Scope open="begin" close="end"/>
in file {path}\HippoEDIT\data\syntax\pascal_spec.xml    (see section A in picture below)


If you want to use your own "folding chars" you can follow this steps.

1) go to {path}\HippoEDIT\data\syntax\

2) open "YOUR" synatx file like pascal_spec.xml
    Note: there are "default" _spec.xml's also.
              If you want this modification for ALL syntaxes use f.ex.  def_spec.xml
              (Or if you like only defsource_spec.xml  or   deftext_spec.xml)

3) add the following text to your *_def.xml file:         (see section B in picture below)
    <Scope open="regionStart" close="regionEnd"/>
Note: "regionStart" is the word to start an folding scope and "regionEnd" is the stop-folding-here term.
(You can also use terms like "fs" for foldStart and "fe" for end or any other you like
as long as the used chars/signs are in <SPECIFICATION> <Words>0-9A-Za-z_</Words> section and don't conflict with your usual typing word. )

4) save your spec.xml

5) re-start HippoEDIT


6) now you can start typing your folding term "regions   "
Note: you will be prompted to finish the typing for you.... just press TAB-key (see point 1 in section C )

If you're finish typing the term regionstart you will be prompted to insert the end-term for you (2 in C )
Press TAB.

(But if you want you can type the terms of your own of course)


Now you should see an folding scope (see point 3 in section C )

If you see nothing .... check your settings (see section D )
You should have "Outline Margin" be enabled.
-- For the current file only you can set settings in View-menu.
-- To set this settings for all files of an syntax go to "Tools > Options... > Syntax Settings > {your syntax}"

code folding c java javascript code folding vbs vbscript wsh pascal code folding html xml programming code folding syntax collaps hiding code source code fold folding
« Last Edit: July 28, 2009, 01:38:56 PM by Stefan »
Stefan, HippoEDIT beta tester 
HippoEDIT - the editor programmers wants to code thyself when they are dreaming.        -Don't just edit. HippoEDIT!-

Offline kryten

  • Registered User
  • Newbie
  • *
  • Posts: 20
  • Karma: +2/-0
Re: HowTo fold your code with code folding
« Reply #1 on: September 13, 2010, 02:44:53 PM »

I'm trying to add code folding for Powershell using regions and having a few problems.

What I want is for everything between




to be collapsible.

I have followed the instructions in the previous post without success.


Added  <Scope open="#region" close="#endregion"/>
to my D:\Program Files\Hippo Edit\data\syntax\Powershell_spec.xml

I also tried adding the same node to the  D:\Program Files\Hippo Edit\data\syntax\Powershell_user.xml
file without success.

I have each time closed and restarted HippoEdit.

I have ensured that "outlining margin" is enabled.

When I type:




automatically appears. But no folding, when I put code into that region.

Am I doing something wrong?

Code folding is working fine on my functions and scriptblocks.

Any assistance appreciated - thanks,

Offline alex

  • Developer
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2225
  • Karma: +37/-3
    • HippoEDIT
Re: HowTo fold your code with code folding
« Reply #2 on: September 13, 2010, 05:18:01 PM »
Hi Stuart,

the reason why it does not work, is that scope definitions allows only word characters in definition (exception is only one char construction). This is not really consistent, but  I will try to adjust it with time. Other problem # is also  occupied by comment starting.
So, to make it running you need to do a little bit more work (example is in cbase_spec.xml + c_spec.xml). Changes should be done in your powershell_spec.xml.

1) Add special style for such regions (helps to distinguish between comments and region definition):
Code: [Select]
     <Style id="format_tag" name="Format tags" bold="2" italic="1" underline="0" clr="Format tag" bkclr="#FFFFFFFF">
          <Block open="#$" close="\n"/>

2) Change description of your scope to this one (to be allowed only in this new style):
Code: [Select]
     <Scope open="region" close="endregion" has_name="true">
        <Containers open="format_tag"/>

3) Add this to labels (optional, will show regions in Navigation Bar):
Code: [Select]
     <Label group="Region" match="region\s+(\w+)\s*$" name="\1" scope="1" image="12">
        <Containers open="format_tag"/>

At the end, this snippet should be recognized as region with name AAAA:
Code: [Select]
#$ region AAAAA
something inside
#$ endregion

I will also update standard powershel_spec.xml soon to be available for others, so you can wait or add this by yourself.

Best regards,
P.S: one more nice thing can be added, is adding of the new code template of such way:
Code: [Select]
#$ region %Region Name%
#$ endregion %Region Name%
than from one side region construction will be suggested inside format tags and from another side you will get additional "surround by template" feature in format menu and in context menu, if something is selected
« Last Edit: September 13, 2010, 05:28:04 PM by alex »

Offline kryten

  • Registered User
  • Newbie
  • *
  • Posts: 20
  • Karma: +2/-0
Re: HowTo fold your code with code folding
« Reply #3 on: September 15, 2010, 09:13:09 AM »
 ;D * 100

Alex, that is AWESOME!!

I could not be any happier with my Powershell editing environment now.
Text editor nirvana!