Trigger a package via ex-mode


#1

I want to trigger the git-blame (or any other) package via ex-mode.

Any ideas how to make this work?

atom.packages.onDidActivatePackage (pack) ->
  if pack.name == 'ex-mode'
    Ex = pack.mainModule.provideEx()
    Ex.registerCommand 'Gblame', ->  'git-blame:toggle'

#2

Look at the example again.

atom.packages.onDidActivatePackage (pack) ->
  if pack.name == 'ex-mode'
    Ex = pack.mainModule.provideEx()
    Ex.registerCommand 'z', -> console.log("Zzzzzz...")

The second argument of registerCommand() is not looking for a string. You’re treating it like atom.commands.dispatch(), but the -> indicates that it’s an anonymous function that wants to execute some code as a callback (it translates into () => {return console.log("Zzzzzz...")}. What you want to do is this:

atom.packages.onDidActivatePackage (pack) ->
  if pack.name == 'ex-mode'
    Ex = pack.mainModule.provideEx()
    Ex.registerCommand 'z', -> atom.commands.dispatch(atom.workspace.element, 'git-blame:toggle')

#3

Thanks for your help and the explanation; it works now!;