[rspec-devel] [ rspec-Patches-11254 ] RSpec syntax coloring and function pop-up integration in TextMate

noreply at rubyforge.org noreply at rubyforge.org
Mon Jul 16 07:06:21 EDT 2007

Patches item #11254, was opened at 2007-05-31 14:43
You can respond by visiting: 

Category: None
Group: None
Status: Open
Resolution: None
Priority: 3
Submitted By: Wincent Colaiuta (wincent)
Assigned to: Aslak Hellesøy (aslak_hellesoy)
Summary: RSpec syntax coloring and function pop-up integration in TextMate

Initial Comment:
This patch makes two additions to the RSpec TextMate bundle to provide a better user experience: syntax coloring of RSpec keywords (before, after, describe, it), and display of behaviours and examples in the function pop-up menu. This latter feature is very useful for navigation when working with files with large numbers of specs. Examples appear indented.

Now, this is my first ever TextMate customization so I am sure someone more experienced could improve on the implementation, but in its basic form it works. Shortcomings of the current implementation:

- recognition occurs at the whole-line level, so syntax colouring only kicks in once you have typed the entire line

- recognition simplisticly divides the behaviour and example descriptions into three parts, the "describe" (or "it"), the "do", and "everything else" between the two

- this in turn means that there is no special syntax colouring of the "everything else"

- it also means that examples such as:

    it "should be valid" do

will appear in the function pop-up with the enclosing quotes:

    "should be valid"

- likewise, a behaviour like:

    describe User, "at creation time" do

Will appear in the function pop-up as:

    User, "at creation time"

- and shared behaviours will appear as:

    "All controllers", :shared => true

Hopefully someone with more knowledge about TextMate customization than I can address these issues, but as it stands I think the basic implementation is useful enough that life is better with the aid of these imperfect changes.

Will also try to attach a screenshot with the patch to show what the pop-up looks like.


>Comment By: Wincent Colaiuta (wincent)
Date: 2007-07-16 11:06

Tried to include this comment when I attached the patch, but
RubyForge logged me out (accepting the upload but rejecting
the comment! darn transparent proxy...); so here it is again:

Ok, Allan responded to the ticket. I'm going to attach an
updated patch which uses "spec.rb" as the file extension
instead of "_spec.rb".

Also, Allan notes that if you have previously (implicitly)
told TextMate to open ".rb" files as Ruby, you'll need to
undo that in one of these ways:

1. Open a test.rb file and then switch away from Ruby and
back again — then TM notices that you’re selecting the
default language, and will remove the explicit binding for
‘.rb’ files (ensure though that only the Ruby bundle has
‘rb’ declared as an extension).

2. defaults delete com.macromates.textmate
OakLanguageFileBindings — this deletes all stored bindings.


Comment By: Wincent Colaiuta (wincent)
Date: 2007-07-08 10:48

Posted a follow-up TextMate ticket here:



Comment By: Wincent Colaiuta (wincent)
Date: 2007-07-08 10:27

Just attached an updated patch with "_spec.rb" denoted as
file extension.


Comment By: Wincent Colaiuta (wincent)
Date: 2007-07-08 10:14

Awesome, looks like the requested change is already
implemented in the new r1405:

[NEW] Add ‘_’ to the set of anchor characters for file types
(extensions) -- ticket 48BF377


Comment By: Wincent Colaiuta (wincent)
Date: 2007-07-07 18:51

Ok, submitted a TextMate feature request here:



Comment By: Wincent Colaiuta (wincent)
Date: 2007-07-07 18:46

Very interesting... Noticed in the changelog for the just
released TextMate r1401 the following:

[CHANGED] File types (extensions) specified in language
grammars are now matched against the full path so e.g.
‘.git/config’ and ‘.ssh/config’ are both valid extensions --
the match is required to be anchored either at an ‘/’ or ‘.’
so e.g. ‘tml’ will not match ‘index.html’. On a tie, the
longest suffix-match is chosen.

So, not quite what would be necessary to distinguish between
".rb" and "_spec.rb", but a step closer. Think I might file
a TextMate feature request to accept "_" as an anchor as
well; that would allow spec files to be auto-detected and
auto-syntax highlighted.


Comment By: Wincent Colaiuta (wincent)
Date: 2007-06-25 09:21

(1) The patch was made against the trunk back at the end of
May (r2060, I think).

The changes to the info.plist (shouldn't it be Info.plist,
btw?) weren't manually done by me, but were inserted by
TextMate when I made the other additions via its Bundle
Editor. These settings are pretty opaque to me and omitting
them seems to make no difference, so I will attach a patch
against the current trunk which does not include the
info.plist changes.

(2) There aren't any new user-settable "preferences" as
such. The two new files in the "Preferences" subdirectory of
the bundle are used to add Behaviours and Examples to the
TextMate symbols list... this is what allows them to appear
in the pop-up.

(3) To see the syntax highlighting you must select "RSpec"
from the language pop-up at the bottom of the window. This
is just like when you have a Rails file and want special
Rails-specific highlighting instead of the default Ruby

It would be nice if TextMate allowed you to specify that all
files ending in "_spec.rb" would be auto-detected as RSpec
files, but as far as I know, TextMate only allows you to
specify the extension part (".rb") and that would override
the default Ruby highlighting. So if we want that feature we
either need to try again get the RSpec syntax rolled into
the Ruby.tmbundle, or try to get Allan to modify Textmate to
allow us to specify not just the extension.

(4) The pop-up menu is the function pop-up at the bottom of
the TextMate window (right hand side). I don't know if there
is a keyboard shortcut; I use the mouse for that.


Comment By: Aslak Hellesøy (aslak_hellesoy)
Date: 2007-06-24 13:06

This sounds great, but I'm having some problems.

1) The patch doesn't apply cleanly against trunk r2121 with "patch -p0 < textmate.diff":

patching file Preferences/Symbol
patching file Preferences/Symbol
patching file info.plist
Hunk #1 FAILED at 280.
1 out of 1 hunk FAILED -- saving rejects to file info.plist.rej
patching file Syntaxes/RSpec.tmLanguage

$ cat info.plist.rej

*** 280,285 ****
--- 280,288 ----
+                <string>923F0A10-96B9-4792-99A4-94FEF66E0B8C</string>
+                <string>57EF6130-05A6-4117-94CB-C0BD63328334</string>
+                <string>28F89786-04F4-43D7-82A6-34B046C2BC6B</string>

2) I tried to add the three rejected lines manually, and in the bundle editor I can see the new RSpec syntax, but I don't see the new preferences. Shouldn't they show up too?

3) There is no new syntax highlighting on my Textmate. How does TextMate know to use this highlighting? Do I need to do anything special to make it work?

4) How do I bring up the list over behaviours and examples shown in your screenshot? It must be some keyboard shortcut I'm unaware of.



You can respond by visiting: 

More information about the rspec-devel mailing list