It’s been a while since I’ve released an update to Code alignment. But I’ve been working on it on and off since that release and I’m ready to release a significant update – Big enough to warrant being version 3.
When Version 2 was released it had some important changes
- It became its own toolbar instead of just adding them to the edit one. This was useful for people like me who knew the shortcuts and wanted an easy way of hiding them from the toolbar.
- It separated the align by string and align by position into different functions. This was great as the old way you had to default the position to zero, but when you actually wanted to align by position you wanted it to be at the caret location.
- A lot of streamlining – The big one was align by space not asking for position, just using your caret location.
Looking at the changes from Version 2 to Version 2.9 it’s amazing how much it has improved. My favourite additions are
- Align by space aligning the last space in the first space block – With this align by space became the most awesome feature of the extension.
- Changed the selection logic for XML style documents
- Releasing a Notepad++ version
So now we come to the list of what’s new in version 3…
Lots of backend changes.
- There is now a common assembly which is shared between the Notepad++. Before the code was common but as shared files. This was to overcome some problems in Notepad++.
- More decoupling - allows for various behaviours to be changed.
You can now specify regular expressions to look for. Even better you can (optionally) add a named group ‘x’ to specify where to perform the alignment. For instance, the regex
will align by the first character after a semicolon. This has allowed a lots of simplifications in the backend. Don’t expect this to work with tabs though – I’ll explain that in a future blog.
New ‘Align by string’ screen
Unknown to most people, Code alignment started off as a macro. A macro I didn’t write myself, but had constantly improved over the years. When Visual Studio 2010 came out with its improved extension model I took the plunge and completely rewrote it from scratch. The entire approach was different (and much better).
The only remnant of the old macro was the ‘Align by string’ screen. Pretty much it was a basic VB dialog. I can’t remember if this was in the original macro or something I added to it. But when I rewrote it, I just add a reference to the VB dll (in my c# project) and used the same code. Why? It was simple, fast and did what I needed.
But that last remnant is gone. The new screen not only allows you to use regular expressions but also keeps a history of the strings you’ve chosen to align by – not just the last one. There’s also a check box to align from caret position.
Align by position is gone replaced by align from caret position
Let’s face it, the only position ever used was the current caret position. Entering the column number was just too annoying. Sure, there could be other ways of choosing the location, but the caret location works so damn well.
Slight change to Align by space
Now that code alignment allows regexes I could simplify the code for a few things. One was the align by space. Before it could be defined as “align the last space in the first space block” this has ever so slightly changed to “Align the first character after the first space block”.
What does this mean? Most of the time nothing. The only difference is it will ignore whitespace at the end of lines (as there is no character after the first space block).
Behaviour in Align by string for align by space or equals has changed
Before if you were in the Align by string dialog and you entered a space or a equals, it would perform the same as if you had done an “Align by space” or “Align by equals”. It no longer does this. You now have full control over the box and what you enter is what you will search for.