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开发者_StackOverflow中文版 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).
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
This was fixed with Textmate update 1.5.10 (1623).
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.
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.
精彩评论