Create command attached to a specific scope


#1

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.


#2

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?


#3

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.


#4

Exactly what I needed, thanks.