From: Steve Hancock Date: Wed, 2 Sep 2020 18:08:37 +0000 (-0700) Subject: changed new -nib feature to be on by default X-Git-Tag: 20200907~15 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=853be30f39ab33d802a86dce09aead17b68e723e;p=perltidy.git changed new -nib feature to be on by default --- diff --git a/CHANGES.md b/CHANGES.md index 2d49007c..ed03c49d 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,10 +1,20 @@ # Perltidy Change Log - Added parameter --non-indenting-braces, or -nib, which prevents - code following an opening brace marked with a special side comment - from indenting one level. This is off by default and turned on - with -nib. It might be useful for preventing code from shifting - when adding or testing closures, for example. + code which follows an opening brace marked with a special side comment, + '#<<<', from indenting one level. For example, + + { #<<< a closure to contain lexical vars + + my $var; # this line does not indent + + } + + # this line cannot 'see' $var; + + This is on by default. If your code happens to have some + opening braces followed by '#<<<', and you + don't want this, you can use -nnib to deactivate it. - Side comment locations reset at a line ending in a level 0 open block, such as when a new multi-line sub begins. This is intended to diff --git a/bin/perltidy b/bin/perltidy index 755ce6a4..39aed2d5 100755 --- a/bin/perltidy +++ b/bin/perltidy @@ -850,22 +850,39 @@ The default is not to do this, indicated by B<-nicb>. =item B<-nib>, B<--non-indenting-braces> -If this flag is set, perltidy will look for opening block braces which are -followed by a special side comment, which is B<#<<<> by default. If found, the -code between this opening brace and its corresponding closing brace will not be -given the normal extra indentation level. As a simple example, +Normally, lines of code contained within a pair of block braces receive one +extra level of indentation. If this flag is set, perltidy will look for +opening block braces which are followed by a special side comment, which is +B<#<<<> by default. If found, the code between this opening brace and its +corresponding closing brace will not be given the normal extra indentation +level. For example: - perltidy -nib: + { #<<< a closure to contain lexical vars - { #<<< - print "hello world\n"; - } + my $var; # this line does not get one level of indentation + ... + + } + + # this line cannot 'see' $var; + +This can be useful, for example, when combining code from different files. +Different sections of code can be placed within braces to keep their lexical +variables from being visible to the end of the file. To keep the new blocks +from causing all of their contained code to be reformatted if you run perltidy, +you can mark the opening braces with this special side comment. + +Only the opening brace needs to be marked, since perltidy knows where the +closing brace is. -This might be useful, for example, to keep large sections of code from -moving to the right when placed in a closure. +This feature is on by default. If your code happens to have some opening +braces followed by '#<<<', and you don't want this, you can use B<-nnib> to +deactivate it. To make it easy to remember, the default string is the same as +the string for starting a B section. There is no confusion +because in that case it is for a block comment rather than a side-comment. -Only the opening brace needs to be marked, and nested braces can be marked. -The special side comment can be changed with the next parameter. +The special side comment can be changed with the next +parameter. =item B<-nibp=s>, B<--non-indenting-brace-prefix=s> @@ -882,9 +899,6 @@ For example, to match the side comment '#++', the parameter would be -nibp='#\+\+' -Note that the default string is the same as the string for starting a -B section, but in that case it is for a block comment -rather than a side-comment. =item B<-olq>, B<--outdent-long-quotes> diff --git a/lib/Perl/Tidy.pm b/lib/Perl/Tidy.pm index 1fa035c0..9c30a8ad 100644 --- a/lib/Perl/Tidy.pm +++ b/lib/Perl/Tidy.pm @@ -2462,10 +2462,10 @@ sub generate_options { nodelete-old-whitespace nohtml nologfile + non-indenting-braces noquiet noshow-options nostatic-side-comments - nonon-indenting-braces notabs nowarning-output one-line-block-semicolons=1 diff --git a/t/snippets/expect/nib.def b/t/snippets/expect/nib.def index dd67a28d..4499f503 100644 --- a/t/snippets/expect/nib.def +++ b/t/snippets/expect/nib.def @@ -1,15 +1,15 @@ { #<<< - { #<<< - { #++ - print "hello world\n"; - } - } +{ #<<< +{ #++ + print "hello world\n"; +} +} } { #++ { #++ { #<<< - print "hello world\n"; + print "hello world\n"; } } } diff --git a/t/snippets/expect/nib.nib1 b/t/snippets/expect/nib.nib1 index 4499f503..dd67a28d 100644 --- a/t/snippets/expect/nib.nib1 +++ b/t/snippets/expect/nib.nib1 @@ -1,15 +1,15 @@ { #<<< -{ #<<< -{ #++ - print "hello world\n"; -} -} + { #<<< + { #++ + print "hello world\n"; + } + } } { #++ { #++ { #<<< - print "hello world\n"; + print "hello world\n"; } } } diff --git a/t/snippets/nib1.par b/t/snippets/nib1.par index b79e8ce6..ed6da7bd 100644 --- a/t/snippets/nib1.par +++ b/t/snippets/nib1.par @@ -1 +1 @@ --nib +-nnib diff --git a/t/snippets/packing_list.txt b/t/snippets/packing_list.txt index 38992371..756bbebb 100644 --- a/t/snippets/packing_list.txt +++ b/t/snippets/packing_list.txt @@ -264,6 +264,9 @@ ../snippets21.t git33.git33 ../snippets21.t rt133130.def ../snippets21.t rt133130.rt133130 +../snippets21.t nib.def +../snippets21.t nib.nib1 +../snippets21.t nib.nib2 ../snippets3.t ce_wn1.ce_wn ../snippets3.t ce_wn1.def ../snippets3.t colin.colin @@ -404,6 +407,3 @@ ../snippets9.t rt98902.def ../snippets9.t rt98902.rt98902 ../snippets9.t rt99961.def -../snippets21.t nib.def -../snippets21.t nib.nib1 -../snippets21.t nib.nib2 diff --git a/t/snippets21.t b/t/snippets21.t index b9436b9a..22033a55 100644 --- a/t/snippets21.t +++ b/t/snippets21.t @@ -41,7 +41,7 @@ BEGIN { ---------- 'gnu' => "-gnu", 'lop' => "-nlop", - 'nib1' => "-nib", + 'nib1' => "-nnib", 'nib2' => <<'----------', -nib -nibp='#\+\+' ---------- @@ -591,17 +591,17 @@ method sum_radlinks { params => "def", expect => <<'#14...........', { #<<< - { #<<< - { #++ - print "hello world\n"; - } - } +{ #<<< +{ #++ + print "hello world\n"; +} +} } { #++ { #++ { #<<< - print "hello world\n"; + print "hello world\n"; } } } @@ -614,17 +614,17 @@ method sum_radlinks { params => "nib1", expect => <<'#15...........', { #<<< -{ #<<< -{ #++ - print "hello world\n"; -} -} + { #<<< + { #++ + print "hello world\n"; + } + } } { #++ { #++ { #<<< - print "hello world\n"; + print "hello world\n"; } } }