Create command attached to a specific scope


Hi there.
How can I create a command for my package wich is only available for a specific scope ?
I Did not found this information in doc nor Discuss.


Since Atom can have essentially unlimited commands, there isn’t much use for restricting commands to being used more specifically than by view type, i.e. tree-view, settings-view, editor-view, etc. Restricting key bindings is a different story. Is that what you’re asking about?


A bit verbose, but you could do

atom.commands.add 'atom-text-editor[data-grammar~="source"][data-grammar~="js"]', 'my-command', ->
  # handle the command

to attach the command only to text editors with the source.js scope.


Exactly what I needed, thanks.