├── .gitignore ├── LICENSE ├── README.md ├── keymaps └── python-autopep8.cson ├── lib ├── index.coffee └── python-autopep8.coffee ├── menus └── python-autopep8.cson └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | npm-debug.log 2 | node_modules 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Mark Baas 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Atom Python Autopep8 2 | 3 | Uses [autopep8](https://github.com/hhatto/autopep8) installed to format python code according to pep8 guidelines. 4 | 5 | 6 | ### Install 7 | 8 | Make sure to have [autopep8](https://github.com/hhatto/autopep8) installed. Install it by running `pip install autopep8` 9 | -------------------------------------------------------------------------------- /keymaps/python-autopep8.cson: -------------------------------------------------------------------------------- 1 | # For more detailed documentation see 2 | # https://atom.io/docs/latest/advanced/keymaps 3 | 'atom-text-editor[data-grammar="source python"]': 4 | 'ctrl-alt-s': 'python-autopep8:format' 5 | -------------------------------------------------------------------------------- /lib/index.coffee: -------------------------------------------------------------------------------- 1 | PythonAutopep8 = require './python-autopep8' 2 | 3 | module.exports = 4 | config: 5 | autopep8Path: 6 | type: 'string' 7 | default: 'autopep8' 8 | formatOnSave: 9 | type: 'boolean' 10 | default: false 11 | maxLineLength: 12 | type: 'integer' 13 | default: 100 14 | cmdLineOptions: 15 | type: 'array' 16 | default: [] 17 | description: 18 | "Cmd line switches passed to autopep8 delimited by commas 19 | (e.g. '-a, -a, --experimental')" 20 | 21 | activate: -> 22 | pi = new PythonAutopep8() 23 | 24 | atom.commands.add 'atom-workspace', 'pane:active-item-changed', -> 25 | pi.removeStatusbarItem() 26 | 27 | atom.commands.add 'atom-workspace', 'python-autopep8:format', -> 28 | pi.format() 29 | 30 | atom.config.observe 'python-autopep8.formatOnSave', (value) -> 31 | atom.workspace.observeTextEditors (editor) -> 32 | if value == true 33 | editor._autopep8Format = editor.onDidSave -> pi.format() 34 | else 35 | editor._autopep8Format?.dispose() 36 | -------------------------------------------------------------------------------- /lib/python-autopep8.coffee: -------------------------------------------------------------------------------- 1 | $ = require 'jquery' 2 | process = require 'child_process' 3 | 4 | module.exports = 5 | class PythonAutopep8 6 | 7 | checkForPythonContext: -> 8 | editor = atom.workspace.getActiveTextEditor() 9 | if not editor? 10 | return false 11 | grammar = editor.getGrammar().name 12 | return grammar == 'Python' or grammar == 'MagicPython' 13 | 14 | removeStatusbarItem: => 15 | @statusBarTile?.destroy() 16 | @statusBarTile = null 17 | 18 | updateStatusbarText: (message, isError) => 19 | if not @statusBarTile 20 | statusBar = document.querySelector("status-bar") 21 | return unless statusBar? 22 | @statusBarTile = statusBar 23 | .addLeftTile( 24 | item: $('