Skip to content

Commit

Permalink
Merge pull request #38 from Glavin001/master
Browse files Browse the repository at this point in the history
Closes #35. Add more options for Python PEP8 beautifying.
  • Loading branch information
karolyi committed Jun 28, 2014
2 parents f7c7fc7 + 65ff7f9 commit e461a67
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 7 deletions.
5 changes: 5 additions & 0 deletions examples/nested-jsbeautifyrc/.jsbeautifyrc
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,8 @@
indent_char: " "
indent_level: 0
indent_with_tabs: false
python:
indent_size: 4
#max_line_length: 79
#ignore:
# - "E24"
File renamed without changes.
8 changes: 4 additions & 4 deletions lib/atom-beautify.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var strip = require('strip-json-comments');
var yaml = require('js-yaml');
// Language options
var beautifier = require('./language-options');
var languages = beautifier.langauges;
var languages = beautifier.languages;
var defaultLanguageOptions = beautifier.defaultLanguageOptions;

// TODO: Copied from jsbeautify, please update it from time to time
Expand Down Expand Up @@ -156,21 +156,21 @@ function findConfig(config, file) {
function getConfigOptionsFromSettings(langs) {
var config = atom.config.getSettings()['atom-beautify'];
var options = {};
// console.log(langs, config);
console.log(langs, config);

// Iterate over keys of the settings
_.every(_.keys(config), function (k) {
// Check if keys start with a language
var p = k.split('_')[0];
var idx = _.indexOf(langs, p);
// console.log(k, p, idx);
console.log(k, p, idx);
if (idx >= 0) {
// Remove the language prefix and nest in options
var lang = langs[idx];
var opt = k.replace(new RegExp('^' + lang + '_'), '');
options[lang] = options[lang] || {};
options[lang][opt] = config[k];
// console.log(lang, opt);
console.log(lang, opt);
}
return true;
});
Expand Down
7 changes: 5 additions & 2 deletions lib/langs/python-beautify.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@ var cliBeautify = require('./cli-beautify');

function getCmd(inputPath, outputPath, options) {
var path = options.autopep8_path; // jshint ignore: line
var optionsStr = '--max-line-length ' + options.max_line_length + // jshint ignore: line
' --indent-size ' + options.indent_size // jshint ignore: line
+ ' --ignore ' + options.ignore.join(','); // jshint ignore: line
if (path) {
// Use absolute path
return 'python "' + path + '" "' + inputPath + '"';
return 'python "' + path + '" "' + inputPath + '" ' + optionsStr;
} else {
// Use command available in $PATH
return 'autopep8 "' + inputPath + '"';
return 'autopep8 "' + inputPath + '" ' + optionsStr;
}
}
var isStdout = true;
Expand Down
5 changes: 4 additions & 1 deletion lib/language-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ module.exports = {
php_beautifier_path: '',
// Python
python_autopep8_path: '',
python_max_line_length: 79,
python_indent_size: 4,
python_ignore: ['E24'],
// Ruby
ruby_rbeautify_path: ''
/* jshint ignore: end */
Expand Down Expand Up @@ -156,4 +159,4 @@ module.exports = {

return options;
}
}
};

0 comments on commit e461a67

Please sign in to comment.