Custom Keyboard Shortcuts for Espresso
I blogged about the indispensable features Ian Beck’s TEA for Espresso brings to Espresso last week which elevate it above the simple (but very good looking) text editor it initially appears to be. TEA is very easy to extend to run shell scripts and insert custom snippets for example and I was planning to add a custom markup formatter but in playing about with TEA, I’ve tried a few simpler additions that make working with HTML, XML and XSL that bit quicker.
The Espresso tab insertion mechanism for snippets is great for dropping in “complex” blocks of code triggered by a snippet name but when it comes to inserting a single character (or character entity) a keyboard shortcut seems more practical, after all typing amp then pressing tab twice involves the same number of keys as just typing &.
Two characters I find myself using often enough that I miss the old Homesite/Eclipse style shortcuts for the XML-friendly equivalents are & and the non-breaking space, & and . When it comes to XSL work, the angle brackets can be simplified too to a single key combo. To that end, I’ve added the following shortcuts to my Espresso installation:
| Shortcut | Output | Description |
|---|---|---|
| Ctrl Shift Space | | Non-Breaking Space |
| Ctrl Shift 7 | & | Ampersand |
| Ctrl Shift , | < | Left Angle Bracket |
| Ctrl Shift . | > | Right Angle Bracket |
[I'd be keen to see the non-breaking space and ampersand added to the core TEA platform (to Espresso as a whole) to bring it in line with many other editors so I'll drop Ian a note and see what he thinks
]
Adding the Shortcuts Above – The Easy Way
To add these shortcuts to your Espresso, download a copy of my Actions.xml file which I’ve shared from Box.net (happy to try another sharing service if people can recommend a better alternative). I’ve shared the file in one of two formats to hopefully circumvent firewall issues:
Download as XML file (2.1kB)
Download as ZIP file (551b)
Either save it into your ~/Library/Application Support/Espresso/TEA/TextActions folder or if you have already created and customised this file, simply open it and merge in the shortcuts you need. Once you drop the Actions.xml file into that folder, choose the Actions > TEA >Toggle Custom User Actions menu item and restart Espresso twice for it to pick up the new options.
The instructions on Ian’s site make creating custom extensions a walk in the park and to save some time, I’m sharing the XML file I used to add the entity shortcuts above to anyone who is interested. I won’t repeat Ian’s instructions here but I will explain why I’ve used the tags and values I’ve chosen.
Using the New Shortcuts
Obviously the HTML/XML-friendly entities can be added to your code by using the shortcut key combinations in the table above, but they also appear in the Espresso menu too.
I’ve chosen to add my new shortcuts into the Actions > Format menu so it’s usable both for HTML and XML and follows the same convention used by other TEA shortcuts so the tag below reflects that.
In each case, the action title and undo_name values are the same, again following the general TEA convention. The menu items appear to be ordered alphabetically by the action ID value so for specific orders, you might like to rename the IDs with numbers after the InsertText value but that’s a personal decision. I’m happy with the default order and the key shortcut is the prize here, not the menu option. Your menu will look something like the one shown below depending on which version of Espresso you are using (1.0.4 shown) and which other Sugars you have installed:

Custom shortcuts added to the Espresso Actions menu
Now, if you press CTRL + SHIFT + SPACE, you should have a non-breaking space appear instantly at your caret location. Similarly, instead of typing & for which you’d have to press SHIFT + 7 anyway, press CTRL at the same time and should get & for 1 keystroke instead of 5. It’s not going to save hours of coding time but it’s one more convenience until we get project-wide searching
This is probably the simplest type of extension you can make to Espresso via TEA and if you favour keyboard shortcuts over tab snippets (both perfectly valid) then there is no reason why you couldn’t add as many different shortcuts as needed.
Filed under: Software, Web Development | 2 Comments
Tags: Espresso, Software, Web Development
I’ve integrated these actions into the TEA for Espresso core project; they should be available within the program by default once Espresso 1.0.5 is released.
The only real difference between Colin’s code above and the bundled versions is that you’ll find the bundled ones in Actions->HTML->Entities.
Ian
Awesome! Thanks Ian