 
     if atom.config.get('fold-functions.autofold')
       atom.workspace.observeTextEditors (editor) =>
-        editor.displayBuffer.tokenizedBuffer.onDidTokenize => @autofold(editor)
+        # editor.displayBuffer.tokenizedBuffer.onDidTokenize => @autofold(editor)
+        editor.tokenizedBuffer.onDidTokenize => @autofold(editor)
+        # editor.onDidChangeGrammar => @autofold(editor)
 
   deactivate: ->
     @subscriptions.dispose()
 
   autofold: (editor) ->
+    @debugMessage('fold functions: autofold')
     if not editor
       editor = atom.workspace.getActiveTextEditor()
 
     # just in case there really is not an editor, don't try to autofold...
     if not editor
+      @debugMessage('fold functions: no editor, not autofolding...')
       return false
 
     grammar = editor.getGrammar()

    editor = atom.workspace.getActiveTextEditor()
    position = editor.getCursorBufferPosition()
    scopes = @getScopesForBufferRow(editor, position.row)
    atom.clipboard.write(list.join(', '))
    list = scopes.map (item) -> "* #{item}"
    content = "Scopes at Row\n#{list.join('\n')}"
    atom.notifications.addInfo(content, dismissable: true)


    # the grammar is not white listed (and there are things whitelisted)
    autofoldGrammars = atom.config.get('fold-functions.autofoldGrammars')
    if autofoldGrammars and autofoldGrammars.length > 0 and grammar.name not in autofoldGrammars
      @debugMessage('fold functions: autofold grammar not whitelisted', grammar.name)
      return false

    # the grammar is not in the ignore grammar list
    autofoldIgnoreGrammars = atom.config.get('fold-functions.autofoldIgnoreGrammars')
    if autofoldIgnoreGrammars and autofoldIgnoreGrammars.length > 0 and grammar.name in autofoldIgnoreGrammars
      @debugMessage('fold functions: autofold ignored grammar', grammar.name)
      return false

    # check if the file is too short to run
    if shortfileCutoff = atom.config.get('fold-functions.shortfileCutoff', 42)
      # make sure the file is longer than the cutoff before folding
      if (shortfileCutoff > 0 and editor.getLineCount() >= shortfileCutoff)
        @debugMessage('fold functions: autofold turned on')
        autofold = true
    # if shortfileCutoff = 0/false/-1 then we should still turn on autofolding
    else
      @debugMessage('fold functions: autofold turned on')
      autofold = true

    # figure out if we should skip autofolding because we are not on the first
    # line of the file.
