Reputation: 9665
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).
Upvotes: 9
Views: 1459
Reputation: 422
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.
Upvotes: 1
Reputation: 6082
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
Upvotes: 2
Reputation: 3639
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.
Upvotes: 0