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

noreply at rubyforge.org noreply at rubyforge.org
Sun Jul 8 06:27:52 EDT 2007


Patches item #11254, was opened at 2007-05-31 14:43
You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=3151&aid=11254&group_id=797

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
    ...
    end

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

    "should be valid"

- likewise, a behaviour like:

    describe User, "at creation time" do
    ...
    end

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-08 10:27

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

----------------------------------------------------------------------

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

Message:
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

Message:
Ok, submitted a TextMate feature request here:

http://macromates.com/ticket/show?ticket_id=48BF3775

----------------------------------------------------------------------

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

Message:
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

Message:
(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
highlighting.

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

Message:
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 ****
                 <string>240FDD9D-CD49-4917-9003-80A3E1DADFBA</string>
                 <string>B5906021-8E54-4863-A13B-EA46333DB5F1</string>
                 <string>67E726E0-63E2-4840-B8BB-37F665CD34B8</string>
         </array>
         <key>uuid</key>
         <string>4CEA47CC-2C3A-45FB-80BE-3820828227C2</string>
--- 280,288 ----
                 <string>240FDD9D-CD49-4917-9003-80A3E1DADFBA</string>
                 <string>B5906021-8E54-4863-A13B-EA46333DB5F1</string>
                 <string>67E726E0-63E2-4840-B8BB-37F665CD34B8</string>
+                <string>923F0A10-96B9-4792-99A4-94FEF66E0B8C</string>
+                <string>57EF6130-05A6-4117-94CB-C0BD63328334</string>
+                <string>28F89786-04F4-43D7-82A6-34B046C2BC6B</string>
         </array>
         <key>uuid</key>
         <string>4CEA47CC-2C3A-45FB-80BE-3820828227C2</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.

Cheers,
Aslak

----------------------------------------------------------------------

You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=3151&aid=11254&group_id=797


More information about the rspec-devel mailing list