Home Download Buy Blog Forum Support

How to insert a snippet from a plugin?

How to insert a snippet from a plugin?

Postby senzo on Tue Jan 03, 2012 10:49 pm

I write a plugin where i would like to insert a snippet (Packages/XML/long-tag.sublime-snippet) via
Code: Select all
self.view.run_command("insert_snippet"...

Does anybody know if this is possible? I can't figure it out. The snippet content looks like this:
Code: Select all
<content><![CDATA[<${1:p}>${2:$SELECTION}</${1/([^ ]+).*/$1/}>]]></content>

Thanks
senzo
 
Posts: 106
Joined: Tue May 24, 2011 9:17 am

Re: How to insert a snippet from a plugin?

Postby svenax on Wed Jan 04, 2012 12:11 pm

Looks like the syntax is
Code: Select all
self.view.run_command("insert_snippet", { "name": "Packages/User/MySnippet.sublime-snippet" })

to use a snippet file, or
Code: Select all
self.view.run_command("insert_snippet", { "contents": "contents($0)" })

to insert a snippet string.
svenax
 
Posts: 154
Joined: Tue Dec 20, 2011 12:47 pm

Re: How to insert a snippet from a plugin?

Postby senzo on Wed Jan 04, 2012 11:00 pm

Thanks, that's actually what i tried. It didn't work because of a prepending self.view.sel().clear(). Without clearing everything works fine now.
senzo
 
Posts: 106
Joined: Tue May 24, 2011 9:17 am

Re: How to insert a snippet from a plugin?

Postby hibbelig on Thu Jan 05, 2012 4:51 am

senzo wrote:Thanks, that's actually what i tried. It didn't work because of a prepending self.view.sel().clear(). Without clearing everything works fine now.

Heh. You removed the cursor by doing that...
hibbelig
 
Posts: 77
Joined: Wed Dec 21, 2011 11:24 pm


Return to Plugin Development

Who is online

Users browsing this forum: Exabot [Bot] and 6 guests