Search code examples
ruby-on-railstextmate

Textmate 2 selecting instance variables


In earlier versions of Textmate, when I double-clicked on a Rails instance variable (e.g. @contract), the selection omitted the @ sign -- which was great. The pasteboard only contained "contract".

In Textmate version 2.0-alpha.9459, double clicking on an instance variable selects the @sign as well as the characters. The pasteboard now contains "@contract".

Is there a way to configure Textmate 2.0 so that the @ of an instance variable is omitted on select?


Solution

  • You can edit the Ruby bundle's language grammar to define "words". There's a section called "variable.other.readwrite.instance.ruby", which looks like this:

    name = 'variable.other.readwrite.instance.ruby';
    match = '(@)[a-zA-Z_]\w*';
    captures = { 1 = { name = 'punctuation.definition.variable.ruby'; }; };
    

    Remove the @-sign from the regex and it will behave like you described:

    name = 'variable.other.readwrite.instance.ruby';
    match = '[a-zA-Z_]\w*';
    captures = { 1 = { name = 'punctuation.definition.variable.ruby'; }; };
    

    Note that now syntax highlighting won't catch the @ as well.