9

I'm using a js.erb template to render some jQuery. When editing an html.erb file in TextMate, I frequently use the convenient key combo, ctrl+>, to create and then toggle the following tags:

<%=  %>
<%  %>
<%-  -%>
<%#  %>

This shortcut doesn't work by default when editing js.erb files. In the Bundle Editor, I found a snippet called "Insert ERb’s <% .. %> or <%= .. %>" under "Ruby". By adding "source.js" to the scope selector I was able to get insertion to work, but when I pressed the key combo multiple times, instead of toggling the tag I got a tag inside of a tag like this:

<%= <%=  %> %>

I've tried changing the scope of the command called "Toggle ERb Tags" but I can't seem to get toggling to work. Any suggestions?

Update November 19, 2010:

This is no longer a problem in the new version of Textmate that came out this week: 1.5.10 (1623).

balexand
  • 9,549
  • 7
  • 41
  • 36

4 Answers4

2

One possible reasono why this is the case is that the snippet that generates the angle brackets for you is defined thus:

<%= $0 %>

This puts this text into your source after the tab-trigger occurs. The $0 is a placeholder for the cursor; it's final resting place after the snippet is completed. Since the cursor rests in the middle and this is a simple snippet, repeatedly performing the tab-trigger will nest these brackets.

To achieve what you want, you have to do it in a script. You can use any scripting language as long as you appropriately specify the shebang line. I am not a proficient scripter so I'll try to solve this using pseudocode.

if selected_text
    if no_wrapping_angle_brackets
        surround_with_angle_brackets
    else
        strip_angle_brackets
else
    if no_wrapping_angle_brackets
        surround_with_angle_brackets
    else
        strip_angle_brackets

It's not much but I hope this helps

Igbanam
  • 5,904
  • 5
  • 44
  • 68
2

This was fixed with Textmate update 1.5.10 (1623).

balexand
  • 9,549
  • 7
  • 41
  • 36
1

I just ran into this problem too, even with updated TextMate and bundles. I fixed it by adding source.js.rails to the scope selector of the snippet "Insert ERb’s <% .. %> or <%= .. %>". Make sure you don't change the scope selector for the similar command "Toggle ERb Tags". This inserts the ERb tags correctly and also toggles them as expected.

MWean
  • 422
  • 1
  • 4
  • 9
0

Your Ruby on Rails Textmate bundle may be outdated due to changes in Ruby 1.9.

Update your tmbundle and this problem should go away.

Raphomet
  • 3,589
  • 1
  • 23
  • 12
  • Thanks for the suggestion, but that didn't solve the problem. I updated both the Ruby on Rails bundle using your link and the Ruby bundle(http://github.com/drnic/ruby-tmbundle). It looks like there are some cool new features, but I'm having the same problem with the tag toggling in js.erb files. – balexand Oct 19 '10 at 02:08
  • Ah, sorry to hear that. Upgrading fixed a similar problem for me. I hope you figure out what the problem is! – Raphomet Oct 19 '10 at 05:14