C preprocessor highlighting

  • Hello, everybody

    I’m new to Notepad++, and I like it… except the way C preprocessor symbols are highlighted.
    In particular, I’d like to see only the keyword highlighted (as in other editors), and not the whole line (as npp is doing). Therefore, I’d like to see a line like:

    #define AAAAA 1000 // Value

    highlighted like: #define (colored) AAAAA (black), 10000 (red, because it’s a number) and the comment (// Value) correctly colored as a comment.
    Reading the documentation, it seems that I should use the property styling.within.preprocessor… which seems not working at all (in my situation).

    Any help would be greatly appreciated.
    Thank you

  • You are exactly correct. Setting styling.within.preprocessor will actually parse out the preprocessor numbers/strings/etc. However there is currently no way for this to be set directly from Notepad++. Your only option that I know of would be to use a plugin. PythonScript and LuaScript come to mind. I’ll be a bit biased here and show you how to do it with LuaScript since I wrote the plugin. You’ll have to download/install it manually from Github, but if you add the following code to the startup script, then it should mostly work.

    npp.AddEventHandler("OnSwitchFile", function(filename, bufferid)
        if npp.BufferLangType[bufferid] == L_CPP then
            editor.Property["styling.within.preprocessor"] = 1

    Alternatively if you are more familiar with or already have it installed, you would be able to do something like that with PythonScript but I’m not familiar with it enough.

  • Thank you, Dail! Your LuaScript tool works very well for me: I tried with the PythonScript (as suggested in the wiki), but I get a “general exception” error.

Log in to reply