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
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
.
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')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With