         @handleEvents(editor)
 
     @subscriptions.add atom.commands.add 'atom-workspace',
-      'rubocop-auto-correct:current-file': =>
-        if editor = atom.workspace.getActiveTextEditor()
-          @run(editor)
+      'rubocop-auto-correct:current-file': => @run(atom.workspace.getActiveTextEditor())
       'rubocop-auto-correct:toggle-auto-run': => @toggleAutoRun()
       'rubocop-auto-correct:toggle-notification': => @toggleNotification()
       'rubocop-auto-correct:toggle-correct-file': => @toggleCorrectFile()

          ''' }
        )

      rubocop = new BufferedProcess({command, args, stdout, stderr})


  makeTempFile: (filename) ->
    directory = temp.mkdirSync()

    @subscriptions.add(bufferSavedSubscription)
    @subscriptions.add(editorDestroyedSubscription)

  toggleMessage: (messagePrepend, enabled) ->
    "Rubocop Auto Correct: "+ messagePrepend + " " +
      (if enabled then "ON" else "OFF")

  toggleAutoRun: ->
    setting = atom.config.get('rubocop-auto-correct.autoRun')
    atom.config.set('rubocop-auto-correct.autoRun', !setting)
    atom.notifications.addSuccess(@toggleMessage("Auto Run", !setting))

  toggleNotification: ->
    setting = atom.config.get('rubocop-auto-correct.notification')
    atom.config.set('rubocop-auto-correct.notification', !setting)
    atom.notifications.addSuccess(@toggleMessage("Notifications", !setting))

  toggleCorrectFile: ->
    setting = atom.config.get('rubocop-auto-correct.correctFile')
    atom.config.set('rubocop-auto-correct.correctFile', !setting)
    atom.notifications.addSuccess(@toggleMessage("Correct File", !setting))

  toggleDebugMode: ->
    setting = atom.config.get('rubocop-auto-correct.debugMode')
    atom.config.set('rubocop-auto-correct.debugMode', !setting)
    atom.notifications.addSuccess(@toggleMessage("Debug Mode", !setting))

  run: (editor) ->
    if editor
      unless editor.getGrammar().scopeName.match("ruby")
        return atom.notifications.addError("Only use source.ruby")
      if atom.config.get('rubocop-auto-correct.correctFile')
        if editor.isModified()
          editor.save()
        @autoCorrectFile(editor.getPath())
      else
        @autoCorrectBuffer(editor.getBuffer())

  projectRootRubocopConfig: (filePath) ->
    [projectPath, relativePath] = atom.project.relativizePath(filePath)
    projectConfigPath = projectPath + '/.rubocop.yml'
    homeConfigPath = fs.getHomeDirectory() + '/.rubocop.yml'
    if (fs.existsSync(projectConfigPath))
      ['--config', projectConfigPath]
    else if (fs.existsSync(homeConfigPath))
      ['--config', homeConfigPath]
    else
      []

