Menu

Adding set of keywords to syntax highlighter

2008-07-12
2012-11-13
  • Nobody/Anonymous

    I am very impressed with Notepad++ so I'm switching from UltraEdit which I've been using for years, keep it up!

    Anyway, I primarily write PHP and Javascript. In UltraEdit the syntax highlighter will do common function/variable/property names in a different color.
    Javascript Example:
    var test = new Array();
    test.push('foo');

    In the above example, I would like:
    var to be blue - operator
    new to be green - alternate operator
    Array to be red - object
    push to be orange - function

    I have the lists of words I want, but I can't get the syntax highlighter to do them.. I've spent hours modifying stylers.xml and langs.xml to no avail. Can anyone help me get this working? I'd like to do similar for PHP (e.g. str_replace in orange).
    stylers.xml:
            <LexerType name="javascript" desc="Javascript" ext="">
                <WordsStyle name="DEFAULT" styleID="41" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" fontSize="" />
                <WordsStyle name="NUMBER" styleID="45" fgColor="FF0000" bgColor="FFFFFF" fontName="" fontStyle="0" fontSize="" />
                <WordsStyle name="WORD" styleID="46" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" fontSize="" />
                <WordsStyle name="KEYWORD" styleID="47" fgColor="0000FF" bgColor="FFFFFF" fontName="" fontStyle="0" fontSize="" keywordClass="instre1" />
                <WordsStyle name="OPERATOR KEYWORD" styleID="53" fgColor="008040" bgColor="FFFFFF" fontName="" fontStyle="0" fontSize="" keywordClass="instre2" />
                <WordsStyle name="TYPE WORD" styleID="16" fgColor="FF0000" bgColor="FFFFFF" fontName="" fontStyle="0" fontSize="" keywordClass="type1" />
                <WordsStyle name="FUNCTION NAME" styleID="54" fgColor="FF8040" bgColor="FFFFFF" fontName="" fontStyle="0" fontSize="" keywordClass="type2" />
                <WordsStyle name="DOUBLESTRING" styleID="48" fgColor="646464" bgColor="FFFFFF" fontName="" fontStyle="0" fontSize="" />
                <WordsStyle name="SINGLESTRING" styleID="49" fgColor="646464" bgColor="FFFFFF" fontName="" fontStyle="0" fontSize="" />
                <WordsStyle name="SYMBOLS" styleID="50" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="1" fontSize="" />
                <WordsStyle name="STRINGEOL" styleID="51" fgColor="646464" bgColor="FFFFFF" fontName="" fontStyle="1" fontSize="" />
                <WordsStyle name="REGEX" styleID="52" fgColor="910000" bgColor="FFFFFF" fontName="" fontStyle="0" fontSize="" />
                <WordsStyle name="COMMENT" styleID="42" fgColor="008080" bgColor="FFFFFF" fontName="" fontStyle="0" fontSize="" />
                <WordsStyle name="COMMENTLINE" styleID="43" fgColor="008080" bgColor="FFFFFF" fontName="" fontStyle="0" fontSize="" />
                <WordsStyle name="COMMENTDOC" styleID="44" fgColor="008080" bgColor="FFFFFF" fontName="" fontStyle="0" fontSize="" />
            </LexerType>

    langs.xml:
    <Language name="javascript" ext="js" commentLine="//" commentStart="/*" commentEnd="*/">
        <Keywords name="instre1">var ...</Keywords>
        <Keywords name="instre2">new ...</Keywords>
        <Keywords name="type1">Array ...</Keywords>
        <Keywords name="type2">push ...</Keywords>-->
    </Language>

    I don't understand why this won't work, but that's probably because I don't know how the highlighter works...

    Thanks!
    Colin

     
    • David Vick

      David Vick - 2008-09-23

      So it cannot be done is what you're saying?  Bummer  :(

      thanks for the reply though

       
    • Nobody/Anonymous

      It would be great to have the ability to do formatting based on regexps!

      I'd also love a little clearer instructions on how to edit the XML directly to do things that can't be done in the GUI.

      I'd love to be able to format the characters ' and " in php differently, for example, and so far haven't been able to by editing the XML or the GUI.  Adding the ability to format based on regexps would solve almost all formatting issues that people have.

       
    • David Vick

      David Vick - 2008-09-17

      I'd like to be able to do the same thing as well. I found a post here (http://forums.facepunchstudios.com/showthread.php?t=572237) that solved part of the problem by getting it listed in the styler configurator but none of the entries I make there get colored.

      What I did was this...

      In langs.xml I added a line in the javascript section (<Language name="javascript" ... )
      <Keywords name="type1"></Keywords>

      And then in stylers.xml I added a line (in the javascript section there)
      <WordsStyle name="KEYWORD2" styleID="53" fgColor="FF0000" bgColor="FFFFFF" fontName="Courier" fontStyle="0" fontSize="" keywordClass="type1"></WordsStyle>

      As I said it shows up now in the configurator but words I add do not get colored. There are several languages I'd like to be able to do this for, has anyone had any success with this?

      thanks

      Dave

       
    • Bill D

      Bill D - 2008-09-20

      Unfortunately, there is a lot of hardcoding in the syntax highlighting from old code that was never made nice and corrected in scintilla. So you are limited in what you can do in some circumstances.