Doug Finke
Doug Finke

Reputation: 6823

How to call an atom package?

I installed the atom-runner package. I want to create a custom command to execute from the palette to save the current file and then execute the runner. Getting the editor and saving the file works.

runner:run fails as does AtomRunner.run()

atom.workspaceView.command 'MyEntry:runner', -> editor = atom.workspace.getActiveEditor() editor.save() runner:run

Upvotes: 4

Views: 1725

Answers (2)

thornomad
thornomad

Reputation: 6797

I found that with version 1.9.x the last line of the accepted answer did not work:

atom.workspaceView.trigger 'runner:run'

After some searching, found that this did:

editorView = atom.views.getView(editor)
atom.commands.dispatch(editorView, 'runner:run')

Upvotes: 3

Lee
Lee

Reputation: 18767

To call a Command Palette command from code, you can use atom.workspaceView.trigger and give it the name of the command as a string. For example:

atom.workspaceView.command 'custom:runner', ->
  editor = atom.workspace.getActiveEditor()
  editor.save()
  atom.workspaceView.trigger 'runner:run'

I changed the name of your custom command to custom:runner to fit in with the conventions of command naming in Atom and the conventions we've been using in the Atom community for simple commands in one's init.coffee. If you wanted to retain the use of "my entry" as the package name (or anything else that has two words in it), I'd recommend formatting it as my-entry:runner.

Upvotes: 5

Related Questions