Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 271
Doug Finke Avatar asked Feb 12 '23 12:02

Doug Finke


2 Answers

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.

like image 193
Lee Avatar answered Feb 15 '23 09:02

Lee


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')
like image 39
thornomad Avatar answered Feb 15 '23 10:02

thornomad