How can I make a command that creates a new file with template text?


#1

Hi, I’m trying to make a command that will open a new text editor with template text. I’ve looked at similar questions and poked through the wiki, but I can’t seem to get it to work. I want to make it a command instead of just doing ctrl+n and using a snippet because I plan on binding it to a toolbar icon. Here’s my code.

atom.commands.add 'atom-text-editor',
'custom:new-template-file', ->
    editor = atom.workspace.buildTextEditor();
    atom.workspace.open().then (editor) ->
    editor.insertText('[insert template text]')

Help would be much appreciated.


#2

Your indentation is wrong. This works:

atom.commands.add 'atom-text-editor', 'custom:new-template-file', ->
  editor = atom.workspace.buildTextEditor()
  atom.workspace.open().then (editor) ->
    editor.insertText('[insert template text]')

#3

Thanks, works perfectly!