Beta 17 notes
Beta 17 of 1.1 was released yesterday, and the major new cool thing is the new snippet capabilities. I already dedicated an entire post about snippets, but as a bonus I recorded a movie showing some intelligent snippets.
The movie shows 5 snippets in action.
- head inserts a source header (I rarely create sources from templates, but instead just use snippets), nothing really special about this snippet other than using niutil to insert the current users full name.
- m inserts an Objective-C method. What’s neat about this snippet is that
return nil;
disappears when the return type is changed tovoid
. - log inserts a log statement and, as can be seen the second time it’s used, when the format string contains an (extra)
%
character, it will make room for an extra argument (which one can tab to). - ⌃⇧B inserts a banner with editable text, and adjusts the size accordingly. This snippet uses the
$TM_COMMENT_START/END
variables, so it also works with Python, XML a.s.o. using appropriate comment characters. - objacc is the last snippet, and it inserts a get and set method for Objective-C. Two nice features shown is that a) it will correctly uppercase first letter of the attribute name for the get method and b) when putting a space in front of the asterisk in the attribute type, it binds this character to the variable in the getter method (i.e. removing a space on the left side of the asterisk).
And that’s probably enough about snippets for this time. Coincidentally some of the new snippet features were not supposed to happen before 1.3, but I was so be smitten with ANTLR that I decided to redo the snippet parser now rather than later, which takes me to the next b17 enhancement.
Scope selectors
I have previously written about scopes. Since then I have decided to refer to scopes (entered in the GUI to restrict something to a fragment of the document) as scope selectors, which is only natural since these are inspired by CSS selectors, although this change hasn’t made it to the interface yet.
I wrote in tips and tricks about how one can override functionality, for certain parts of a source, by using scopes, but it has a shortcoming. Let’s for example say we want the #
key in Ruby strings to insert #{$0}
(as a snippet). We create the snippet, set the key to #
and scope to source.ruby string
. Unfortunately if we press #
inside embedded code in a string, we get the expansion there as well.
Starting with b17 it’s possible to perform boolean operations on scope selectors and take the asymmetric difference between two scope selectors. So in the example above we want our custom action on #
to expand in source.ruby string
but we don’t want it for string source
(embedded code in strings). For this we can now set the scope to:
(source.ruby string) - (string source)
I added the parentheses for clarity, they are not necessary (since -
has lowest precedence).
Go to previous file
There have been requests for a way to jump between open buffers (in addition to ⌘1-⌘9 and ⌥⌘ arrow left/right/up), in particular, a consistent way to get to the last file worked upon. Until now TextMate only offered the file chooser (old movie), but Jonathan Ragan-Kelley suggested that this file chooser could also take the role of jumping to previous buffer(s), by keeping the list sorted based on last visit (when there is no filter string).
This turned out to be much more useful than I had initially imagined. So now there is a quick way to jump between two arbitrary files in a project: ⌘T followed by return.