diff options
Diffstat (limited to 'Master/texmf-dist/scripts/latexindent/LatexIndent/Arguments.pm')
-rw-r--r-- | Master/texmf-dist/scripts/latexindent/LatexIndent/Arguments.pm | 44 |
1 files changed, 23 insertions, 21 deletions
diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/Arguments.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/Arguments.pm index 9643bf11375..fc6cab0c33a 100644 --- a/Master/texmf-dist/scripts/latexindent/LatexIndent/Arguments.pm +++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/Arguments.pm @@ -18,8 +18,9 @@ use strict; use warnings; use LatexIndent::Tokens qw/%tokens/; use LatexIndent::TrailingComments qw/$trailingCommentRegExp/; -use LatexIndent::Switches qw/$is_t_switch_active $is_tt_switch_active/; +use LatexIndent::Switches qw/$is_m_switch_active $is_t_switch_active $is_tt_switch_active/; use LatexIndent::GetYamlSettings qw/%masterSettings/; +use LatexIndent::LogFile qw/$logger/; use Data::Dumper; use Exporter qw/import/; our @ISA = "LatexIndent::Document"; # class inheritance, Programming Perl, pg 321 @@ -38,14 +39,15 @@ sub construct_arguments_regexp{ sub indent{ my $self = shift; - $self->logger("Arguments object doesn't receive any direct indentation, but its children will...",'heading') if $is_t_switch_active; + ${$self}{body} =~ s/\R$//s if ($is_m_switch_active and ${$self}{IDFollowedImmediatelyByLineBreak}); + $logger->trace("*Arguments object doesn't receive any direct indentation, but its children will...") if $is_t_switch_active; return; } sub find_opt_mand_arguments{ my $self = shift; - $self->logger("Searching ${$self}{name} for optional and mandatory arguments",'heading') if $is_t_switch_active; + $logger->trace("*Searching ${$self}{name} for optional and mandatory arguments") if $is_t_switch_active; # blank line token my $blankLineToken = $tokens{blanklines}; @@ -54,7 +56,7 @@ sub find_opt_mand_arguments{ my $objectDependentOptAndMandRegExp = (defined ${$self}{optAndMandArgsRegExp} ? ${$self}{optAndMandArgsRegExp} : $optAndMandRegExpWithLineBreaks); if(${$self}{body} =~ m/^$objectDependentOptAndMandRegExp\h*($trailingCommentRegExp)?/){ - $self->logger("Optional/Mandatory arguments found in ${$self}{name}: $1",'heading') if $is_t_switch_active; + $logger->trace("Optional/Mandatory arguments".(${$masterSettings{commandCodeBlocks}}{roundParenthesesAllowed}?" (possibly round Parentheses)":q())." found in ${$self}{name}: $1") if $is_t_switch_active; # create a new Arguments object # The arguments object is a little different to most @@ -81,14 +83,14 @@ sub find_opt_mand_arguments{ if(${$arguments}{body} =~ m/.*?((?<!\\)\{|\[)/s){ if($1 eq "\["){ - $self->logger("Searching for optional arguments, and then mandatory (optional found first)") if $is_t_switch_active; + $logger->trace("Searching for optional arguments, and then mandatory (optional found first)") if $is_t_switch_active; # look for optional arguments $arguments->find_optional_arguments; # look for mandatory arguments $arguments->find_mandatory_arguments; } else { - $self->logger("Searching for mandatory arguments, and then optional (mandatory found first)") if $is_t_switch_active; + $logger->trace("Searching for mandatory arguments, and then optional (mandatory found first)") if $is_t_switch_active; # look for mandatory arguments $arguments->find_mandatory_arguments; @@ -97,7 +99,7 @@ sub find_opt_mand_arguments{ } } else { - $self->logger("Searching for round brackets ONLY") if $is_t_switch_active; + $logger->trace("Searching for round brackets ONLY") if $is_t_switch_active; # look for round brackets $arguments->find_round_brackets; } @@ -111,8 +113,8 @@ sub find_opt_mand_arguments{ and ${$self}{body} !~ m/^$blankLineToken/){ my $BodyStringLogFile = ${$self}{aliases}{BodyStartsOnOwnLine}||"BodyStartsOnOwnLine"; my $BeginStringLogFile = ${${${$arguments}{children}}[0]}{aliases}{BeginStartsOnOwnLine}||"BeginStartsOnOwnLine"; - $self->logger("$BodyStringLogFile = 1 (in ${$self}{name}), but first argument should not begin on its own line (see $BeginStringLogFile)") if $is_t_switch_active; - $self->logger("Removing line breaks at the end of ${$self}{begin}") if $is_t_switch_active; + $logger->trace("$BodyStringLogFile = 1 (in ${$self}{name}), but first argument should not begin on its own line (see $BeginStringLogFile)") if $is_t_switch_active; + $logger->trace("Removing line breaks at the end of ${$self}{begin}") if $is_t_switch_active; ${$self}{begin} =~ s/\R*$//s; ${$self}{linebreaksAtEnd}{begin} = 0; } @@ -121,7 +123,7 @@ sub find_opt_mand_arguments{ # situation: preserveBlankLines is active, so the body may well begin with a blank line token # which means that ${$self}{linebreaksAtEnd}{begin} *should be* 1 if(${${${$arguments}{children}}[0]}{body} =~ m/^($blankLineToken)/){ - $self->logger("Updating {linebreaksAtEnd}{begin} for ${$self}{name} as $blankLineToken or blank line found at beginning of argument child") if $is_t_switch_active; + $logger->trace("Updating {linebreaksAtEnd}{begin} for ${$self}{name} as $blankLineToken or blank line found at beginning of argument child") if $is_t_switch_active; ${$self}{linebreaksAtEnd}{begin} = 1 } @@ -140,20 +142,20 @@ sub find_opt_mand_arguments{ my $BodyStringLogFile = ${$self}{aliases}{BodyStartsOnOwnLine}||"BodyStartsOnOwnLine"; my $BeginStringLogFile = ${${${$arguments}{children}}[0]}{aliases}{BeginStartsOnOwnLine}||"BeginStartsOnOwnLine"; my $BodyValue = (defined ${$self}{BodyStartsOnOwnLine}) ? ${$self}{BodyStartsOnOwnLine} : "0"; - $self->logger("$BodyStringLogFile = $BodyValue (in ${$self}{name}), but first argument *should* begin on its own line (see $BeginStringLogFile)") if $is_t_switch_active; + $logger->trace("$BodyStringLogFile = $BodyValue (in ${$self}{name}), but first argument *should* begin on its own line (see $BeginStringLogFile)") if $is_t_switch_active; # possibly add a comment or a blank line, depending on if BeginStartsOnOwnLine == 2 or 3 respectively # at the end of the begin statement my $trailingCharacterToken = q(); if(${${${$arguments}{children}}[0]}{BeginStartsOnOwnLine}==1){ - $self->logger("Adding line breaks at the end of ${$self}{begin} (first argument, see $BeginStringLogFile == ${${${$arguments}{children}}[0]}{BeginStartsOnOwnLine})") if $is_t_switch_active; + $logger->trace("Adding line breaks at the end of ${$self}{begin} (first argument, see $BeginStringLogFile == ${${${$arguments}{children}}[0]}{BeginStartsOnOwnLine})") if $is_t_switch_active; } elsif(${${${$arguments}{children}}[0]}{BeginStartsOnOwnLine}==2){ - $self->logger("Adding a % at the end of begin, ${$self}{begin} followed by a linebreak ($BeginStringLogFile == 2)") if $is_t_switch_active; + $logger->trace("Adding a % at the end of begin, ${$self}{begin} followed by a linebreak ($BeginStringLogFile == 2)") if $is_t_switch_active; $trailingCharacterToken = "%".$self->add_comment_symbol; - $self->logger("Removing trailing space on ${$self}{begin}") if $is_t_switch_active; + $logger->trace("Removing trailing space on ${$self}{begin}") if $is_t_switch_active; ${$self}{begin} =~ s/\h*$//s; } elsif (${${${$arguments}{children}}[0]}{BeginStartsOnOwnLine}==3) { - $self->logger("Adding a blank line immediately ${$self}{begin} ($BeginStringLogFile==3)") if $is_t_switch_active; + $logger->trace("Adding a blank line immediately ${$self}{begin} ($BeginStringLogFile==3)") if $is_t_switch_active; $trailingCharacterToken = "\n".(${$masterSettings{modifyLineBreaks}}{preserveBlankLines}?$tokens{blanklines}:q()); } @@ -168,7 +170,7 @@ sub find_opt_mand_arguments{ # children need to receive ancestor information, see test-cases/commands/commands-triple-nested.tex foreach (@{${$arguments}{children}}){ - $self->logger("Updating argument children of ${$self}{name} to include ${$self}{id} in ancestors") if $is_t_switch_active; + $logger->trace("Updating argument child of ${$self}{name} to include ${$self}{id} in ancestors") if $is_t_switch_active; push(@{${$_}{ancestors}},{ancestorID=>${$self}{id},ancestorIndentation=>${$self}{indentation},type=>"natural"}); } @@ -176,7 +178,7 @@ sub find_opt_mand_arguments{ # did not add one at the end, and if BodyStartsOnOwnLine >= 1 if( (defined ${${${$arguments}{children}}[-1]}{EndFinishesWithLineBreak} and ${${${$arguments}{children}}[-1]}{EndFinishesWithLineBreak}<1) and (defined ${$self}{BodyStartsOnOwnLine} and ${$self}{BodyStartsOnOwnLine}>=1) ){ - $self->logger("Updating replacementtext to include a linebreak for arguments in ${$self}{name}") if $is_t_switch_active; + $logger->trace("Updating replacementtext to include a linebreak for arguments in ${$self}{name}") if $is_t_switch_active; ${$arguments}{replacementText} .= "\n" if(${$arguments}{linebreaksAtEnd}{end}); } @@ -189,10 +191,10 @@ sub find_opt_mand_arguments{ # delete the regexp, as there's no need for it delete ${${${$self}{children}}[-1]}{regexp}; - $self->logger(Dumper(\%{$arguments}),'ttrace') if($is_tt_switch_active); - $self->logger("replaced with ID: ${$arguments}{id}") if $is_t_switch_active; + $logger->trace(Dumper(\%{$arguments})) if($is_tt_switch_active); + $logger->trace("replaced with ID: ${$arguments}{id}") if $is_tt_switch_active; } else { - $self->logger("... no arguments found") if $is_t_switch_active; + $logger->trace("... no arguments found") if $is_t_switch_active; } } @@ -247,7 +249,7 @@ sub get_arguments_regexp{ } # report to log file - $self->logger("Strings allowed between arguments $stringsBetweenArguments (see stringsAllowedBetweenArguments)",'heading') if $is_t_switch_active; + $logger->trace("*Strings allowed between arguments: $stringsBetweenArguments (see stringsAllowedBetweenArguments)") if $is_t_switch_active; } if(defined ${input}{roundBrackets} and ${input}{roundBrackets}==1){ |