PowerShell Block Comment Highlighting

2014-06-18
2014-08-13
  • Lee Wilmott

    Lee Wilmott - 2014-06-18

    I appreciate this isn't a major issue, but it is something I would like to report.

    I use Notepad++ to write some of my PowerShell scripts.

    All of my 'single line' comments are written in a green font (as I have learnt to expect).

    However, when I use block comments...

    <#
    These are block comments...
    And this is...
    ...This is the final comment
    #>

    What I would expect is 'all' of the above in a green font...but it isn't...it's black like 'normal' code.

    Should the entire Block Comment be highlighted in green?

    Lee

     
  • Loreia2

    Loreia2 - 2014-06-18

    Hi Lee,

    open your sytlers.xml file, locate PowerShell styler and duplicate (CTRL+D in Notepad++) this line:

    ~~~~~~~~~~~~~~~~~~~~~~~~
    <WordsStyle name="COMMENT" styleID="1" fgColor="008000" bgColor="FFFFFF" fontName="" fontStyle="0" fontSize=""/>
    ~~~~~~~~~~~~~~~~~~~~~~

    Now, edit second line to create styling for stream comments:

    <WordsStyle name="SCE_POWERSHELL_COMMENTSTREAM" styleID="13" fgColor="008000" bgColor="FFFFFF" fontName="" fontStyle="0" fontSize="" />
    

    Restart, and that's it.

    Regards,
    Loreia

     
  • Lee Wilmott

    Lee Wilmott - 2014-06-18

    I have just noticed that the Block Comments aren't working for KiXtart either. 'But' the langs.model.xml file doesn't have the "commentStart" and "commentEnd" attributes populated.

      <Language name="kix" ext="kix" commentLine=";" commentStart="" commentEnd="">
    ...should be...
      <Language name="kix" ext="kix" commentLine=";" commentStart="/*" commentEnd="*/">

    For the record the langs.model.xml is correct for PowerShell...

      <Language name="powershell" ext="ps1 psm1" commentLine="#" commentStart="<#" commentEnd="#>">

    Lee

     
  • Lee Wilmott

    Lee Wilmott - 2014-06-18

    Hi Loreia, sorry...our posts crossed. I'll give that a go now.

     
  • Lee Wilmott

    Lee Wilmott - 2014-06-18

    Perfect Loreia, the change you suggested worked. PowerShell is now formatted as I would expect. Thank you.

     
  • Lee Wilmott

    Lee Wilmott - 2014-06-19

    Loreia,

    Although the block comments in PowerShell scripts are now styled EXACTLY how I want, the block comments in KiXtart script aren't.

    I've modified the KiXtart line in langs.model.xml to...

     <Language name="kix" ext="kix" commentLine=";" commentStart="/*" commentEnd="*/">

    I have also updated stylers.xml with the following...

     <WordsStyle name="COMMENT BLOCK" styleID="10" fgColor="008000" bgColor="FFFFFF" fontName="" fontStyle="0" fontSize="" />
    ...and...
     <WordsStyle name="SCE_KIXTART_COMMENTSTREAM" styleID="13" fgColor="008000" bgColor="FFFFFF" fontName="" fontStyle="0" fontSize="" />
    ...and...
     <WordsStyle name="SCE_KIX_COMMENTSTREAM" styleID="13" fgColor="008000" bgColor="FFFFFF" fontName="" fontStyle="0" fontSize="" />

    Any idea how I make the 'block' comments styled as comments in KiXtart?

    Lee

     
  • Loreia2

    Loreia2 - 2014-06-19

    Hi Lee,

    correct values for styleID should be read directly from source code. You can find a list of constants here (search for SCE_KIX):
    http://svn.tuxfamily.org/viewvc.cgi/notepadplus_repository/trunk/scintilla/include/SciLexer.h?revision=1104&view=markup

    However, there is no styleID for stream comments on that page. Which made me check the source code of the lexer:

    http://svn.tuxfamily.org/viewvc.cgi/notepadplus_repository/trunk/scintilla/lexers/LexKix.cxx?revision=742&view=markup

    It is an exceptionally simple lexer. And one thing you can notice is that it does not support stream comments at all. So, there is no easy patch for this problem because it needs to be addressed at source code level.

    I guess patching this lexer to include support for stream comments should be trivial. Something along these lines:

    #define SCE_KIX_STREAM_COMMENT 10
    
    if (sc.state == SCE_KIX_COMMENT) {
        if (sc.atLineEnd) {
            sc.SetState(SCE_KIX_DEFAULT);
        }
    } else if (sc.state == SCE_KIX_STREAM_COMMENT) {
        if (sc.ch == '*' && sc.chNext == '/') {
            sc.ForwardSetState(SCE_KIX_DEFAULT);
    }
    } else if (sc.state == SCE_KIX_STRING1) {
        // This is a doubles quotes string
        if (sc.ch == '\"') {
            sc.ForwardSetState(SCE_KIX_DEFAULT);
    }
    .
    .
    .
    
    if (sc.state == SCE_KIX_DEFAULT) {
        if (sc.ch == ';') {
            sc.SetState(SCE_KIX_COMMENT);
        } else if (sc.ch == '/' && sc.chNext == '*') {
            sc.SetState(SCE_KIX_STREAM_COMMENT);
        } else if (sc.ch == '\"') {
            sc.SetState(SCE_KIX_STRING1);
    .
    .
    .
    

    Find a maintainer of this lexer (over at scintilla project) and propose a patch similar to my sample code above.

    Regards,
    Loreia

     
  • Lee Wilmott

    Lee Wilmott - 2014-06-20

    Hi Loreia, I have logged a Feature Request with Scintilla (https://sourceforge.net/p/scintilla/feature-requests/1053/). I'll see how I get on.

    Lee

     
  • Lee Wilmott

    Lee Wilmott - 2014-08-13

    Loreia/Don,

    I have now made a change to Scintilla (which exists in v3.5.0) (reference https://sourceforge.net/p/scintilla/feature-requests/1053). Can I ask if it is possible to update Notepad++ to include the latest version of Scintilla?

    Many thanks,

    Lee

     

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks