Home Download Buy Blog Forum Support

Snippets problem

Snippets problem

Postby Jay on Wed Sep 30, 2009 9:44 am

Hi Sublime team,

Am i the only one to experience Snippet problems ?
Snippets are pretty much unusable because new snippets are trigged even when I am in previous Tab Stop editable zone.

To reproduce it, create a new document, choose the HTML package, type "html" then tab.

Code: Select all
<html>
<head>
   <title>*TAB STOP*</title>
</head>
<body>

</body>
</html>


Now, in the title area, type a title than ends with a 'u' (ex. "Tutu") and press Tab to jump to the next Tab Stop... It does'nt jump but add a new snippet <u></u> to the title.

Code: Select all
<title>Tut<u></u></title>


Worse, I made my own img tag snippet.

Code: Select all
<img src="$1" alt="$2" />


When I type "mypicture.jpg" as an image src and press tab to jump to the 2d spot, Sublime gives me that:

Code: Select all
<img src="<mypicture class="jpg"></mypicture>" title="" />


Impossible to type an image src.

I think the most obvious solution would be to disabled trigger in Tab Stops.
Is there a bug or is there something I don't understand ?

Thanks in advance for your reply.
Jay
 
Posts: 1
Joined: Wed Sep 30, 2009 9:23 am

Re: Snippets problem

Postby Anomareh on Thu Oct 01, 2009 7:58 pm

sublimator wrote:
Code: Select all
<binding key="/([\w-]+)/,.,/([\w-]+)/,tab" command="insertSnippet 'Packages/HTML/elementclass.sublime-snippet' $1 $2">
    <context name="selector" value="text.html - meta.tag - source, meta.scope.between-tag-pair.html"/>
</binding>



I've also been having a similar issue. I tried your fix but it also disabled the snippet in tags which severely reduces the usefulness of the snippet. For example, you can't insert the snippet in any html tag such as in a paragraph or div tag. I assume that's what 'meta.scope.between-tag-pair.html' was meant to fix but it doesn't seem to. Is there a scope that would just simply disable the snippet in a tag attribute? because that would easily solve the problem.

Also is there any sort of functionality similar to TextMates ctrl + shift + p that shows the scopes of what's selected?

Thanks.
Anomareh
 
Posts: 222
Joined: Thu Oct 01, 2009 7:32 pm

Re: Snippets problem

Postby EJ12N on Thu Oct 01, 2009 8:22 pm

Also is there any sort of functionality similar to TextMates ctrl + shift + p that shows the scopes of what's selected?


ctrl+alt+p
Watch the status bar
EJ12N
 
Posts: 281
Joined: Tue Apr 21, 2009 5:23 pm

Re: Snippets problem

Postby Anomareh on Thu Oct 01, 2009 8:44 pm

EJ12N wrote:ctrl+alt+p
Watch the status bar


Awesome! Thanks.

EDIT After some playing around with this there are some really odd things going on.

Code: Select all
<html>
<head>
   <title>Some Title</title>
</head>

<body>
   <div>
      <p>Some text to test.</p>
      
      Some text to test.
   </div>
   
   Some text to test.
</body>
</html>


Take the above situation. I have an <a> snippet with the scope of 'text.html - meta.tag'. Now this stops it from being triggered in tag attributes but stops it in some odd places. For instance, it won't trigger in the <p> tag but it will trigger in the <div> and <body> tags. Now I used that mentioned command on all 'Some text to test.' and they all came back the exact same as 'text.html.basic'. So why will it trigger in the <body> and <div> tags but not the <p> tag?
Anomareh
 
Posts: 222
Joined: Thu Oct 01, 2009 7:32 pm

Re: Snippets problem

Postby Anomareh on Fri Oct 02, 2009 1:10 am

sublimator wrote:I think replacing the "meta.scope.between-tag-pair.html" with "punctuation.definition.tag.begin" should remove the need for this.


That did the trick. Thanks a bunch. Also real quick, what does that last '- source' actually do?
Anomareh
 
Posts: 222
Joined: Thu Oct 01, 2009 7:32 pm

Re: Snippets problem

Postby jps on Fri Oct 02, 2009 1:41 am

The '- source' portion prevents it from matching against any names with source in them: in this case, it disables the HTML snippets within <script> tags.
jps
Site Admin
 
Posts: 3067
Joined: Wed Mar 19, 2008 12:33 pm

Re: Snippets problem

Postby Anomareh on Fri Oct 02, 2009 1:56 am

sublimator wrote:TBH I'm not sure :) But I'm not arrogant enough to assume it does nothing

EDIT:

Just to be clear, I wasn't calling you arrogant in some roundabout way or anything. I just don't know and was too lazy to check. The best resource for information about scoping is the TextMate manual. If you get a answer please post back. Cheers.


Haha, nah I know what you meant.

I wish there was a better resource for scopes. The best I've found is this in the TextMate manual but it still leaves some things out. A giant list of all the difference selectors would be nice.
Anomareh
 
Posts: 222
Joined: Thu Oct 01, 2009 7:32 pm

Re: Snippets problem

Postby Anomareh on Fri Oct 02, 2009 2:42 am

Ah cool. Thanks a bunch.
Anomareh
 
Posts: 222
Joined: Thu Oct 01, 2009 7:32 pm

Re: Snippets problem

Postby jps on Fri Oct 02, 2009 3:53 pm

These issues are somewhat fixed in 20091002. HTML snippets have better scopes assigned by default now. The first issue, of typing a string with a tab trigger suffix and pressing tab, is still there.
jps
Site Admin
 
Posts: 3067
Joined: Wed Mar 19, 2008 12:33 pm

Next

Return to Technical Support

Who is online

Users browsing this forum: Exabot [Bot], Orlmente and 36 guests