diff options
Diffstat (limited to 'support/latexindent/LatexIndent/Environment.pm')
-rw-r--r-- | support/latexindent/LatexIndent/Environment.pm | 47 |
1 files changed, 25 insertions, 22 deletions
diff --git a/support/latexindent/LatexIndent/Environment.pm b/support/latexindent/LatexIndent/Environment.pm index 0f51dfec56..9cb9850d2b 100644 --- a/support/latexindent/LatexIndent/Environment.pm +++ b/support/latexindent/LatexIndent/Environment.pm @@ -1,4 +1,5 @@ package LatexIndent::Environment; + # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or @@ -26,17 +27,17 @@ use LatexIndent::IfElseFi qw/$ifElseFiBasicRegExp/; use LatexIndent::Heading qw/$allHeadingsRegexp/; use LatexIndent::Special qw/$specialBeginAndBracesBracketsBasicRegExp/; use Exporter qw/import/; -our @ISA = "LatexIndent::Document"; # class inheritance, Programming Perl, pg 321 +our @ISA = "LatexIndent::Document"; # class inheritance, Programming Perl, pg 321 our @EXPORT_OK = qw/find_environments $environmentBasicRegExp construct_environments_regexp/; our $environmentCounter; our $environmentBasicRegExp = qr/\\begin\{/; our $environmentRegExp; # store the regular expresssion for matching and replacing the \begin{}...\end{} statements -sub construct_environments_regexp{ - +sub construct_environments_regexp { + # read from fine tuning - my $environmentNameRegExp = qr/${${$mainSettings{fineTuning}}{environments}}{name}/; + my $environmentNameRegExp = qr/${${$mainSettings{fineTuning}}{environments}}{name}/; $environmentRegExp = qr/ ( \\begin\{ @@ -63,14 +64,13 @@ sub construct_environments_regexp{ /sx; } -sub find_environments{ +sub find_environments { my $self = shift; + while ( ${$self}{body} =~ m/$environmentRegExp\h*($trailingCommentRegExp)?/ ) { - while( ${$self}{body} =~ m/$environmentRegExp\h*($trailingCommentRegExp)?/){ - - # global substitution - ${$self}{body} =~ s/ + # global substitution + ${$self}{body} =~ s/ $environmentRegExp(\h*)($trailingCommentRegExp)? / # create a new Environment object @@ -95,36 +95,40 @@ sub find_environments{ $self->get_settings_and_store_new_object($env); ${@{${$self}{children}}[-1]}{replacementText}.($9?$9:q()).($10?$10:q()); /xseg; - $self->adjust_line_breaks_end_parent if $is_m_switch_active; - } + $self->adjust_line_breaks_end_parent if $is_m_switch_active; + } return; } -sub tasks_particular_to_each_object{ +sub tasks_particular_to_each_object { my $self = shift; # if the environment is empty, we may need to update linebreaksAtEnd{body} - if(${$self}{body} =~ m/^\h*$/s and ${${$self}{linebreaksAtEnd}}{begin}){ - $logger->trace("empty environment body (${$self}{name}), updating linebreaksAtEnd{body} to be 1") if($is_t_switch_active); - ${${$self}{linebreaksAtEnd}}{body} = 1; + if ( ${$self}{body} =~ m/^\h*$/s and ${ ${$self}{linebreaksAtEnd} }{begin} ) { + $logger->trace("empty environment body (${$self}{name}), updating linebreaksAtEnd{body} to be 1") + if ($is_t_switch_active); + ${ ${$self}{linebreaksAtEnd} }{body} = 1; } # lookForAlignDelims: lookForChildCodeBlocks set to 0 means no child objects searched for # see: test-cases/alignment/issue-308.tex # - if( defined ${$self}{lookForChildCodeBlocks} and !${$self}{lookForChildCodeBlocks} ){ - $logger->trace("lookForAlignDelims: lookForChildCodeBlocks set to 0, so child objects will *NOT* be searched for") if($is_t_switch_active); - return; + if ( defined ${$self}{lookForChildCodeBlocks} and !${$self}{lookForChildCodeBlocks} ) { + $logger->trace( + "lookForAlignDelims: lookForChildCodeBlocks set to 0, so child objects will *NOT* be searched for") + if ($is_t_switch_active); + return; } # search for items as the first order of business - $self->find_items if ${$mainSettings{indentAfterItems}}{${$self}{name}}; + $self->find_items if ${ $mainSettings{indentAfterItems} }{ ${$self}{name} }; # search for headings (important to do this before looking for commands!) $self->find_heading if ${$self}{body} =~ m/$allHeadingsRegexp/s; # search for commands and special code blocks - $self->find_commands_or_key_equals_values_braces_and_special if ${$self}{body} =~ m/$specialBeginAndBracesBracketsBasicRegExp/s; + $self->find_commands_or_key_equals_values_braces_and_special + if ${$self}{body} =~ m/$specialBeginAndBracesBracketsBasicRegExp/s; # search for arguments $self->find_opt_mand_arguments if ${$self}{body} =~ m/$braceBracketRegExpBasic/s; @@ -134,7 +138,7 @@ sub tasks_particular_to_each_object{ } -sub create_unique_id{ +sub create_unique_id { my $self = shift; $environmentCounter++; @@ -142,5 +146,4 @@ sub create_unique_id{ return; } - 1; |