Skip to content

Commit

Permalink
Proof of concept: Auto execute on "# => " snippet expansion
Browse files Browse the repository at this point in the history
Needs to be cleaned up, this was just to see if it is possible, which it is.
I'm committing it on a branch to maybe prompt consideration in the snippets package.
It seems like maybe the way to do this for real would be for the snippets package
to emit an event for did-expand-snippet. Though I don't fully grasp how all the
pieces fit together.

For context, see:
  #25
  atom/snippets#221
  • Loading branch information
JoshCheek committed Feb 4, 2017
1 parent 7b80ae3 commit fb62dcc
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lib/seeing-is-believing.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,25 @@ module.exports = SeeingIsBelieving =
activate: ->
@notifications = []
@subscriptions = new CompositeDisposable
# The snippets package subscribes to "atom-text-editor"
# what's the difference? Sounds like it's what we actually want and would let
# us get rid fo teh `return unless editor` check down below
@subscriptions.add atom.commands.add 'atom-workspace',
'seeing-is-believing:annotate-document': => @run [],
'seeing-is-believing:annotate-magic-comments': => @run ['--xmpfilter-style'],
'seeing-is-believing:remove-annotations': => @run ['--clean']
@subscriptions.add atom.commands.onDidDispatch (event) =>
return unless event.type == "snippets:expand"
editor = atom.workspace.getActiveTextEditor() # I think we can assume this since snippets:expand did dispatch, note they use @getModel, to do this, but a quick glance around didn't locate it, so maybe look for it if I keep this
scope = editor.getLastCursor().getScopeDescriptor()
scopes = scope?.getScopesArray?() # IDK if I need the ?s, just cargo culting their work: https://github.com/atom/snippets/blob/c93956cc7306632beede152d77a7d4f757bc70a9/lib/snippets.coffee#L193
return unless scopes && scopes.includes("source.ruby")
didExpand = false
editor.getCursors().forEach (cursor) =>
{row, column} = cursor.getBufferPosition()
text = editor.getTextInRange([{row, column: column-5}, {row, column: column}])
console.log(text)
@run ['--xmpfilter-style'] if text == "# => "

deactivate: ->
@subscriptions.dispose()
Expand Down

0 comments on commit fb62dcc

Please sign in to comment.