Closes #91. Add configuration option for custom Uncrustify path

This commit is contained in:
Glavin Wiechert 2014-09-15 00:04:28 -03:00
parent 0f51d0e124
commit fefb25bf38
5 changed files with 57 additions and 54 deletions

View File

@ -120,7 +120,7 @@ getConfigOptionsFromSettings = (langs) ->
opt = k.replace(new RegExp("^" + lang + "_"), "")
options[lang] = options[lang] or {}
options[lang][opt] = config[k]
# console.log(lang, opt);
# console.log(lang, opt);
true
# console.log(options);
options

View File

@ -4,6 +4,7 @@ Requires http://pear.php.net/package/PHP_Beautifier
"use strict"
fs = require("fs")
temp = require("temp").track()
possibleOptions = require "./possible-options.json"
module.exports = (options, cb) ->
text = ""
@ -35,20 +36,24 @@ module.exports = (options, cb) ->
# jshint ignore: end
# Remove misc
delete options.languageOverride
delete options.configPath
# Iterate over each property and write to configuration file
for k of options
v = options[k]
vs = v
if typeof vs is "boolean"
if vs is true
vs = "True"
else
vs = "False"
text += k + " = " + vs + "\n"
# Remove all non-possible options
isPossible = possibleOptions.indexOf(k) isnt -1
if isPossible
v = options[k]
vs = v
if typeof vs is "boolean"
if vs is true
vs = "True"
else
vs = "False"
text += k + " = " + vs + "\n"
else
# console.log("removing #{k} option")
delete options[k]
# Create temp input file
temp.open

View File

@ -1,45 +1,38 @@
###
Requires http://pear.php.net/package/PHP_Beautifier
Requires http://uncrustify.sourceforge.net/
###
getCmd = (inputPath, outputPath, options, cb) ->
# console.log('Uncrustify options:', options);
done = (configPath) ->
# console.log(configPath);
if pathToCommand
# Use path given by user
cmd = pathToCommand + " -c \"" + configPath + "\" -f \"" + inputPath + "\" -o \"" + outputPath + "\" -l \"" + lang + "\""
else
# Use command available in $PATH
cmd = "uncrustify -c \"" + configPath + "\" -f \"" + inputPath + "\" -o \"" + outputPath + "\" -l \"" + lang + "\""
# console.log(cmd);
cb cmd
configPath = options.configPath
lang = options.languageOverride or "C"
pathToCommand = atom.config.get("atom-beautify.uncrustifyPath")
# console.log(pathToCommand)
unless configPath
# No custom config path
cfg options, (error, path) ->
throw error if error
done path
else
# Has custom config path
editor = atom.workspace.getActiveEditor()
basePath = path.dirname(editor.getPath())
# console.log(basePath);
configPath = path.resolve(basePath, configPath)
done configPath
return
"use strict"
cliBeautify = require("../cli-beautify")
cfg = require("./cfg")
path = require("path")
getCmd = (inputPath, outputPath, options, cb) ->
uncrustifyPath = options.uncrustifyPath
# console.log('Uncrustify options:', options);
# console.log("Uncrustify path: #{uncrustifyPath}")
# Complete callback
done = (configPath) ->
# console.log(configPath);
if uncrustifyPath
# Use path given by user
cmd = "#{uncrustifyPath} -c \"#{configPath}\" -f \"#{inputPath}\" -o \"#{outputPath}\" -l \"#{lang}\""
else
# Use command available in $PATH
cmd = "uncrustify -c \"#{configPath}\" -f \"#{inputPath}\" -o \"#{outputPath}\" -l \"#{lang}\""
# console.log(cmd);
cb cmd
configPath = options.configPath
lang = options.languageOverride or "C" # Default is C
unless configPath
# No custom config path
cfg options, (error, cPath) ->
throw error if error
done cPath
else
# Has custom config path
editor = atom.workspace.getActiveEditor()
basePath = path.dirname(editor.getPath())
# console.log(basePath);
configPath = path.resolve(basePath, configPath)
done configPath
return
module.exports = cliBeautify(getCmd)

File diff suppressed because one or more lines are too long

View File

@ -100,33 +100,37 @@ module.exports =
ruby_rbeautify_path: ""
# C
c_uncrustifyPath: ""
c_configPath: ""
# C++
cpp_uncrustifyPath: ""
cpp_configPath: ""
# Objective-C
objectivec_uncrustifyPath: ""
objectivec_configPath: ""
# C#
cs_uncrustifyPath: ""
cs_configPath: ""
# Objective-C
# D
d_uncrustifyPath: ""
d_configPath: ""
# Java
java_uncrustifyPath: ""
java_configPath: ""
# Pawn
pawn_uncrustifyPath: ""
pawn_configPath: ""
# VALA
vala_uncrustifyPath: ""
vala_configPath: ""
# Uncrustify
uncrustifyPath: ""
# jshint ignore: end
# Process each language