diff --git a/keymaps/python-isort.cson b/keymaps/python-isort.cson index 6b03ad7..30a09c5 100644 --- a/keymaps/python-isort.cson +++ b/keymaps/python-isort.cson @@ -1,4 +1,4 @@ # For more detailed documentation see # https://atom.io/docs/latest/advanced/keymaps -'.editor.python': - 'ctrl-alt-s': 'python-isort:sortImports' +'atom-text-editor[data-grammar="source python"]': + 'ctrl-alt-s': 'python-isort:sortImports' diff --git a/lib/index.coffee b/lib/index.coffee index 9df09e3..4d0b5ae 100644 --- a/lib/index.coffee +++ b/lib/index.coffee @@ -2,36 +2,32 @@ PythonIsort = require './python-isort' module.exports = configDefaults: - isortPath: "/usr/bin/isort" + isortPath: "isort" sortOnSave: false checkOnSave: true - activate: (state) -> + activate: -> pi = new PythonIsort() - atom.workspaceView.command 'pane:active-item-changed', -> + atom.commands.add 'atom-workspace', 'pane:active-item-changed', -> pi.removeStatusbarItem() - atom.workspaceView.command 'python-isort:sortImports', -> + atom.commands.add 'atom-workspace', 'python-isort:sortImports', -> pi.sortImports() - atom.workspaceView.command 'python-isort:checkImports', -> + atom.commands.add 'atom-workspace', 'python-isort:checkImports', -> pi.checkImports() - atom.config.observe 'python-isort.sortOnSave', {callNow: true}, (value) -> - atom.workspace.eachEditor (editor) -> + atom.config.observe 'python-isort.sortOnSave', (value) -> + atom.workspace.observeTextEditors (editor) -> if value == true - editor.buffer.on "saved", -> - pi.sortImports() + editor._isortSort = editor.onDidSave -> pi.sortImports() else - editor.buffer.off "saved", -> - pi.sortImports() + editor._isortSort?.dispose() - atom.config.observe 'python-isort.checkOnSave', {callNow: true}, (value) -> - atom.workspace.eachEditor (editor) -> + atom.config.observe 'python-isort.checkOnSave', (value) -> + atom.workspace.observeTextEditors (editor) -> if value == true - editor.buffer.on "saved", -> - pi.checkForUnsortedImports() + editor._isortCheck = editor.onDidSave -> pi.checkImports() else - editor.buffer.off "saved", -> - pi.checkForUnsortedImports() + editor._isortCheck?.dispose() diff --git a/lib/python-isort.coffee b/lib/python-isort.coffee index 9c7293d..166709d 100644 --- a/lib/python-isort.coffee +++ b/lib/python-isort.coffee @@ -1,5 +1,5 @@ fs = require 'fs' -jquery = require('atom').$ +$ = require('atom').$ process = require 'child_process' module.exports = @@ -11,20 +11,23 @@ class PythonIsort return false return editor.getGrammar().name == 'Python' - removeStatusbarItem: -> - if not @checkForPythonContext() - jquery("#python-isort-status").remove() + removeStatusbarItem: => + @statusBarTile?.destroy() + @statusBarTile = null - updateStatusbarText: (message, isError) -> - if jquery("#python-isort-status").length == 0 - statusBar = atom.workspaceView.statusBar + updateStatusbarText: (message, isError) => + if not @statusBarTile + statusBar = document.querySelector("status-bar") return unless statusBar? - statusBar.appendLeft('