mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
Load snippets from .atom/snippets when snippets extension is activated
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user