From 5c9674880206f66c109adc1bedf8f786166f125f Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Tue, 15 Jan 2019 17:48:14 -0800 Subject: Fix for formatting indented code with the format tool. --- lib/tools/format.nom | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'lib/tools') diff --git a/lib/tools/format.nom b/lib/tools/format.nom index eee1316..c2e6a1c 100755 --- a/lib/tools/format.nom +++ b/lib/tools/format.nom @@ -24,19 +24,19 @@ command line program with $args: $file = (read file $filename) unless $file: fail "File does not exist: \$filename" - $leading_indent = ($file, matching "\n*([ ]*)") + $leading_indent = ($file, matching "^\n*([ ]*)") $code = (NomsuCode from ($Source $filename 1 (size of $file)) $file) try: $tree = ($code parsed) ..if it fails with $msg: + $tree = (nil) if $args.q: $formatted = $file ..else: say $msg - if ($tree and (not $formatted)): - $formatted = - "\$leading_indent\($tree as nomsu, text, with "\n" -> "\n\$leading_indent")" + if $tree: + $formatted = ($tree as nomsu, text, indented $leading_indent) if $formatted: if $args.i: -- cgit v1.2.3