nitpretty: new option --no-inline
authorJean Privat <jean@pryen.org>
Fri, 24 Apr 2015 14:48:03 +0000 (21:48 +0700)
committerJean Privat <jean@pryen.org>
Mon, 4 May 2015 20:08:12 +0000 (16:08 -0400)
Signed-off-by: Jean Privat <jean@pryen.org>

src/nitpretty.nit
src/pretty.nit

index 71313c8..e86e373 100644 (file)
@@ -35,6 +35,9 @@ redef class ToolContext
        # --line-width
        var opt_line_width = new OptionInt("Maximum length of lines (use 0 to disable automatic line breaks)", 80, "--line-width")
 
+       # --no-inline
+       var opt_no_inline = new OptionBool("Disable automatic one-liners", "--no-inline")
+
        # Break too long string literals.
        var opt_break_str = new OptionBool("Break too long string literals", "--break-strings")
 
@@ -73,6 +76,7 @@ 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_line_width, toolcontext.opt_break_str, toolcontext.opt_inline_do)
+opts.add_option(toolcontext.opt_no_inline)
 opts.add_option(toolcontext.opt_skip_empty)
 
 toolcontext.tooldescription = "Usage: nitpretty [OPTION]... <file.nit>\n" +
@@ -110,6 +114,9 @@ end
 if toolcontext.opt_skip_empty.value then
        v.skip_empty = true
 end
+if toolcontext.opt_no_inline.value then
+       v.no_inline = true
+end
 
 for mmodule in mmodules do
        var nmodule = mbuilder.mmodule2node(mmodule)
index f037479..67b67ca 100644 (file)
@@ -121,6 +121,7 @@ class PrettyPrinterVisitor
        # Is the node inlinable and can fit on the line.
        fun can_inline(n: nullable ANode): Bool do
                if n == null then return true
+               if no_inline and n.location.line_start != n.location.line_end then return false
                if n.must_be_inline then return true
                if n.must_be_block then return false
                # check length
@@ -284,6 +285,9 @@ class PrettyPrinterVisitor
 
        # Do we force the deletion of empty lines?
        var skip_empty = false is public writable
+
+       # Disable automatic inlining.
+       var no_inline = false is writable
 end
 
 # Base framework redefs