Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TextMate js.erb: toggle <%= %>, <% %>

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

like image 897
balexand Avatar asked Oct 19 '10 00:10

balexand


2 Answers

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

like image 156
Igbanam Avatar answered Sep 23 '22 03:09

Igbanam


This was fixed with Textmate update 1.5.10 (1623).

like image 43
balexand Avatar answered Sep 21 '22 03:09

balexand