Today I was testing events in one of our myriad of prototypes,
which triggered an sample TextEditorControl to apply the BAT
syntax definition found in BAT-Mode.xshd.
While it validated the particular piece of code I was working on
rather nicely, I was less then enamoured with the highlighting.
The image below shows an example of this.
Pretty ugly isn't it? However, I was actually doing a vaguely
real-world test as I did want to see some simple batch file
syntax highlighting. Perfect timing for a distraction to go look
at another problem.
The following screenshot shows my new and improved syntax
highlighting file, based on my experiences creating the CSS
version. I couldn't do everything I tried/wanted, and I suspect
this will be limitations of the TextEditorControl, but fixing
that is "rainy day" stuff. Otherwise, simple as this was, it was
a nice distraction with immediate benefits!
The XML Definition
The definition is very straightforward, as it's basically just
keyword tokens and a single highlighting span for environment
variables.
I was trying for something similar to how Notepad++ highlights
batch files, in which if the first "word" on a line isn't a
command, it's assumed to be a program and highlighted
accordingly, but I couldn't get that working correctly so it's
commented out in the definition - if you know of a trick or code
patch to make it work, please let me know!
A sample project
I've attached a basic sample project, which shows how to dynamic
load in the definition file. And yes, that is a (stripped down)
version of one of the build scripts used by Spriter. I'm still
an old school guy at heart, and so I use msbuild to compile a
solution, but for anything else I still tend to turn to batch
scripts and custom console apps first rather than MSBuild tasks
or PowerShell cmdlets.
Although the example project loads in the definition from an
external file, I would recommend that you build it into the
TextEditorControl assembly itself to make deployment easier. I
covered this in the Compiling the definition into the
assembly section of the previous article so I won't
replicate that here.
Update History
2014-06-23 - First published
2020-11-21 - Updated formatting
Like what you're reading? Perhaps you like to buy us a coffee?
The founder of Cyotek, Richard enjoys creating new blog content for the site. Much more though, he likes to develop programs, and can often found writing reams of code. A long term gamer, he has aspirations in one day creating an epic video game - but until that time comes, he is mostly content with adding new bugs to WebCopy and the other Cyotek products.
A brief article which describes how to create a definition ruleset to allow better Batch/Command style formatting in the DigitalRune/SharpDevelop Text Editor control.
An article which describes how to create a definition ruleset to allow CSS formatting in the DigitalRune/SharpDevelop Text Editor Controls, and how to load custom definition rulesets into the control.