One thought after another opening a new document

Opening documents in, is managed through the open method of the workspace object.

To open a new document in, omit the URI parameter of the open call:

{CompositeDisposable} = require 'atom'

module.exports = MyPackage =

    subscriptions: null

    activate: (state) ->
        # Events subscribed to in atom's system can be easily cleaned up with a CompositeDisposable
        @subscriptions = new CompositeDisposable

        # Register command that toggles this view
        @subscriptions.add atom.commands.add 'atom-workspace', 'my-package:execute': => @execute()

    deactivate: ->

    execute: ->
        # no URI given

When saving the document, you will be prompted for a filename.

If you provide a URI to a non-existing file, a new document will be created with that filename. The file is not created before you hit the save command. You will not be prompted for filename.

execute: ->
    # URI for non-existing URI given'c:\\temp\\temp.txt')

If you do not provide a full URI, just a name, it will use the current projects root folder. If no project is open, you will get a new un-named document.

execute: ->
    # relative URI for non-existing file'newdoc')

At this time, this is undocumented behavior, but hopefully, not for long.

comments powered by Disqus