Load snippets from .atom/snippets when snippets extension is activated

This commit is contained in:
David Graham & Nathan Sobo
2012-06-20 11:49:29 -06:00
parent dc6c0a3e35
commit d992458c8c
2 changed files with 35 additions and 2 deletions

View File

@@ -7,14 +7,31 @@ module.exports =
snippetsParser: PEG.buildParser(fs.read(require.resolve 'extensions/snippets/snippets.pegjs'))
activate: (@rootView) ->
@loadSnippets()
for editor in rootView.editors()
@enableSnippetsForEditor(editor)
rootView.on 'editor-open', (e, editor) =>
editor.preempt 'tab', =>
return false if @expandSnippet()
@enableSnippetsForEditor(editor)
enableSnippetsForEditor: (editor) ->
editor.preempt 'tab', => return false if @expandSnippet()
loadSnippets: ->
snippetsDir = fs.join(atom.configDirPath, 'snippets')
return unless fs.exists(snippetsDir)
@loadSnippetsFile(path) for path in fs.list(snippetsDir) when fs.extension(path) == '.snippets'
loadSnippetsFile: (path) ->
@evalSnippets(fs.base(path, '.snippets'), fs.read(path))
evalSnippets: (extension, text) ->
@snippetsByExtension[extension] = @snippetsParser.parse(text)
console.log @snippetsByExtension
expandSnippet: ->
console.log "EXPAND SNIPPET"
editSession = @rootView.activeEditor().activeEditSession
return unless snippets = @snippetsByExtension[editSession.buffer.getExtension()]
prefix = editSession.getLastCursor().getCurrentWordPrefix()