Sublime Forum

Ruby { } blocks are broken

#1

Hello,

Currently the Ruby package/snippets do not correctly support {+tab.

Hitting it, It produces the following output:

{ variablevariablevariable }

Ideally, the output should be:

do block used to suffer from similar issue.

Tried to find where this is defined without avail.

Thank you.

0 Likes

#2

Confirming that the do … end snippet works correctly and that this {+tab snippet results in ‘variablevariablevariable’ junk. It’s in .Sublime Text 2/Packages/Ruby/open-yield-block*.sublime-snippet but I didn’t test the regex.

On a similar note the Ruby package could use some updates to support 1.9 and JRuby conventions… has anyone already undertaken this effort?

0 Likes

#3

any news on this issue? or a viable workaround?

0 Likes

#4

Yes, I found this annoying too.

I did a quick fix by replacing the contents of Sublime Text 2/Packages/Ruby/open-yield-block-({).sublime-snippet with:

<snippet>
    <content><![CDATA[{${1/(^.+$)|^$/(?1: |)/}${1:variable}${1/(^.+$)|^$/(?1:|)/} $0 ]]></content>
    <tabTrigger>{</tabTrigger>
    <scope>source.ruby</scope>
    <description>Insert { |variable| … }</description>
</snippet>

(You may wish to comment out the original contents and add the above, so you can easily revert it).

The original tag expression was attempting to take your context (writing ruby, inside a string or in a comment) into account, but as I tend not to hit {[tab] inside strings or comments I wasn’t so worried about those two scenarios. I haven’t had time to investigate how to fix it directly (and the regex is challenging), so what you see is adapted from the mechanism in the do-obj-…-end-(doo).sublime-snippet.

The result generates the expected { |variable| } and supports tabbing from the variable to writing an expression. It works for me, but hasn’t been widely tested.

0 Likes