Home Download Buy Blog Forum Support

Cursor position on insert date snippet

Cursor position on insert date snippet

Postby quodlibet on Fri Oct 05, 2012 12:38 pm

I would like to bind a command to get the following string:

Code: Select all
- [ ] |   {2012-10-05}


(The | represents the position of the caret.)

This can't be done with a snippet because the date has to be dynamic. I'm no programmer, but I've been messing around with the itodo plugin to arrive at what I want:

Code: Select all
line_contents = '- [ ] \t{%s}' % datetime.now().strftime("%Y-%m-%d")
self.view.insert(edit, line.begin(), line_contents)


This is quite close but I would like the caret to be after the "checkbox" (the square bracekts). Any pointers?

P.S. Sorry if this has been answered before. I recall reading similar questions, but I couldn't find an answer to the specific issue I'm having.

Edit: added a parenthetical explanation.
quodlibet
 
Posts: 503
Joined: Sat Jun 18, 2011 5:53 pm

Re: Cursor position on insert date snippet

Postby quarnster on Mon Oct 08, 2012 11:58 am

I'd probably just insert a dynamic snippet:
Code: Select all
view.run_command("insert_snippet", {"contents":'- [ ] ${1:something}\t{%s}' % datetime.now().strftime("%Y-%m-%d")})
quarnster
 
Posts: 389
Joined: Tue Nov 29, 2011 11:34 am

Re: Cursor position on insert date snippet

Postby quodlibet on Mon Oct 08, 2012 9:19 pm

@quarnster Thank you! That's even better than what I asked for, because it allows me setup a couple of placeholders as well:

Code: Select all
self.view.run_command("insert_snippet", { "contents": "- [ ] ${1:Next action} +${2:Project}\t{%s}" %  datetime.date.today().isoformat() } )
quodlibet
 
Posts: 503
Joined: Sat Jun 18, 2011 5:53 pm


Return to General Discussion

Who is online

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