     catch error
       console.error error
 
+  ###
+  This is a lightly modified version of AutocompleteManager.prefixForCursor
+  which allows autocomplete-bibtex to define its own wordRegex.
+
+  N.B. Setting `allowPrevious` to `false` is absolutely essential in order to
+  make this perform as expected.
+  ###
+  prefixForCursor: (cursor, buffer) =>
+    return '' unless buffer? and cursor?
+    start = cursor.getBeginningOfCurrentWordBufferPosition({ wordRegex: @wordRegex, allowPrevious: false })
+    end = cursor.getBufferPosition()
+    return '' unless start? and end?
+    buffer.getTextInRange([start, end])
+
   prettifyTitle: (title) ->
     if (colon = title.indexOf(':')) isnt -1 and title.words().length > 5
       title = title.substring(0, colon)


module.exports =
class BibtexProvider
  constructor: ->
    @buildWordList(atom.config.get "autocomplete-bibtex.bibtex")
    atom.config.observe "autocomplete-bibtex.bibtex", (bibtexFiles) =>

      blacklist: ''
      providerblacklist: '' # Give the user the option to configure this.
      requestHandler: (options) =>
        prefix = @prefixForCursor(options.cursor, options.buffer)

        return if not prefix.length or prefix[0] is not '@'

        normalizedPrefix = options.prefix.normalize().replace(/^@/, '')

        words = fuzzaldrin.filter @possibleWords, normalizedPrefix, { key: 'author' }

        suggestions = for word in words
          {
            word: @resultTemplate.replace('[key]', word.key)
            prefix: prefix
            label: word.label
            renderLabelAsHtml: false
            className: '',
