Syntax Highlighting in Notepad++
I do a lot of work with PowerCLI and my favorite text editor is Notepad++. Recently, I've been adding more modules to my repertoire (PowerNSX and PowerVRNI, I'm looking at you!) and I've finally decided that I need to add all of these modules' cmdlets to my syntax highlighting in NPP. The proper way to do this is to define a custom language and add everything to it. This can be done through the GUI (yuk) or by editing a custom language xml file.
Unfortunately, there's no way to clone an existing language as a start for a custom language (or at least, I couldn't find a way to do it). Even more unfortunately, the custom language definitions file syntax is pretty different from the inbuilt ones, so you can't just copy and then edit the XML from the already existing PowerShell language.
Not if you want to do it the proper way. It looks to me like I can trivially edit my default langs.xml file (where PowerShell is defined) and add an arbitrary set of keywords to the list of existing cmdlets. When you open this XML file, there's a note in it saying that you should not touch it, so you probably shouldn't do this. That said, I did it anyway and so far, so good... but if you do this, I suppose there's a risk of blowing up your NPP installation and requiring a reinstall. Maybe even a whole OS reinstall, or needing to rebuild a whole new PC, or even datacenter... who knows! That said, when I did blow up my langs.xml file, all that I did was delete it and allow NPP to recreate it from its langs.model.xml file (automatically done by closing and then re-opening NPP)... but your mileage may vary.
So, what is this process? It's a quick script that loads the specified modules, gets all of their commands, and appends them to the existing list of PowerShell commands in NPP. The script takes 2 parameters: langspath and modules. Langspath is the path to your langs.xml file which, by default, is in your AppData\Roaming directory (which is what it defaults to if you don't supply anything). Modules is an array of the names of the various modules that you want the script to work with (which must be already installed on your system).
The script loads your existing langs.xml file, imports each module, grabs the list of commands from each module, and puts them back into your langs.xml file. After that's done, you just restart NotePad++ and it should highlight all of those lovely new cmdlets!
Like I said, this is really the wrong way to go about doing this... but I just needed a quick fix and this served my needs. Do it at your own risk, as I really have no idea how NPP might respond to this sort of change over time.
Unfortunately, there's no way to clone an existing language as a start for a custom language (or at least, I couldn't find a way to do it). Even more unfortunately, the custom language definitions file syntax is pretty different from the inbuilt ones, so you can't just copy and then edit the XML from the already existing PowerShell language.
Not if you want to do it the proper way. It looks to me like I can trivially edit my default langs.xml file (where PowerShell is defined) and add an arbitrary set of keywords to the list of existing cmdlets. When you open this XML file, there's a note in it saying that you should not touch it, so you probably shouldn't do this. That said, I did it anyway and so far, so good... but if you do this, I suppose there's a risk of blowing up your NPP installation and requiring a reinstall. Maybe even a whole OS reinstall, or needing to rebuild a whole new PC, or even datacenter... who knows! That said, when I did blow up my langs.xml file, all that I did was delete it and allow NPP to recreate it from its langs.model.xml file (automatically done by closing and then re-opening NPP)... but your mileage may vary.
So, what is this process? It's a quick script that loads the specified modules, gets all of their commands, and appends them to the existing list of PowerShell commands in NPP. The script takes 2 parameters: langspath and modules. Langspath is the path to your langs.xml file which, by default, is in your AppData\Roaming directory (which is what it defaults to if you don't supply anything). Modules is an array of the names of the various modules that you want the script to work with (which must be already installed on your system).
The script loads your existing langs.xml file, imports each module, grabs the list of commands from each module, and puts them back into your langs.xml file. After that's done, you just restart NotePad++ and it should highlight all of those lovely new cmdlets!
Like I said, this is really the wrong way to go about doing this... but I just needed a quick fix and this served my needs. Do it at your own risk, as I really have no idea how NPP might respond to this sort of change over time.
Comments
Post a Comment
Sorry guys, I've been getting a lot of spam recently, so I've had to turn on comment moderation. I'll do my best to moderate them swiftly after they're submitted,