comment line open with a character and space
I am trying to create a user defined language syntax where the comment line opens with a letter C and space. I was not able to just type a space after C on the User Define Language dialog box. Can this be done? Thanks!
Can this be done?
Unfortunately, not natively (that I can tell). The keywords have the Prefix Mode toggle, which when off requires a space; the operators have the operators 2 which require separators; but there doesn’t appear to be a similar option for comments.
That said, you can add extra highlighting to a UDL language using regexes via the script
EnhanceUDLLexer.pythat @Ekopalypse shares in this linked post – so instead of being a “comment”, you could set up that script to highlight lines that match with
^\h*C\h+(that regex should work, but I haven’t tested it with the script)
Thank you. I was hoping there was a native solution for simply task like that. regards.
Peter Brand last edited by
Looking at the langs.xml file in NPP configuration folder, I see the commentLine attribute of the langage sometimes uses html entities. Try using "C ".
Looking at the langs.xml file in NPP configuration folder, I see the commentLine attribute of the langage sometimes uses html entities. Try using “
Two problems with that: First,
C would be the non-breaking-space, which wouldn’t be the character that @jason1820 would use; it would be
C . Second, that entry doesn’t fully use entities: when I have the following:
<Keywords name="Comments">00C  00C 00>>> 00C  00C  01 02 03 04</Keywords>
it recognizes the entities for the
>>>, but not for the space or NBSP:
– it treats the
as literals (so if you have that literal text in your document, it will recognize those as comments), though it seems to recognize
00C as being something, but doesn’t match them when the NBSP character is present.
Reminding myself, the Wikipedia article on character entities points out that XML only has a short list of pre-defined entities, compared to the fuller list of HTML entities: only
"&'<>have default XML entities.
If I expand to more options
<Keywords name="Comments">00C  00C 00>>> 00C  00C  00C  00C  01 02 03 04</Keywords>
It appears to be treating the
C[space], but that then behaves like a normal space is there separating entries, so anything starting with C is commented again.
Thanks @PeterJones and @Peter-Brand. I tried the different options you guys suggested by modifying userDefinedLang.xml. Nothing works exactly like I wanted. BTW, I also tried to modify langs.xml under AppData\Roaming\Notepad++ (to adapt a predefined language for my own) and it appears changes made there commentLine="C " did not take effect - original comment character still works. is that not the file supposed to be changed?
Sorry, I hadn’t noticed the mention of that file earlier. No, that’s not the right file. UDL syntax highlighting is found in
userDefineLangssubfolder (one XML file per UDL) or in the
langs.xmlonly applies to the builtin syntax highlighter languages, and cannot be adapted to work with a UDL
Nothing works exactly like I wanted.
That was actually the point of the experiments I showed; AFAICT, you cannot trick the UDL engine into requiring a space after the comment start sequence.
did not take effect
Editing NPP config files inside NPP takes a bit of finesse. The best sequence is close all Notepad++ windows, then open one, do the edits, save and exit, then reload for it to take effect. (Not that “adapt[ing] a predefined language for my own” will work; but even a valid change requires that sequence)