How to launch a command from the context menu


#1

How can I add this scrpit (taken here will be in the Init File) in the context menu ?

atom.commands.add 'atom-text-editor', 'markdown:paste-as-link', ->
  return unless editor = atom.workspace.getActiveTextEditor()

  selection = editor.getLastSelection()
  clipboardText = atom.clipboard.read()

  selection.insertText("[#{selection.getText()}](#{clipboardText})")

Any advice would be very precious.

Thanks!


#2

I recommend looking at the API docs


#3
atom.contextMenu.add {
  "atom-text-editor": [{
    label: "Paste as link"
    command: "markdown:paste-as-link"
  }]
}

#4

Thanks a lot both of you, it’s exactly what I was looking for!