Community
    • Login

    Can't make default C++ style to highlight custom macros

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    6 Posts 3 Posters 695 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Civ01C
      Civ01
      last edited by

      I’ve edited stylers.xml and added my own rule:

      <LexerType name="cpp" desc="C++" ext="">
                  <WordsStyle name="UE WORD" styleID="98" fgColor="7C00F9" bgColor="FFFFFF" fontName="" fontStyle="2" fontSize="" keywordClass="type3"></WordsStyle>
      

      I’ve edited langs.xml and added my type:

      <Language name="cpp" ext="cpp cxx cc h hh hpp hxx ino" commentLine="//" commentStart="/*" commentEnd="*/">
          <Keywords name="instre1">SNIP</Keywords>
          <Keywords name="type1">SNIP</Keywords>
          <Keywords name="type2">SNIP</Keywords>
          <Keywords name="type3">UPROPERTY UFUNCTION UCLASS USTRUCT GENERATED_BODY AdvancedDisplay AssetRegistrySearchable BlueprintAssignable BlueprintAuthorityOnly BlueprintCallable BlueprintGetter BlueprintReadOnly BlueprintReadWrite BlueprintSetter Config Const DuplicateTransient EditAnywhere EditDefaultsOnly EditFixedSize EditInline EditInstanceOnly Export FieldNotify Getter GlobalConfig Instanced Interp Localized NoClear NonPIEDuplicateTransient NonPIETransient NonTransactional NotReplicated Ref Replicated ReplicatedUsing RepRetry SaveGame Setter SimpleDisplay SkipSerialization TextExportTransient Transient VisibleAnywhere VisibleDefaultsOnly VisibleInstanceOnly BlueprintAuthorityOnly BlueprintCallable BlueprintCosmetic BlueprintGetter BlueprintImplementableEvent BlueprintNativeEvent BlueprintPure BlueprintSetter Client CustomThunk Exec FieldNotify NetMulticast Reliable SealedEvent Server ServiceRequest ServiceResponse Unreliable WithValidation</Keywords>
      </Language>
      

      In the Style Editor I see my entry below TYPE WORD with appropriate color and keywords but it is not being applied.

      PeterJonesP 1 Reply Last reply Reply Quote 0
      • PeterJonesP
        PeterJones @Civ01
        last edited by

        @Civ01 ,

        The Notepad++ executable does not have any knowledge of styleID="98" or name="UE WORD" for the C++ syntax highlighting, so it just completely ignores those lines. You cannot add new categories of highlighting to the language syntax highlighter by just making up new styleIDs or names: that’s not the way it works. You would have to change Notepad++ source code and rebuild the application to teach the syntax highlighter what to do with that style.

        You can use the Settings > Style Configurator > C++ to add User-defined keywords to either the INSTRUCTION WORD or TYPE WORD style categories.

        Or you can use a plugin like EnhanceAnyLexer to add a regex-based “additional highlighting” for those keywords: Plugins > EnhanceAnyLexer > Enhance Current Language

        [c++]
        ; color each word, 0x66ad1 is the color used, see the description above for more information on the color coding.
        0x066ad1 = \b(UPROPERTY|UFUNCTION|UCLASS)\b
        ; check in the respective styler xml if the following IDs are valid
        ; excluded_styles = 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,20,21,22,23
        

        If you want more in the list using EnhanceAnyLexer, just add more |XXXX inside those parentheses.

        PeterJonesP Lycan ThropeL 3 Replies Last reply Reply Quote 3
        • PeterJonesP
          PeterJones @PeterJones
          last edited by PeterJones

          @Civ01 ,

          After more investigation, it appears that the underlying lexer library has one more category in the C++ lexer that Notepad++ isn’t using. It cannot be accessed using the Notepad++ config files (using stylers.xml/langs.xml). But a scripting plugin could be used to add the words.

          So, if you don’t like that EnhanceAnyLexer can only change the foreground color, and if you’re willing to install the PythonScript plugin, I could write a script for you that would add in the extra keyword list whenever you loaded or switched to a C++ file.

          The script would have a place where you’d have to input your foreground and background color choices, and a place for you to put in your list of keywords in the script code. It would be automatically loaded when you load Notepad++, and then every time you open or switch to a C++ file in Notepad++, it would make sure your extra list of keywords was visible to the underlying library, so it would color them properly.

          If you want that, let me know, and I’ll work on it as I have spare time. But if EnhanceAnyLexer is sufficient for you, that’s great, too.

          1 Reply Last reply Reply Quote 2
          • Lycan ThropeL
            Lycan Thrope @PeterJones
            last edited by

            @PeterJones ,
            Thanks. This was a simple enough explanation that I went and got the plug in and played with it according to your post, so now I have another toy to play with and extend my UDL projects. Arghh. :)
            Now that I’ve seen it work, good job kudos to @Ekopalypse, as well.
            :-)

            1 Reply Last reply Reply Quote 2
            • PeterJonesP
              PeterJones @PeterJones
              last edited by PeterJones

              @PeterJones said in Can’t make default C++ style to highlight custom macros:

              Enhance Current Language

              [c++]
              ; color each word, 0x66ad1 is the color used, see the description above for more information on the color coding.
              0x066ad1 = \b(UPROPERTY|UFUNCTION|UCLASS)\b
              ; check in the respective styler xml if the following IDs are valid
              ; excluded_styles = 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,20,21,22,23
              

              I had just commented out all excluded styles, because at the time, I hadn’t figured out which could be safely excluded and still have it highlight in the right place. But that will allow it to colorize those keywords, even when they are in comments or strings or the like.

              If UPROPERTY and the others in your list are only used in places where either variable names, function or method names, data types, and the like will go, you can exclude everything except StyleID 11, and I think it will work as you expect. So remove the semicolon and use:

              excluded_styles = 1,2,3,4,5,6,7,8,9,10,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27
              

              … and that should prevent it from colorizing anywhere but in normal code.

              Also, I was interested enough (and already had a similar framework), so I made the PythonScript version:

              1. Main Instructions = FAQ: How to Install and Run a script in PythonScript
              2. Save the script from this link as cppEnableGlobalclassKeywords.py (per Main Instructions)
              3. set the colorForeground , colorBackground, and keywordList variables starting on line 27 of the script, and save the script
              4. put the lines below in your startup script – do not indent
                import cppEnableGlobalclassKeywords
                lexer_interface_cpp_globalclass = cppEnableGlobalclassKeywords.cppEnableGlobalclassKeywords()
                
                (see info in the “startup script” section of the Main Instructions)
              5. Exit Notepad++ and restart, so that it will run your startup script.

              When you load a C++ file with UPROPERTY or other keywords from the list in the original post (or whatever list you specify in step 3), they should be highlighted with the foreground and background colors you specified when you saved the script.

              PeterJonesP 1 Reply Last reply Reply Quote 1
              • PeterJonesP PeterJones referenced this topic on
              • PeterJonesP
                PeterJones @PeterJones
                last edited by

                To future readers:

                As of v8.6.6, you don’t need my script anymore to enable the GLOBALCLASS keywords. Instead, follow the instructions in this post.

                1 Reply Last reply Reply Quote 1
                • First post
                  Last post
                The Community of users of the Notepad++ text editor.
                Powered by NodeBB | Contributors