         'storage.type.arrow',
         'entity.name.function.constructor'
       )
-      @debugMessage('fold functions: is foldable', (foldable and isFunction and not isCommented), 'foldable', foldable, 'isFunction', isFunction, 'isCommented', isCommented)
+      @debugMessage 'fold functions: is foldable',
+        lines,
+        (foldable and isFunction and not isCommented),
+        'foldable', foldable,
+        'isFunction', isFunction,
+        'isCommented', isCommented
       if isFunction and not (foldable and isFunction and not isCommented)
-        @debugMessage('fold functions: line is a function, but cannot be folded', foldable, isCommented)
-      if foldable and isFunction and not isCommented
+        @debugMessage 'fold functions: line is a function, but cannot be folded', foldable, isCommented
+      else if isFunction and foldable and not isCommented
+        @debugMessage '?'
         foldableLines++
         if @indentLevel == null
           @indentLevel = thisIndentLevel
+          @debugMessage 'fold functions: indentLevel set at', @indentLevel
         if action == 'toggle'
-          editor.toggleFoldAtBufferRow(row)
+          editor.toggleFoldAtBufferRow row
           toggle++
         else if action == 'unfold' and isFolded
-          editor.unfoldBufferRow(row)
+          editor.unfoldBufferRow row
           unfold++
-        else if !editor.isFoldedAtBufferRow(row)
-          editor.foldBufferRow(row)
+        else if !editor.isFoldedAtBufferRow row
+          editor.foldBufferRow row
           fold++
     @debugMessage('fold functions: done scanning ' + lines + ' lines (' + fold + ':' + unfold + ':' + toggle + ')')
     @debugMessage('foldable lines: ' + foldableLines)
+    @debugMessage('indentLevel: ' + @indentLevel)
 
   toggle: ->
     @fold('toggle')

      editor = atom.workspace.getActiveTextEditor()

    if not editor
      @debugMessage('fold functions: ’no editor, skipping')
      return

    @debugMessage('fold functions: action=', action)
    @indentLevel = @indentLevel || null

  getScopesForBufferRow: (editor, row) ->
    scopes = []
    text = editor.lineTextForBufferRow(row).trim()
    if text and text.length > 0
      # scan the text line to see if there is a function somewhere
      for pos in [0..text.length]
        positionScopes = editor.scopeDescriptorForBufferPosition([row, pos])
