fat-arrow という Atomプラグインを作りました

fat-arrow

textmateでは ctrl + L で fat-arrow (" => ") が表示でき
sublime text2 ではsnippetに定義すればokですが
Atomではできません。私が知らないだけかもしれませんが。
 
ちょっとイライラが溜まってきたので、プラグインとして作ってしまいました。

使い方

ctrl + L を押すと、以下の順で値が変わります。

' => '
' -> '
'=>'
'->'

こんな感じ

A screenshot of your spankin' package
gifはちょっと前のバージョンです。

個人的には

もう少しいじるかもしれませんが、今のところ満足です。
あとテストが結構面倒でした。

# fat-arrow/spec/fat-arrow-spec.coffee
{WorkspaceView} = require 'atom'

describe "FatArrow", ->
  [activationPromise, editor, editorView] = []

  arrowShow = (calledTimes, actual) ->
    for [1..calledTimes]
      editorView.trigger 'fat-arrow:show'
    waitsForPromise -> activationPromise
    runs ->
      expect(editor.getSelectedText()).toEqual(actual)

  beforeEach ->
    atom.workspaceView = new WorkspaceView
    atom.workspaceView.openSync()
    editorView = atom.workspaceView.getActiveView()
    editor = editorView.getEditor()
    activationPromise = atom.packages.activatePackage('fat-arrow')

  describe 'when the fat-arrow:show event is triggered', ->
    describe 'once', ->
      it 'is selected a fat arrow', ->
        arrowShow(1, ' => ')

    describe 'twice', ->
      it 'is selected a narrow arrow', ->
        arrowShow(2, ' -> ')

    describe '3 times', ->
      it 'is selected a fat arrow without space', ->
        arrowShow(3, '=>')

    describe '4 times', ->
      it 'is selected a narrow arrow without space', ->
        arrowShow(4, '->')

    describe '5 times', ->
      it 'is selected a narrow arrow', ->
        arrowShow(5, ' => ')

これだけなんですが、非同期処理に待を入れる必要があるところと、その書き方にはまってしまいました。