Showing posts with label downloads. Show all posts
Showing posts with label downloads. Show all posts

Wednesday, 28 May 2008

BDD test naming with AutoHotKey

Update 2008-05-29: JP has posted a much better version of this script (with suggestions from a few of his readers). I've updated the script on this post to work more like JP's version, but you're probably best off grabbing it from his post, or searching his site for his latest version.

Was having a chat earlier with my good mate JP Boodhoo... er, well, more accurately, I left a comment on his blog and he was nice enough to email me back. Anyway, JP has started trying AutoHotKey rather than his previous macro for BDD-style test naming.

I thought I'd post an extremely over-engineering version of this AutoHotKey script, which has a toggle-approach similar to the Emacs Everywhere script I posted earlier.

Once you have AHK installed, you can just extract the ZIP below and double click the .AHK file to load the script. The script will let you toggle "test-naming mode" (i.e. replacing spaces with underscores) using Ctrl + Shift + U. You can cancel out of test naming mode by pressing ENTER, ESCAPE or starting the method signature by typing a '('. Pressing Ctrl + Alt + U will insert a new test template before switching on test naming mode (although you might be better off using R# templates for this). All this is simply to make it easier to type out tests like this:

[Test]
public void Test_naming_mode_turns_spaces_to_underscores() {}

Version 2 of the script can be downloaded here:

Feel free to change the hotkeys and the dodgy icons :). I haven't had a good test of it yet so use at your own risk.

If you're happy with how it works you can add it to your Startup programs and have BDD-style test naming goodness whenever you like. Hope_this_helps! :-)

Change log

  • 2008-05-29: Uploaded v2, synching with JP's version 2, adding test templates, and made test mode exit after typing '(' for test method signature
  • 2008-05-28: Updated hotkeys to match JP's version
  • 2008-05-28: Original post

Monday, 11 February 2008

Emacs key bindings everywhere

I used to use Emacs for everything, and I loved it. You could do absolutely everything really efficiently from the keyboard using a number of arcane key combinations, and once the learning curve had been overcome you could absolutely fly through your work.

Now I use Visual Studio for my coding work, MS Word for documentation, and NotePad++ for everything else, I find myself wishing that I didn't have to move positions on the keyboard to move the cursor, delete characters and words, and do basic document navigation. I know VS.NET has Emacs key bindings available, but I find that their incompleteness means I have to mentally figure out whether to use Windows or Emacs shortcuts. This is especially difficult when switching between applications.

So I decided to whip up a quick AutoHotKey script that reproduces the basic Emacs document navigation key bindings, sticking to the shortcuts that don't interfere too much with standard Windows shortcuts (for example, I left Ctrl-V alone :)). You can toggle "Emacs Mode" on and off using the CapsLock key, and because it uses AutoHotKey to translate key strokes, it works everywhere your keyboard does :). I've been using it for months and found it quite useful, so I thought I'd put it online before I lose it. :)

You can download the script from here [ZIP]. You'll also need AutoHotKey. I'm far from an expert on AutoHotKey, so feel free to comment or email if you find any problems with the script.

Key bindings

The keys mapped by the script are described below. The mappings aren't perfect, they simply translate Emacs keys into similar Windows key combinations. Because different applications implement concepts like "next word" differently, sometimes you get results that are slightly different to expected. C is Control, M is meta key (Alt).

CapsLockToggle Emacs mode on/off
C-pPrevious line (move up)
C-nNext line (move down)
C-fForward one character (move right) Note: conflicts with normal "find" shortcut
C-bBack one character (move left) Note: conflicts with normal "bold" shortcut
M-fForward one word
M-bBack one word
C-aStart of line Note: conflicts with normal "Select all" shortcut
C-eEnd of line
C-<Start of page
C->End of page
C-_Undo
C-dDelete character after cursor
M-dDelete word after cursor
M-DelDelete word before cursor
C-kKill line
C-wCut region
M-wCopy region
C-yPaste (no kill ring, so don't get full Emacs yank ability)

If you want to use regular CapsLock functionality, try holding down Shift while pressing CapsLock. For me at least, this lets me toggle CapsLock on and off without being caught by the script.