Friday, June 24, 2011

DevTnT v2.2 – Notepad++/SpecFlow: Syntax Highlighting for Feature Files

Of course, our favorite text editor Notepad++ gives us syntax highlighting. Although the installation comes with a great set of predefined languages, the gherkin format used for SpecFlow-/Cucumber feature files is not supported out of the box.

Luckily, it is possible to define the bits and pieces for custom languages. In this blog post, Jaco Swarts provides the complete XML file with the language definition for for the gherkin language.

Great!

Due to the mismatch of language features of Notepad++ and language constructs in gherkin, some things are not possible with syntax highlighting:

Tables and Comments

In Jaco’s language definition, tables are considered single line comments as this seems to be the only way to format tables nicely. But table headers cannot be treated differently as done in Visual Studio (see comparison below). As second consequence, real gherkin comments (prefaced by a hash mark – #) are not supported at all. But I think this was a good consideration since tables will be more vital on skimming over a feature file than comments are.

Multiline strings

Gherkin supports multiline strings, delimited by triple quotes. Also this seems not to be possible with the language features of Notepad++.

See the following screenshot for a comparison of the different renderings:

Formatting of English feature file both in Visual Studio and Notepad++

Version for Feature Files in German

Since one major goal of BDD is to raise the bandwidth of the communication channel between all stakeholders of a project including the business/domain experts, it is vital to have feature files in the communication language of the project.

If you are using feature files in German, you want to take advantage of that language definition for Notepad++: http://dl.dropbox.com/u/9238896/gherkin_de.xml. The keywords in this file are taken from the language file of the SpecFlow project.

Issue with gherkin keyword “Funktionalit√§t” (Feature)

Up to now, I did not manage to get Notepad++ to accept the keyword “Funktionalit√§t” correctly. That seems to be the case because of the umlaut a. Although stated as XML entity and displayed properly in the language dialog, it is not rendered as the other keywords:

Formatting of German feature file both in Visual Studio and Notepad++

Note

There seems to be a problem having both the English and the German version installed in parallel. Sometimes the highlighting worked fine, but sometimes event a manual language switch from German to English gherkin (language menu) did not work.

Any hints regarding that are appreciated!

DevTnT v2.1 – Visual Studio/ReSharper: Alternative shortcut for Attach to Process command

If you need to attach to a process from Visual Studio 2010 there is the obvious way to go via the Debug menu:

Attach to Process in Debug menu

But as a dev you might want to avoid using the mouse as much as possible and therefore look for a shortcut for this. Although there is no explicit shortcut for that command, one can always operate the menu via Alt-shortcuts. Unfortunately, the shortcut P is used for two commands, not just for our “Attach to Process”, but also for “Import Data Tips” (who uses that?). So, that might be ambiguous.

BTW, there is also a similar issue on Microsoft Connect: http://connect.microsoft.com/VisualStudio/feedback/details/524763/vs-2010-attach-to-process-hotkey

Strangely, there is another menu containing the Attach to Process command, namely the Tools menu:

Attach to Process in Tools menu

Funny as it is we see here, that in fact there is a shortcut attached to our desired command: Cltr+Alt+P.

The Problem

Great and done? Not if you’re using ReSharper. Because Ctrl+Alt+P is ReSharper’s shortcut for the Introduce Parameter refactoring.

Looking to the command mappings for the shortcut, we see that the Visual Studio shortcut is defined for the global scope, while the ReSharper-shortcut is defined for the scope of the text editor:

Shortcut mappings for Ctrl+Alt+P with ReSharper installed That situation means that every time you have the input focus on any kind of text editor window (what you might have most of the time), the shortcut Ctrl+Alt+P will trigger ReSharper, but not Visual Studio Attacht to Process command.

The Solution

Having understood that, it is obvious what to do: Just move the focus to some non text editor window and press the shortcut then. I prefer moving the focus to the solution explorer using Ctrl+Alt+L. Then, the key for P is next to no additional effort.

So, train your fingers to Ctrl+Alt+L, P for the Attach to Process command!

Final remark

This is a typical situation where something looked just broken, but made totally sense when understood. So please, think twice before yelling out all too loud! :)

DevTnT v2.1 – Visual Studio: Delete Line(s) with Ctrl+L

If you want to delete the current line or a block of lines in Visual Studio you don’t have to select the line(s) and press DEL. But there’s another possibility you may want to consider:

Use Ctrl+L do delete the current line or all the lines touched by the current selection.

Warnings

Easy as it is, there are two warnings for you:

Warning 1: Ctrl+L is Cut

Actually, Ctrl+L does a cut operation, so it will overwrite the content of your clipboard.

Warning 2: Mind the last line

If you have selected multiple lines and your selection ends with the first column of a line, that line will be deleted as well in its entirety although you may have no visual clue that it is part of the selection!

Especially, when you select your lines by holding the shift key and moving the cursor down, there might be always a line more involved than you might expect:

Whole line selection

This will cut the line with the closing brace as well (what you might not want to). Instead, if you just select until the end of the line that will not happen. Mind the length of the selection-rectangle and the position of the caret in contrast to the previous example:

Selection of line just to its end

DevTnT v2.1 – Windows: Remove Formatting via the Shell’s Run Dialog

Sometimes you want to copy text from a formatted source and paste just the text without the formatting. For example when you write an e-mail to a colleague citing some source code you might not want to disturb your mail’s formatting by pasting the source code with its original formatting.

To illustrate the problem, here is the effect of pasting from Visual Studio into a mail window in OWA (Outlook Web Access):

Effect of pasting formatted text into a mail window in OWA (Outlook Web Access)

If you are pasting into a Microsoft Office application, there is the feature to paste as text only using the smarttag shown after pasting:

SmartTag Paste Options in Microsoft Office

But if your paste target does not provide such feature you’re out of luck.

Unformatting

The solution for this problem is to perform an intermediate unformatting step between copy and paste. For that you just need to paste your formatted text into some application that does not support formatting. Typically, any text editor can be used for that.

But since launching another application may be too disturbing just for the merit of copy and paste, there is an application always at your fingertips: the Run dialog of your Windows shell.

Thus, to remove the formatting of a single line of text, you just press Win+R, paste using Ctrl+V, select the whole text using Ctrl+A and copy it again with Ctrl+C (and close it afterwards with ESC):

Text pasted to the Windows Run dialog

Remark: In Windows XP the Ctrl+A shortcut does not work. As a workaround, you have to move the caret back to the beginning of the text while holding down the shift key.

Then the clipboard contains just the characters but no formatting, and that’s what keeps your target formatting sane:

Pasting unformatted text into a mail window in OWA (Outlook Web Access)

Great and easy.

DevTnT v2.1 – Notepad++: Map file extension to language

You might find it useful, to open files of your .NET-solution directly from Windows Explorer without launching Visual Studio. For that purpose, Notepad++ is a perfect choice.

Besides other goodness, Notepad++ provides syntax highlighting. But for that to work properly, Notepad++ must know the language of the file’s content. Especially there are several files in an XML format that do have a file extension other than xml. The best example may be project files (*.csproj, *.vbproj). Other examples are the extensions xaml, config, wsdl, etc. For those files, it may be cumbersome to tell Notepad++ after opening the file, what language the file content is.

Fortunately, the mappings of file extensions to languages can be configured in the file langs.xml, found in %AppData%\Notepad++. That file has a Language-element for each language along with a ext attribute. That ext-attribute lists all file extensions that Notepad++ recognizes for the respective language.

Mine looks like this:

Language name="xml" ext="xml xsml xsl xsd kml wsdl config vdf csproj targets xaml"

After relaunching Notepad++, it automatically chooses the language of a newly opened file according to that mapping.

Tip: For a selection of file editors (including Notepad++), see this post.

DevTnT Relaunch (aka DevTnT v2)

Hi!

It’s been a long time since our last activities on DevTnT (short for Developer Tips and Tricks).

Fortunately, we relaunched both the company-internal event and this blog.

A ramp up regarding the DevTnT event

DevTnT is short for Developer Tips and Tricks. First and foremost it is one of the formats to spread knowledge within our company (TechTalk). Despite all other formats we live (such as developer meetings, pizza talks, breakfasts and demos on special topics), DevTnT works somewhat different:

  • It focuses on the little things, not broad concepts
  • It is low-ceremony, highly focused and short (15 minutes)
  • It utilizes on an absolutely stable cadence (every two weeks on a Friday at the same time just before lunch)
  • It is an open format, where everybody is invited to contribute
  • It explicitly targets all dev-staff (developers and architects)

For more information about the format and the ideas behind, refer to my introductory post.

This blog

Since the explicit focus of the DevTnT are the little things, even in 15 minutes a group of experienced professionals may gather an overwhelming amount of little bits and pieces. Therefore, from the beginning on, it was clear to provide some open format for documentation these little blooms. We decided to try utilizing a blog for that purpose.

On the first season, we used the blog “From The Life Of A Developing Developer” (http://devingdever.blogspot.com). I registered that blog several years ago, but did not use it before DevTnT. Since I want to start over with that as a personal blog, we decided to move all DevTnT-related stuff to this new blog (devtnt.blogspot.com). All the original DevTnT-posts on that other blog will depricate on devingdever.

Monday, November 2, 2009

DevTnT 15 – Reflector Power Commands

Reflector Power Commands is a collection of additional Reflector commands that includes such goodies as “Reorder Assemblies” “Enum Viewer” (with Bit Flag calculator), “Assembly List Import/Export”.

PowerCommandsImages

The CodePlex site does a good job of describing all commands.  For those who want to dive a bit deeper, there’s a blog post that describes installation and the finer points of usage. The post is written in an Asian-looking language but there are lots of images that tell you all you need to know.