diff --git a/README.md b/README.md index 841263a..b3084de 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,17 @@ Install both [vim-mode](https://github.com/atom/vim-mode) and ex-mode. Type `:` ## Extend -See `lib/ex.coffee` to add more commands. Contributions are very welcome! +Use the service to register commands, from your own package, or straight from `init.coffee`: + +```coffee +# in Atom's init.coffee +atom.packages.onDidActivatePackage (pack) -> + if pack.name == 'ex-mode' + Ex = pack.mainModule.provideEx() + Ex.registerCommand 'z', -> console.log("Zzzzzz...") +``` + +See `lib/ex.coffee` for some examples commands. Contributions are very welcome! ## Status diff --git a/lib/command.coffee b/lib/command.coffee index cc85247..851f859 100644 --- a/lib/command.coffee +++ b/lib/command.coffee @@ -13,7 +13,7 @@ class Command return unless input.characters.length > 0 [command, args...] = input.characters.split(" ") - func = (new Ex)[command] + func = Ex.singleton()[command] if func? func(args...) else diff --git a/lib/ex-mode.coffee b/lib/ex-mode.coffee index 264f2ce..7a548f8 100644 --- a/lib/ex-mode.coffee +++ b/lib/ex-mode.coffee @@ -1,5 +1,6 @@ GlobalExState = require './global-ex-state' ExState = require './ex-state' +Ex = require './ex' {Disposable, CompositeDisposable} = require 'event-kit' module.exports = ExMode = @@ -26,3 +27,6 @@ module.exports = ExMode = deactivate: -> @disposables.dispose() + + provideEx: -> + registerCommand: Ex.registerCommand.bind(Ex) diff --git a/lib/ex.coffee b/lib/ex.coffee index 303afa8..4839413 100644 --- a/lib/ex.coffee +++ b/lib/ex.coffee @@ -1,6 +1,12 @@ path = require 'path' class Ex + @singleton: => + @ex ||= new Ex + + @registerCommand: (name, func) => + @singleton()[name] = func + quit: -> atom.workspace.getActivePane().destroyActiveItem() diff --git a/package.json b/package.json index a72812d..623c06c 100644 --- a/package.json +++ b/package.json @@ -14,5 +14,13 @@ "dependencies": { "underscore-plus": "1.x", "event-kit": "^0.7.2" + }, + "providedServices": { + "ex-mode": { + "description": "Ex commands", + "versions": { + "0.20.0": "provideEx" + } + } } }