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

Offline Stefan

  • Administrator
  • Hero Member
  • *****
  • Posts: 775
  • Karma: +6/-0
    • View Profile
HowTo fold your code with code folding
« on: July 28, 2009, 11:32:53 am »
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:
   <SCOPES>
     <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)
   <SCOPES>
    <Scope open="regionStart" close="regionEnd"/>
   </SCOPES>
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, 12: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
    • View Profile
Re: HowTo fold your code with code folding
« Reply #1 on: September 13, 2010, 01:44:53 pm »
Hi,

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

What I want is for everything between

#region

and

#endregion

to be collapsible.

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

I've:-

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:

#region

..then..

#endregion

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,
Stuart
 

Offline alex

  • Developer
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2181
  • Karma: +37/-3
    • View Profile
    • HippoEDIT
Re: HowTo fold your code with code folding
« Reply #2 on: September 13, 2010, 04: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">
        <Blocks>
          <Block open="#$" close="\n"/>
        </Blocks>
      </Style>

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"/>
      </Scope>

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"/>
      </Label>

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,
Alex.
P.S: one more nice thing can be added, is adding of the new code template of such way:
Code: [Select]
#$ region %Region Name%
%SelectedText%
#$ 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, 04:28:04 pm by alex »

Offline kryten

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

Alex, that is AWESOME!!
THANK YOU.

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

Cheers,
Stuart

 

Related Topics

  Subject / Started by Replies Last post
5 Replies
3390 Views
Last post March 08, 2009, 11:41:32 pm
by alex
1 Replies
1761 Views
Last post March 14, 2009, 03:54:26 pm
by alex
1 Replies
2002 Views
Last post June 29, 2010, 08:20:16 pm
by alex
2 Replies
2069 Views
Last post August 31, 2011, 12:37:26 am
by RickF
2 Replies
1196 Views
Last post September 16, 2014, 02:38:47 pm
by Andreas