-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathpython-autopep8.coffee
More file actions
61 lines (50 loc) · 1.81 KB
/
python-autopep8.coffee
File metadata and controls
61 lines (50 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
$ = require 'jquery'
process = require 'child_process'
module.exports =
class PythonAutopep8
checkForPythonContext: ->
editor = atom.workspace.getActiveTextEditor()
if not editor?
return false
grammarNames = atom.config.get "python-autopep8.grammars"
grammarName = editor.getGrammar().name
return grammarName in grammarNames
removeStatusbarItem: =>
@statusBarTile?.destroy()
@statusBarTile = null
updateStatusbarText: (message, isError) =>
if not @statusBarTile
statusBar = document.querySelector("status-bar")
return unless statusBar?
@statusBarTile = statusBar
.addLeftTile(
item: $('<div id="status-bar-python-autopep8" class="inline-block">
<span style="font-weight: bold">Autopep8: </span>
<span id="python-autopep8-status-message"></span>
</div>'), priority: 100)
statusBarElement = @statusBarTile.getItem()
.find('#python-autopep8-status-message')
if isError == true
statusBarElement.addClass("text-error")
else
statusBarElement.removeClass("text-error")
statusBarElement.text(message)
getFilePath: ->
editor = atom.workspace.getActiveTextEditor()
return editor.getPath()
format: ->
if not @checkForPythonContext()
@updateStatusbarText("x", true)
return
cmd = atom.config.get "python-autopep8.autopep8Path"
maxLineLength = atom.config.get "python-autopep8.maxLineLength"
cmdLineOptions = atom.config.get "python-autopep8.cmdLineOptions"
params = cmdLineOptions.concat [
"--max-line-length", maxLineLength, "-i", @getFilePath()
]
returnCode = process.spawnSync(cmd, params).status
if returnCode != 0
@updateStatusbarText("x", true)
else
@updateStatusbarText("√", false)
@reload