xeronuro
6/1/2016 - 4:54 PM

Atom autocomplete suggestions on tab

Atom autocomplete suggestions on tab

{Point} = require 'atom'

atom.commands.add 'atom-text-editor', 'custom:tabcomplete', (e) ->
  editor = atom.workspace.getActiveTextEditor()
  cursor = editor.getLastCursor()

  {row, column} = cursor.getBufferPosition()
  precedingCharacter = editor.getTextInBufferRange([[row, column - 1], [row, column]])

  if /\S/.test(precedingCharacter)
    autocomplete = atom.packages.getActivePackage('autocomplete-plus')
    return unless autocomplete?

    manager = autocomplete.mainModule.activate()
    manager.shouldDisplaySuggestions = true
    manager.findSuggestions(true)
  else
    e.abortKeyBinding()