Merge pull request #113 from GertjanReynaert:master
Add option to register alias keys in atom init config
This commit is contained in:
commit
b55d2857b0
4 changed files with 26 additions and 1 deletions
|
|
@ -18,6 +18,8 @@ atom.packages.onDidActivatePackage (pack) ->
|
|||
if pack.name == 'ex-mode'
|
||||
Ex = pack.mainModule.provideEx()
|
||||
Ex.registerCommand 'z', -> console.log("Zzzzzz...")
|
||||
# Register an alias - Now :W acts like :w
|
||||
Ex.registerAlias 'W', 'w'
|
||||
```
|
||||
|
||||
See `lib/ex.coffee` for some examples commands. Contributions are very welcome!
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ module.exports = ExMode =
|
|||
|
||||
provideEx: ->
|
||||
registerCommand: Ex.registerCommand.bind(Ex)
|
||||
registerAlias: Ex.registerAlias.bind(Ex)
|
||||
|
||||
consumeVim: (vim) ->
|
||||
@vim = vim
|
||||
|
|
|
|||
|
|
@ -106,6 +106,9 @@ class Ex
|
|||
@registerCommand: (name, func) =>
|
||||
@singleton()[name] = func
|
||||
|
||||
@registerAlias: (alias, name) =>
|
||||
@singleton()[alias] = (args) => @singleton()[name](args)
|
||||
|
||||
quit: ->
|
||||
atom.workspace.getActivePane().destroyActiveItem()
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@ os = require 'os'
|
|||
uuid = require 'node-uuid'
|
||||
helpers = require './spec-helper'
|
||||
|
||||
Ex = require('../lib/ex').singleton()
|
||||
ExClass = require('../lib/ex')
|
||||
Ex = ExClass.singleton()
|
||||
|
||||
describe "the commands", ->
|
||||
[editor, editorElement, vimState, exState, dir, dir2] = []
|
||||
|
|
@ -732,3 +733,21 @@ describe "the commands", ->
|
|||
atom.commands.dispatch(editorElement, 'ex-mode:open')
|
||||
submitNormalModeInputText(':set nonumber')
|
||||
expect(atom.config.get('editor.showLineNumbers')).toBe(false)
|
||||
|
||||
describe "aliases", ->
|
||||
it "calls the aliased function without arguments", ->
|
||||
ExClass.registerAlias('W', 'w')
|
||||
spyOn(Ex, 'write')
|
||||
keydown(':')
|
||||
submitNormalModeInputText('W')
|
||||
expect(Ex.write).toHaveBeenCalled()
|
||||
|
||||
it "calls the aliased function with arguments", ->
|
||||
ExClass.registerAlias('W', 'write')
|
||||
spyOn(Ex, 'W').andCallThrough()
|
||||
spyOn(Ex, 'write')
|
||||
keydown(':')
|
||||
submitNormalModeInputText('W')
|
||||
WArgs = Ex.W.calls[0].args[0]
|
||||
writeArgs = Ex.write.calls[0].args[0]
|
||||
expect(WArgs).toBe writeArgs
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue