Color User defined global variable words e.g. TEST=
-
Hi,
Long time Notepad++ user, finally making my first theme. It is for Zeiss Calypso Coordinate Measuring Machine PCM coding (actually smalltalk), however small talk formatting is not accurate.
I’ve managed to theme some of it, I am wondering how to color variable words such as
DELTA= CONTAINER= VARIABLE= … all of the strings before an = sign.
In smalltalk theme they are recognized and colored the right color (almost) . I’ve tried coping the <wordStyles> from the .xml, however I realize it’s more than that with the Legex etc…
In smalltalk the variable is defined as GLOBAL.Thank you everyone. Happy coding !
-Chris
-
![alt text]( image url)
-
The Smalltalk lexer already recognizes those as a GLOBAL style. So if you’re really just editing a Theme, you just need to change the color of the GLOBAL style for Smalltalk in that Theme.
However, based on your phrasing, I think what you are saying is that even though the Zeiss Calypso Coordinate Measuring Machine PCM syntax is essentially Smalltalk, the Smalltalk lexer isn’t sufficient for your needs (though you don’t explain what’s missing), and so you are instead trying to create a “User Defined Language” (UDL) that will end up similar to the Smalltalk lexer, but you are hoping you will be able to give it whatever “extra” was missing from Smalltalk.
If this is the case, then unfortunately for you, the UDL system cannot supply as many features as a builtin lexer can, so a UDL cannot recognize a generic variable name and highlight it when it comes right before an = and when it is again used later, even if it’s not before an =. That’s impossible to do in a UDL.
If you installed the EnhanceAnyLexer plugin, you could use a regex to define that a single group of word characters before an = could be colored differently (something like
\w+=
) – but that would only add the color forDELTA=
andCONTAINER=
, but would not work if you later used that variable somewhere else.It might be easier to just see if we can help you configure the builtin Smalltalk lexer to do what you want, rather than trying to help you create a UDL that will mimic your Smalltalk behavior. But it also may be that the Smalltalk lexer which Notepad++ gets from the Lexilla library isn’t powerful enough, nor is the UDL system powerful enough (even with EnhanceAnyLexer), in which case the only suggestion would be to write your own Lexer Plugin (as described in the user manual – but that’s not for the faint of heart).
—
PS: after posting, I did some searches into the Scintilla/Lexilla library’s history with Smalltalk: apparently, some user gave them a really simple Smalltalk lexer in 2005, and it essentially has not been touched since then. As such, it’s not surprising it doesn’t have many changes – Scintilla/Lexilla has changed a lot in the nearly 2 decades since then, so it’s not making use of many of the Lexilla features. And unfortunately, the Notepad++ developers don’t update lexers, they just use the lexers that Lexilla provides, so you cannot make a feature request with Notepad++ to improve its Smalltalk handling; and given how untouched Lexilla’s Smalltalk implementation is, I am doubtful that Lexilla would do any enhancements to their Smalltalk lexer even if you put in a feature request with the Lexilla project. Sorry for more bad news. -
Thank you Mr Jones for the info.
Yes the smalltalk theme is a bit dated and not quite accurate enough.
How could I try to then highlight my variable words (other than possibly entering them manually for each code snippet etc - which may be an option if needed),
they are typically mix of Uppercase lowercase underscore and numbers.
TOP_1 > MID2 etc
and either have a math operator, parenthesis, or possibly a space next to them ?
would it ve keyword? AaBbCc…_1234567890
and for close = / < > * or “” (space) ?Thank you for any suggestions . help !
-
Yes the smalltalk theme is a bit dated and not quite accurate enough.
Well, with that, we are not going to be able to help you see if it possibly could work. I think it had a better chance of making you happy, but you’ve chosen to bypass that route. That’s too bad for you.
(A note on terminology: it’s not a “smalltalk theme”. It is the Smalltalk lexer, which has its colors defined by whichever Notepad++ Theme you are using. “Theme” is the group of colors across all languages. Each built-in “Language” (like Smalltalk) has its own group of Style settings within a theme; each built-in Language has an associated lexer which actually handles reading the text and deciding which Style to apply to each piece of text.)
Back to User Defined Language:
How could I try to them my variable words (other than possibly entering them manually for each code snippet etc - which may be an option if needed),
With Notepad++'s UDL system, you cannot.
You might be able to make something work with Enhance Any Lexer. Here’s a somewhat working example:
- I defined a UDL called “ZeissSmalltalk”, with a few minimal highlighting based on what I saw in your screenshot, and associated that UDL with the
.st
extension - I then used the EnhanceAnyLexer plugin’s Enhance current language action to get it to open
EnhanceAnyLexer.ini
and create a section called[zeisssmalltalk]
for enhancing my UDL.[zeisssmalltalk] 0x007700 = (\w+(?=\h?[=+*/-]\h?))|(\h?[=+*/-]\h?\K\w+) ; 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
0x007700
: I told it to do darkish green (0x007700) when it matches my regex(\w+(?=\h?[=+*/-]\h?))|(\h?[=+*/-]\h?\K\w+)
: My regex says “if it matches one or more word characters (A-Za-z0-9_), followed by any of the characters= + * / -
(optionally with a space before or after the symbol); or if it matches one of those characters (optionally with spaces before/after) coming right before a sequence of one or more word characters (A-Za-z0-9_)”excluded_styles = 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15
says that if it’s a comment (1,2) or a number (3) or any defined keywords (4-11), or an operator (12) or folding keywords (13-15) then it should not apply my green color.
- I defined a UDL called “ZeissSmalltalk”, with a few minimal highlighting based on what I saw in your screenshot, and associated that UDL with the
-
Mr Jones,
Well done. this should be enough for me to tinker with. Thank you for the help and suggestions.
If I wanted to ‘request an update’ to the smalltalk language, any idea what is my best route? Email developer support?
Thank you again, happy holidays !
-Chris
-
@Christopher-Rotolo said in Color User defined global variable words e.g. TEST=:
If I wanted to ‘request an update’ to the smalltalk language, any idea what is my best route
The Lexilla project has an issues page, which is where official feature requests for the Smalltalk lexer would go.
Again, given that they haven’t updated the Smalltalk lexer in 18 years, I am doubtful that they will add any new features to the lexer; but I have been wrong about such guesses before.