Perl Code Folding

I took some first steps in working on Perl code folding for the Perl/NetBeans project that Sudeep Hazra is working on.

You can see the first signs of code folding above, though not completely correct yet.

The main class I changed was this one, as follows, giving you a lot of default functionality out of the box:

import org.netbeans.api.lexer.Language;
import org.netbeans.modules.csl.spi.DefaultLanguageConfig;
import org.netbeans.modules.csl.spi.LanguageRegistration;
import org.netbeans.perl.lexer.PerlTokenId;

//@org.openide.util.lookup.ServiceProvider(service=org.netbeans.spi.lexer.LanguageProvider.class)
@LanguageRegistration(mimeType = "text/x-perl")
public class PerlLanguageProvider extends DefaultLanguageConfig {

    @Override
    public Language getLexerLanguage() {
        return PerlTokenId.getLanguage();
    }

    @Override
    public String getDisplayName() {
        return "Perl";
    }
//    @Override
//    public Language findLanguage(String mimeType) {
//        if ("text/x-perl".equals(mimeType)){
//            return new PerlLanguageHierarchy().language();
//        }
//
//        return null;
//    }
//
//    @Override
//    public LanguageEmbedding findLanguageEmbedding(Token token, LanguagePath lp, InputAttributes ia) {
//         return null;
//    }
} 

Next, unrelated but helpful, the brace matcher can be made to work quite simply by doing the following, which means that two classes can be deleted:

import org.netbeans.spi.editor.bracesmatching.BracesMatcher;
import org.netbeans.spi.editor.bracesmatching.BracesMatcherFactory;
import org.netbeans.spi.editor.bracesmatching.MatcherContext;
import org.netbeans.spi.editor.bracesmatching.support.BracesMatcherSupport;

@MimeRegistration(mimeType="text/x-perl", service=BracesMatcherFactory.class)
public class PerlBracesMatcherFactory implements BracesMatcherFactory {
    
    @Override
    public BracesMatcher createMatcher(MatcherContext context) {
        return BracesMatcherSupport.defaultMatcher(context, -1, -1);
    }
 
}

The Editors/text/x-perl section of the layer needs to be rewritten to the following:

 <folder name="Editors">
    <folder name="text">
        <folder name="x-perl">
            <attr name="displayName" bundlevalue="org.netbeans.perl.file.Bundle#Editors/text/x-perl"/>
            <folder name="FoldManager">
                <file name="org-netbeans-editor-CustomFoldManager$Factory.instance"/>
            </folder>
            <file name="org-netbeans-perl-parser-PerlParserFactory.instance"/>
            <file name="org-netbeans-perl-parser-SyntaxErrorsHighlightingTaskFactory.instance"/>
            <folder name="FontsColors">
                <folder name="NetBeans">
                    <folder name="Defaults">
                        <file name="org-netbeans-perl-file-FontAndColors.xml" url="FontAndColors.xml">
                            <attr name="SystemFileSystem.localizingBundle" bundlevalue="org.netbeans.perl.file.Bundle"/>
                        </file>
                    </folder>
                </folder>
            </folder>
        </folder>
    </folder>
</folder>

Surprised by any of the above information? Ha. That means you haven't followed the related tutorials:

http://platform.netbeans.org/tutorials/nbm-javacc-lexer.html
http://platform.netbeans.org/tutorials/nbm-javacc-parser.html

Do yourself a favor and follow the above two tutorials before even thinking about creating your own editor on top of the NetBeans IDE APIs. 

Next, I'm working on the FoldManager and its factory, which I so far have based on the following:

http://svn.debux.org/webmotion-ext/webmotion-plugin-netbeans/trunk/src/org/debux/webmotion/netbeans/WebMotionFoldManager.java

More soon. I'm aiming to have quite some fun documentation relating to code folding, which is one of the NetBeans IDE APIs about which sporadically (since, after all, how many people in the world are creating editors?) questions arise, soon!

Comments:

Post a Comment:
  • HTML Syntax: NOT allowed
About

Geertjan Wielenga (@geertjanw) is a Principal Product Manager in the Oracle Developer Tools group living & working in Amsterdam. He is a Java technology enthusiast, evangelist, trainer, speaker, and writer. He blogs here daily.

The focus of this blog is mostly on NetBeans (a development tool primarily for Java programmers), with an occasional reference to NetBeans, and sometimes diverging to topics relating to NetBeans. And then there are days when NetBeans is mentioned, just for a change.

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
12
13
14
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today