var opt_meld = new OptionBool("Show diff between source and output using meld",
"--meld")
+ # --line-width
+ var opt_line_width = new OptionInt("Maximum length of lines (use 0 to disable automatic line breaks)", 80, "--line-width")
+
# Break too long string literals.
var opt_break_str = new OptionBool("Break too long string literals", "--break-strings")
var opts = toolcontext.option_context
opts.add_option(toolcontext.opt_dir, toolcontext.opt_output)
opts.add_option(toolcontext.opt_diff, toolcontext.opt_meld, toolcontext.opt_check)
-opts.add_option(toolcontext.opt_break_str, toolcontext.opt_inline_do)
+opts.add_option(toolcontext.opt_line_width, toolcontext.opt_break_str, toolcontext.opt_inline_do)
opts.add_option(toolcontext.opt_skip_empty)
toolcontext.tooldescription = "Usage: nitpretty [OPTION]... <file.nit>\n" +
if not dir.file_exists then dir.mkdir
var v = new PrettyPrinterVisitor
+v.max_size = toolcontext.opt_line_width.value
if toolcontext.opt_break_str.value then
v.break_strings = true
end
if n.must_be_inline then return true
if n.must_be_block then return false
# check length
- if n.collect_length + current_length > max_size then return false
+ if max_size > 0 and n.collect_length + current_length > max_size then return false
# check block is inlinable
return n.is_inlinable
end
var tab_size = 8
# Max line size.
- var max_size = 80
+ # 0 (or negative) to disable.
+ var max_size = 80 is writable
# Length of the current line.
var current_length = 0
while i < text.length do
v.add text[i].to_s
- if v.current_length >= v.max_size and i <= text.length - 3 then
+ if v.max_size > 0 and v.current_length >= v.max_size and i <= text.length - 3 then
v.add "\" +"
if was_inline then
v.forcen