Home Download Buy Blog Forum Support

Please help me keep Sublime Text 2!

Re: Please help me keep Sublime Text 2!

Postby kakubei on Mon Dec 19, 2011 7:37 pm

I hate to sound stupid, but I'm not having any luck creating a snippet for <% to create and close the tags. Any pointers would be appreciated.

thanks.
kakubei
 
Posts: 58
Joined: Sun Sep 25, 2011 9:19 am

Re: Please help me keep Sublime Text 2!

Postby C0D312 on Mon Dec 19, 2011 8:14 pm

Try this (add it to your user keybindings):
Code: Select all
  {
    "args": {
      "contents": "=$0%>"
    },
    "command": "insert_snippet",
    "context": [
      {
        "key": "selector",
        "match_all": true,
        "operand": "source.ruby",
        "operator": "equal"
      },
      { "key": "preceding_text", "operator": "regex_contains", "operand": "<%", "match_all": true }
    ],
    "keys": [
      "="
    ]
  }
C0D312
 
Posts: 1063
Joined: Sun Jul 10, 2011 3:23 am

Re: Please help me keep Sublime Text 2!

Postby kakubei on Mon Dec 19, 2011 9:31 pm

COD312, thanks a lot this works perfectly, I really appreciate it.

Now, if I may try your patience I'm trying to accomplish the same thing for <% so I have this code:

Code: Select all
{
       "args": {
         "contents": "% $0 %>"
       },
       "command": "insert_snippet",
       "context": [
         {
           "key": "selector",
           "match_all": true,
           "operand": "source.ruby",
           "operator": "equal"
         },
         { "key": "preceding_text", "operator": "regex_contains", "operand": "<", "match_all": true }
       ],
       "keys": [
         "%"
       ]
   }

Could you tell me what I'm doing wrong here?
kakubei
 
Posts: 58
Joined: Sun Sep 25, 2011 9:19 am

Re: Please help me keep Sublime Text 2!

Postby C0D312 on Mon Dec 19, 2011 9:48 pm

Could you tell me what I'm doing wrong here?


What seems to be the problem? I just copied and pasted your code and it seems to work fine.
C0D312
 
Posts: 1063
Joined: Sun Jul 10, 2011 3:23 am

Re: Please help me keep Sublime Text 2!

Postby kakubei on Mon Dec 19, 2011 10:32 pm

C0D312 wrote:What seems to be the problem? I just copied and pasted your code and it seems to work fine.

Well, this one works <%=

But just typing this <% will not create the closing brackets. You say it's working for you? It creates the %> after typing <% ?
kakubei
 
Posts: 58
Joined: Sun Sep 25, 2011 9:19 am

Re: Please help me keep Sublime Text 2!

Postby kakubei on Tue Dec 20, 2011 9:12 am

Another problem I have is that any time I type an equal sign it adds %>. I only want the closing bracket if the equal sign is preceded by <

Let me clarify, it does this while inside a <%= when I try to type something like ':controller =>' because of course it's matching the '<%=' from the beginning of the line. Just wondering if there is a way to avoid this.
kakubei
 
Posts: 58
Joined: Sun Sep 25, 2011 9:19 am

Re: Please help me keep Sublime Text 2!

Postby eike on Tue Dec 20, 2011 3:54 pm

Take a look at https://github.com/kevinansfield/SublimeERB -- it adds a ERB-Block command similar to that of Textmate.
eike
 
Posts: 2
Joined: Mon Nov 14, 2011 7:50 am

Re: Please help me keep Sublime Text 2!

Postby natebeaty on Tue Dec 20, 2011 5:31 pm

eike wrote:Take a look at https://github.com/kevinansfield/SublimeERB -- it adds a ERB-Block command similar to that of Textmate.


I use this all the time -- really handy command. It won't auto close your <% like you're asking, but once you get accustomed to ctrl-shift-period to quickly insert a <%= %> block (and cycle through the variations thereof), it's much faster than manually typing the starting <%.
natebeaty
 
Posts: 119
Joined: Wed Apr 06, 2011 8:28 pm
Location: Chicago, IL

Re: Please help me keep Sublime Text 2!

Postby C0D312 on Tue Dec 20, 2011 8:36 pm

If you're not content with sublimeERB, you can try this keybinding:
Code: Select all
  {
       "args": {
         "contents": "% $0 %>"
       },
       "command": "insert_snippet",
       "context": [
         {
           "key": "selector",
           "match_all": true,
           "operand": "source.ruby",
           "operator": "equal"
         },
         { "key": "preceding_text", "operator": "regex_match", "operand": ".*<", "match_all": true }
       ],
       "keys": [
         "%"
       ]
   },


This should fix the issue with triggering the autocomplete on the same line as "<%"
C0D312
 
Posts: 1063
Joined: Sun Jul 10, 2011 3:23 am

Re: Please help me keep Sublime Text 2!

Postby kakubei on Wed Dec 21, 2011 4:46 pm

C0D312 wrote:This should fix the issue with triggering the autocomplete on the same line as "<%"

Unfortunately, it doesn't fix it. But I'm using SublimeERB and that seems fine for now. Eventually I'd really like to find out how to close those tags with the snippets.
kakubei
 
Posts: 58
Joined: Sun Sep 25, 2011 9:19 am

PreviousNext

Return to Technical Support

Who is online

Users browsing this forum: No registered users and 13 guests

cron