How do you color certain text after a keyword in notepad++?
-
does the configuration file open as described?
-
Some demo
-
@Ekopalypse Thanks, I’ll try later.
-
@Ekopalypse Also, what are the codes you are entering? Looks like hexadecimals.
-
Yes, this is a hexadecimal value that specifies the color used to highlight the matches.
To quote the documentation from the configuration file:; Each configured lexer must have a section with its name, ; (NOTE: use the menu function "Enhance current language" as it takes care of the correct naming) ; followed by one or more lines with the syntax ; color = regular expression. ; A color is a number in the range 0 - 16777215. ; The notation is either pure digits or a hex notation starting with 0x or #, ; such as 0xff00ff or #ff00ff. ; Please note: ; * red goes in the lowest byte (0x0000FF) ; * green goes in the center byte (0x00FF00) ; * blue goes in the biggest byte (0xFF0000) ; * this BGR order might conflict with your expectation of RGB order. ; * see Microsoft COLORREF documentation https://docs.microsoft.com/en-us/windows/win32/gdi/colorref
-
@Ekopalypse Works like a charm, now, how do i make it so that for example, i want my text to be colored blue after the keyword ‘function’. I have absolutely no idea what an .ini file is.
-
I have absolutely no idea what an .ini file is.
The
.ini
file is the configuration file that you opened when you clicked Plugins > Enhance Any Lexer > Enhance current language – ie, the file that has the color codes in it.i want my text to be colored blue after the keyword ‘function’.
Then you need to come up with a regular expression (regex) that matches the word after the keyword
function
. In the.ini
file, the color goes on the left of the equal sign, and the regex goes on the right. So in the original example that Enhance current language created for you,0x66ad1 = \w+
:- the color is
0x66ad1
, which means 6 units of blue,6a
=106 units of green, andd1
=209 units of red; - the regex is
\w+
which means “one or more word characters” (where a word character is defined as letters, numbers, and underscore).
So you would need to create a regex that does what you want. Those regex follow the same rules for Notepad++'s regular-expression search, as defined here in the user manual.
To give you a freebie, you want it to require the prefix
function
, then match one or more word characters: that would look likefunction \w+
. But that changes the color of thefunction
keyword as well as the function’s name, which is probably not what you want.Instead, you will want to either “reset” the regex between with a
\K
(everything before the\K
is “thrown out” after it matches, so usingfunction \K\w+
will matchfunction
-space, throw it out, and then match-and-color one or more word charaters) or use a positive lookbehind with(?<=...)
(so in your case, lookbehind forfunction
-space, then normal match on one or more words would be(?<=function )\w+
).Hope this helps.
- the color is
-
@PeterJones Thank you so much Peter. You have no idea how much this is gonna help me.
-
@PeterJones If i wanted to, can i add multiple ones? such as void or function?
-
You have no idea how much this is gonna help me.
I think the discussion in this thread has also helped others understand the EnhanceAnyLexer plugin a little better, too. I know it has helped me.
-
@Leahnn-Rey said in How do you color certain text after a keyword in notepad++?:
If i wanted to, can i add multiple ones? such as void or function?
Yes.
There are two ways: you could either do a separate
color = regex
pair, if you want them each different colors (or even the same color but simple maintenance), or you could build a more complicated regex0x66ad1 = function \K\w+ 0x22CD7 = void \K\w+
vs
0x66ad1 = (?<=function |void )\w+
-
@PeterJones If i do that, it just says “Invalid lookbehind assertion encountered in the regular expression.”
-
0x66ad1 = (function|void) \K\w+
Sorry, I had forgotten that alternation is not a “fixed length lookbehind”: I remembered you couldn’t have + or * or ? modifiers in a lookbehind, but you also cannot have the alternation if the lengths of the alternates are different. Switch to alternation with the
\K
, as I show in this reply, gets rid of that problem (because\K
doesn’t have the fixed-width requirement) -
@PeterJones Didn’t work. It works when i do:
0xb0c94e = void \K\w+ 0xb0c94e = function \K\w+
So i will keep it that way. I’m having an issue with the positive lookahead. Since i like monokai (Which is the theme i’m using) i want my text to be colore green when there is a () at the end. But, when i do:
0x600e6a3 = (?=\(\))\w+
It doesn’t color the text before the parenthesis. Am i doing something wrong here?
NOTE: i read the documentation -
This should work:
\w+(?=\(\))
Think of the look-ahead as a kind of modifier of the active (ie, already specified, and so, to the left of the look-ahead) match specification.
-
@Alan-Kilborn said in How do you color certain text after a keyword in notepad++?:
You have no idea how much this is gonna help me.
I think the discussion in this thread has also helped others understand the EnhanceAnyLexer plugin a little better, too. I know it has helped me.
Then I thoroughly missed my target with the in-place documentation within the confuiguration file, because I had hoped that it would be as easy to understand as it could be.
:-( -
@Ekopalypse said in How do you color certain text after a keyword in notepad++?:
Then I thoroughly missed my target with the in-place documentation within the confuiguration file, because I had hoped that it would be as easy to understand as it could be.
Well, I don’t know about that.
Maybe I meant it more like: “Some real world examples (e.g. from this thread) have encouraged me to get more into the EnhanceAnyLexer plugin”. -
@Neil-Schipper said in How do you color certain text after a keyword in notepad++?:
\w+(?=\(\))
Works like a charm. Thanks!
-
@Neil-Schipper The thing is, when i enter in function parameters, the coloring disappears.
-
@Ekopalypse said in How do you color certain text after a keyword in notepad++?:
I had hoped that it would be as easy to understand as it could be.
Trust me: getting documentation so that everyone can understand is hard. ;-)
And, as Alan said, sometimes it just takes seeing a few examples of people doing interesting-to-me things with a specific plugin before I see the usefulness of a given plugin.