Home Download Buy Blog Forum Support

Single quotes in snippets

Single quotes in snippets

Postby guillermooo on Mon May 10, 2010 9:14 pm

Code: Select all
class InsertDateWithSnippetCommand(sublimeplugin.TextCommand):
    def run(self, view, args):
        dateAsStr = datetime.datetime.today().strftime("%x")
        snippet = "Today's Date: $1 abc $2 abc ${3:%s}" % dateAsStr
        view.runCommand("insertInlineSnippet '%s'" % snippet)


This will insert only Today into the buffer. Is this intended? How do we escape characters in snippets?
guillermooo
 
Posts: 729
Joined: Thu Jul 23, 2009 9:06 am

Re: Single quotes in snippets

Postby guillermooo on Mon May 10, 2010 9:26 pm

Ok. Just do \\'.
guillermooo
 
Posts: 729
Joined: Thu Jul 23, 2009 9:06 am

Re: Single quotes in snippets

Postby jps on Tue May 11, 2010 10:38 pm

You can also let runCommand do the escaping for you:

Code: Select all
view.runCommand("insertInlineSnippet", [snippet])
jps
Site Admin
 
Posts: 3071
Joined: Wed Mar 19, 2008 12:33 pm


Return to Technical Support

Who is online

Users browsing this forum: Google [Bot] and 21 guests