Help with using commands


#1

When defining commands for keymaps or menus to call, how does one name or setup the command to point to a function call in a particular library or file? For example, if I do the following within a file named blah.cson in my projects keymaps directory

'.workspace':
  'ctrl-alt-h': 'blah:toggle'

What do blah and toggle refer to in the command mapping?

  • Does toggle after the colon refer to a function called toggle?
  • Does blah refer to a file named lib/blah.[js|coffee]?

Currently I’ve noticed that in my project with :toggle on the end, it invokes the activate function once but subsequent invocations do nothing. And without the :toggle on the end, it seems to do nothing.


#2

blah:toggle is the name of the command. By convention, blah is the dasherized name of the package and toggle is an identifier specific to that one command, also in hyphen-separated, all lower-case form. The command is created by executing the atom.commands.add method, typically in your package’s activate method.

The behavior you mention here:

is due to the activationCommands feature:

In essence, what this feature does is allows your package to load, but not activate, i.e. perform costly initializations, when Atom launches. Then when a command is triggered through the Command Palette, in a menu or keybinding, the package is activated and the command actually executed.