Home Download Buy Blog Forum Support

end of a snippet

end of a snippet

Postby kib2 on Tue Jul 22, 2008 7:47 am

Hi,

there's something I really don't understand about snippets.
Suppose I wanted to write one that writes a Python's class attribute like this :

self.attribute = attribute

So, I wrote my snippet :

Code: Select all
<snippet>
    <content><![CDATA[self.${1:property} = $1]]></content>
</snippet>


Now, when I run it, all is fine but once I write "whatever"
like this (| is the cursor pos) :

Code: Select all
self.whatever| = whatever


and I hit the tab key, I've got this :

Code: Select all
   
self.whatever    | = whatever


I expected :

Code: Select all
   
self.whatever = whatever|


So how could I set the cursor pos at the end of the snippet ?
I've also tried

Code: Select all
<snippet>
    <content><![CDATA[self.${1:property} = $1$0]]></content>
</snippet>


because it was TextMate behaviour, but it fails.

Thanks for any hint.
kib2
 
Posts: 38
Joined: Sun Mar 23, 2008 8:30 am
Location: France

Re: end of a snippet

Postby kib2 on Tue Jul 22, 2008 10:46 pm

Thanks for the lesson sublimator :

  • you fixed my problem ;
  • I was not aware that the keybindings were sequential ; that's somewhat annoying, but maye we could write a macro for deleting the current word under the cursor.

Other points :
  • With
    Code: Select all
    <snippet>
        <content><![CDATA[self.${1:property} = $1
    $2]]></content>
    </snippet>
    once expanded, hitting tab brings me to
    Code: Select all
    self.property = |
    , I was expecting
    Code: Select all
    self.property = property|
    because $1 is supposed to be a mirror no ?!
  • Why can't we set the shortcut inside the snippet defintion ? We have to edit 2 files just for one snippet (a keymap and a snippet).
kib2
 
Posts: 38
Joined: Sun Mar 23, 2008 8:30 am
Location: France

Re: end of a snippet

Postby kib2 on Wed Jul 23, 2008 7:56 am

>> EDIT: ah I understand you now, yeah the mirroring is buggy/not working

Yes, that's the problem.

e has a nice a nice GUI for such things. I'll give your EditPreferences plugin a try, thanks for pointing it to me.

In fact I've made a snippets engine a long time ago in Python (for the PyK! http://kib2.free.fr/PyK/ project),
and I'm now a little confused about the way Sublime handles snippets.
kib2
 
Posts: 38
Joined: Sun Mar 23, 2008 8:30 am
Location: France


Return to Technical Support

Who is online

Users browsing this forum: Exabot [Bot], Soulsbane, Topic and 29 guests