Snippet with current date


#1

Hi everyone.
I use a bunch of ‘today’s dates’ on my markdown files.
Would it be possible to make a snippet so it prints today’s date for markdown source files?
Not even sure if that is possible in cson.

Thank you a lot!


#2

This isn’t possible with the current snippet system. I created something for my init.coffee that does this though:

atom.commands.add 'atom-workspace',
  'custom:insert-timestamp': ->
    now = new Date()
    atom.workspace.getActiveTextEditor().insertText(now.toISOString())

#3

Boss!,
I think i needed to brush up my CoffeeSCript-CSON understanding, this really helped me to push to that.
I configured your init.coffee entry like so:

atom.commands.add 'atom-workspace',
  'custom:insert-timestamp': ->
    now = new Date()
    atom.workspace.getActiveTextEditor().insertText(now.toISOString().split('T')[0])

and then added a custom shortcut for markdown:

'atom-text-editor[data-grammar="source gfm"]':
  'ctrl-shift-a': 'custom:insert-timestamp'

Tnx a lot!


#4

Is this still NOT possible? I too would like to insert current date/time into my source files using snippet.


#5

The previous posts in the thread show the way in which it is possible. If you would like to propose an additional feature for the snippets package, you can do so at the GitHub repo.


#6

The previous posts show how to use a shortcut to insert it, but I want to have it in my snippet so when I tab and it inserts the template, the date is already there.


#7

That sounds like a great feature request. Go for it. :slight_smile: