diff options
Diffstat (limited to 'Master/texmf-dist/scripts/latexindent/LatexIndent')
31 files changed, 992 insertions, 584 deletions
diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/AlignmentAtAmpersand.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/AlignmentAtAmpersand.pm index 14f141b060c..50fe2410141 100644 --- a/Master/texmf-dist/scripts/latexindent/LatexIndent/AlignmentAtAmpersand.pm +++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/AlignmentAtAmpersand.pm @@ -20,10 +20,12 @@ use utf8; use Unicode::GCString; use Data::Dumper; use Exporter qw/import/; +use List::Util qw(max); use LatexIndent::TrailingComments qw/$trailingCommentRegExp/; use LatexIndent::Switches qw/$is_t_switch_active $is_tt_switch_active/; use LatexIndent::GetYamlSettings qw/%masterSettings/; use LatexIndent::Tokens qw/%tokens/; +use LatexIndent::LogFile qw/$logger/; our @ISA = "LatexIndent::Document"; # class inheritance, Programming Perl, pg 321 our @EXPORT_OK = qw/align_at_ampersand find_aligned_block/; our $alignmentBlockCounter; @@ -38,16 +40,16 @@ sub find_aligned_block{ # 1 & 2 & 3 & 4 \\ # 5 & & 6 & \\ # %* \end{tabular} - $self->logger('looking for ALIGNED blocks marked by comments','heading')if($is_t_switch_active); - $self->logger(Dumper(\%{$masterSettings{lookForAlignDelims}})) if($is_t_switch_active); + $logger->trace('*Searching for ALIGNED blocks marked by comments')if($is_t_switch_active); + $logger->trace(Dumper(\%{$masterSettings{lookForAlignDelims}})) if($is_tt_switch_active); while( my ($alignmentBlock,$yesno)= each %{$masterSettings{lookForAlignDelims}}){ if(ref $yesno eq "HASH"){ $yesno = (defined ${$yesno}{delims} ) ? ${$yesno}{delims} : 1; } if($yesno){ - $self->logger("looking for $alignmentBlock:$yesno environments"); + $logger->trace("looking for %*\\begin\{$alignmentBlock\} environments"); - my $noIndentRegExp = qr/ + my $alignmentRegExp = qr/ ( (?!<\\) % @@ -71,13 +73,13 @@ sub find_aligned_block{ #\R /sx; - while( ${$self}{body} =~ m/$noIndentRegExp/sx){ + while( ${$self}{body} =~ m/$alignmentRegExp/sx){ ${$self}{body} =~ s/ - $noIndentRegExp + $alignmentRegExp / # create a new Environment object - my $alignmentBlock = LatexIndent::AlignmentAtAmpersand->new( begin=>$1, + my $alignmentBlockObj = LatexIndent::AlignmentAtAmpersand->new( begin=>$1, body=>$2, end=>$3, name=>$alignmentBlock, @@ -89,13 +91,17 @@ sub find_aligned_block{ }, ); + # log file output + $logger->trace("*Alignment block found: %*\\begin\{$alignmentBlock\}") if $is_t_switch_active; + # the settings and storage of most objects has a lot in common - $self->get_settings_and_store_new_object($alignmentBlock); + $self->get_settings_and_store_new_object($alignmentBlockObj); + ${@{${$self}{children}}[-1]}{replacementText}; /xseg; } } else { - $self->logger("*not* looking for $alignmentBlock as $alignmentBlock:$yesno"); + $logger->trace("*not* looking for $alignmentBlock as $alignmentBlock:$yesno"); } } return; @@ -252,12 +258,16 @@ sub align_at_ampersand{ } # output some of the info so far to the log file - $self->logger("Maximum column sizes of horizontally stripped formatted block (${$self}{name}): @maximumColumnWidth") if $is_t_switch_active; - $self->logger("align at ampersand: ${$self}{lookForAlignDelims}") if $is_t_switch_active; - $self->logger("align at \\\\: ${$self}{alignDoubleBackSlash}") if $is_t_switch_active; - $self->logger("spaces before \\\\: ${$self}{spacesBeforeDoubleBackSlash}") if $is_t_switch_active; - $self->logger("multi column grouping: ${$self}{multiColumnGrouping}") if $is_t_switch_active; - $self->logger("align rows without maximum delimeters: ${$self}{alignRowsWithoutMaxDelims}") if $is_t_switch_active; + $logger->trace("*Alignment at ampersand routine") if $is_t_switch_active; + $logger->trace("Maximum column sizes of horizontally stripped formatted block (${$self}{name}): @maximumColumnWidth") if $is_t_switch_active; + $logger->trace("align at ampersand: ${$self}{lookForAlignDelims}") if $is_t_switch_active; + $logger->trace("align at \\\\: ${$self}{alignDoubleBackSlash}") if $is_t_switch_active; + $logger->trace("spaces before \\\\: ${$self}{spacesBeforeDoubleBackSlash}") if $is_t_switch_active; + $logger->trace("multi column grouping: ${$self}{multiColumnGrouping}") if $is_t_switch_active; + $logger->trace("align rows without maximum delimeters: ${$self}{alignRowsWithoutMaxDelims}") if $is_t_switch_active; + $logger->trace("spaces before ampersand: ${$self}{spacesBeforeAmpersand}") if $is_t_switch_active; + $logger->trace("spaces after ampersand: ${$self}{spacesAfterAmpersand}") if $is_t_switch_active; + $logger->trace("justification: ${$self}{justification}") if $is_t_switch_active; # acount for multicolumn grouping, if the appropriate switch is set if(${$self}{multiColumnGrouping}){ @@ -306,19 +316,34 @@ sub align_at_ampersand{ $maxGroupingWidth = $groupingWidth if($groupingWidth > $maxGroupingWidth); # the cells that receive multicolumn grouping need extra padding; in particular - # the *last* cell of the multicol group receives the padding, hence the - # use of $columnMax below - if(defined @{${$_}{columnSizes}}[$columnMax] and ($columnWidth > ($groupingWidth+3*($multiColSpan-1)) ) and @{${$_}{columnSizes}}[$columnMax] >= 0){ - @{${$_}{multiColPadding}}[$columnMax] = $columnWidth-$groupingWidth-3*($multiColSpan-1); + # if the justification is *left*: + # the *last* cell of the multicol group receives the padding + # if the justification is *right*: + # the *first* cell of the multicol group receives the padding + # + # this motivates the introduction of $columnOffset, which is + # 0 if justification is left + # $multiColSpan if justification is right + my $columnOffset = (${$self}{justification} eq "left") ? $columnMax : $columnCount; + if(defined @{${$_}{columnSizes}}[$columnMax] and ($columnWidth > ($groupingWidth+(${$self}{spacesBeforeAmpersand}+1+${$self}{spacesAfterAmpersand})*($multiColSpan-1)) ) and @{${$_}{columnSizes}}[$columnMax] >= 0){ + my $multiColPadding = $columnWidth-$groupingWidth-(${$self}{spacesBeforeAmpersand}+1+${$self}{spacesAfterAmpersand})*($multiColSpan-1); + + # it's possible that multiColPadding might already be assigned; in which case, + # we need to check that the current value of $multiColPadding is greater than the existing one + if(defined @{${$_}{multiColPadding}}[$columnOffset]){ + @{${$_}{multiColPadding}}[$columnOffset] = max($multiColPadding,@{${$_}{multiColPadding}}[$columnOffset]); + } else { + @{${$_}{multiColPadding}}[$columnOffset] = $multiColPadding; + } # also need to account for maximum column width *including* other multicolumn statements - if($maximumColumnWidthMC[$columnCount]>$columnWidth){ - @{${$_}{multiColPadding}}[$columnMax] += ($maximumColumnWidthMC[$columnCount]-$columnWidth); + if($maximumColumnWidthMC[$columnCount]>$columnWidth and $column !~ m/\\multicolumn\{(\d+)\}/){ + @{${$_}{multiColPadding}}[$columnOffset] += ($maximumColumnWidthMC[$columnCount]-$columnWidth); } } } - # update it to account for the ampersands and 1 space either side of ampersands (total of 3) - $maxGroupingWidth += ($multiColSpan-1)*3; + # update it to account for the ampersands and the spacing either side of ampersands + $maxGroupingWidth += ($multiColSpan-1)*(${$self}{spacesBeforeAmpersand}+1+${$self}{spacesAfterAmpersand}); # store the maxGroupingWidth for use in the next loop @{${$_}{maxGroupingWidth}}[$columnCount] = $maxGroupingWidth; @@ -362,12 +387,29 @@ sub align_at_ampersand{ # underneath the \multicolumn{} statement my $maxGroupingWidth = ${${$_}{maxGroupingWidth}}[$columnCount]; + # it's possible to have situations such as + # + # \multicolumn{3}{l}{one} & \multicolumn{3}{l}{two} & \\ + # \multicolumn{6}{l}{one} & \\ + # + # in which case we need to loop through the @maximumColumnWidthMC + my $groupingWidthMC = 0; + my $multicolsEncountered =0; + for ($columnCount..($columnCount + ($multiColSpan-1))){ + if(defined $maximumColumnWidthMC[$_]){ + $groupingWidthMC += $maximumColumnWidthMC[$_]; + $multicolsEncountered++ if $maximumColumnWidthMC[$_]>0; + } + } + + # need to account for (spacesBeforeAmpersands) + length of ampersands (which is 1) + (spacesAfterAmpersands) + $groupingWidthMC += ($multicolsEncountered-1)*(${$self}{spacesBeforeAmpersand}+1+${$self}{spacesAfterAmpersand}); + # set the padding; we need # maximum( $maxGroupingWidth, $maximumColumnWidthMC[$columnCount] ) - # rather than load another module to give the 'max' function, I use the ternary operator my $maxValueToUse = 0; if(defined $maximumColumnWidthMC[$columnCount]){ - $maxValueToUse = ($maxGroupingWidth>$maximumColumnWidthMC[$columnCount]?$maxGroupingWidth:$maximumColumnWidthMC[$columnCount]); + $maxValueToUse = max($maxGroupingWidth,$maximumColumnWidthMC[$columnCount],$groupingWidthMC); } else { $maxValueToUse = $maxGroupingWidth; } @@ -375,6 +417,19 @@ sub align_at_ampersand{ # calculate the padding $padding = " " x ( $maxValueToUse >= $columnWidth ? $maxValueToUse - $columnWidth : 0 ); + # to the log file + if($is_tt_switch_active){ + $logger->trace("*---------column-------------"); + $logger->trace($column); + $logger->trace("multiColSpan: $multiColSpan"); + $logger->trace("groupingWidthMC: $groupingWidthMC"); + $logger->trace("padding length: ",$maxValueToUse - $columnWidth); + $logger->trace("multicolsEncountered: $multicolsEncountered"); + $logger->trace("maxValueToUse: $maxValueToUse"); + $logger->trace("maximumColumnWidth: ",join(",",@maximumColumnWidth)); + $logger->trace("maximumColumnWidthMC: ",join(",",@maximumColumnWidthMC)); + } + # update the columnCount to account for the multiColSpan $columnCount += $multiColSpan - 1; } else { @@ -383,13 +438,19 @@ sub align_at_ampersand{ } # either way, the row is formed of "COLUMN + PADDING" - $tmpRow .= $column.$padding.(defined @{${$_}{multiColPadding}}[$columnCount] ? " " x @{${$_}{multiColPadding}}[$columnCount]: q())." & "; + if(${$self}{justification} eq "left"){ + $tmpRow .= $column.$padding.(defined @{${$_}{multiColPadding}}[$columnCount] ? " " x @{${$_}{multiColPadding}}[$columnCount]: q()).(" " x ${$self}{spacesBeforeAmpersand})."&".(" " x ${$self}{spacesAfterAmpersand}); + } else { + $tmpRow .= $padding.(defined @{${$_}{multiColPadding}}[$columnCount] ? " " x @{${$_}{multiColPadding}}[$columnCount]: q()).$column.(" " x ${$self}{spacesBeforeAmpersand})."&".(" " x ${$self}{spacesAfterAmpersand}); + } $columnCount++; } # remove the final & - $tmpRow =~ s/\h&\h*$/ /; - $tmpRow =~ s/\h*$/ /; + $tmpRow =~ s/\h*&\h*$/ /; + my $finalSpacing = q(); + $finalSpacing = " " x (${$self}{spacesBeforeDoubleBackSlash}) if ${$self}{spacesBeforeDoubleBackSlash}>=1; + $tmpRow =~ s/\h*$/$finalSpacing/; # replace the row with the formatted row ${$_}{row} = $tmpRow; @@ -430,7 +491,7 @@ sub align_at_ampersand{ # to the log file if($is_tt_switch_active){ - $self->logger(${$_}{row},'ttrace') for @formattedBody; + $logger->trace(${$_}{row}) for @formattedBody; } # delete the original body 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){ diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/BackUpFileProcedure.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/BackUpFileProcedure.pm index dcb3b5bb74e..a0374552b43 100644 --- a/Master/texmf-dist/scripts/latexindent/LatexIndent/BackUpFileProcedure.pm +++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/BackUpFileProcedure.pm @@ -18,6 +18,7 @@ use strict; use warnings; use LatexIndent::GetYamlSettings qw/%masterSettings/; use LatexIndent::Switches qw/%switches/; +use LatexIndent::LogFile qw/$logger/; use File::Basename; # to get the filename and directory path use File::Copy; # to copy the original file to backup (if overwrite option set) use Exporter qw/import/; @@ -31,7 +32,7 @@ sub create_back_up_file{ return unless($switches{overwrite}); # if we want to over write the current file create a backup first - $self->logger("Backup procedure (-w flag active):",'heading'); + $logger->info("*Backup procedure (-w flag active):"); my $fileName = ${$self}{fileName}; @@ -56,8 +57,8 @@ sub create_back_up_file{ # if both ($onlyOneBackUp and $maxNumberOfBackUps) then we have # a conflict- er on the side of caution and turn off onlyOneBackUp if($onlyOneBackUp and $maxNumberOfBackUps>1) { - $self->logger("WARNING: onlyOneBackUp=$onlyOneBackUp and maxNumberOfBackUps: $maxNumberOfBackUps"); - $self->logger("setting onlyOneBackUp=0 which will allow you to reach $maxNumberOfBackUps back ups"); + $logger->warn("*onlyOneBackUp=$onlyOneBackUp and maxNumberOfBackUps: $maxNumberOfBackUps"); + $logger->warn("setting onlyOneBackUp=0 which will allow you to reach $maxNumberOfBackUps back ups"); $onlyOneBackUp = 0; } @@ -65,7 +66,7 @@ sub create_back_up_file{ # they only want one backup if($maxNumberOfBackUps==1) { $onlyOneBackUp=1 ; - $self->logger("FYI: you set maxNumberOfBackUps=1, so I'm setting onlyOneBackUp: 1 "); + $logger->info("you set maxNumberOfBackUps=1, so I'm setting onlyOneBackUp: 1 "); } elsif($maxNumberOfBackUps<=0 and !$onlyOneBackUp) { $onlyOneBackUp=0 ; $maxNumberOfBackUps=-1; @@ -75,8 +76,8 @@ sub create_back_up_file{ # be overwritten each time if($onlyOneBackUp) { $backupFile .= $backupExtension; - $self->logger("copying $fileName to $backupFile"); - $self->logger("$backupFile was overwritten (see onlyOneBackUp)") if (-e $backupFile); + $logger->info("copying $fileName to $backupFile"); + $logger->info("$backupFile was overwritten (see onlyOneBackUp)") if (-e $backupFile); } else { # start with a backup file .bak0 (or whatever $backupExtension is present) my $backupCounter = 0; @@ -85,7 +86,7 @@ sub create_back_up_file{ # if it exists, then keep going: .bak0, .bak1, ... while (-e $backupFile or $maxNumberOfBackUps>1) { if($backupCounter==$maxNumberOfBackUps) { - $self->logger("maxNumberOfBackUps reached ($maxNumberOfBackUps, see maxNumberOfBackUps)"); + $logger->info("maxNumberOfBackUps reached ($maxNumberOfBackUps, see maxNumberOfBackUps)"); # some users may wish to cycle through back up files, e.g: # copy myfile.bak1 to myfile.bak0 @@ -94,7 +95,7 @@ sub create_back_up_file{ # # current back up is stored in myfile.bak4 if($cycleThroughBackUps) { - $self->logger("cycleThroughBackUps detected (see cycleThroughBackUps) "); + $logger->info("cycleThroughBackUps detected (see cycleThroughBackUps) "); for(my $i=1;$i<=$maxNumberOfBackUps;$i++) { # remove number from backUpFile my $oldBackupFile = $backupFile; @@ -107,7 +108,7 @@ sub create_back_up_file{ # check that the oldBackupFile exists if(-e $oldBackupFile){ - $self->logger(" copying $oldBackupFile to $newBackupFile "); + $logger->info(" copying $oldBackupFile to $newBackupFile "); copy($oldBackupFile,$newBackupFile) or die "Could not write to backup file $backupFile. Please check permissions. Exiting."; } } @@ -120,16 +121,16 @@ sub create_back_up_file{ $maxNumberOfBackUps=1; last; # break out of the loop } - $self->logger(" $backupFile already exists, incrementing by 1... (see maxNumberOfBackUps and onlyOneBackUp)"); + $logger->info("$backupFile already exists, incrementing by 1... (see maxNumberOfBackUps and onlyOneBackUp)"); $backupCounter++; $backupFile =~ s/$backupExtension.*/$backupExtension$backupCounter/; } - $self->logger("copying $fileName to $backupFile"); + $logger->info("copying $fileName to $backupFile"); } # output these lines to the log file - $self->logger("Backup file: ",$backupFile,""); - $self->logger("Overwriting file: ",$fileName,""); + $logger->info("Backup file: $backupFile"); + $logger->info("$fileName will be overwritten after indentation"); copy($fileName,$backupFile) or die "Could not write to backup file $backupFile. Please check permissions. Exiting."; } 1; diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/BlankLines.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/BlankLines.pm index 7f5c5b63cca..e4041ce26d5 100644 --- a/Master/texmf-dist/scripts/latexindent/LatexIndent/BlankLines.pm +++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/BlankLines.pm @@ -19,6 +19,7 @@ use warnings; use LatexIndent::Tokens qw/%tokens/; use LatexIndent::GetYamlSettings qw/%masterSettings/; use LatexIndent::Switches qw/$is_m_switch_active $is_t_switch_active $is_tt_switch_active/; +use LatexIndent::LogFile qw/$logger/; use Exporter qw/import/; our @EXPORT_OK = qw/protect_blank_lines unprotect_blank_lines condense_blank_lines/; @@ -27,11 +28,11 @@ sub protect_blank_lines{ my $self = shift; unless(${$masterSettings{modifyLineBreaks}}{preserveBlankLines}){ - $self->logger("Blank lines will not be protected (preserveBlankLines=0)",'heading') if $is_t_switch_active; + $logger->trace("*Blank lines will not be protected (preserveBlankLines=0)") if $is_t_switch_active; return } - $self->logger("Protecting blank lines (see preserveBlankLines)",'heading') if $is_t_switch_active; + $logger->trace("*Protecting blank lines (see preserveBlankLines)") if $is_t_switch_active; ${$self}{body} =~ s/^(\h*)?\R/$tokens{blanklines}\n/mg; return; } @@ -43,6 +44,7 @@ sub condense_blank_lines{ my $self = shift; + $logger->trace("*condense blank lines routine") if $is_t_switch_active; # if preserveBlankLines is set to 0, then the blank-line-token will not be present # in the document -- we change that here if(${$masterSettings{modifyLineBreaks}}{preserveBlankLines}==0){ @@ -50,12 +52,12 @@ sub condense_blank_lines{ ${$masterSettings{modifyLineBreaks}}{preserveBlankLines}=1; # log file information - $self->logger("Updating body to inclued blank line token, this requires preserveBlankLines = 1",'ttrace') if($is_tt_switch_active); - $self->logger("(any blanklines that could have been removed, would have done so by this point)",'ttrace') if($is_tt_switch_active); + $logger->trace("Updating body to include blank line token, this requires preserveBlankLines = 1") if($is_tt_switch_active); + $logger->trace("(any blanklines that could have been removed, would have done so by this point)") if($is_tt_switch_active); # make the call $self->protect_blank_lines ; - $self->logger("body now looks like:\n${$self}{body}",'ttrace') if($is_tt_switch_active); + $logger->trace("body now looks like:\n${$self}{body}") if($is_tt_switch_active); } # grab the value from the settings @@ -65,15 +67,15 @@ sub condense_blank_lines{ my $blankLineToken = $tokens{blanklines}; # condense! - $self->logger("Condensing multiple blank lines into $condenseMultipleBlankLinesInto (see condenseMultipleBlankLinesInto)",'heading') if $is_t_switch_active; + $logger->trace("Condensing multiple blank lines into $condenseMultipleBlankLinesInto (see condenseMultipleBlankLinesInto)") if $is_t_switch_active; my $replacementToken = $blankLineToken; for (my $i=1; $i<$condenseMultipleBlankLinesInto; $i++ ){ $replacementToken .= "\n$blankLineToken"; } - $self->logger("blank line replacement token: $replacementToken",'ttrace') if($is_tt_switch_active); + $logger->trace("blank line replacement token: $replacementToken") if($is_tt_switch_active); ${$self}{body} =~ s/($blankLineToken\h*\R*\h*){1,}$blankLineToken/$replacementToken/mgs; - $self->logger("body now looks like:\n${$self}{body}",'ttrace') if($is_tt_switch_active); + $logger->trace("body now looks like:\n${$self}{body}") if($is_tt_switch_active); return; } @@ -83,7 +85,7 @@ sub unprotect_blank_lines{ return unless ${$masterSettings{modifyLineBreaks}}{preserveBlankLines}; my $self = shift; - $self->logger("Unprotecting blank lines (see preserveBlankLines)",'heading') if $is_t_switch_active; + $logger->trace("Unprotecting blank lines (see preserveBlankLines)") if $is_t_switch_active; my $blankLineToken = $tokens{blanklines}; # loop through the body, looking for the blank line token @@ -100,8 +102,9 @@ sub unprotect_blank_lines{ # when there is only stuff *after* the blank line token ${$self}{body} =~ s/^$blankLineToken\h*(.*?)$/$1."\n"/emg; } - $self->logger("Finished unprotecting lines (see preserveBlankLines)",'heading') if $is_t_switch_active; - $self->logger("body now looks like ${$self}{body}",'ttrace') if($is_tt_switch_active); + $logger->trace("Finished unprotecting lines (see preserveBlankLines)") if $is_t_switch_active; + $logger->trace("body now looks like:") if($is_tt_switch_active); + $logger->trace("${$self}{body}") if($is_tt_switch_active); } 1; diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/Braces.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/Braces.pm index c5122fd1275..b1c8fc47555 100644 --- a/Master/texmf-dist/scripts/latexindent/LatexIndent/Braces.pm +++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/Braces.pm @@ -22,6 +22,7 @@ use LatexIndent::KeyEqualsValuesBraces qw/$key_equals_values_bracesRegExp $key_e use LatexIndent::NamedGroupingBracesBrackets qw/$grouping_braces_regexp $grouping_braces_regexpTrailingComment/; use LatexIndent::UnNamedGroupingBracesBrackets qw/$un_named_grouping_braces_RegExp $un_named_grouping_braces_RegExp_trailing_comment/; use LatexIndent::Switches qw/$is_t_switch_active $is_tt_switch_active/; +use LatexIndent::LogFile qw/$logger/; use Data::Dumper; use Exporter qw/import/; our @ISA = "LatexIndent::Document"; # class inheritance, Programming Perl, pg 321 @@ -32,7 +33,7 @@ sub find_commands_or_key_equals_values_braces{ my $self = shift; - $self->logger("Searching for commands with optional and/or mandatory arguments AND key = {value}",'heading') if $is_t_switch_active ; + $logger->trace("*Searching for commands with optional and/or mandatory arguments AND key = {value}") if $is_t_switch_active ; # match either a \\command or key={value} while( ${$self}{body} =~ m/$commandRegExpTrailingComment/ @@ -49,9 +50,6 @@ sub find_commands_or_key_equals_values_braces{ ${$self}{body} =~ s/ $commandRegExpTrailingComment / - # log file output - $self->logger("command found: $2",'heading') if $is_t_switch_active ; - # create a new command object my $command = LatexIndent::Command->new(begin=>$1.$2.($3?$3:q()).($4?$4:q()), name=>$2, @@ -71,6 +69,9 @@ sub find_commands_or_key_equals_values_braces{ }, optAndMandArgsRegExp=>$optAndMandAndRoundBracketsRegExpLineBreaks, ); + + # log file output + $logger->trace("*command found: $2") if $is_t_switch_active ; # the settings and storage of most objects has a lot in common $self->get_settings_and_store_new_object($command); @@ -83,9 +84,6 @@ sub find_commands_or_key_equals_values_braces{ ${$self}{body} =~ s/ $key_equals_values_bracesRegExpTrailingComment / - # log file output - $self->logger("key_equals_values_braces found: $3",'heading') if $is_t_switch_active ; - # create a new key_equals_values_braces object my $key_equals_values_braces = LatexIndent::KeyEqualsValuesBraces->new( begin=>($2?$2:q()).$3.$4.($5?$5:q()), @@ -107,6 +105,9 @@ sub find_commands_or_key_equals_values_braces{ }, additionalAssignments=>["EqualsStartsOnOwnLine"], ); + + # log file output + $logger->trace("*key_equals_values_braces found: $3") if $is_t_switch_active ; # the settings and storage of most objects has a lot in common $self->get_settings_and_store_new_object($key_equals_values_braces); @@ -119,9 +120,6 @@ sub find_commands_or_key_equals_values_braces{ ${$self}{body} =~ s/ $grouping_braces_regexpTrailingComment / - # log file output - $self->logger("named grouping braces found: $2",'heading') if $is_t_switch_active ; - # create a new key_equals_values_braces object my $grouping_braces = LatexIndent::NamedGroupingBracesBrackets->new( begin=>$2.($3?$3:q()).($4?$4:q()), @@ -142,6 +140,8 @@ sub find_commands_or_key_equals_values_braces{ BodyStartsOnOwnLine=>"NameFinishesWithLineBreak", }, ); + # log file output + $logger->trace("*named grouping braces found: $2") if $is_t_switch_active ; # the settings and storage of most objects has a lot in common $self->get_settings_and_store_new_object($grouping_braces); @@ -153,9 +153,6 @@ sub find_commands_or_key_equals_values_braces{ ${$self}{body} =~ s/ $un_named_grouping_braces_RegExp_trailing_comment / - # log file output - $self->logger("UNnamed grouping braces found: (no name, by definition!)",'heading') if $is_t_switch_active ; - # create a new Un-named-grouping-braces-brackets object my $un_named_grouping_braces = LatexIndent::UnNamedGroupingBracesBrackets->new( begin=>q(), @@ -175,6 +172,9 @@ sub find_commands_or_key_equals_values_braces{ BodyStartsOnOwnLine=>0, ); + # log file output + $logger->trace("*UNnamed grouping braces found: (no name, by definition!)") if $is_t_switch_active ; + # the settings and storage of most objects has a lot in common $self->get_settings_and_store_new_object($un_named_grouping_braces); ${@{${$self}{children}}[-1]}{replacementText}.($6?($8?$8:q()):q()); diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/Command.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/Command.pm index db876c4c8c5..acd118ecf6d 100755 --- a/Master/texmf-dist/scripts/latexindent/LatexIndent/Command.pm +++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/Command.pm @@ -20,6 +20,7 @@ use LatexIndent::Tokens qw/%tokens/; use LatexIndent::TrailingComments qw/$trailingCommentRegExp/; use LatexIndent::Switches qw/$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 @@ -58,7 +59,7 @@ sub construct_command_regexp{ } # details to log file - $self->logger("The special command names regexp is: $commandNameSpecialRegExp (see commandNameSpecial)",'heading') if $is_t_switch_active; + $logger->trace("*The special command names regexp is: $commandNameSpecialRegExp (see commandNameSpecial)") if $is_t_switch_active; # construct the command regexp $commandRegExp = qr/ @@ -92,7 +93,7 @@ sub tasks_particular_to_each_object{ if(${${$self}{linebreaksAtEnd}}{end} == 1 and ${${${$self}{children}}[0]}{body} =~ m/\R$/s and !${$self}{endImmediatelyFollowedByComment}){ - $self->logger("Removing linebreak from argument container of ${$self}{name}") if $is_t_switch_active; + $logger->trace("Removing linebreak from argument container of ${$self}{name}") if $is_t_switch_active; ${${${$self}{children}}[0]}{body} =~ s/\R$//s; ${${${${$self}{children}}[0]}{linebreaksAtEnd}}{body} = 0; } @@ -103,7 +104,7 @@ sub tasks_particular_to_each_object{ and defined ${${${${$self}{children}}[0]}{children}[-1]}{EndFinishesWithLineBreak} and ${${${${$self}{children}}[0]}{children}[-1]}{EndFinishesWithLineBreak} == -1 ){ - $self->logger("Switching linebreaksAtEnd{end} to be 0 in command ${$self}{name} as last argument specifies EndFinishesWithLineBreak == 0") if $is_t_switch_active; + $logger->trace("Switching linebreaksAtEnd{end} to be 0 in command ${$self}{name} as last argument specifies EndFinishesWithLineBreak == 0") if $is_t_switch_active; ${${$self}{linebreaksAtEnd}}{end} = 0; ${$self}{EndFinishesWithLineBreak} = -1; } @@ -117,30 +118,30 @@ sub tasks_particular_to_each_object{ and !${$self}{endImmediatelyFollowedByComment}){ # update the Command object - $self->logger("Adjusting linebreaksAtEnd in command ${$self}{name}") if $is_t_switch_active; + $logger->trace("Adjusting linebreaksAtEnd in command ${$self}{name}") if $is_t_switch_active; ${${$self}{linebreaksAtEnd}}{end} = ${${${${${$self}{children}}[0]}{children}[-1]}{linebreaksAtEnd}}{end}; ${$self}{replacementText} .= "\n"; # if the last argument has EndFinishesWithLineBreak == 3 if (${${${${$self}{children}}[0]}{children}[-1]}{EndFinishesWithLineBreak} == 3 ){ my $EndStringLogFile = ${${${${$self}{children}}[0]}{children}[-1]}{aliases}{EndFinishesWithLineBreak}||"EndFinishesWithLineBreak"; - $self->logger("Adding another blank line to replacement text for ${$self}{name} as last argument has $EndStringLogFile == 3 ") if $is_t_switch_active; + $logger->trace("Adding another blank line to replacement text for ${$self}{name} as last argument has $EndStringLogFile == 3 ") if $is_t_switch_active; ${$self}{replacementText} .= (${$masterSettings{modifyLineBreaks}}{preserveBlankLines}?$tokens{blanklines}:"\n")."\n"; } # update the argument object - $self->logger("Adjusting argument object in command, ${$self}{name}") if $is_t_switch_active; + $logger->trace("Adjusting argument object in command, ${$self}{name}") if $is_t_switch_active; ${${${${$self}{children}}[0]}{linebreaksAtEnd}}{body} = 0; ${${${$self}{children}}[0]}{body} =~ s/\R$//s; # update the last mandatory/optional argument - $self->logger("Adjusting last argument in command, ${$self}{name}") if $is_t_switch_active; + $logger->trace("Adjusting last argument in command, ${$self}{name}") if $is_t_switch_active; ${${${${${$self}{children}}[0]}{children}[-1]}{linebreaksAtEnd}}{end} = 0; ${${${${$self}{children}}[0]}{children}[-1]}{EndFinishesWithLineBreak} = -1; ${${${${$self}{children}}[0]}{children}[-1]}{replacementText} =~ s/\R$//s; # output to log file - $self->logger(Dumper(${${${$self}{children}}[0]}{children}[-1])) if $is_t_switch_active; + $logger->trace(Dumper(${${${$self}{children}}[0]}{children}[-1])) if $is_tt_switch_active; } # situation: ${${$self}{linebreaksAtEnd}}{end} == 1 and the last argument has added @@ -152,12 +153,12 @@ sub tasks_particular_to_each_object{ and !${$self}{endImmediatelyFollowedByComment}){ # last argument adjustment - $self->logger("Adjusting last argument in command, ${$self}{name} to avoid double line break") if $is_t_switch_active; + $logger->trace("Adjusting last argument in command, ${$self}{name} to avoid double line break") if $is_t_switch_active; ${${${${$self}{children}}[0]}{children}[-1]}{replacementText}=~s/\R$//s; ${${${${${$self}{children}}[0]}{children}[-1]}{linebreaksAtEnd}}{end} = 0; # argument object adjustment - $self->logger("Adjusting argument object in command, ${$self}{name} to avoid double line break") if $is_t_switch_active; + $logger->trace("Adjusting argument object in command, ${$self}{name} to avoid double line break") if $is_t_switch_active; ${${${${$self}{children}}[0]}{linebreaksAtEnd}}{body} = 0; ${${${$self}{children}}[0]}{body}=~s/\R$//s; } @@ -167,7 +168,7 @@ sub tasks_particular_to_each_object{ # # see ../test-cases/texexchange/5461.tex which was the first example to demonstrate the need for this if(!${${${$self}{children}}[0]}{endImmediatelyFollowedByComment} and ${${${$self}{children}}[0]}{body} =~ m/\h*$/ and ${$self}{replacementText} !~ m/\R$/){ - $self->logger("${$self}{name}: trailling horizontal space found in arguments -- removing it from arguments, adding to replacement text") if $is_t_switch_active; + $logger->trace("${$self}{name}: trailling horizontal space found in arguments -- removing it from arguments, adding to replacement text") if $is_t_switch_active; ${${${$self}{children}}[0]}{body} =~ s/(\h*)$//s; ${$self}{replacementText} .= "$1"; } diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/Document.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/Document.pm index 8697c20e86c..03817c8d7cf 100644 --- a/Master/texmf-dist/scripts/latexindent/LatexIndent/Document.pm +++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/Document.pm @@ -22,12 +22,12 @@ use open ':std', ':encoding(UTF-8)'; # gain access to subroutines in the following modules use LatexIndent::Switches qw/storeSwitches %switches $is_m_switch_active $is_t_switch_active $is_tt_switch_active/; -use LatexIndent::LogFile qw/logger output_logfile processSwitches/; +use LatexIndent::LogFile qw/processSwitches $logger/; use LatexIndent::GetYamlSettings qw/readSettings modify_line_breaks_settings get_indentation_settings_for_this_object get_every_or_custom_value get_indentation_information get_object_attribute_for_indentation_settings alignment_at_ampersand_settings %masterSettings/; use LatexIndent::FileExtension qw/file_extension_check/; use LatexIndent::BackUpFileProcedure qw/create_back_up_file/; use LatexIndent::BlankLines qw/protect_blank_lines unprotect_blank_lines condense_blank_lines/; -use LatexIndent::ModifyLineBreaks qw/modify_line_breaks_body modify_line_breaks_end remove_line_breaks_begin adjust_line_breaks_end_parent max_char_per_line paragraphs_on_one_line construct_paragraph_reg_exp/; +use LatexIndent::ModifyLineBreaks qw/modify_line_breaks_body modify_line_breaks_end remove_line_breaks_begin adjust_line_breaks_end_parent max_char_per_line paragraphs_on_one_line construct_paragraph_reg_exp one_sentence_per_line/; use LatexIndent::TrailingComments qw/remove_trailing_comments put_trailing_comments_back_in add_comment_symbol construct_trailing_comment_regexp/; use LatexIndent::HorizontalWhiteSpace qw/remove_trailing_whitespace remove_leading_space/; use LatexIndent::Indent qw/indent wrap_up_statement determine_total_indentation indent_begin indent_body indent_end_statement final_indentation_check get_surrounding_indentation indent_children_recursively check_for_blank_lines_at_beginning put_blank_lines_back_in_at_beginning add_surrounding_indentation_to_begin_statement post_indentation_check/; @@ -64,6 +64,7 @@ sub new{ my $invocant = shift; my $class = ref($invocant) || $invocant; my $self = {@_}; + $logger->trace(${$masterSettings{logFilePreferences}}{showDecorationStartCodeBlockTrace}) if ${$masterSettings{logFilePreferences}}{showDecorationStartCodeBlockTrace}; bless ($self,$class); return $self; } @@ -72,7 +73,6 @@ sub latexindent{ my $self = shift; $self->storeSwitches; $self->processSwitches; - $self->readSettings; $self->file_extension_check; $self->operate_on_file; } @@ -94,6 +94,7 @@ sub operate_on_file{ $self->find_file_contents_environments_and_preamble; $self->dodge_double_backslash; $self->remove_leading_space; + $self->one_sentence_per_line if $is_m_switch_active; $self->process_body_of_text; $self->remove_trailing_whitespace(when=>"after"); $self->condense_blank_lines; @@ -103,7 +104,6 @@ sub operate_on_file{ $self->put_trailing_comments_back_in; $self->put_verbatim_commands_back_in; $self->output_indented_text; - $self->output_logfile; return } @@ -125,25 +125,32 @@ sub construct_regular_expressions{ sub output_indented_text{ my $self = shift; - # output to screen, unless silent mode - print ${$self}{body} unless $switches{silentMode}; - - $self->logger("Output routine",'heading'); + $logger->info("*Output routine:"); # if -overwrite is active then output to original fileName if($switches{overwrite}) { - $self->logger("Overwriting file ${$self}{fileName}"); + $logger->info("Overwriting file ${$self}{fileName}"); open(OUTPUTFILE,">",${$self}{fileName}); print OUTPUTFILE ${$self}{body}; close(OUTPUTFILE); } elsif($switches{outputToFile}) { - $self->logger("Outputting to file $switches{outputToFile}"); + $logger->info("Outputting to file $switches{outputToFile}"); open(OUTPUTFILE,">",$switches{outputToFile}); print OUTPUTFILE ${$self}{body}; close(OUTPUTFILE); } else { - $self->logger("Not outputting to file; see -w and -o switches for more options."); + $logger->info("Not outputting to file; see -w and -o switches for more options."); } + + # put the final line in the logfile + $logger->info("${$masterSettings{logFilePreferences}}{endLogFileWith}") if ${$masterSettings{logFilePreferences}}{endLogFileWith}; + + # github info line + $logger->info("*Please direct all communication/issues to:\nhttps://github.com/cmhughes/latexindent.pl") if ${$masterSettings{logFilePreferences}}{showGitHubInfoFooter}; + + # output to screen, unless silent mode + print ${$self}{body} unless $switches{silentMode}; + return; } @@ -151,19 +158,19 @@ sub process_body_of_text{ my $self = shift; # find objects recursively - $self->logger('Phase 1: searching for objects','heading'); + $logger->info('*Phase 1: searching for objects'); $self->find_objects; # find all hidden child - $self->logger('Phase 2: finding surrounding indentation','heading'); + $logger->info('*Phase 2: finding surrounding indentation'); $self->find_surrounding_indentation_for_children; # indentation recursively - $self->logger('Phase 3: indenting objects','heading'); + $logger->info('*Phase 3: indenting objects'); $self->indent_children_recursively; # final indentation check - $self->logger('Phase 4: final indentation check','heading'); + $logger->info('*Phase 4: final indentation check'); $self->final_indentation_check; return; @@ -173,15 +180,15 @@ sub find_objects{ my $self = shift; # search for environments - $self->logger('looking for ENVIRONMENTS') if $is_t_switch_active; + $logger->trace('looking for ENVIRONMENTS') if $is_t_switch_active; $self->find_environments; # search for ifElseFi blocks - $self->logger('looking for IFELSEFI') if $is_t_switch_active; + $logger->trace('looking for IFELSEFI') if $is_t_switch_active; $self->find_ifelsefi; # search for headings (part, chapter, section, setc) - $self->logger('looking for HEADINGS (chapter, section, part, etc)') if $is_t_switch_active; + $logger->trace('looking for HEADINGS (chapter, section, part, etc)') if $is_t_switch_active; $self->find_heading; # the ordering of finding commands and special code blocks can change @@ -195,16 +202,14 @@ sub find_objects{ # if there are no children, return if(${$self}{children}){ - $self->logger("Objects have been found.",'heading') if $is_t_switch_active; + $logger->trace("*Objects have been found.") if $is_t_switch_active; } else { - $self->logger("No objects found."); + $logger->trace("No objects found."); return; } # logfile information - $self->logger(Dumper(\%{$self}),'ttrace') if($is_tt_switch_active); - $self->logger("Operating on: ${$self}{name}",'heading')if $is_t_switch_active; - $self->logger("Number of children: ".scalar (@{${$self}{children}})) if $is_t_switch_active; + $logger->trace(Dumper(\%{$self})) if($is_tt_switch_active); return; } @@ -216,19 +221,19 @@ sub find_commands_or_key_equals_values_braces_and_special{ # can change depending upon specialBeforeCommand if(${$masterSettings{specialBeginEnd}}{specialBeforeCommand}){ # search for special begin/end - $self->logger('looking for SPECIAL begin/end *before* looking for commands (see specialBeforeCommand)') if $is_t_switch_active; + $logger->trace('looking for SPECIAL begin/end *before* looking for commands (see specialBeforeCommand)') if $is_t_switch_active; $self->find_special; # search for commands with arguments - $self->logger('looking for COMMANDS and key = {value}') if $is_t_switch_active; + $logger->trace('looking for COMMANDS and key = {value}') if $is_t_switch_active; $self->find_commands_or_key_equals_values_braces; } else { # search for commands with arguments - $self->logger('looking for COMMANDS and key = {value}') if $is_t_switch_active; + $logger->trace('looking for COMMANDS and key = {value}') if $is_t_switch_active; $self->find_commands_or_key_equals_values_braces; # search for special begin/end - $self->logger('looking for SPECIAL begin/end') if $is_t_switch_active; + $logger->trace('looking for SPECIAL begin/end') if $is_t_switch_active; $self->find_special; } return; @@ -236,7 +241,7 @@ sub find_commands_or_key_equals_values_braces_and_special{ sub tasks_particular_to_each_object{ my $self = shift; - $self->logger("There are no tasks particular to ${$self}{name}") if $is_t_switch_active; + $logger->trace("There are no tasks particular to ${$self}{name}") if $is_t_switch_active; } sub get_settings_and_store_new_object{ @@ -254,6 +259,8 @@ sub get_settings_and_store_new_object{ # store children in special hash push(@{${$self}{children}},$latexIndentObject); + # possible decoration in log file + $logger->trace(${$masterSettings{logFilePreferences}}{showDecorationFinishCodeBlockTrace}) if ${$masterSettings{logFilePreferences}}{showDecorationFinishCodeBlockTrace}; } sub tasks_common_to_each_object{ @@ -264,12 +271,12 @@ sub tasks_common_to_each_object{ # update/create the ancestor information if($parent{ancestors}){ - $self->logger("Ancestors *have* been found for ${$self}{name}") if($is_t_switch_active); + $logger->trace("Ancestors *have* been found for ${$self}{name}") if($is_t_switch_active); push(@{${$self}{ancestors}},@{$parent{ancestors}}); } else { - $self->logger("No ancestors found for ${$self}{name}") if($is_t_switch_active); + $logger->trace("No ancestors found for ${$self}{name}") if($is_t_switch_active); if(defined $parent{id} and $parent{id} ne ''){ - $self->logger("Creating ancestors with $parent{id} as the first one") if($is_t_switch_active); + $logger->trace("Creating ancestors with $parent{id} as the first one") if($is_t_switch_active); push(@{${$self}{ancestors}},{ancestorID=>$parent{id},ancestorIndentation=>\$parent{indentation},type=>"natural",name=>${$self}{name}}); } } @@ -328,7 +335,7 @@ sub adjust_replacement_text_line_breaks_at_end{ # the above regexp, when used below, will remove the trailing linebreak in ${$self}{linebreaksAtEnd}{end} # so we compensate for it here - $self->logger("Putting linebreak after replacementText for ${$self}{name}") if($is_t_switch_active); + $logger->trace("Putting linebreak after replacementText for ${$self}{name}") if($is_t_switch_active); if(defined ${$self}{horizontalTrailingSpace}){ ${$self}{replacementText} .= ${$self}{horizontalTrailingSpace} unless(!${$self}{endImmediatelyFollowedByComment} and defined ${$self}{EndFinishesWithLineBreak} and ${$self}{EndFinishesWithLineBreak}==2); } @@ -345,7 +352,7 @@ sub count_body_line_breaks{ my $bodyLineBreaks = 0; $bodyLineBreaks++ while(${$self}{body} =~ m/\R/sxg); ${$self}{bodyLineBreaks} = $bodyLineBreaks; - $self->logger("bodyLineBreaks ${$self}{bodyLineBreaks}") if((${$self}{bodyLineBreaks} != $oldBodyLineBreaks) and $is_t_switch_active); + $logger->trace("bodyLineBreaks ${$self}{bodyLineBreaks}") if((${$self}{bodyLineBreaks} != $oldBodyLineBreaks) and $is_t_switch_active); } sub wrap_up_tasks{ @@ -357,8 +364,8 @@ sub wrap_up_tasks{ # check if the last object was the last thing in the body, and if it has adjusted linebreaks $self->adjust_line_breaks_end_parent; - $self->logger(Dumper(\%{$child})) if($is_tt_switch_active); - $self->logger("replaced with ID: ${$child}{id}") if $is_t_switch_active; + $logger->trace(Dumper(\%{$child})) if($is_tt_switch_active); + $logger->trace("replaced with ID: ${$child}{id}") if $is_t_switch_active; } diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/Else.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/Else.pm index 878a68dc1cb..fe2664cf1dd 100644 --- a/Master/texmf-dist/scripts/latexindent/LatexIndent/Else.pm +++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/Else.pm @@ -19,6 +19,7 @@ use warnings; use LatexIndent::Tokens qw/%tokens/; use LatexIndent::TrailingComments qw/$trailingCommentRegExp/; use LatexIndent::Switches qw/$is_m_switch_active $is_t_switch_active $is_tt_switch_active/; +use LatexIndent::LogFile qw/$logger/; use Data::Dumper; use Exporter qw/import/; our @ISA = "LatexIndent::Document"; # class inheritance, Programming Perl, pg 321 @@ -37,12 +38,10 @@ our $elseRegExp = qr/ sub check_for_else_statement{ my $self = shift; - $self->logger("Looking for \\else statement (${$self}{name})",'heading') if $is_t_switch_active; + $logger->trace("*Looking for \\else statement (${$self}{name})") if $is_t_switch_active; ${$self}{body} =~ s/$elseRegExp(\h*)($trailingCommentRegExp)? - / # log file output - $self->logger("else found: ${$self}{name}",'heading')if $is_t_switch_active; - + / # create a new IfElseFi object my $else = LatexIndent::Else->new(begin=>$1, name=>${$self}{name}, @@ -64,6 +63,9 @@ sub check_for_else_statement{ endImmediatelyFollowedByComment=>0, horizontalTrailingSpace=>q(), ); + # log file output + $logger->trace("*else found: ${$self}{name}")if $is_t_switch_active; + # the settings and storage of most objects has a lot in common $self->get_settings_and_store_new_object($else); ${@{${$self}{children}}[-1]}{replacementText}; @@ -76,7 +78,7 @@ sub remove_line_breaks_begin{ # there is no white space my $self = shift; my $BodyStringLogFile = ${$self}{aliases}{BodyStartsOnOwnLine}||"BodyStartsOnOwnLine"; - $self->logger("Removing linebreak at the end of begin (see $BodyStringLogFile)"); + $logger->trace("Removing linebreak at the end of begin (see $BodyStringLogFile)"); ${$self}{begin} =~ s/\R*$//sx; ${$self}{begin} .= " " unless(${$self}{begin} =~ m/\h$/s or ${$self}{body} =~ m/^\h/s or ${$self}{body} =~ m/^\R/s ); ${$self}{linebreaksAtEnd}{begin} = 0; diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/Environment.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/Environment.pm index 0dd2fa80174..b3b5b431855 100755 --- a/Master/texmf-dist/scripts/latexindent/LatexIndent/Environment.pm +++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/Environment.pm @@ -19,6 +19,7 @@ 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::LogFile qw/$logger/; use Data::Dumper; use Exporter qw/import/; our @ISA = "LatexIndent::Document"; # class inheritance, Programming Perl, pg 321 @@ -61,9 +62,6 @@ sub find_environments{ ${$self}{body} =~ s/ $environmentRegExp(\h*)($trailingCommentRegExp)? / - # log file output - $self->logger("environment found: $2",'heading') if $is_t_switch_active; - # create a new Environment object my $env = LatexIndent::Environment->new(begin=>$1, name=>$2, @@ -79,6 +77,9 @@ sub find_environments{ horizontalTrailingSpace=>$7?$7:q(), ); + # log file output + $logger->trace("*environment found: $2") if $is_t_switch_active; + # the settings and storage of most objects has a lot in common $self->get_settings_and_store_new_object($env); ${@{${$self}{children}}[-1]}{replacementText}.($9?$9:q()).($10?$10:q()); @@ -93,7 +94,7 @@ sub tasks_particular_to_each_object{ # if the environment is empty, we may need to update linebreaksAtEnd{body} if(${$self}{body} =~ m/^\h*$/s and ${${$self}{linebreaksAtEnd}}{begin}){ - $self->logger("empty environment body (${$self}{name}), updating linebreaksAtEnd{body} to be 1") if($is_t_switch_active); + $logger->trace("empty environment body (${$self}{name}), updating linebreaksAtEnd{body} to be 1") if($is_t_switch_active); ${${$self}{linebreaksAtEnd}}{body} = 1; } diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/FileContents.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/FileContents.pm index 802b2a1ef9d..4ad2623fe0d 100644 --- a/Master/texmf-dist/scripts/latexindent/LatexIndent/FileContents.pm +++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/FileContents.pm @@ -19,6 +19,7 @@ use warnings; use LatexIndent::Tokens qw/%tokens/; use LatexIndent::GetYamlSettings qw/%masterSettings/; use LatexIndent::Switches qw/$is_t_switch_active $is_tt_switch_active/; +use LatexIndent::LogFile qw/$logger/; use Data::Dumper; use Exporter qw/import/; our @EXPORT_OK = qw/find_file_contents_environments_and_preamble/; @@ -34,11 +35,11 @@ sub find_file_contents_environments_and_preamble{ my @fileContentsStorageArray; # fileContents environments - $self->logger('looking for FILE CONTENTS environments (see fileContentsEnvironments)','heading') if $is_t_switch_active; - $self->logger(Dumper(\%{$masterSettings{fileContentsEnvironments}})) if($is_t_switch_active); + $logger->trace('*Searching for FILE CONTENTS environments (see fileContentsEnvironments)') if $is_t_switch_active; + $logger->trace(Dumper(\%{$masterSettings{fileContentsEnvironments}})) if($is_tt_switch_active); while( my ($fileContentsEnv,$yesno)= each %{$masterSettings{fileContentsEnvironments}}){ if($yesno){ - $self->logger("looking for $fileContentsEnv:$yesno environments") if $is_t_switch_active; + $logger->trace("looking for $fileContentsEnv environments") if $is_t_switch_active; # the trailing * needs some care if($fileContentsEnv =~ m/\*$/){ @@ -93,15 +94,15 @@ sub find_file_contents_environments_and_preamble{ push(@fileContentsStorageArray,$fileContentsBlock); # log file output - $self->logger("FILECONTENTS environment found: $fileContentsEnv"); + $logger->trace("FILECONTENTS environment found: $fileContentsEnv"); # remove the environment block, and replace with unique ID ${$self}{body} =~ s/$fileContentsRegExp/${$fileContentsBlock}{replacementText}/sx; - $self->logger("replaced with ID: ${$fileContentsBlock}{id}"); + $logger->trace("replaced with ID: ${$fileContentsBlock}{id}") if $is_tt_switch_active; } } else { - $self->logger("*not* looking for $fileContentsEnv as $fileContentsEnv:$yesno"); + $logger->trace("*not* looking for $fileContentsEnv as $fileContentsEnv:$yesno"); } } @@ -119,7 +120,7 @@ sub find_file_contents_environments_and_preamble{ # try and find the preamble if( ${$self}{body} =~ m/$preambleRegExp/sx and ${$masterSettings{lookForPreamble}}{${$self}{fileExtension}}){ - $self->logger("\\begin{document} found in body (after searching for filecontents)-- assuming that a preamble exists",'heading') if $is_t_switch_active ; + $logger->trace("\\begin{document} found in body (after searching for filecontents)-- assuming that a preamble exists",'heading') if $is_t_switch_active ; # create a preamble object $preamble = LatexIndent::Preamble->new( begin=>q(), @@ -142,19 +143,19 @@ sub find_file_contents_environments_and_preamble{ $preamble->get_replacement_text; # log file output - $self->logger("preamble found: $preamble") if $is_t_switch_active; + $logger->trace("preamble found: preamble") if $is_t_switch_active; # remove the environment block, and replace with unique ID ${$self}{body} =~ s/$preambleRegExp/${$preamble}{replacementText}/sx; - $self->logger("replaced with ID: ${$preamble}{replacementText}") if $is_t_switch_active; + $logger->trace("replaced with ID: ${$preamble}{replacementText}") if $is_tt_switch_active; # indentPreamble set to 1 if($masterSettings{indentPreamble}){ - $self->logger("storing ${$preamble}{id} for indentation (see indentPreamble)"); + $logger->trace("storing ${$preamble}{id} for indentation (see indentPreamble)"); $needToStorePreamble = 1; } else { # indentPreamble set to 0 - $self->logger("NOT storing ${$preamble}{id} for indentation -- will store as VERBATIM object (see indentPreamble)") if $is_t_switch_active; + $logger->trace("NOT storing ${$preamble}{id} for indentation -- will store as VERBATIM object (because indentPreamble:0)") if $is_t_switch_active; $preamble->unprotect_blank_lines; ${$self}{verbatim}{${$preamble}{id}} = $preamble; } @@ -167,18 +168,18 @@ sub find_file_contents_environments_and_preamble{ my $indentThisChild = 0; # verbatim children go in special hash if($preamble ne '' and ${$preamble}{body} =~ m/${$_}{id}/){ - $self->logger("filecontents (${$_}{id}) is within preamble"); + $logger->trace("filecontents (${$_}{id}) is within preamble"); # indentPreamble set to 1 if($masterSettings{indentPreamble}){ - $self->logger("storing ${$_}{id} for indentation (indentPreamble is 1)"); + $logger->trace("storing ${$_}{id} for indentation (indentPreamble is 1)"); $indentThisChild = 1; } else { # indentPreamble set to 0 - $self->logger("Storing ${$_}{id} as a VERBATIM object (indentPreamble is 0)"); + $logger->trace("Storing ${$_}{id} as a VERBATIM object (indentPreamble is 0)"); ${$self}{verbatim}{${$_}{id}}=$_; } } else { - $self->logger("storing ${$_}{id} for indentation (${$_}{name} found outside of preamble)"); + $logger->trace("storing ${$_}{id} for indentation (${$_}{name} found outside of preamble)"); $indentThisChild = 1; } # store the child, if necessary @@ -187,6 +188,9 @@ sub find_file_contents_environments_and_preamble{ $_->get_indentation_settings_for_this_object; $_->tasks_particular_to_each_object; push(@{${$self}{children}},$_); + + # possible decoration in log file + $logger->trace(${$masterSettings{logFilePreferences}}{showDecorationFinishCodeBlockTrace}) if ${$masterSettings{logFilePreferences}}{showDecorationFinishCodeBlockTrace}; } } diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/FileExtension.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/FileExtension.pm index c2f6d0fcf3f..93f8016f030 100644 --- a/Master/texmf-dist/scripts/latexindent/LatexIndent/FileExtension.pm +++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/FileExtension.pm @@ -21,6 +21,7 @@ use PerlIO::encoding; use open ':std', ':encoding(UTF-8)'; use File::Basename; # to get the filename and directory path use Exporter qw/import/; +use Log::Log4perl qw(get_logger :levels); use LatexIndent::GetYamlSettings qw/%masterSettings/; use LatexIndent::Switches qw/%switches/; our @EXPORT_OK = qw/file_extension_check/; @@ -28,6 +29,9 @@ our @EXPORT_OK = qw/file_extension_check/; sub file_extension_check{ my $self = shift; + # grab the logger object + my $logger = get_logger("Document"); + # grab the filename my $fileName = ${$self}{fileName}; @@ -44,50 +48,47 @@ sub file_extension_check{ # check to make sure given file type is supported if( -e $fileName and !$ext ){ my $message = "The file $fileName exists , but the extension does not correspond to any given in fileExtensionPreference; consinder updating fileExtensionPreference."; - $self->logger($message,'heading'); - $self->output_logfile; + $logger->fatal("*$message"); die($message); } # if no extension, search according to fileExtensionPreference - if (!$ext) { - $self->logger("File extension work:",'heading'); - $self->logger("latexindent called to act upon $fileName with an, as yet, unrecognised file extension;"); - $self->logger("searching for file with an extension in the following order (see fileExtensionPreference):"); - $self->logger(join("\n",@fileExtensions)); - - my $fileFound = 0; - # loop through the known file extensions (see @fileExtensions) - foreach (@fileExtensions ){ - if ( -e $fileName.$_ ) { - $self->logger("$fileName$_ found!"); - $fileName .= $_; - $self->logger("Updated fileName to $fileName"); - ${$self}{fileName} = $fileName ; - $fileFound = 1; - $ext = $_; - last; + if ($fileName ne "-"){ + if (!$ext) { + $logger->info("*File extension work:"); + $logger->info("latexindent called to act upon $fileName with a file extension;\nsearching for file with an extension in the following order (see fileExtensionPreference):"); + $logger->info(join("\n",@fileExtensions)); + + my $fileFound = 0; + # loop through the known file extensions (see @fileExtensions) + foreach (@fileExtensions ){ + if ( -e $fileName.$_ ) { + $logger->info("$fileName$_ found!"); + $fileName .= $_; + $logger->info("Updated fileName to $fileName"); + ${$self}{fileName} = $fileName ; + $fileFound = 1; + $ext = $_; + last; + } + } + unless($fileFound){ + $logger->fatal("*I couldn't find a match for $fileName in fileExtensionPreference (see defaultSettings.yaml)"); + foreach (@fileExtensions ){ + $logger->fatal("I searched for $fileName$_"); + } + $logger->fatal("but couldn't find any of them.\nConsider updating fileExtensionPreference.\nExiting, no indendation done."); + die "I couldn't find a match for $fileName in fileExtensionPreference.\nExiting, no indendation done."; + } + } else { + # if the file has a recognised extension, check that the file exists + unless( -e $fileName ){ + my $message = "I couldn't find $fileName, are you sure it exists?.\nNo indentation done.\nExiting."; + $logger->fatal("*$message"); + die $message; } - } - unless($fileFound){ - $self->logger("I couldn't find a match for $fileName in fileExtensionPreference (see defaultSettings.yaml)"); - foreach (@fileExtensions ){ - $self->logger("I searched for $fileName$_"); } - $self->logger("but couldn't find any of them."); - $self->logger("Consider updating fileExtensionPreference. Error: Exiting, no indendation done."); - $self->output_logfile; - die "I couldn't find a match for $fileName in fileExtensionPreference.\nExiting, no indendation done."; - } - } else { - # if the file has a recognised extension, check that the file exists - unless( -e $fileName ){ - my $message = "Error: I couldn't find $fileName, are you sure it exists?. No indentation done. Exiting."; - $self->logger($message); - $self->output_logfile; - die $message; - } - } + } # store the file extension ${$self}{fileExtension} = $ext; @@ -95,53 +96,62 @@ sub file_extension_check{ # check to see if -o switch is active if($switches{outputToFile}){ - $self->logger("Output file check",'heading'); + $logger->info("*-o switch active: output file check"); + if ($fileName eq "-" and $switches{outputToFile} =~ m/^\+/){ + $logger->info("STDIN input mode active, -o switch is removing all + symbols"); + $switches{outputToFile} =~ s/\+//g; + } # the -o file name might begin with a + symbol if($switches{outputToFile} =~ m/^\+(.*)/ and $1 ne "+"){ - $self->logger("-o switch called with + symbol at the beginning: $switches{outputToFile}"); + $logger->info("-o switch called with + symbol at the beginning: $switches{outputToFile}"); $switches{outputToFile} = ${$self}{baseName}.$1; - $self->logger("output file is now: $switches{outputToFile}"); + $logger->info("output file is now: $switches{outputToFile}"); } my $strippedFileExtension = ${$self}{fileExtension}; $strippedFileExtension =~ s/\.//; + $strippedFileExtension = "tex" if ($strippedFileExtension eq ""); # grab the name, directory, and extension of the output file my ($name, $dir, $ext) = fileparse($switches{outputToFile}, $strippedFileExtension); # if there is no extension, then add the extension from the file to be operated upon if(!$ext){ - $self->logger("-o switch called with file name without extension: $switches{outputToFile}"); + $logger->info("-o switch called with file name without extension: $switches{outputToFile}"); $switches{outputToFile} = $name.($name=~m/\.\z/ ? q() : ".").$strippedFileExtension; - $self->logger("Updated to $switches{outputToFile} as the file extension of the input file is $strippedFileExtension"); + $logger->info("Updated to $switches{outputToFile} as the file extension of the input file is $strippedFileExtension"); } # the -o file name might end with ++ in which case we wish to search for existence, # and then increment accordingly $name =~ s/\.$//; if($name =~ m/\+\+$/){ - $self->logger("-o switch called with file name ending with ++: $switches{outputToFile}"); + $logger->info("-o switch called with file name ending with ++: $switches{outputToFile}"); $name =~ s/\+\+$//; $name = ${$self}{baseName} if ($name eq ""); my $outputFileCounter = 0; my $fileName = $name.$outputFileCounter.".".$strippedFileExtension; - $self->logger("will search for exisitence and increment counter, starting with $fileName"); + $logger->info("will search for existence and increment counter, starting with $fileName"); while( -e $fileName ){ - $self->logger("$fileName exists, incrementing counter"); + $logger->info("$fileName exists, incrementing counter"); $outputFileCounter++; $fileName = $name.$outputFileCounter.".".$strippedFileExtension; } - $self->logger("$fileName does not exist, and will be the output file"); + $logger->info("$fileName does not exist, and will be the output file"); $switches{outputToFile} = $fileName; } } # read the file into the Document body my @lines; - open(MAINFILE, $fileName) or die "Could not open input file, $fileName"; - push(@lines,$_) while(<MAINFILE>); - close(MAINFILE); + if($fileName ne "-"){ + open(MAINFILE, $fileName) or die "Could not open input file, $fileName"; + push(@lines,$_) while(<MAINFILE>); + close(MAINFILE); + } else { + push(@lines,$_) while (<>) + } # the all-important step: update the body ${$self}{body} = join("",@lines); diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/GetYamlSettings.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/GetYamlSettings.pm index bb0e47f2576..5f86e0008f5 100644 --- a/Master/texmf-dist/scripts/latexindent/LatexIndent/GetYamlSettings.pm +++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/GetYamlSettings.pm @@ -20,6 +20,7 @@ use LatexIndent::Switches qw/%switches $is_m_switch_active $is_t_switch_active $ use YAML::Tiny; # interpret defaultSettings.yaml and other potential settings files use File::Basename; # to get the filename and directory path use File::HomeDir; +use Log::Log4perl qw(get_logger :levels); use Exporter qw/import/; our @EXPORT_OK = qw/readSettings modify_line_breaks_settings get_indentation_settings_for_this_object get_every_or_custom_value get_indentation_information get_object_attribute_for_indentation_settings alignment_at_ampersand_settings %masterSettings/; @@ -32,18 +33,32 @@ our %masterSettings; # previously found settings is a hash, global to this module our %previouslyFoundSettings; +# default values for align at ampersand routine +our @alignAtAmpersandInformation = ( {name=>"lookForAlignDelims",yamlname=>"delims",default=>1}, + {name=>"alignDoubleBackSlash",default=>1}, + {name=>"spacesBeforeDoubleBackSlash",default=>1}, + {name=>"multiColumnGrouping",default=>0}, + {name=>"alignRowsWithoutMaxDelims",default=>1}, + {name=>"spacesBeforeAmpersand",default=>1}, + {name=>"spacesAfterAmpersand",default=>1}, + {name=>"justification",default=>"left"}, + ); + sub readSettings{ my $self = shift; + # read the default settings $defaultSettings = YAML::Tiny->read( "$FindBin::RealBin/defaultSettings.yaml" ); - $self->logger("YAML settings read: defaultSettings.yaml",'heading'); - $self->logger("Reading defaultSettings.yaml from $FindBin::RealBin/defaultSettings.yaml"); + + # grab the logger object + my $logger = get_logger("Document"); + $logger->info("*YAML settings read: defaultSettings.yaml\nReading defaultSettings.yaml from $FindBin::RealBin/defaultSettings.yaml"); # if latexindent.exe is invoked from TeXLive, then defaultSettings.yaml won't be in # the same directory as it; we need to navigate to it if(!$defaultSettings) { $defaultSettings = YAML::Tiny->read( "$FindBin::RealBin/../../texmf-dist/scripts/latexindent/defaultSettings.yaml"); - $self->logger("Reading defaultSettings.yaml (2nd attempt, TeXLive, Windows) from $FindBin::RealBin/../../texmf-dist/scripts/latexindent/defaultSettings.yaml"); + $logger->info("Reading defaultSettings.yaml (2nd attempt, TeXLive, Windows) from $FindBin::RealBin/../../texmf-dist/scripts/latexindent/defaultSettings.yaml"); } # need to exit if we can't get defaultSettings.yaml @@ -60,7 +75,7 @@ sub readSettings{ # we'll need the home directory a lot in what follows my $homeDir = File::HomeDir->my_home; - $self->logger("YAML settings read: indentconfig.yaml or .indentconfig.yaml",'heading'); + $logger->info("*YAML settings read: indentconfig.yaml or .indentconfig.yaml") unless $switches{onlyDefault}; # get information about user settings- first check if indentconfig.yaml exists my $indentconfig = "$homeDir/indentconfig.yaml"; @@ -70,39 +85,39 @@ sub readSettings{ # messages for indentconfig.yaml and/or .indentconfig.yaml if ( -e $indentconfig and !$switches{onlyDefault}) { - $self->logger("Reading path information from $indentconfig"); + $logger->info("Reading path information from $indentconfig"); # if both indentconfig.yaml and .indentconfig.yaml exist if ( -e File::HomeDir->my_home . "/indentconfig.yaml" and -e File::HomeDir->my_home . "/.indentconfig.yaml") { - $self->logger("$homeDir/.indentconfig.yaml has been found, but $indentconfig takes priority"); + $logger->info("$homeDir/.indentconfig.yaml has been found, but $indentconfig takes priority"); } elsif ( -e File::HomeDir->my_home . "/indentconfig.yaml" ) { - $self->logger("(Alternatively $homeDir/.indentconfig.yaml can be used)"); + $logger->info("(Alternatively $homeDir/.indentconfig.yaml can be used)"); } elsif ( -e File::HomeDir->my_home . "/.indentconfig.yaml" ) { - $self->logger("(Alternatively $homeDir/indentconfig.yaml can be used)"); + $logger->info("(Alternatively $homeDir/indentconfig.yaml can be used)"); } - + # read the absolute paths from indentconfig.yaml $userSettings = YAML::Tiny->read( "$indentconfig" ); # output the contents of indentconfig to the log file - $self->logger(Dump \%{$userSettings->[0]}); - + $logger->info(Dump \%{$userSettings->[0]}); + # update the absolute paths @absPaths = @{$userSettings->[0]->{paths}}; } else { if($switches{onlyDefault}) { - $self->logger("Only default settings requested, not reading USER settings from $indentconfig"); - $self->logger("Ignoring $switches{readLocalSettings} (you used the -d switch)") if($switches{readLocalSettings}); - $self->logger("Ignoring the -y switch: $switches{yaml} (you used the -d switch)") if($switches{yaml}); + $logger->info("*-d switch active: only default settings requested"); + $logger->info("not reading USER settings from $indentconfig") if (-e $indentconfig); + $logger->info("Ignoring the -l switch: $switches{readLocalSettings} (you used the -d switch)") if($switches{readLocalSettings}); + $logger->info("Ignoring the -y switch: $switches{yaml} (you used the -d switch)") if($switches{yaml}); $switches{readLocalSettings}=0; $switches{yaml}=0; } else { # give the user instructions on where to put indentconfig.yaml or .indentconfig.yaml - $self->logger("Home directory is $homeDir (didn't find either indentconfig.yaml or .indentconfig.yaml)"); - $self->logger("To specify user settings you would put indentconfig.yaml here: $homeDir/indentconfig.yaml"); - $self->logger("Alternatively, you can use the hidden file .indentconfig.yaml as: $homeDir/.indentconfig.yaml"); + $logger->info("Home directory is $homeDir (didn't find either indentconfig.yaml or .indentconfig.yaml)\nTo specify user settings you would put indentconfig.yaml here: $homeDir/indentconfig.yaml\nAlternatively, you can use the hidden file .indentconfig.yaml as: $homeDir/.indentconfig.yaml"); } } + # local settings can be called with a + symbol, for example # -l=+myfile.yaml # -l "+ myfile.yaml" @@ -117,20 +132,20 @@ sub readSettings{ # will *only* load localSettings.yaml, and myfile.yaml will be ignored my @localSettings; - $self->logger("YAML settings read: -l switch",'heading') if $switches{readLocalSettings}; + $logger->info("*YAML settings read: -l switch") if $switches{readLocalSettings}; # remove leading, trailing, and intermediate space $switches{readLocalSettings} =~ s/^\h*//g; $switches{readLocalSettings} =~ s/\h*$//g; $switches{readLocalSettings} =~ s/\h*,\h*/,/g; if($switches{readLocalSettings} =~ m/\+/){ - $self->logger("+ found in call for -l switch: will add localSettings.yaml"); + $logger->info("+ found in call for -l switch: will add localSettings.yaml"); # + can be either at the beginning or the end, which determines if where the comma should go my $commaAtBeginning = ($switches{readLocalSettings} =~ m/^\h*\+/ ? q() : ","); my $commaAtEnd = ($switches{readLocalSettings} =~ m/^\h*\+/ ? "," : q()); $switches{readLocalSettings} =~ s/\h*\+\h*/$commaAtBeginning."localSettings.yaml".$commaAtEnd/e; - $self->logger("New value of -l switch: $switches{readLocalSettings}"); + $logger->info("New value of -l switch: $switches{readLocalSettings}"); } # local settings can be separated by , @@ -138,8 +153,9 @@ sub readSettings{ # -l = myyaml1.yaml,myyaml2.yaml # and in which case, we need to read them all if($switches{readLocalSettings} =~ m/,/){ - $self->logger("Multiple localSettings found, separated by commas:"); + $logger->info("Multiple localSettings found, separated by commas:"); @localSettings = split(/,/,$switches{readLocalSettings}); + $logger->info(join(', ',@localSettings)); } else { push(@localSettings,$switches{readLocalSettings}) if($switches{readLocalSettings}); } @@ -161,21 +177,21 @@ sub readSettings{ # check for existence and non-emptiness if ( (-e $_) and !(-z $_)) { - $self->logger("Adding $_ to YAML read paths"); + $logger->info("Adding $_ to YAML read paths"); push(@absPaths,"$_"); } elsif ( !(-e $_) ) { - $self->logger("WARNING yaml file not found: $_ not found. Proceeding without it."); + $logger->warn("*yaml file not found: $_ not found. Proceeding without it."); } } # heading for the log file - $self->logger("YAML settings, reading from the following files:",'heading') if @absPaths; + $logger->info("*YAML settings, reading from the following files:") if @absPaths; # read in the settings from each file foreach my $settings (@absPaths) { # check that the settings file exists and that it isn't empty if (-e $settings and !(-z $settings)) { - $self->logger("Reading USER settings from $settings"); + $logger->info("Reading USER settings from $settings"); $userSettings = YAML::Tiny->read( "$settings" ); # if we can read userSettings @@ -189,14 +205,14 @@ sub readSettings{ # if masterSettings already contains a *scalar* value in secondLevelKey # then we need to delete it (test-cases/headings-first.tex with indentRules1.yaml first demonstrated this) if(ref $masterSettings{$firstLevelKey}{$secondLevelKey} ne "HASH"){ - $self->logger("masterSettings{$firstLevelKey}{$secondLevelKey} currently contains a *scalar* value, but it needs to be updated with a hash (see $settings); deleting the scalar") if($is_t_switch_active); + $logger->trace("*masterSettings{$firstLevelKey}{$secondLevelKey} currently contains a *scalar* value, but it needs to be updated with a hash (see $settings); deleting the scalar") if($is_t_switch_active); delete $masterSettings{$firstLevelKey}{$secondLevelKey} ; } while(my ($thirdLevelKey,$thirdLevelValue) = each %{$secondLevelValue}) { if (ref $thirdLevelValue eq "HASH"){ # similarly for third level if (ref $masterSettings{$firstLevelKey}{$secondLevelKey}{$thirdLevelKey} ne "HASH"){ - $self->logger("masterSettings{$firstLevelKey}{$secondLevelKey}{$thirdLevelKey} currently contains a *scalar* value, but it needs to be updated with a hash (see $settings); deleting the scalar") if($is_t_switch_active); + $logger->trace("*masterSettings{$firstLevelKey}{$secondLevelKey}{$thirdLevelKey} currently contains a *scalar* value, but it needs to be updated with a hash (see $settings); deleting the scalar") if($is_t_switch_active); delete $masterSettings{$firstLevelKey}{$secondLevelKey}{$thirdLevelKey} ; } while(my ($fourthLevelKey,$fourthLevelValue) = each %{$thirdLevelValue}) { @@ -217,21 +233,21 @@ sub readSettings{ # output settings to $logfile if($masterSettings{logFilePreferences}{showEveryYamlRead}){ - $self->logger(Dump \%{$userSettings->[0]}); + $logger->info(Dump \%{$userSettings->[0]}); } else { - $self->logger("Not showing settings in the log file (see showEveryYamlRead and showAmalgamatedSettings)."); + $logger->info("Not showing settings in the log file (see showEveryYamlRead and showAmalgamatedSettings)."); } } else { # otherwise print a warning that we can not read userSettings.yaml - $self->logger("WARNING $settings contains invalid yaml format- not reading from it"); + $logger->warn("*$settings contains invalid yaml format- not reading from it"); } } else { # otherwise keep going, but put a warning in the log file - $self->logger("WARNING: $homeDir/indentconfig.yaml"); + $logger->warn("*$homeDir/indentconfig.yaml"); if (-z $settings) { - $self->logger("specifies $settings but this file is EMPTY -- not reading from it"); + $logger->info("specifies $settings but this file is EMPTY -- not reading from it"); } else { - $self->logger("specifies $settings but this file does not exist - unable to read settings from this file"); + $logger->info("specifies $settings but this file does not exist - unable to read settings from this file"); } } } @@ -239,16 +255,16 @@ sub readSettings{ # read settings from -y|--yaml switch if($switches{yaml}){ # report to log file - $self->logger("YAML settings read: -y switch",'heading'); + $logger->info("*YAML settings read: -y switch"); # remove any horizontal space before or after , OR : OR ; or at the beginning or end of the switch value - $switches{yaml} =~ s/\h*(,|:|;)\h*/$1/g; + $switches{yaml} =~ s/\h*(,|(?<!\\):|;)\h*/$1/g; $switches{yaml} =~ s/^\h*//g; # store settings, possibly multiple ones split by commas my @yamlSettings; - if($switches{yaml} =~ m/,/){ - @yamlSettings = split(/,/,$switches{yaml}); + if($switches{yaml} =~ m/(?<!\\),/){ + @yamlSettings = split(/(?<!\\),/,$switches{yaml}); } else { push(@yamlSettings,$switches{yaml}); } @@ -274,8 +290,8 @@ sub readSettings{ $settingsCounter++; # check for a match of the ; - if($_ =~ m/;/){ - my (@subfield) = split(/;/,$_); + if($_ =~ m/(?<!\\);/){ + my (@subfield) = split(/(?<!\\);/,$_); # the content up to the first ; is called the 'root' my $root = shift @subfield; @@ -312,7 +328,7 @@ sub readSettings{ # reform the root $root = join(":",@keysValues); - $self->logger("Sub-field detected (; present) and the root is: $root") if $is_t_switch_active; + $logger->trace("*Sub-field detected (; present) and the root is: $root") if $is_t_switch_active; # now we need to attach the $root back together with any subfields foreach(@subfield){ @@ -322,18 +338,22 @@ sub readSettings{ # increment the counter $settingsCounter++; } - $self->logger("-y switch value interpreted as: ".join(',',@yamlSettings)); + $logger->info("-y switch value interpreted as: ".join(',',@yamlSettings)); } } # loop through each of the settings specified in the -y switch foreach(@yamlSettings){ # split each value at semi-colon - my (@keysValues) = split(/:/,$_); + my (@keysValues) = split(/(?<!\\):/,$_); # $value will always be the last element my $value = $keysValues[-1]; + # it's possible that the 'value' will contain an escaped + # semi-colon, so we replace it with just a semi-colon + $value =~ s/\\:/:/; + # horizontal space needs special treatment if($value =~ m/^(?:"|')(\h*)(?:"|')$/){ # pure horizontal space @@ -348,20 +368,20 @@ sub readSettings{ if(scalar(@keysValues) == 2){ # for example, -y="defaultIndent: ' '" my $key = $keysValues[0]; - $self->logger("Updating masterSettings with $key: $value"); + $logger->info("Updating masterSettings with $key: $value"); $masterSettings{$key} = $value; } elsif(scalar(@keysValues) == 3){ # for example, -y="indentRules: one: '\t\t\t\t'" my $parent = $keysValues[0]; my $child = $keysValues[1]; - $self->logger("Updating masterSettings with $parent: $child: $value"); + $logger->info("Updating masterSettings with $parent: $child: $value"); $masterSettings{$parent}{$child} = $value; } elsif(scalar(@keysValues) == 4){ # for example, -y='modifyLineBreaks : environments: EndStartsOnOwnLine:3' -m my $parent = $keysValues[0]; my $child = $keysValues[1]; my $grandchild = $keysValues[2]; - $self->logger("Updating masterSettings with $parent: $child: $grandchild: $value"); + $logger->info("Updating masterSettings with $parent: $child: $grandchild: $value"); $masterSettings{$parent}{$child}{$grandchild} = $value; } elsif(scalar(@keysValues) == 5){ # for example, -y='modifyLineBreaks : environments: one: EndStartsOnOwnLine:3' -m @@ -369,7 +389,7 @@ sub readSettings{ my $child = $keysValues[1]; my $grandchild = $keysValues[2]; my $greatgrandchild = $keysValues[3]; - $self->logger("Updating masterSettings with $parent: $child: $grandchild: $greatgrandchild: $value"); + $logger->info("Updating masterSettings with $parent: $child: $grandchild: $greatgrandchild: $value"); $masterSettings{$parent}{$child}{$grandchild}{$greatgrandchild} = $value; } } @@ -379,8 +399,8 @@ sub readSettings{ # which details the overall state of the settings modified # from the default in various user files if($masterSettings{logFilePreferences}{showAmalgamatedSettings}){ - $self->logger("Amalgamated/overall settings to be used:",'heading'); - $self->logger(Dump \%masterSettings); + $logger->info("Amalgamated/overall settings to be used:"); + $logger->info(Dump \%masterSettings); } return; @@ -392,12 +412,15 @@ sub get_indentation_settings_for_this_object{ # create a name for previously found settings my $storageName = ${$self}{name}.${$self}{modifyLineBreaksYamlName}.(defined ${$self}{storageNameAppend}?${$self}{storageNameAppend}:q()); + # grab the logging object + my $logger = get_logger("Document"); + # check for storage of repeated objects if ($previouslyFoundSettings{$storageName}){ - $self->logger("Using stored settings for $storageName") if($is_t_switch_active); + $logger->trace("*Using stored settings for $storageName") if($is_t_switch_active); } else { my $name = ${$self}{name}; - $self->logger("Storing settings for $storageName") if($is_t_switch_active); + $logger->trace("Storing settings for $storageName") if($is_t_switch_active); # check for noAdditionalIndent and indentRules # otherwise use defaultIndent @@ -420,11 +443,9 @@ sub get_indentation_settings_for_this_object{ ); # don't forget alignment settings! - ${${previouslyFoundSettings}{$storageName}}{lookForAlignDelims} = ${$self}{lookForAlignDelims} if(defined ${$self}{lookForAlignDelims}); - ${${previouslyFoundSettings}{$storageName}}{alignDoubleBackSlash} = ${$self}{alignDoubleBackSlash} if(defined ${$self}{alignDoubleBackSlash}); - ${${previouslyFoundSettings}{$storageName}}{spacesBeforeDoubleBackSlash} = ${$self}{spacesBeforeDoubleBackSlash} if(defined ${$self}{spacesBeforeDoubleBackSlash}); - ${${previouslyFoundSettings}{$storageName}}{multiColumnGrouping} = ${$self}{multiColumnGrouping} if(defined ${$self}{multiColumnGrouping}); - ${${previouslyFoundSettings}{$storageName}}{alignRowsWithoutMaxDelims} = ${$self}{alignRowsWithoutMaxDelims} if(defined ${$self}{alignRowsWithoutMaxDelims}); + foreach (@alignAtAmpersandInformation){ + ${${previouslyFoundSettings}{$storageName}}{${$_}{name}} = ${$self}{${$_}{name}} if(defined ${$self}{${$_}{name}}); + } # some objects, e.g ifElseFi, can have extra assignments, e.g ElseStartsOnOwnLine # these need to be stored as well! @@ -432,6 +453,10 @@ sub get_indentation_settings_for_this_object{ ${${previouslyFoundSettings}{$storageName}}{$_} = ${$self}{$_}; } + # log file information + $logger->trace("Settings for $name (stored for future use):") if $is_tt_switch_active; + $logger->trace(Dump \%{${previouslyFoundSettings}{$storageName}}) if $is_tt_switch_active; + } # append indentation settings to the current object @@ -461,17 +486,25 @@ sub alignment_at_ampersand_settings{ return unless ${$masterSettings{lookForAlignDelims}}{$name}; if(ref ${$masterSettings{lookForAlignDelims}}{$name} eq "HASH"){ - ${$self}{lookForAlignDelims} = (defined ${${$masterSettings{lookForAlignDelims}}{$name}}{delims} ) ? ${${$masterSettings{lookForAlignDelims}}{$name}}{delims} : 1; - ${$self}{alignDoubleBackSlash} = (defined ${${$masterSettings{lookForAlignDelims}}{$name}}{alignDoubleBackSlash} ) ? ${${$masterSettings{lookForAlignDelims}}{$name}}{alignDoubleBackSlash} : 1; - ${$self}{spacesBeforeDoubleBackSlash} = (defined ${${$masterSettings{lookForAlignDelims}}{$name}}{spacesBeforeDoubleBackSlash} ) ? ${${$masterSettings{lookForAlignDelims}}{$name}}{spacesBeforeDoubleBackSlash} : -1; - ${$self}{multiColumnGrouping} = (defined ${${$masterSettings{lookForAlignDelims}}{$name}}{multiColumnGrouping} ) ? ${${$masterSettings{lookForAlignDelims}}{$name}}{multiColumnGrouping} : 0; - ${$self}{alignRowsWithoutMaxDelims} = (defined ${${$masterSettings{lookForAlignDelims}}{$name}}{alignRowsWithoutMaxDelims} ) ? ${${$masterSettings{lookForAlignDelims}}{$name}}{alignRowsWithoutMaxDelims} : 1; + # specified as a hash, e.g + # + # lookForAlignDelims: + # tabular: + # delims: 1 + # alignDoubleBackSlash: 1 + # spacesBeforeDoubleBackSlash: 2 + foreach (@alignAtAmpersandInformation){ + my $yamlname = (defined ${$_}{yamlname} ? ${$_}{yamlname}: ${$_}{name}); + ${$self}{${$_}{name}} = (defined ${${$masterSettings{lookForAlignDelims}}{$name}}{$yamlname} ) ? ${${$masterSettings{lookForAlignDelims}}{$name}}{$yamlname} : ${$_}{default}; + } } else { - ${$self}{lookForAlignDelims} = 1; - ${$self}{alignDoubleBackSlash} = 1; - ${$self}{spacesBeforeDoubleBackSlash} = -1; - ${$self}{multiColumnGrouping} = 0; - ${$self}{alignRowsWithoutMaxDelims} = 1; + # specified as a scalar, e.g + # + # lookForAlignDelims: + # tabular: 1 + foreach (@alignAtAmpersandInformation){ + ${$self}{${$_}{name}} = ${$_}{default}; + } } return; } @@ -482,8 +515,11 @@ sub modify_line_breaks_settings{ my $self = shift; + # grab the logging object + my $logger = get_logger("Document"); + # details to the log file - $self->logger("-m modifylinebreaks switch active, looking for settings for ${$self}{name} ",'heading') if $is_t_switch_active; + $logger->trace("*-m modifylinebreaks switch active, looking for settings for ${$self}{name} ") if $is_t_switch_active; # some objects, e.g ifElseFi, can have extra assignments, e.g ElseStartsOnOwnLine my @toBeAssignedTo = ${$self}{additionalAssignments} ? @{${$self}{additionalAssignments}} : (); @@ -522,11 +558,11 @@ sub modify_line_breaks_settings{ my $name = ($YamlName =~ m/Arguments/) ? ${$self}{parent} : ${$self}{name}; if(ref ${$masterSettings{modifyLineBreaks}{removeParagraphLineBreaks}}{$YamlName} eq "HASH"){ - $self->logger("$YamlName specified with fields in removeParagraphLineBreaks, looking for $name") if $is_t_switch_active; + $logger->trace("*$YamlName specified with fields in removeParagraphLineBreaks, looking for $name") if $is_t_switch_active; ${$self}{removeParagraphLineBreaks} = ${${$masterSettings{modifyLineBreaks}{removeParagraphLineBreaks}}{$YamlName}}{$name}||0; } else { if(defined ${$masterSettings{modifyLineBreaks}{removeParagraphLineBreaks}}{$YamlName}){ - $self->logger("$YamlName specified with just a number in removeParagraphLineBreaks ${$masterSettings{modifyLineBreaks}{removeParagraphLineBreaks}}{$YamlName}") if $is_t_switch_active; + $logger->trace("*$YamlName specified with just a number in removeParagraphLineBreaks ${$masterSettings{modifyLineBreaks}{removeParagraphLineBreaks}}{$YamlName}") if $is_t_switch_active; ${$self}{removeParagraphLineBreaks} = ${$masterSettings{modifyLineBreaks}{removeParagraphLineBreaks}}{$YamlName}; } } @@ -540,9 +576,12 @@ sub get_every_or_custom_value{ my $toBeAssignedTo = $input{toBeAssignedTo}; my $toBeAssignedToAlias = $input{toBeAssignedToAlias}; + # grab the logging object + my $logger = get_logger("Document"); + # alias if(${$self}{aliases}{$toBeAssignedTo}){ - $self->logger("aliased $toBeAssignedTo using ${$self}{aliases}{$toBeAssignedTo}") if($is_t_switch_active); + $logger->trace("aliased $toBeAssignedTo using ${$self}{aliases}{$toBeAssignedTo}") if($is_t_switch_active); } # name of the object in the modifyLineBreaks yaml (e.g environments, ifElseFi, etc) @@ -557,12 +596,12 @@ sub get_every_or_custom_value{ # check for the *custom* value if (defined $customValue){ - $self->logger("$name: $toBeAssignedToAlias=$customValue, (*custom* value) adjusting $toBeAssignedTo") if($is_t_switch_active); + $logger->trace("$name: $toBeAssignedToAlias=$customValue, (*custom* value) adjusting $toBeAssignedTo") if($is_t_switch_active); ${$self}{$toBeAssignedTo} = $customValue !=0 ? $customValue : undef; } else { # check for the *every* value if (defined $everyValue and $everyValue != 0){ - $self->logger("$name: $toBeAssignedToAlias=$everyValue, (*every* value) adjusting $toBeAssignedTo") if($is_t_switch_active); + $logger->trace("$name: $toBeAssignedToAlias=$everyValue, (*every* value) adjusting $toBeAssignedTo") if($is_t_switch_active); ${$self}{$toBeAssignedTo} = $everyValue; } } @@ -619,24 +658,27 @@ sub get_indentation_information{ # if the YamlName is not optionalArguments, mandatoryArguments, heading (possibly others) then assume we're looking for 'body' my $YamlName = $self->get_object_attribute_for_indentation_settings; + # grab the logging object + my $logger = get_logger("Document"); + my $indentationInformation; foreach my $indentationAbout ("noAdditionalIndent","indentRules"){ # check that the 'thing' is defined if(defined ${$masterSettings{$indentationAbout}}{$name}){ if(ref ${$masterSettings{$indentationAbout}}{$name} eq "HASH"){ - $self->logger("$indentationAbout indentation specified with multiple fields for $name, searching for $name: $YamlName (see $indentationAbout)") if $is_t_switch_active ; + $logger->trace("$indentationAbout indentation specified with multiple fields for $name, searching for $name: $YamlName (see $indentationAbout)") if $is_t_switch_active ; $indentationInformation = ${${$masterSettings{$indentationAbout}}{$name}}{$YamlName}; } else { $indentationInformation = ${$masterSettings{$indentationAbout}}{$name}; - $self->logger("$indentationAbout indentation specified for $name (for *all* fields, body, optionalArguments, mandatoryArguments, afterHeading), using '$indentationInformation' (see $indentationAbout)") if $is_t_switch_active ; + $logger->trace("$indentationAbout indentation specified for $name (for *all* fields, body, optionalArguments, mandatoryArguments, afterHeading), using '$indentationInformation' (see $indentationAbout)") if $is_t_switch_active ; } # return, after performing an integrity check if(defined $indentationInformation){ if($indentationAbout eq "noAdditionalIndent" and $indentationInformation == 1){ - $self->logger("Found! Using '' (see $indentationAbout)") if $is_t_switch_active; + $logger->trace("Found! Using '' (see $indentationAbout)") if $is_t_switch_active; return q(); } elsif($indentationAbout eq "indentRules" and $indentationInformation=~m/^\h*$/){ - $self->logger("Found! Using '$indentationInformation' (see $indentationAbout)") if $is_t_switch_active; + $logger->trace("Found! Using '$indentationInformation' (see $indentationAbout)") if $is_t_switch_active; return $indentationInformation ; } } @@ -651,20 +693,20 @@ sub get_indentation_information{ my $globalInformation = $indentationAbout."Global"; next if(!(defined ${$masterSettings{$globalInformation}}{$YamlName})); if( ($globalInformation eq "noAdditionalIndentGlobal") and ${$masterSettings{$globalInformation}}{$YamlName}==1){ - $self->logger("$globalInformation specified for $YamlName (see $globalInformation)") if $is_t_switch_active; + $logger->trace("$globalInformation specified for $YamlName (see $globalInformation)") if $is_t_switch_active; return q(); } elsif($globalInformation eq "indentRulesGlobal") { if(${$masterSettings{$globalInformation}}{$YamlName}=~m/^\h*$/){ - $self->logger("$globalInformation specified for $YamlName (see $globalInformation)") if $is_t_switch_active; + $logger->trace("$globalInformation specified for $YamlName (see $globalInformation)") if $is_t_switch_active; return ${$masterSettings{$globalInformation}}{$YamlName}; } else { - $self->logger("$globalInformation specified (${$masterSettings{$globalInformation}}{$YamlName}) for $YamlName, but it needs to only contain horizontal space -- I'm ignoring this one") if $is_t_switch_active; + $logger->trace("$globalInformation specified (${$masterSettings{$globalInformation}}{$YamlName}) for $YamlName, but it needs to only contain horizontal space -- I'm ignoring this one") if $is_t_switch_active; } } } # return defaultIndent, by default - $self->logger("Using defaultIndent for $name") if $is_t_switch_active; + $logger->trace("Using defaultIndent for $name") if $is_t_switch_active; return $masterSettings{defaultIndent}; } diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/Heading.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/Heading.pm index 9a2f7187531..3dca1b7eefb 100644 --- a/Master/texmf-dist/scripts/latexindent/LatexIndent/Heading.pm +++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/Heading.pm @@ -20,6 +20,7 @@ use LatexIndent::Tokens qw/%tokens/; use LatexIndent::Switches qw/$is_m_switch_active $is_t_switch_active $is_tt_switch_active/; use LatexIndent::TrailingComments qw/$trailingCommentRegExp/; 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 @@ -35,20 +36,20 @@ sub construct_headings_levels{ my %headingsLevels = %{$masterSettings{indentAfterHeadings}}; # output to log file - $self->logger("Constructing headings reg exp for example, chapter, section, etc (see indentAfterThisHeading)") if $is_t_switch_active ; + $logger->trace("*Constructing headings reg exp for example, chapter, section, etc (see indentAfterThisHeading)") if $is_t_switch_active ; # delete the values that have indentAfterThisHeading set to 0 while( my ($headingName,$headingInfo)= each %headingsLevels){ if(!${$headingsLevels{$headingName}}{indentAfterThisHeading}){ - $self->logger("Not indenting after $headingName (see indentAfterThisHeading)",'heading') if $is_t_switch_active; + $logger->trace("Not indenting after $headingName (see indentAfterThisHeading)") if $is_t_switch_active; delete $headingsLevels{$headingName}; } else { - # *all heading* regexp, remembering put starred headings at the front of the regexp + # *all heading* regexp, remembering to put starred headings at the front of the regexp if($headingName =~ m/\*/){ - $self->logger("Putting $headingName at the beginning of the allHeadings regexp, as it contains a *") if $is_t_switch_active ; + $logger->trace("Putting $headingName at the beginning of the allHeadings regexp, as it contains a *") if $is_t_switch_active ; $allHeadingsRegexp = $headingName.($allHeadingsRegexp eq '' ?q():"|$allHeadingsRegexp"); } else { - $self->logger("Putting $headingName at the END of the allHeadings regexp, as it contains a *") if $is_t_switch_active ; + $logger->trace("Putting $headingName at the END of the allHeadings regexp") if $is_t_switch_active ; $allHeadingsRegexp .= ($allHeadingsRegexp eq '' ?q():"|").$headingName ; } } @@ -63,8 +64,8 @@ sub construct_headings_levels{ # it could be that @sortedByLevels is empty; return if !@sortedByLevels; - $self->logger("All headings regexp: $allHeadingsRegexp",'heading') if $is_t_switch_active; - $self->logger("Now to construct headings regexp for each level:",'heading') if $is_t_switch_active; + $logger->trace("*All headings regexp: $allHeadingsRegexp") if $is_tt_switch_active; + $logger->trace("*Now to construct headings regexp for each level:") if $is_t_switch_active; # loop through the levels, and create a regexp for each (min and max values are the first and last values respectively from sortedByLevels) for(my $i = ${$headingsLevels{$sortedByLevels[0]}}{level}; $i <= ${$headingsLevels{$sortedByLevels[-1]}}{level}; $i++ ){ @@ -75,10 +76,10 @@ sub construct_headings_levels{ foreach(@tmp){ # put starred headings at the front of the regexp if($_ =~ m/\*/){ - $self->logger("Putting $_ at the beginning of this regexp, as it contains a *") if $is_t_switch_active; + $logger->trace("Putting $_ at the beginning of this regexp (level $i), as it contains a *") if $is_t_switch_active; $headingsAtThisLevel = $_.($headingsAtThisLevel eq '' ?q():"|$headingsAtThisLevel"); } else { - $self->logger("Putting $_ at the END of this regexp, as it contains a *") if $is_t_switch_active; + $logger->trace("Putting $_ at the END of this regexp (level $i)") if $is_t_switch_active; $headingsAtThisLevel .= ($headingsAtThisLevel eq '' ?q():"|").$_ ; } } @@ -86,7 +87,7 @@ sub construct_headings_levels{ # make the stars escaped correctly $headingsAtThisLevel =~ s/\*/\\\*/g; push(@headingsRegexpArray,$headingsAtThisLevel); - $self->logger("Heading level regexp for level $i will contain: $headingsAtThisLevel") if $is_t_switch_active; + $logger->trace("Heading level regexp for level $i will contain: $headingsAtThisLevel") if $is_t_switch_active; } } } @@ -99,7 +100,7 @@ sub find_heading{ my $self = shift; # otherwise loop through the headings regexp - $self->logger("Searching for headings ") if $is_t_switch_active; + $logger->trace("*Searching ${$self}{name} for headings ") if $is_t_switch_active; # loop through each headings match; note that we need to # do it in *reverse* so as to ensure that the lower level headings get matched first of all @@ -120,7 +121,7 @@ sub find_heading{ while(${$self}{body} =~ m/$headingRegExp/){ # log file output - $self->logger("heading found: $2",'heading'); + $logger->trace("heading found: $2") if $is_t_switch_active; ${$self}{body} =~ s/ $headingRegExp @@ -154,7 +155,7 @@ sub get_replacement_text{ my $self = shift; # the replacement text for a heading (chapter, section, etc) needs to put the trailing part back in - $self->logger("Custom replacement text routine for heading ${$self}{name}"); + $logger->trace("Custom replacement text routine for ${$self}{name}") if $is_t_switch_active; ${$self}{replacementText} = ${$self}{id}.${$self}{afterbit}; delete ${$self}{afterbit}; } @@ -209,15 +210,15 @@ sub tasks_particular_to_each_object{ # # then we need to transfer this information to the heading object if($is_m_switch_active){ - $self->logger("Searching for linebreak preferences immediately infront of ${$self}{parent}",'heading'); + $logger->trace("Searching for linebreak preferences immediately infront of ${$self}{parent}") if $is_t_switch_active; foreach(@{${$self}{children}}){ if(${$_}{name} eq ${$self}{parent}){ - $self->logger("Named child found: ${$_}{name}"); + $logger->trace("Named child found: ${$_}{name}") if $is_t_switch_active; if(defined ${$_}{BeginStartsOnOwnLine}){ - $self->logger("Transferring information from ${$_}{id} (${$_}{name}) to ${$self}{id} (${$self}{name}) for BeginStartsOnOwnLine"); + $logger->trace("Transferring information from ${$_}{id} (${$_}{name}) to ${$self}{id} (${$self}{name}) for BeginStartsOnOwnLine") if $is_t_switch_active; ${$self}{BeginStartsOnOwnLine} = ${$_}{BeginStartsOnOwnLine}; } else { - $self->logger("No information found in ${$_}{name} for BeginStartsOnOwnLine"); + $logger->trace("No information found in ${$_}{name} for BeginStartsOnOwnLine") if $is_t_switch_active; } last; } @@ -235,7 +236,7 @@ sub add_surrounding_indentation_to_begin_statement{ # but some (e.g HEADING) have their own method my $self = shift; - $self->logger("Adding surrounding indentation after (empty, by design!) begin statement of ${$self}{name} (${$self}{id})"); + $logger->trace("Adding surrounding indentation after (empty, by design!) begin statement of ${$self}{name} (${$self}{id})") if $is_t_switch_active; ${$self}{begin} .= ${$self}{surroundingIndentation}; # add indentation } diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/HiddenChildren.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/HiddenChildren.pm index 594e7dbd14e..af7d513809d 100644 --- a/Master/texmf-dist/scripts/latexindent/LatexIndent/HiddenChildren.pm +++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/HiddenChildren.pm @@ -18,6 +18,7 @@ use strict; use warnings; use LatexIndent::Switches qw/$is_t_switch_active $is_tt_switch_active/; use LatexIndent::Tokens qw/%tokens/; +use LatexIndent::LogFile qw/$logger/; use Data::Dumper; use Exporter qw/import/; our @EXPORT_OK = qw/find_surrounding_indentation_for_children update_family_tree get_family_tree check_for_hidden_children %familyTree/; @@ -71,23 +72,23 @@ sub find_surrounding_indentation_for_children{ my $self = shift; # output to logfile - $self->logger("FamilyTree before update:",'heading') if $is_t_switch_active; - $self->logger(Dumper(\%familyTree)) if($is_t_switch_active); + $logger->trace("*FamilyTree before update:") if $is_tt_switch_active; + $logger->trace(Dumper(\%familyTree)) if($is_tt_switch_active); # update the family tree with ancestors $self->update_family_tree; # output information to the logfile - $self->logger("FamilyTree after update:",'heading') if $is_t_switch_active; - $self->logger(Dumper(\%familyTree)) if($is_t_switch_active); + $logger->trace("*FamilyTree after update:") if $is_tt_switch_active; + $logger->trace(Dumper(\%familyTree)) if($is_tt_switch_active); while( my ($idToSearch,$ancestorToSearch) = each %familyTree){ - $self->logger("Hidden child ID: ,$idToSearch, here are its ancestors:",'heading') if $is_t_switch_active; + $logger->trace("*Hidden child ID: ,$idToSearch, here are its ancestors:") if $is_t_switch_active; foreach(@{${$ancestorToSearch}{ancestors}}){ - $self->logger("ID: ${$_}{ancestorID}") if($is_t_switch_active); + $logger->trace("ID: ${$_}{ancestorID}") if($is_t_switch_active); my $tmpIndentation = ref(${$_}{ancestorIndentation}) eq 'SCALAR'?${${$_}{ancestorIndentation}}:${$_}{ancestorIndentation}; $tmpIndentation = $tmpIndentation ? $tmpIndentation : q(); - $self->logger("indentation: '$tmpIndentation'") if($is_t_switch_active); + $logger->trace("indentation: '$tmpIndentation'") if($is_t_switch_active); } } @@ -98,19 +99,19 @@ sub update_family_tree{ my $self = shift; # loop through the hash - $self->logger("Updating FamilyTree...",'heading') if $is_t_switch_active; + $logger->trace("*Updating FamilyTree...") if $is_t_switch_active; while( my ($idToSearch,$ancestorToSearch)= each %familyTree){ foreach(@{${$ancestorToSearch}{ancestors}}){ my $ancestorID = ${$_}{ancestorID}; - $self->logger("current ID: $idToSearch, ancestor: $ancestorID") if($is_t_switch_active); + $logger->trace("current ID: $idToSearch, ancestor: $ancestorID") if($is_t_switch_active); if($familyTree{$ancestorID}){ - $self->logger("$ancestorID is a key within familyTree, grabbing its ancestors") if($is_t_switch_active); + $logger->trace("$ancestorID is a key within familyTree, grabbing its ancestors") if($is_t_switch_active); my $naturalAncestors = q(); foreach(@{${$familyTree{$idToSearch}}{ancestors}}){ $naturalAncestors .= "---".${$_}{ancestorID} if(${$_}{type} eq "natural"); } foreach(@{${$familyTree{$ancestorID}}{ancestors}}){ - $self->logger("ancestor of *hidden* child: ${$_}{ancestorID}") if($is_t_switch_active); + $logger->trace("ancestor of *hidden* child: ${$_}{ancestorID}") if($is_t_switch_active); my $newAncestorId = ${$_}{ancestorID}; my $type; if($naturalAncestors =~ m/$ancestorID/){ @@ -126,7 +127,7 @@ sub update_family_tree{ foreach(@{${$familyTree{$idToSearch}}{ancestors}}){ $naturalAncestors .= "---".${$_}{ancestorID} if(${$_}{type} eq "natural"); } - $self->logger("natural ancestors of $ancestorID: $naturalAncestors") if($is_t_switch_active); + $logger->trace("natural ancestors of $ancestorID: $naturalAncestors") if($is_t_switch_active); foreach(@{${$allChildren{$ancestorID}}{ancestors}}){ my $newAncestorId = ${$_}{ancestorID}; my $type; @@ -137,7 +138,7 @@ sub update_family_tree{ } my $matched = grep { $_->{ancestorID} eq $newAncestorId } @{${$familyTree{$idToSearch}}{ancestors}}; unless($matched){ - $self->logger("ancestor of UNHIDDEN child: ${$_}{ancestorID}") if($is_t_switch_active); + $logger->trace("ancestor of UNHIDDEN child: ${$_}{ancestorID}") if($is_t_switch_active); push(@{${$familyTree{$idToSearch}}{ancestors}},{ancestorID=>${$_}{ancestorID},ancestorIndentation=>${$_}{ancestorIndentation},type=>$type}); } } @@ -158,8 +159,8 @@ sub check_for_hidden_children{ my @matched = (${$self}{body} =~ /((?:$tokens{ifelsefiSpecial})?$tokens{beginOfToken}.[-a-z0-9]+?$tokens{endOfToken})/ig); # log file - $self->logger("Hidden children check") if $is_t_switch_active; - $self->logger(join("|",@matched)) if $is_t_switch_active; + $logger->trace("*Hidden children check") if $is_t_switch_active; + $logger->trace(join("|",@matched)) if $is_t_switch_active; my $naturalAncestors = ${$self}{naturalAncestors}; @@ -171,7 +172,7 @@ sub check_for_hidden_children{ my $newAncestorId = ${$_}{ancestorID}; unless (grep { $_->{ancestorID} eq $newAncestorId } @{${$familyTree{$match}}{ancestors}}){ my $type = ($naturalAncestors =~ m/${$_}{ancestorID}/ ) ? "natural" : "adopted"; - $self->logger("Adding ${$_}{ancestorID} to the $type family tree of $match") if($is_t_switch_active); + $logger->trace("Adding ${$_}{ancestorID} to the $type family tree of $match") if($is_t_switch_active); push(@{$familyTree{$match}{ancestors}},{ancestorID=>${$_}{ancestorID},ancestorIndentation=>${$_}{ancestorIndentation},type=>$type}); } } @@ -180,7 +181,7 @@ sub check_for_hidden_children{ # update the family tree with self unless (grep { $_->{ancestorID} eq ${$self}{id}} @{${$familyTree{$match}}{ancestors}}){ my $type = ($naturalAncestors =~ m/${$self}{id}/ ) ? "natural" : "adopted"; - $self->logger("Adding ${$self}{id} to the $type family tree of hiddenChild $match") if($is_t_switch_active); + $logger->trace("Adding ${$self}{id} to the $type family tree of hiddenChild $match") if($is_t_switch_active); push(@{$familyTree{$match}{ancestors}},{ancestorID=>${$self}{id},ancestorIndentation=>${$self}{indentation},type=>$type}); } } diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/HorizontalWhiteSpace.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/HorizontalWhiteSpace.pm index 09e96ecc879..9c5a04e2fb1 100644 --- a/Master/texmf-dist/scripts/latexindent/LatexIndent/HorizontalWhiteSpace.pm +++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/HorizontalWhiteSpace.pm @@ -18,6 +18,7 @@ use strict; use warnings; use LatexIndent::GetYamlSettings qw/%masterSettings/; use LatexIndent::Switches qw/$is_t_switch_active $is_tt_switch_active/; +use LatexIndent::LogFile qw/$logger/; use Exporter qw/import/; our @EXPORT_OK = qw/remove_trailing_whitespace remove_leading_space/; @@ -25,10 +26,12 @@ sub remove_trailing_whitespace{ my $self = shift; my %input = @_; + $logger->trace("*Horizontal space removal routine") if $is_t_switch_active; + # removeTrailingWhitespace can be either a hash or a scalar, but if # it's a scalar, we need to fix it if(ref($masterSettings{removeTrailingWhitespace}) ne 'HASH'){ - $self->logger("removeTrailingWhitespace specified as scalar, will update it to be a hash",'heading') if $is_t_switch_active; + $logger->trace("removeTrailingWhitespace specified as scalar, will update it to be a hash") if $is_t_switch_active; # grab the value my $removeTWS = $masterSettings{removeTrailingWhitespace}; @@ -38,17 +41,17 @@ sub remove_trailing_whitespace{ # redefine it as a hash ${$masterSettings{removeTrailingWhitespace}}{beforeProcessing} = $removeTWS; ${$masterSettings{removeTrailingWhitespace}}{afterProcessing} = $removeTWS; - $self->logger("removeTrailingWhitespace: beforeProcessing is now $removeTWS") if $is_t_switch_active; - $self->logger("removeTrailingWhitespace: afterProcessing is now $removeTWS") if $is_t_switch_active; + $logger->trace("removeTrailingWhitespace: beforeProcessing is now $removeTWS") if $is_t_switch_active; + $logger->trace("removeTrailingWhitespace: afterProcessing is now $removeTWS") if $is_t_switch_active; } # this method can be called before the indendation, and after, depending upon the input if($input{when} eq "before"){ return unless(${$masterSettings{removeTrailingWhitespace}}{beforeProcessing}); - $self->logger("Removing trailing white space *before* the document is processed (see removeTrailingWhitespace: beforeProcessing)",'heading') if $is_t_switch_active; + $logger->trace("Removing trailing white space *before* the document is processed (see removeTrailingWhitespace: beforeProcessing)") if $is_t_switch_active; } elsif($input{when} eq "after"){ return unless(${$masterSettings{removeTrailingWhitespace}}{afterProcessing}); - $self->logger("Removing trailing white space *after* the document is processed (see removeTrailingWhitespace: afterProcessing)",'heading') if $is_t_switch_active; + $logger->trace("Removing trailing white space *after* the document is processed (see removeTrailingWhitespace: afterProcessing)") if $is_t_switch_active; } else { return; } @@ -58,14 +61,11 @@ sub remove_trailing_whitespace{ $ # up to the end of a line //xsmg; - $self->logger("Processed body, *$input{when}* indentation (${$self}{name}):") if($is_t_switch_active); - $self->logger(${$self}{body}) if($is_t_switch_active); - } sub remove_leading_space{ my $self = shift; - $self->logger("Removing leading space from ${$self}{name} (verbatim/noindentblock already accounted for)",'heading') if $is_t_switch_active; + $logger->trace("*Removing leading space from ${$self}{name} (verbatim/noindentblock already accounted for)") if $is_t_switch_active; ${$self}{body} =~ s/ ( ^ # beginning of the line diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/IfElseFi.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/IfElseFi.pm index 5e4040d5cef..1a0529d3aac 100755 --- a/Master/texmf-dist/scripts/latexindent/LatexIndent/IfElseFi.pm +++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/IfElseFi.pm @@ -19,6 +19,7 @@ use warnings; use LatexIndent::Tokens qw/%tokens/; use LatexIndent::TrailingComments qw/$trailingCommentRegExp/; use LatexIndent::Switches qw/$is_m_switch_active $is_t_switch_active $is_tt_switch_active/; +use LatexIndent::LogFile qw/$logger/; use Data::Dumper; use Exporter qw/import/; our @ISA = "LatexIndent::Document"; # class inheritance, Programming Perl, pg 321 @@ -62,9 +63,6 @@ sub find_ifelsefi{ ${$self}{body} =~ s/ $ifElseFiRegExp(\h*)($trailingCommentRegExp)? / - # log file output - $self->logger("IfElseFi found: $2",'heading')if $is_t_switch_active; - # create a new IfElseFi object my $ifElseFi = LatexIndent::IfElseFi->new(begin=>$1.(($4 eq "\n" and !$3)?"\n":q()), name=>$2, @@ -88,6 +86,9 @@ sub find_ifelsefi{ endImmediatelyFollowedByComment=>$9?0:($11?1:0), horizontalTrailingSpace=>$8?$8:q(), ); + # log file output + $logger->trace("*IfElseFi found: $2")if $is_t_switch_active; + # the settings and storage of most objects has a lot in common $self->get_settings_and_store_new_object($ifElseFi); ${@{${$self}{children}}[-1]}{replacementText}.($10?$10:q()).($11?$11:q()); @@ -104,7 +105,7 @@ sub post_indentation_check{ and !(${$self}{body} =~ m/^\h*\\else/s and ${$self}{linebreaksAtEnd}{begin}==0) ){ - $self->logger("Adding surrounding indentation to \\else statement ('${$self}{surroundingIndentation}')") if $is_t_switch_active; + $logger->trace("*Adding surrounding indentation to \\else statement ('${$self}{surroundingIndentation}')") if $is_t_switch_active; ${$self}{body} =~ s/^\h*\\else/${$self}{surroundingIndentation}\\else/sm; } return; @@ -155,10 +156,10 @@ sub wrap_up_statement{ # text # after: # \fitext - $self->logger("Adding a single space after \\fi statement (otherwise \\fi can be comined with next line of text in an unwanted way)",'heading') if $is_t_switch_active; + $logger->trace("*Adding a single space after \\fi statement (otherwise \\fi can be comined with next line of text in an unwanted way)") if $is_t_switch_active; ${$self}{end} =${$self}{end}." "; } - $self->logger("Finished indenting ${$self}{name}",'heading') if $is_t_switch_active; + $logger->trace("*Finished indenting ${$self}{name}") if $is_t_switch_active; return $self; } diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/Indent.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/Indent.pm index c9d05269d92..57bcd225add 100644 --- a/Master/texmf-dist/scripts/latexindent/LatexIndent/Indent.pm +++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/Indent.pm @@ -20,6 +20,7 @@ use LatexIndent::Tokens qw/%tokens/; use LatexIndent::Switches qw/$is_m_switch_active $is_t_switch_active $is_tt_switch_active/; use LatexIndent::HiddenChildren qw/%familyTree/; use LatexIndent::GetYamlSettings qw/%masterSettings/; +use LatexIndent::LogFile qw/$logger/; use Text::Tabs; use Data::Dumper; use Exporter qw/import/; @@ -42,7 +43,7 @@ sub indent{ $self->indent_end_statement; # output the completed object to the log file - $self->logger("Complete indented object (${$self}{name}) after indentation:\n${$self}{begin}${$self}{body}${$self}{end}") if $is_t_switch_active; + $logger->trace("Complete indented object (${$self}{name}) after indentation:\n${$self}{begin}${$self}{body}${$self}{end}") if $is_tt_switch_active; # wrap-up statement $self->wrap_up_statement; @@ -51,7 +52,7 @@ sub indent{ sub wrap_up_statement{ my $self = shift; - $self->logger("Finished indenting ${$self}{name}",'heading') if $is_t_switch_active; + $logger->trace("*Finished indenting ${$self}{name}") if $is_t_switch_active; return $self; } @@ -63,13 +64,13 @@ sub determine_total_indentation{ # logfile information my $surroundingIndentation = ${$self}{surroundingIndentation}; - $self->logger("indenting object ${$self}{name}") if($is_t_switch_active); + $logger->trace("indenting object ${$self}{name}") if($is_t_switch_active); (my $during = $surroundingIndentation) =~ s/\t/TAB/g; - $self->logger("indentation *surrounding* object: '$during'") if($is_t_switch_active); + $logger->trace("indentation *surrounding* object: '$during'") if($is_t_switch_active); ($during = ${$self}{indentation}) =~ s/\t/TAB/g; - $self->logger("indentation *of* object: '$during'") if($is_t_switch_active); + $logger->trace("indentation *of* object: '$during'") if($is_t_switch_active); ($during = $surroundingIndentation.${$self}{indentation}) =~ s/\t/TAB/g; - $self->logger("*total* indentation to be added: '$during'") if($is_t_switch_active); + $logger->trace("*total* indentation to be added: '$during'") if($is_t_switch_active); # form the total indentation of the object ${$self}{indentation} = $surroundingIndentation.${$self}{indentation}; @@ -82,11 +83,11 @@ sub get_surrounding_indentation{ my $surroundingIndentation = q(); if($familyTree{${$self}{id}}){ - $self->logger("Adopted ancestors found!") if($is_t_switch_active); + $logger->trace("Adopted ancestors found!") if($is_t_switch_active); foreach(@{${$familyTree{${$self}{id}}}{ancestors}}){ if(${$_}{type} eq "adopted"){ my $newAncestorId = ${$_}{ancestorID}; - $self->logger("ancestor ID: $newAncestorId, adding indentation of $newAncestorId to surroundingIndentation of ${$self}{id}") if($is_t_switch_active); + $logger->trace("ancestor ID: $newAncestorId, adding indentation of $newAncestorId to surroundingIndentation of ${$self}{id}") if($is_t_switch_active); $surroundingIndentation .= ref(${$_}{ancestorIndentation}) eq 'SCALAR' ? (${${$_}{ancestorIndentation}}?${${$_}{ancestorIndentation}}:q()) @@ -111,7 +112,7 @@ sub indent_body{ my $indentation = ${$self}{indentation}; # output to the logfile - $self->logger("Body (${$self}{name}) before indentation:\n${$self}{body}") if $is_t_switch_active; + $logger->trace("Body (${$self}{name}) before indentation:\n${$self}{body}") if $is_tt_switch_active; # last minute check for modified bodyLineBreaks $self->count_body_line_breaks if $is_m_switch_active; @@ -128,10 +129,10 @@ sub indent_body{ # body indendation if(${$self}{linebreaksAtEnd}{begin}==1){ if(${$self}{body} =~ m/^\h*$/s){ - $self->logger("Body of ${$self}{name} is empty, not applying indentation") if $is_t_switch_active; + $logger->trace("Body of ${$self}{name} is empty, not applying indentation") if $is_t_switch_active; } else { # put any existing horizontal space after the current indentation - $self->logger("Entire body of ${$self}{name} receives indendentation") if $is_t_switch_active; + $logger->trace("Entire body of ${$self}{name} receives indendentation") if $is_t_switch_active; ${$self}{body} =~ s/^(\h*)/$indentation$1/mg; # add indentation } } elsif(${$self}{linebreaksAtEnd}{begin}==0 and ${$self}{bodyLineBreaks}>0) { @@ -142,12 +143,12 @@ sub indent_body{ /sx){ my $bodyFirstLine = $1; my $remainingBody = $2; - $self->logger("first line of body: $bodyFirstLine",'heading') if $is_t_switch_active; - $self->logger("remaining body (before indentation):\n'$remainingBody'") if($is_t_switch_active); + $logger->trace("first line of body: $bodyFirstLine") if $is_tt_switch_active; + $logger->trace("remaining body (before indentation):\n'$remainingBody'") if($is_tt_switch_active); # add the indentation to all the body except first line $remainingBody =~ s/^/$indentation/mg unless($remainingBody eq ''); # add indentation - $self->logger("remaining body (after indentation):\n$remainingBody'") if($is_t_switch_active); + $logger->trace("remaining body (after indentation):\n$remainingBody'") if($is_tt_switch_active); # put the body back together ${$self}{body} = $bodyFirstLine."\n".$remainingBody; @@ -162,12 +163,12 @@ sub indent_body{ # the final linebreak can be modified by a child object; see test-cases/commands/figureValign-mod5.tex, for example if($is_m_switch_active and defined ${$self}{linebreaksAtEnd}{body} and ${$self}{linebreaksAtEnd}{body}==1 and ${$self}{body} !~ m/\R$/ and ${$self}{body} ne ''){ - $self->logger("Adding a linebreak at end of body for ${$self}{name} to contain a linebreak at the end (linebreaksAtEnd is 1, but there isn't currently a linebreak)") if($is_t_switch_active); + $logger->trace("Adding a linebreak at end of body for ${$self}{name} to contain a linebreak at the end (linebreaksAtEnd is 1, but there isn't currently a linebreak)") if($is_t_switch_active); ${$self}{body} .= "\n"; } # output to the logfile - $self->logger("Body (${$self}{name}) after indentation:\n${$self}{body}") if $is_t_switch_active; + $logger->trace("Body (${$self}{name}) after indentation:\n${$self}{body}") if $is_tt_switch_active; return $self; } @@ -195,7 +196,7 @@ sub indent_end_statement{ # end{statement} indentation, e.g \end{environment}, \fi, }, etc if(${$self}{linebreaksAtEnd}{body}){ ${$self}{end} =~ s/^\h*/$surroundingIndentation/mg; # add indentation - $self->logger("Adding surrounding indentation to ${$self}{end} (${$self}{name}: '$surroundingIndentation')") if($is_t_switch_active); + $logger->trace("Adding surrounding indentation to ${$self}{end} (${$self}{name}: '$surroundingIndentation')") if($is_t_switch_active); } return $self; } @@ -222,12 +223,12 @@ sub final_indentation_check{ # count the number of tabs $numberOfTABS = () = $indentation=~ \/\t\/g; - $self->logger("Number of tabs: $numberOfTABS") if($is_t_switch_active); + $logger->trace("Number of tabs: $numberOfTABS") if($is_t_switch_active); # log the after ($after = $indentation) =~ s|\t||g; $after = "TAB"x$numberOfTABS.$after; - $self->logger("Indentation after: '$after'") if($is_t_switch_active); + $logger->trace("Indentation after: '$after'") if($is_t_switch_active); ($indentation = $after) =~s|TAB|\t|g; $indentation; @@ -236,7 +237,7 @@ sub final_indentation_check{ return unless($masterSettings{maximumIndentation} =~ m/^\h+$/); # maximum indentation check - $self->logger("Maximum indentation check",'heading') if($is_t_switch_active); + $logger->trace("*Maximum indentation check") if($is_t_switch_active); # replace any leading tabs with spaces, and update the body my @expanded_lines = expand(${$self}{body}); @@ -255,29 +256,29 @@ sub indent_children_recursively{ my $self = shift; unless(defined ${$self}{children}) { - $self->logger("No child objects (${$self}{name})") if $is_t_switch_active; + $logger->trace("No child objects (${$self}{name})") if $is_t_switch_active; return; } - $self->logger('Pre-processed body:','heading') if $is_t_switch_active; - $self->logger(${$self}{body}) if($is_t_switch_active); + $logger->trace('Pre-processed body:') if $is_tt_switch_active; + $logger->trace(${$self}{body}) if($is_tt_switch_active); # send the children through this indentation routine recursively if(defined ${$self}{children}){ foreach my $child (@{${$self}{children}}){ - $self->logger("Indenting child objects on ${$child}{name}") if $is_t_switch_active; + $logger->trace("Indenting child objects on ${$child}{name}") if $is_t_switch_active; $child->indent_children_recursively; } } - $self->logger("Replacing ids with begin, body, and end statements:",'heading') if $is_t_switch_active; + $logger->trace("*Replacing ids with begin, body, and end statements:") if $is_t_switch_active; # loop through document children hash while( scalar (@{${$self}{children}}) > 0 ){ my $index = 0; # we work through the array *in order* foreach my $child (@{${$self}{children}}){ - $self->logger("Searching ${$self}{name} for ${$child}{id}...",'heading') if $is_t_switch_active; + $logger->trace("Searching ${$self}{name} for ${$child}{id}...") if $is_t_switch_active; if(${$self}{body} =~ m/${$child}{id}/s){ # we only care if id is first non-white space character # and if followed by line break @@ -291,13 +292,14 @@ sub indent_children_recursively{ or ${$self}{body} =~ m/^\h\h*${$child}{id}/m ) ?1:0; - $IDFollowedImmediatelyByLineBreak = (${$self}{body} =~ m/${$child}{id}\h*\R*/m) ?1:0; + $IDFollowedImmediatelyByLineBreak = (${$self}{body} =~ m/${$child}{id}\h*\R+/m) ?1:0; + ${$child}{IDFollowedImmediatelyByLineBreak} = $IDFollowedImmediatelyByLineBreak; } # log file info - $self->logger("${$child}{id} found!") if($is_t_switch_active); - $self->logger("Indenting ${$child}{name} (id: ${$child}{id})",'heading') if $is_t_switch_active; - $self->logger("looking up indentation scheme for ${$child}{name}") if($is_t_switch_active); + $logger->trace("${$child}{id} found!") if($is_t_switch_active); + $logger->trace("*Indenting ${$child}{name} (id: ${$child}{id})") if $is_t_switch_active; + $logger->trace("looking up indentation scheme for ${$child}{name}") if($is_t_switch_active); # line break checks *after* <end statement> if (defined ${$child}{EndFinishesWithLineBreak} @@ -305,7 +307,7 @@ sub indent_children_recursively{ and $IDFollowedImmediatelyByLineBreak) { # remove line break *after* <end statement>, if appropriate my $EndStringLogFile = ${$child}{aliases}{EndFinishesWithLineBreak}||"EndFinishesWithLineBreak"; - $self->logger("Removing linebreak after ${$child}{end} (see $EndStringLogFile)") if $is_t_switch_active; + $logger->trace("Removing linebreak after ${$child}{end} (see $EndStringLogFile)") if $is_t_switch_active; ${$self}{body} =~ s/${$child}{id}(\h*)?(\R|\h)*/${$child}{id}$1/s; ${$child}{linebreaksAtEnd}{end} = 0; } @@ -329,15 +331,15 @@ sub indent_children_recursively{ # by default, assume that no trailing comment token is needed my $trailingCharacterToken = q(); if(${$child}{BeginStartsOnOwnLine}==2){ - $self->logger("Removing space immediately before ${$child}{id}, in preparation for adding % ($BeginStringLogFile == 2)") if $is_t_switch_active; + $logger->trace("Removing space immediately before ${$child}{id}, in preparation for adding % ($BeginStringLogFile == 2)") if $is_t_switch_active; ${$self}{body} =~ s/\h*${$child}{id}/${$child}{id}/s; - $self->logger("Adding a % at the end of the line that ${$child}{begin} is on, then a linebreak ($BeginStringLogFile == 2)") if $is_t_switch_active; + $logger->trace("Adding a % at the end of the line that ${$child}{begin} is on, then a linebreak ($BeginStringLogFile == 2)") if $is_t_switch_active; $trailingCharacterToken = "%".$self->add_comment_symbol; } elsif (${$child}{BeginStartsOnOwnLine}==3){ - $self->logger("Adding a blank line at the end of the line that ${$child}{begin} is on, then a linebreak ($BeginStringLogFile == 3)") if $is_t_switch_active; + $logger->trace("Adding a blank line at the end of the line that ${$child}{begin} is on, then a linebreak ($BeginStringLogFile == 3)") if $is_t_switch_active; $trailingCharacterToken = "\n".(${$masterSettings{modifyLineBreaks}}{preserveBlankLines}?$tokens{blanklines}:q()); } else { - $self->logger("Adding a linebreak at the beginning of ${$child}{begin} (see $BeginStringLogFile)") if $is_t_switch_active; + $logger->trace("Adding a linebreak at the beginning of ${$child}{begin} (see $BeginStringLogFile)") if $is_t_switch_active; } # the trailing comment/linebreak magic @@ -351,33 +353,33 @@ sub indent_children_recursively{ # important to check we don't move the begin statement next to a blank-line-token my $blankLineToken = $tokens{blanklines}; if(${$self}{body} !~ m/$blankLineToken\R*\h*${$child}{id}/s){ - $self->logger("Removing linebreak before ${$child}{begin} (see $BeginStringLogFile in ${$child}{modifyLineBreaksYamlName} YAML)") if $is_t_switch_active; + $logger->trace("Removing linebreak before ${$child}{begin} (see $BeginStringLogFile in ${$child}{modifyLineBreaksYamlName} YAML)") if $is_t_switch_active; ${$self}{body} =~ s/(\h*)(?:\R*|\h*)+${$child}{id}/$1${$child}{id}/s; } else { - $self->logger("Not removing linebreak ahead of ${$child}{begin}, as blank-line-token present (see preserveBlankLines)") if $is_t_switch_active; + $logger->trace("Not removing linebreak ahead of ${$child}{begin}, as blank-line-token present (see preserveBlankLines)") if $is_t_switch_active; } } } - $self->logger(Dumper(\%{$child}),'ttrace') if($is_tt_switch_active); + $logger->trace(Dumper(\%{$child})) if($is_tt_switch_active); # replace ids with body ${$self}{body} =~ s/${$child}{id}/${$child}{begin}${$child}{body}${$child}{end}/; # log file info - $self->logger("Body (${$self}{name}) now looks like:",'heading') if $is_t_switch_active; - $self->logger(${$self}{body}) if($is_t_switch_active); + $logger->trace("Body (${$self}{name}) now looks like:") if $is_tt_switch_active; + $logger->trace(${$self}{body}) if($is_tt_switch_active); # remove element from array: http://stackoverflow.com/questions/174292/what-is-the-best-way-to-delete-a-value-from-an-array-in-perl splice(@{${$self}{children}}, $index, 1); # output to the log file - $self->logger("deleted child key ${$child}{name} (parent is: ${$self}{name})") if $is_t_switch_active; + $logger->trace("deleted child key ${$child}{name} (parent is: ${$self}{name})") if $is_t_switch_active; # restart the loop, as the size of the array has changed last; } else { - $self->logger("${$child}{id} not found") if($is_t_switch_active); + $logger->trace("${$child}{id} not found") if($is_t_switch_active); } # increment the loop counter @@ -386,10 +388,10 @@ sub indent_children_recursively{ } # logfile info - $self->logger("${$self}{name} has this many children:",'heading') if $is_t_switch_active; - $self->logger(scalar @{${$self}{children}}) if $is_t_switch_active; - $self->logger("Post-processed body (${$self}{name}):") if($is_t_switch_active); - $self->logger(${$self}{body}) if($is_t_switch_active); + $logger->trace("${$self}{name} has this many children:") if $is_tt_switch_active; + $logger->trace(scalar @{${$self}{children}}) if $is_tt_switch_active; + $logger->trace("Post-processed body (${$self}{name}):") if($is_tt_switch_active); + $logger->trace(${$self}{body}) if($is_tt_switch_active); } diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/Item.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/Item.pm index 4861cb9f82c..8a72257e70d 100644 --- a/Master/texmf-dist/scripts/latexindent/LatexIndent/Item.pm +++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/Item.pm @@ -20,6 +20,7 @@ use LatexIndent::Tokens qw/%tokens/; use LatexIndent::TrailingComments qw/$trailingCommentRegExp/; use LatexIndent::GetYamlSettings qw/%masterSettings/; use LatexIndent::Switches qw/$is_t_switch_active $is_tt_switch_active/; +use LatexIndent::LogFile qw/$logger/; use Data::Dumper; use Exporter qw/import/; our @ISA = "LatexIndent::Document"; # class inheritance, Programming Perl, pg 321 @@ -37,7 +38,7 @@ sub construct_list_of_items{ } # detail items in the log - $self->logger("List of items: $listOfItems (see itemNames)",'heading') if $is_t_switch_active; + $logger->trace("*List of items: $listOfItems (see itemNames)") if $is_t_switch_active; $itemRegExp = qr/ ( @@ -68,13 +69,13 @@ sub find_items{ return unless ${$masterSettings{indentAfterItems}}{${$self}{name}}; # otherwise loop through the item names - $self->logger("Searching for items (see itemNames) in ${$self}{name} (see indentAfterItems)") if $is_t_switch_active; - $self->logger(Dumper(\%{$masterSettings{itemNames}})) if $is_t_switch_active; + $logger->trace("Searching for items (see itemNames) in ${$self}{name} (see indentAfterItems)") if $is_t_switch_active; + $logger->trace(Dumper(\%{$masterSettings{itemNames}})) if $is_tt_switch_active; while(${$self}{body} =~ m/$itemRegExp\h*($trailingCommentRegExp)?/){ # log file output - $self->logger("Item found: $2",'heading') if $is_t_switch_active; + $logger->trace("*Item found: $2") if $is_t_switch_active; ${$self}{body} =~ s/ $itemRegExp(\h*)($trailingCommentRegExp)? @@ -137,7 +138,7 @@ sub remove_line_breaks_begin{ # there is no white space my $self = shift; my $BodyStringLogFile = ${$self}{aliases}{BodyStartsOnOwnLine}||"BodyStartsOnOwnLine"; - $self->logger("Removing linebreak at the end of begin (see $BodyStringLogFile)"); + $logger->trace("Removing linebreak at the end of begin (see $BodyStringLogFile)"); ${$self}{begin} =~ s/\R*$//sx; ${$self}{begin} .= " " unless(${$self}{begin} =~ m/\h$/s or ${$self}{body} =~ m/^\h/s or ${$self}{body} =~ m/^\R/s ); ${$self}{linebreaksAtEnd}{begin} = 0; diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/KeyEqualsValuesBraces.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/KeyEqualsValuesBraces.pm index 974003d3a87..0e939731015 100755 --- a/Master/texmf-dist/scripts/latexindent/LatexIndent/KeyEqualsValuesBraces.pm +++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/KeyEqualsValuesBraces.pm @@ -18,8 +18,8 @@ use strict; use warnings; use LatexIndent::Tokens qw/%tokens/; use LatexIndent::TrailingComments qw/$trailingCommentRegExp/; -use LatexIndent::Switches qw/$is_m_switch_active/; -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::LogFile qw/$logger/; use Data::Dumper; use Exporter qw/import/; our @ISA = "LatexIndent::Command"; # class inheritance, Programming Perl, pg 321 @@ -73,7 +73,7 @@ sub indent_begin{ my $blankLineToken = $tokens{blanklines}; if(${$self}{begin} =~ /\R=/s or ${$self}{begin} =~ /$blankLineToken\h*=/s ){ - $self->logger("= found on own line in ${$self}{name}, adding indentation") if $is_t_switch_active; + $logger->trace("= found on own line in ${$self}{name}, adding indentation") if $is_t_switch_active; ${$self}{begin} =~ s/=/${$self}{indentation}=/s; } } @@ -87,15 +87,15 @@ sub check_linebreaks_before_equals{ # linebreaks *infront* of = symbol if(${$self}{begin} =~ /\R\h*=/s){ if(defined ${$self}{EqualsStartsOnOwnLine} and ${$self}{EqualsStartsOnOwnLine}==-1){ - $self->logger("Removing linebreak before = symbol in ${$self}{name} (see EqualsStartsOnOwnLine)") if $is_t_switch_active; + $logger->trace("Removing linebreak before = symbol in ${$self}{name} (see EqualsStartsOnOwnLine)") if $is_t_switch_active; ${$self}{begin} =~ s/(\R|\h)*=/=/s; } } else { if(defined ${$self}{EqualsStartsOnOwnLine} and ${$self}{EqualsStartsOnOwnLine}==1){ - $self->logger("Adding a linebreak before = symbol for ${$self}{name} (see EqualsStartsOnOwnLine)") if $is_t_switch_active; + $logger->trace("Adding a linebreak before = symbol for ${$self}{name} (see EqualsStartsOnOwnLine)") if $is_t_switch_active; ${$self}{begin} =~ s/=/\n=/s; } elsif(defined ${$self}{EqualsStartsOnOwnLine} and ${$self}{EqualsStartsOnOwnLine}==2){ - $self->logger("Adding a % linebreak immediately before = symbol for ${$self}{name} (see EqualsStartsOnOwnLine)") if $is_t_switch_active; + $logger->trace("Adding a % linebreak immediately before = symbol for ${$self}{name} (see EqualsStartsOnOwnLine)") if $is_t_switch_active; ${$self}{begin} =~ s/\h*=/%\n=/s; } } @@ -114,7 +114,7 @@ sub get_replacement_text{ my $self = shift; # the replacement text for a key = {value} needes to accomodate the leading [ OR { OR % OR , OR any combination thereof - $self->logger("Custom replacement text routine for ${$self}{name}") if $is_t_switch_active; + $logger->trace("Custom replacement text routine for ${$self}{name}") if $is_t_switch_active; ${$self}{replacementText} = ${$self}{beginningbit}.${$self}{id}; delete ${$self}{beginningbit}; } diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/LogFile.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/LogFile.pm index 128034a2881..ff118352762 100644 --- a/Master/texmf-dist/scripts/latexindent/LatexIndent/LogFile.pm +++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/LogFile.pm @@ -16,39 +16,25 @@ package LatexIndent::LogFile; # For all communication, please visit: https://github.com/cmhughes/latexindent.pl use strict; use warnings; -use LatexIndent::GetYamlSettings qw/%masterSettings/; -use LatexIndent::Switches qw/%switches/; -use LatexIndent::Version qw/$versionNumber $versionDate/; use FindBin; use File::Basename; # to get the filename and directory path use Exporter qw/import/; -our @EXPORT_OK = qw/logger output_logfile processSwitches/; +use Log::Log4perl qw(get_logger :levels); +use Log::Log4perl::Appender::Screen; +use Log::Dispatch::File; +use LatexIndent::GetYamlSettings qw/%masterSettings/; +use LatexIndent::Switches qw/%switches/; +use LatexIndent::Version qw/$versionNumber $versionDate/; +our @EXPORT_OK = qw/processSwitches $logger/; our @logFileNotes; +our $logger = get_logger("Document"); -# log file methods -# log file methods -# log file methods -# reference: http://stackoverflow.com/questions/6736998/help-calling-a-sub-routine-from-a-perl-module-and-printing-to-logfile - -sub logger{ - shift; - my $line = shift; - my $infoLevel = shift; - push(@logFileNotes,{line=>$line,level=>$infoLevel?$infoLevel:'default'}); - return -} +# log file methods, using log4perl; references +# pattern layout: http://search.cpan.org/~mschilli/Log-Log4perl-1.32/lib/Log/Log4perl/Layout/PatternLayout.pm +# multiple appenders: https://stackoverflow.com/questions/8620347/perl-log4perl-printing-and-logging-at-the-same-time-in-a-line?rq=1 +# getting started: https://www.perl.com/pub/2002/09/11/log4perl.html sub processSwitches{ - my $self = shift; - - # details of the script to log file - $self->logger("$FindBin::Script version $versionNumber, $versionDate, a script to indent .tex files",'heading'); - $self->logger("$FindBin::Script lives here: $FindBin::RealBin/"); - - # time the script is used - my $time = localtime(); - $self->logger("$time"); - # -v switch is just to show the version number if($switches{version}) { print $versionNumber,", ",$versionDate,"\n"; @@ -63,6 +49,8 @@ usage: latexindent.pl [options] [file][.tex|.sty|.cls|.bib|...] displays the version number and date of release -h, --help help (see the documentation for detailed instructions and examples) + -sl, --screenlog + log file will also be output to the screen -o, --outputfile=<name-of-output-file> output to another file; sample usage: latexindent.pl -o outputfile.tex myfile.tex @@ -97,84 +85,154 @@ ENDQUOTE exit(2); } + # if we've made it this far, the processing of switches and logging begins + my $self = shift; + + ($switches{trace}||$switches{ttrace}) ? $logger->level($TRACE): $logger->level($INFO); + + # cruft directory + ${$self}{cruftDirectory} = $switches{cruftDirectory}||(dirname ${$self}{fileName}); + die "Could not find directory ${$self}{cruftDirectory}\nExiting, no indentation done." if(!(-d ${$self}{cruftDirectory})); + + my $logfileName = ($switches{cruftDirectory} ? ${$self}{cruftDirectory} : '').($switches{logFileName}||"indent.log"); + + # layout of the logfile information, for example + # + # 2017/09/16 11:59:09 INFO: message + # 2017/09/16 12:23:53 INFO: LogFile.pm:156 LatexIndent::LogFile::processSwitches - message + # reference: https://stackoverflow.com/questions/46262844/log4perl-grouping-messages/46309392#46309392 + Log::Log4perl::Layout::PatternLayout::add_global_cspec( + 'A', sub { + if($_[1] =~ /^\*/){ + $_[1]=~s/^\*//; + if($_[1]=~m/\R/s){ + my $indentation = ' '.(' ' x length $_[3]); + $_[1] =~ s/\R/\n$indentation/gs; + } + return "$_[3]: ".$_[1]; + } else { + my $indentation = ' '.(' ' x length $_[3]); + $_[1] =~ s/\R/\n$indentation/gs if($_[1]=~m/\R/s); + return $indentation.$_[1]; + } + }); + + my $layout = Log::Log4perl::Layout::PatternLayout->new("%A%n"); + + # details for the Log4perl logging + my $appender = Log::Log4perl::Appender->new( + "Log::Dispatch::File", + filename => $logfileName, + mode => "write", + utf8 => 1, + ); + + # add the layout + $appender->layout($layout); + + # adjust the logger object + $logger->add_appender($appender); + + # appender object for output to screen + my $appender_screen = q(); + + # output to screen, if appropriate + if($switches{screenlog}){ + $appender_screen = Log::Log4perl::Appender->new( + "Log::Log4perl::Appender::Screen", + stderr => 0, + utf8 => 1, + ); + + $appender_screen->layout($layout); + $logger->add_appender($appender_screen); + } + + # details of the script to log file + $logger->info("*$FindBin::Script version $versionNumber, $versionDate, a script to indent .tex files"); + $logger->info("$FindBin::Script lives here: $FindBin::RealBin/"); + + my $time = localtime(); + $logger->info($time); + + if (${$self}{fileName} ne "-"){ + $logger->info("Filename: ${$self}{fileName}"); + } else { + $logger->info("Reading input from STDIN"); + } + # log the switches from the user - $self->logger('Processing switches','heading'); + $logger->info("*Processing switches:"); # check on the trace mode switch (should be turned on if ttrace mode active) $switches{trace} = $switches{ttrace} ? 1 : $switches{trace}; - + # output details of switches - $self->logger('-t|--trace: Trace mode active (you have used either -t or --trace)') if($switches{trace} and !$switches{ttrace}); - $self->logger('-tt|--ttrace: TTrace mode active (you have used either -tt or --ttrace)') if($switches{tracingModeVeryDetailed}); - $self->logger('-s|--silent: Silent mode active (you have used either -s or --silent)') if($switches{silentMode}); - $self->logger('-d|--onlydefault: Only defaultSettings.yaml will be used (you have used either -d or --onlydefault)') if($switches{onlyDefault}); - $self->logger("-w|--overwrite: Overwrite mode active, will make a back up of ${$self}{fileName} first") if($switches{overwrite}); - $self->logger("-l|--localSettings: Read localSettings YAML file") if($switches{readLocalSettings}); - $self->logger("-y|--yaml: YAML settings specified via command line") if($switches{yaml}); - $self->logger("-o|--outputfile: output to file") if($switches{outputToFile}); - $self->logger("-m|--modifylinebreaks: modify line breaks") if($switches{modifyLineBreaks}); - $self->logger("-g|--logfile: logfile name") if($switches{logFileName}); - $self->logger("-c|--cruft: cruft directory") if($switches{cruftDirectory}); + $logger->info("-sl|--screenlog: log file will also be output to the screen") if($switches{screenlog}); + $logger->info("-t|--trace: Trace mode active (you have used either -t or --trace)") if($switches{trace} and !$switches{ttrace}); + $logger->info("-tt|--ttrace: TTrace mode active (you have used either -tt or --ttrace)") if($switches{ttrace}); + $logger->info("-s|--silent: Silent mode active (you have used either -s or --silent)") if($switches{silentMode}); + $logger->info("-d|--onlydefault: Only defaultSettings.yaml will be used (you have used either -d or --onlydefault)") if($switches{onlyDefault}); + $logger->info("-w|--overwrite: Overwrite mode active, will make a back up of ${$self}{fileName} first") if($switches{overwrite}); + $logger->info("-l|--localSettings: Read localSettings YAML file") if($switches{readLocalSettings}); + $logger->info("-y|--yaml: YAML settings specified via command line") if($switches{yaml}); + $logger->info("-o|--outputfile: output to file") if($switches{outputToFile}); + $logger->info("-m|--modifylinebreaks: modify line breaks") if($switches{modifyLineBreaks}); + $logger->info("-g|--logfile: logfile name") if($switches{logFileName}); + $logger->info("-c|--cruft: cruft directory") if($switches{cruftDirectory}); # check if overwrite and outputfile are active similtaneously if($switches{overwrite} and $switches{outputToFile}){ - $self->logger("Options check",'heading'); - $self->logger("You have called latexindent.pl with both -o and -w"); - $self->logger("-o (output to file) will take priority, and -w (over write) will be ignored"); + $logger->info("Options check, -w and -o specified\nYou have called latexindent.pl with both -o and -w\noutput to file) will take priority, and -w (over write) will be ignored"); $switches{overwrite}=0; } - # cruft directory - ${$self}{cruftDirectory} = $switches{cruftDirectory}||(dirname ${$self}{fileName}); - die "Could not find directory ${$self}{cruftDirectory}\nExiting, no indentation done." if(!(-d ${$self}{cruftDirectory})); - my $logfileName = $switches{logFileName}||"indent.log"; - $self->logger("Directory for backup files and $logfileName: ${$self}{cruftDirectory}",'heading'); + $logger->info("*Directory for backup files and $logfileName: ${$self}{cruftDirectory}"); # output location of modules if($FindBin::Script eq 'latexindent.pl' or ($FindBin::Script eq 'latexindent.exe' and $switches{trace} )) { - my @listOfModules = ('FindBin', 'YAML::Tiny', 'File::Copy', 'File::Basename', 'Getopt::Long','File::HomeDir','Unicode::GCString'); - $self->logger("Perl modules are being loaded from the following directories:",'heading'); + my @listOfModules = ('FindBin', 'YAML::Tiny', 'File::Copy', 'File::Basename', 'Getopt::Long','File::HomeDir','Unicode::GCString','Log::Log4perl'); + $logger->info("*Perl modules are being loaded from the following directories:"); foreach my $moduleName (@listOfModules) { (my $file = $moduleName) =~ s|::|/|g; - require $file . '.pm'; - $self->logger($INC{$file .'.pm'}); + $logger->info($INC{$file .'.pm'}); } - $self->logger("Latex Indent perl modules are being loaded from, for example:",'heading'); + $logger->info("*Latex Indent perl modules are being loaded from, for example:"); (my $file = 'LatexIndent::Document') =~ s|::|/|g; - require $file . '.pm'; - $self->logger($INC{$file .'.pm'}); + $logger->info($INC{$file .'.pm'}); } - return; -} -sub output_logfile{ - my $self = shift; - my $logfile; - my $logfileName = $switches{logFileName}||"indent.log"; - - open($logfile,">","${$self}{cruftDirectory}/$logfileName") or die "Can't open $logfileName"; - - # put the final line in the logfile - $self->logger("${$masterSettings{logFilePreferences}}{endLogFileWith}",'heading'); - - # github info line - $self->logger("Please direct all communication/issues to: ",'heading') if ${$masterSettings{logFilePreferences}}{showGitHubInfoFooter}; - $self->logger("https://github.com/cmhughes/latexindent.pl") if ${$masterSettings{logFilePreferences}}{showGitHubInfoFooter}; - - # output the logfile - foreach my $line (@logFileNotes){ - if(${$line}{level} eq 'heading'){ - print $logfile ${$line}{line},"\n"; - } elsif(${$line}{level} eq 'default') { - # add tabs to the beginning of lines - # for default logfile lines - ${$line}{line} =~ s/^/\t/mg; - print $logfile ${$line}{line},"\n"; - } - } - - close($logfile); -} + # read the YAML settings + $self->readSettings; + + # the user may have specified their own settings for the rest of the log file, + # for example: + # + # logFilePreferences: + # PatternLayout: + # default: "%p: %m{indent}%n" + # trace: "%p: %m{indent}%n" + # ttrace: "%d %p: %F{1}:%L %M - %m{indent}%n" + # + # e.g, default mode: + # 2017/09/16 11:59:09 INFO: message + # or trace mode: + # 2017/09/16 11:59:09 INFO: message + # or in trace mode: + # 2017/09/16 12:23:53 INFO: LogFile.pm:156 LatexIndent::LogFile::processSwitches - message + my $pattern = q(); + if($switches{ttrace}){ + $pattern = ${${$masterSettings{logFilePreferences}}{PatternLayout}}{ttrace}; + } elsif($switches{trace}){ + $pattern = ${${$masterSettings{logFilePreferences}}{PatternLayout}}{trace}; + } else { + $pattern = ${${$masterSettings{logFilePreferences}}{PatternLayout}}{default}; + } + $layout = Log::Log4perl::Layout::PatternLayout->new($pattern); + $appender->layout($layout); + $appender_screen->layout($layout) if $switches{screenlog}; + return; +} 1; diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/MandatoryArgument.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/MandatoryArgument.pm index 47b538d2ca2..51fc9e64d39 100644 --- a/Master/texmf-dist/scripts/latexindent/LatexIndent/MandatoryArgument.pm +++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/MandatoryArgument.pm @@ -19,6 +19,7 @@ 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::LogFile qw/$logger/; use Exporter qw/import/; our @ISA = "LatexIndent::Document"; # class inheritance, Programming Perl, pg 321 our @EXPORT_OK = qw/find_mandatory_arguments get_mand_arg_reg_exp/; @@ -32,8 +33,8 @@ sub find_mandatory_arguments{ # pick out the mandatory arguments while(${$self}{body} =~ m/$mandArgRegExp\h*($trailingCommentRegExp)*(.*)/s){ # log file output - $self->logger("Mandatory argument found, body in ${$self}{name}",'heading') if $is_t_switch_active; - $self->logger("(last argument)") if($9 eq '' and $is_t_switch_active); + $logger->trace("*Mandatory argument found, body in ${$self}{name}") if $is_t_switch_active; + $logger->trace("(last argument)") if($9 eq '' and $is_t_switch_active); ${$self}{body} =~ s/ $mandArgRegExp(\h*)($trailingCommentRegExp)*(.*) diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/ModifyLineBreaks.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/ModifyLineBreaks.pm index d527f5d7986..7b704736c02 100644 --- a/Master/texmf-dist/scripts/latexindent/LatexIndent/ModifyLineBreaks.pm +++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/ModifyLineBreaks.pm @@ -24,7 +24,8 @@ use LatexIndent::Tokens qw/%tokens/; use LatexIndent::TrailingComments qw/$trailingCommentRegExp/; use LatexIndent::Switches qw/$is_m_switch_active $is_t_switch_active $is_tt_switch_active/; use LatexIndent::Item qw/$listOfItems/; -our @EXPORT_OK = qw/modify_line_breaks_body modify_line_breaks_end adjust_line_breaks_end_parent remove_line_breaks_begin max_char_per_line paragraphs_on_one_line construct_paragraph_reg_exp/; +use LatexIndent::LogFile qw/$logger/; +our @EXPORT_OK = qw/modify_line_breaks_body modify_line_breaks_end adjust_line_breaks_end_parent remove_line_breaks_begin max_char_per_line paragraphs_on_one_line construct_paragraph_reg_exp one_sentence_per_line/; our $paragraphRegExp = q(); @@ -42,33 +43,33 @@ sub modify_line_breaks_body{ # BodyStartsOnOwnLine == 3 add a blank line, and then new line if(${$self}{BodyStartsOnOwnLine}==1){ # modify the begin statement - $self->logger("Adding a linebreak at the end of begin, ${$self}{begin} (see $BodyStringLogFile)") if $is_t_switch_active; + $logger->trace("Adding a linebreak at the end of begin, ${$self}{begin} (see $BodyStringLogFile)") if $is_t_switch_active; ${$self}{begin} .= "\n"; ${$self}{linebreaksAtEnd}{begin} = 1; - $self->logger("Removing leading space from body of ${$self}{name} (see $BodyStringLogFile)") if $is_t_switch_active; + $logger->trace("Removing leading space from body of ${$self}{name} (see $BodyStringLogFile)") if $is_t_switch_active; ${$self}{body} =~ s/^\h*//; } elsif(${$self}{BodyStartsOnOwnLine}==2){ # by default, assume that no trailing comment token is needed my $trailingCommentToken = q(); if(${$self}{body} !~ m/^\h*$trailingCommentRegExp/s){ # modify the begin statement - $self->logger("Adding a % at the end of begin ${$self}{begin} followed by a linebreak ($BodyStringLogFile == 2)") if $is_t_switch_active; + $logger->trace("Adding a % at the end of begin ${$self}{begin} followed by a linebreak ($BodyStringLogFile == 2)") if $is_t_switch_active; $trailingCommentToken = "%".$self->add_comment_symbol; ${$self}{begin} =~ s/\h*$//; ${$self}{begin} .= "$trailingCommentToken\n"; ${$self}{linebreaksAtEnd}{begin} = 1; - $self->logger("Removing leading space from body of ${$self}{name} (see $BodyStringLogFile)") if $is_t_switch_active; + $logger->trace("Removing leading space from body of ${$self}{name} (see $BodyStringLogFile)") if $is_t_switch_active; ${$self}{body} =~ s/^\h*//; } else { - $self->logger("Even though $BodyStringLogFile == 2, ${$self}{begin} already finishes with a %, so not adding another.") if $is_t_switch_active; + $logger->trace("Even though $BodyStringLogFile == 2, ${$self}{begin} already finishes with a %, so not adding another.") if $is_t_switch_active; } } elsif (${$self}{BodyStartsOnOwnLine}==3){ my $trailingCharacterToken = q(); - $self->logger("Adding a blank line at the end of begin ${$self}{begin} followed by a linebreak ($BodyStringLogFile == 3)") if $is_t_switch_active; + $logger->trace("Adding a blank line at the end of begin ${$self}{begin} followed by a linebreak ($BodyStringLogFile == 3)") if $is_t_switch_active; ${$self}{begin} =~ s/\h*$//; ${$self}{begin} .= (${$masterSettings{modifyLineBreaks}}{preserveBlankLines}?$tokens{blanklines}:"\n")."\n"; ${$self}{linebreaksAtEnd}{begin} = 1; - $self->logger("Removing leading space from body of ${$self}{name} (see $BodyStringLogFile)") if $is_t_switch_active; + $logger->trace("Removing leading space from body of ${$self}{name} (see $BodyStringLogFile)") if $is_t_switch_active; ${$self}{body} =~ s/^\h*//; } } elsif (${$self}{BodyStartsOnOwnLine}==-1 and ${$self}{linebreaksAtEnd}{begin}){ @@ -81,7 +82,7 @@ sub modify_line_breaks_body{ sub remove_line_breaks_begin{ my $self = shift; my $BodyStringLogFile = ${$self}{aliases}{BodyStartsOnOwnLine}||"BodyStartsOnOwnLine"; - $self->logger("Removing linebreak at the end of begin (see $BodyStringLogFile)") if $is_t_switch_active; + $logger->trace("Removing linebreak at the end of begin (see $BodyStringLogFile)") if $is_t_switch_active; ${$self}{begin} =~ s/\R*$//sx; ${$self}{linebreaksAtEnd}{begin} = 0; } @@ -98,16 +99,16 @@ sub modify_line_breaks_end{ # EndStartsOnOwnLine == 1 just add a new line # EndStartsOnOwnLine == 2 add a comment, and then new line # EndStartsOnOwnLine == 3 add a blank line, and then new line - $self->logger("Adding a linebreak at the end of body (see $EndStringLogFile)") if $is_t_switch_active; + $logger->trace("Adding a linebreak at the end of body (see $EndStringLogFile)") if $is_t_switch_active; # by default, assume that no trailing character token is needed my $trailingCharacterToken = q(); if(${$self}{EndStartsOnOwnLine}==2){ - $self->logger("Adding a % immediately after body of ${$self}{name} ($EndStringLogFile==2)") if $is_t_switch_active; + $logger->trace("Adding a % immediately after body of ${$self}{name} ($EndStringLogFile==2)") if $is_t_switch_active; $trailingCharacterToken = "%".$self->add_comment_symbol; ${$self}{body} =~ s/\h*$//s; } elsif (${$self}{EndStartsOnOwnLine}==3) { - $self->logger("Adding a blank line immediately after body of ${$self}{name} ($EndStringLogFile==3)") if $is_t_switch_active; + $logger->trace("Adding a blank line immediately after body of ${$self}{name} ($EndStringLogFile==3)") if $is_t_switch_active; $trailingCharacterToken = "\n".(${$masterSettings{modifyLineBreaks}}{preserveBlankLines}?$tokens{blanklines}:q()); ${$self}{body} =~ s/\h*$//s; } @@ -125,11 +126,11 @@ sub modify_line_breaks_end{ # check to see that body does *not* finish with blank-line-token, # if so, then don't remove that final line break if(${$self}{body} !~ m/$tokens{blanklines}$/s){ - $self->logger("Removing linebreak at the end of body (see $EndStringLogFile)") if $is_t_switch_active; + $logger->trace("Removing linebreak at the end of body (see $EndStringLogFile)") if $is_t_switch_active; ${$self}{body} =~ s/\R*$//sx; ${$self}{linebreaksAtEnd}{body} = 0; } else { - $self->logger("Blank line token found at end of body (${$self}{name}), see preserveBlankLines, not removing line break before ${$self}{end}") if $is_t_switch_active; + $logger->trace("Blank line token found at end of body (${$self}{name}), see preserveBlankLines, not removing line break before ${$self}{end}") if $is_t_switch_active; } } } @@ -145,7 +146,7 @@ sub modify_line_breaks_end{ # EndFinishesWithLineBreak == 3 add a blank line, and then new line my $EndStringLogFile = ${$self}{aliases}{EndFinishesWithLineBreak}||"EndFinishesWithLineBreak"; if(${$self}{EndFinishesWithLineBreak}==1){ - $self->logger("Adding a linebreak at the end of ${$self}{end} ($EndStringLogFile==1)") if $is_t_switch_active; + $logger->trace("Adding a linebreak at the end of ${$self}{end} ($EndStringLogFile==1)") if $is_t_switch_active; ${$self}{linebreaksAtEnd}{end} = 1; # modified end statement @@ -153,17 +154,17 @@ sub modify_line_breaks_end{ } elsif(${$self}{EndFinishesWithLineBreak}==2){ if(${$self}{endImmediatelyFollowedByComment}){ # no need to add a % if one already exists - $self->logger("Even though $EndStringLogFile == 2, ${$self}{end} is immediately followed by a %, so not adding another; not adding line break.") if $is_t_switch_active; + $logger->trace("Even though $EndStringLogFile == 2, ${$self}{end} is immediately followed by a %, so not adding another; not adding line break.") if $is_t_switch_active; } else { # otherwise, create a trailing comment, and tack it on - $self->logger("Adding a % immediately after, ${$self}{end} ($EndStringLogFile==2)") if $is_t_switch_active; + $logger->trace("Adding a % immediately after, ${$self}{end} ($EndStringLogFile==2)") if $is_t_switch_active; my $trailingCommentToken = "%".$self->add_comment_symbol; ${$self}{end} =~ s/\h*$//s; ${$self}{replacementText} .= "$trailingCommentToken\n"; ${$self}{linebreaksAtEnd}{end} = 1; } } elsif(${$self}{EndFinishesWithLineBreak}==3){ - $self->logger("Adding a blank line at the end of ${$self}{end} ($EndStringLogFile==3)") if $is_t_switch_active; + $logger->trace("Adding a blank line at the end of ${$self}{end} ($EndStringLogFile==3)") if $is_t_switch_active; ${$self}{linebreaksAtEnd}{end} = 1; # modified end statement @@ -185,9 +186,9 @@ sub adjust_line_breaks_end_parent{ # adjust parent linebreaks information if(${$child}{linebreaksAtEnd}{end} and ${$self}{body} =~ m/${$child}{replacementText}\h*\R*$/s and !${$self}{linebreaksAtEnd}{body}){ - $self->logger("ID: ${$child}{id}") if($is_t_switch_active); - $self->logger("${$child}{begin}...${$child}{end} is found at the END of body of parent, ${$self}{name}, avoiding a double line break:") if($is_t_switch_active); - $self->logger("adjusting ${$self}{name} linebreaksAtEnd{body} to be 1") if($is_t_switch_active); + $logger->trace("ID: ${$child}{id}") if($is_t_switch_active); + $logger->trace("${$child}{begin}...${$child}{end} is found at the END of body of parent, ${$self}{name}, avoiding a double line break:") if($is_t_switch_active); + $logger->trace("adjusting ${$self}{name} linebreaksAtEnd{body} to be 1") if($is_t_switch_active); ${$self}{linebreaksAtEnd}{body}=1; } @@ -197,8 +198,8 @@ sub adjust_line_breaks_end_parent{ and !${$child}{linebreaksAtEnd}{body} and ${$child}{body} =~ m/\R(?:$trailingCommentRegExp\h*)?$/s ){ # log file information - $self->logger("Undisclosed line break at the end of body of ${$child}{name}: '${$child}{end}'") if($is_t_switch_active); - $self->logger("Adding a linebreak at the end of body for ${$child}{id}") if($is_t_switch_active); + $logger->trace("Undisclosed line break at the end of body of ${$child}{name}: '${$child}{end}'") if($is_t_switch_active); + $logger->trace("Adding a linebreak at the end of body for ${$child}{id}") if($is_t_switch_active); # make the adjustments ${$child}{body} .= "\n"; @@ -224,6 +225,7 @@ sub max_char_per_line{ sub construct_paragraph_reg_exp{ my $self = shift; + $logger->trace("*Constructing the paragraph-stop regexp (see paragraphsStopAt)") if $is_t_switch_active ; my $stopAtRegExp = q(); while( my ($paragraphStopAt,$yesNo)= each %{${$masterSettings{modifyLineBreaks}{removeParagraphLineBreaks}}{paragraphsStopAt}}){ if($yesNo){ @@ -234,7 +236,7 @@ sub construct_paragraph_reg_exp{ $paragraphStopAt = "trailingComment" if($paragraphStopAt eq "comments"); # output to log file - $self->logger("The paragraph-stop regexp WILL include $tokens{$paragraphStopAt} (see paragraphsStopAt)",'heading') if $is_t_switch_active ; + $logger->trace("The paragraph-stop regexp WILL include $tokens{$paragraphStopAt} (see paragraphsStopAt)") if $is_t_switch_active ; # update the regexp if($paragraphStopAt eq "items"){ @@ -243,7 +245,7 @@ sub construct_paragraph_reg_exp{ $stopAtRegExp .= "|(?:".($paragraphStopAt eq "trailingComment" ? "%" : q() ).$tokens{$paragraphStopAt}."\\d+)"; } } else { - $self->logger("The paragraph-stop regexp won't include $tokens{$paragraphStopAt} (see paragraphsStopAt)",'heading') if ($tokens{$paragraphStopAt} and $is_t_switch_active); + $logger->trace("The paragraph-stop regexp won't include $tokens{$paragraphStopAt} (see paragraphsStopAt)") if ($tokens{$paragraphStopAt} and $is_t_switch_active); } } @@ -265,8 +267,8 @@ sub construct_paragraph_reg_exp{ \z # end of string )/sxm; - $self->logger("The paragraph-stop-regexp is:",'heading') if $is_tt_switch_active ; - $self->logger($paragraphRegExp) if $is_tt_switch_active ; + $logger->trace("The paragraph-stop-regexp is:") if $is_tt_switch_active ; + $logger->trace($paragraphRegExp) if $is_tt_switch_active ; } sub paragraphs_on_one_line{ @@ -276,7 +278,7 @@ sub paragraphs_on_one_line{ # alignment at ampersand can take priority return if(${$self}{lookForAlignDelims} and ${$masterSettings{modifyLineBreaks}{removeParagraphLineBreaks}}{alignAtAmpersandTakesPriority}); - $self->logger("Checking ${$self}{name} for paragraphs (see removeParagraphLineBreaks)") if $is_t_switch_active; + $logger->trace("Checking ${$self}{name} for paragraphs (see removeParagraphLineBreaks)") if $is_t_switch_active; my $paragraphCounter; my @paragraphStorage; @@ -296,4 +298,197 @@ sub paragraphs_on_one_line{ } } +sub one_sentence_per_line{ + my $self = shift; + + return unless ${$masterSettings{modifyLineBreaks}{oneSentencePerLine}}{manipulateSentences}; + $logger->trace("*One sentence per line regular expression construction: (see oneSentencePerLine: manipulateSentences)") if $is_t_switch_active; + + # sentences FOLLOW + # sentences FOLLOW + # sentences FOLLOW + my $sentencesFollow = q(); + + while( my ($sentencesFollowEachPart,$yesNo)= each %{${$masterSettings{modifyLineBreaks}{oneSentencePerLine}}{sentencesFollow}}){ + if($yesNo){ + if($sentencesFollowEachPart eq "par"){ + $sentencesFollowEachPart = qr/\R?\\par/s; + } elsif ($sentencesFollowEachPart eq "blankLine"){ + $sentencesFollowEachPart = qr/ + (?:\A(?:$tokens{blanklines}\R)+) # the order of each of these + | # is important, as (like always) the first + (?:\G(?:$tokens{blanklines}\R)+) # thing to be matched will + | # be accepted + (?:(?:$tokens{blanklines}\h*\R)+) + | + \R{2,} + | + \G + /sx; + } elsif ($sentencesFollowEachPart eq "fullStop"){ + $sentencesFollowEachPart = qr/\./s; + } elsif ($sentencesFollowEachPart eq "exclamationMark"){ + $sentencesFollowEachPart = qr/\!/s; + } elsif ($sentencesFollowEachPart eq "questionMark"){ + $sentencesFollowEachPart = qr/\?/s; + } elsif ($sentencesFollowEachPart eq "rightBrace"){ + $sentencesFollowEachPart = qr/\}/s; + } elsif ($sentencesFollowEachPart eq "commentOnPreviousLine"){ + $sentencesFollowEachPart = qr/$trailingCommentRegExp\h*\R/s; + } elsif ($sentencesFollowEachPart eq "other"){ + $sentencesFollowEachPart = qr/$yesNo/; + } + $sentencesFollow .= ($sentencesFollow eq '' ? q() : "|").qr/$sentencesFollowEachPart/sx; + } + } + # if blankLine is not active from sentencesFollow then we need to set up the + # beginning of the string, but make sure that it is *not* followed by a + # blank line token, or a blank line + if(!${${$masterSettings{modifyLineBreaks}{oneSentencePerLine}}{sentencesFollow}}{blankLine}){ + $sentencesFollow .= ($sentencesFollow eq '' ? q() : "|"). + qr/ + \G + (?!$tokens{blanklines}) + /sx; + } + + if(${${$masterSettings{modifyLineBreaks}{oneSentencePerLine}}{sentencesFollow}}{blankLine}){ + $sentencesFollow = ($sentencesFollow eq '' ? q() : qr/(?:$sentencesFollow)(?:\h|\R)*/sx ); + } else { + $sentencesFollow = ($sentencesFollow eq '' ? q() : qr/(?:$sentencesFollow)(?:\h*\R?)/sx ); + } + + + $logger->trace("Sentences follow regexp:") if $is_tt_switch_active; + $logger->trace($sentencesFollow) if $is_tt_switch_active; + + # sentences BEGIN with + # sentences BEGIN with + # sentences BEGIN with + my $sentencesBeginWith = q(); + + while( my ($sentencesBeginWithEachPart,$yesNo)= each %{${$masterSettings{modifyLineBreaks}{oneSentencePerLine}}{sentencesBeginWith}}){ + if($yesNo){ + if($sentencesBeginWithEachPart eq "A-Z"){ + $logger->trace("sentence BEGINS with capital letters (see oneSentencePerLine:sentencesBeginWith:A-Z)") if $is_t_switch_active; + $sentencesBeginWithEachPart = qr/(?!(?:$tokens{blanklines}|$tokens{verbatim}|$tokens{preamble}))[A-Z]/; + } elsif ($sentencesBeginWithEachPart eq "a-z"){ + $logger->trace("sentence BEGINS with lower-case letters (see oneSentencePerLine:sentencesBeginWith:a-z)") if $is_t_switch_active; + $sentencesBeginWithEachPart = qr/[a-z]/; + } elsif ($sentencesBeginWithEachPart eq "other"){ + $logger->trace("sentence BEGINS with other $yesNo (reg exp) (see oneSentencePerLine:sentencesBeginWith:other)") if $is_t_switch_active; + $sentencesBeginWithEachPart = qr/$yesNo/; + } + $sentencesBeginWith .= ($sentencesBeginWith eq "" ? q(): "|" ).$sentencesBeginWithEachPart; + } + } + $sentencesBeginWith = qr/$sentencesBeginWith/; + + # sentences END with + # sentences END with + # sentences END with + ${${$masterSettings{modifyLineBreaks}{oneSentencePerLine}}{sentencesEndWith}}{basicFullStop} = 0 if ${${$masterSettings{modifyLineBreaks}{oneSentencePerLine}}{sentencesEndWith}}{betterFullStop}; + my $sentencesEndWith = q(); + + while( my ($sentencesEndWithEachPart,$yesNo)= each %{${$masterSettings{modifyLineBreaks}{oneSentencePerLine}}{sentencesEndWith}}){ + if($yesNo){ + if($sentencesEndWithEachPart eq "basicFullStop"){ + $logger->trace("sentence ENDS with full stop (see oneSentencePerLine:sentencesEndWith:basicFullStop") if $is_t_switch_active; + $sentencesEndWithEachPart = qr/\./; + } elsif($sentencesEndWithEachPart eq "betterFullStop"){ + $logger->trace("sentence ENDS with *better* full stop (see oneSentencePerLine:sentencesEndWith:betterFullStop") if $is_t_switch_active; + $sentencesEndWithEachPart = qr/(?:\.\)(?!\h*[a-z]))|(?:(?<!(?:(?:e\.g)|(?:i\.e)|(?:etc))))\.(?!(?:[a-z]|[A-Z]|\-|\,|[0-9]))/; + } elsif ($sentencesEndWithEachPart eq "exclamationMark"){ + $logger->trace("sentence ENDS with exclamation mark (see oneSentencePerLine:sentencesEndWith:exclamationMark)") if $is_t_switch_active; + $sentencesEndWithEachPart = qr/!/; + } elsif ($sentencesEndWithEachPart eq "questionMark"){ + $logger->trace("sentence ENDS with question mark (see oneSentencePerLine:sentencesEndWith:questionMark)") if $is_t_switch_active; + $sentencesEndWithEachPart = qr/\?/; + } elsif ($sentencesEndWithEachPart eq "other"){ + $logger->trace("sentence ENDS with other $yesNo (reg exp) (see oneSentencePerLine:sentencesEndWith:other)") if $is_t_switch_active; + $sentencesEndWithEachPart = qr/$yesNo/; + } + $sentencesEndWith .= ($sentencesEndWith eq "" ? q(): "|" ).$sentencesEndWithEachPart; + } + } + $sentencesEndWith = qr/$sentencesEndWith/; + + # the OVERALL sentence regexp + # the OVERALL sentence regexp + # the OVERALL sentence regexp + $logger->trace("Overall sentences end with regexp:") if $is_tt_switch_active; + $logger->trace($sentencesEndWith) if $is_tt_switch_active; + + $logger->trace("Finding sentences...") if $is_t_switch_active; + + my $notWithinSentence = qr/$trailingCommentRegExp/s; + + # if + # + # modifyLineBreaks + # oneSentencePerLine + # sentencesFollow + # blankLine + # + # is set to 0 then we need to *exclude* the $tokens{blanklines} from the sentence routine, + # otherwise we could begin a sentence with $tokens{blanklines}. + if(!${${$masterSettings{modifyLineBreaks}{oneSentencePerLine}}{sentencesFollow}}{blankLine}){ + $notWithinSentence .= "|".qr/(?:\h*\R?$tokens{blanklines})/s; + } + + # similarly for \par + if(${${$masterSettings{modifyLineBreaks}{oneSentencePerLine}}{sentencesFollow}}{par}){ + $notWithinSentence .= "|".qr/(?:\R?\\par)/s; + } + + # initiate the sentence counter + my $sentenceCounter; + my @sentenceStorage; + + # make the sentence manipulation + ${$self}{body} =~ s/((?:$sentencesFollow)) + (\h*) + (?!$notWithinSentence) + ((?:$sentencesBeginWith).*?) + ($sentencesEndWith)/ + my $beginning = $1; + my $h_space = ($2?$2:q()); + my $middle = $3; + my $end = $4; + my $trailingComments = q(); + # remove trailing comments from within the body of the sentence + while($middle =~ m|$trailingCommentRegExp|){ + $middle =~ s|\h*($trailingCommentRegExp)||s; + $trailingComments .= $1; + } + # remove line breaks from within a sentence + $middle =~ s| + (?!\A) # not at the *beginning* of a match + (\h*)\R # possible horizontal space, then line break + |$1?$1:" ";|esgx if ${$masterSettings{modifyLineBreaks}{oneSentencePerLine}}{removeSentenceLineBreaks}; + $middle =~ s|$tokens{blanklines}\h*\R?|$tokens{blanklines}\n|sg; + $logger->trace("follows: $beginning") if $is_tt_switch_active; + $logger->trace("sentence: $middle") if $is_tt_switch_active; + $logger->trace("ends with: $end") if $is_tt_switch_active; + # reconstruct the sentence + $sentenceCounter++; + push(@sentenceStorage,{id=>$tokens{sentence}.$sentenceCounter.$tokens{endOfToken},value=>$middle.$end}); + $beginning.$h_space.$tokens{sentence}.$sentenceCounter.$tokens{endOfToken}.$trailingComments; + /xsge; + + # loop back through the sentenceStorage and replace with the sentence, adjusting line breaks + # before and after appropriately + while( my $sentence = pop @sentenceStorage){ + my $sentenceStorageID = ${$sentence}{id}; + my $sentenceStorageValue = ${$sentence}{value}; + # sentence at the very END + ${$self}{body} =~ s/\h*$sentenceStorageID\h*$/$sentenceStorageValue/s; + # sentence at the very BEGINNING + ${$self}{body} =~ s/^$sentenceStorageID\h*\R?/$sentenceStorageValue\n/s; + # all other sentences + ${$self}{body} =~ s/\R?\h*$sentenceStorageID\h*\R?/\n$sentenceStorageValue\n/s; + } + +} + 1; diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/NamedGroupingBracesBrackets.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/NamedGroupingBracesBrackets.pm index d18281f4ee9..22429677894 100755 --- a/Master/texmf-dist/scripts/latexindent/LatexIndent/NamedGroupingBracesBrackets.pm +++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/NamedGroupingBracesBrackets.pm @@ -19,6 +19,7 @@ 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::LogFile qw/$logger/; use Exporter qw/import/; our @ISA = "LatexIndent::Command"; # class inheritance, Programming Perl, pg 321 our @EXPORT_OK = qw/construct_grouping_braces_brackets_regexp $grouping_braces_regexp $grouping_braces_regexpTrailingComment/; @@ -63,7 +64,7 @@ sub get_replacement_text{ my $self = shift; # the replacement text for a key = {value} needes to accomodate the leading [ OR { OR % OR , OR any combination thereof - $self->logger("Custom replacement text routine for ${$self}{name}") if $is_t_switch_active; + $logger->trace("Custom replacement text routine for ${$self}{name}") if $is_t_switch_active; ${$self}{replacementText} = ${$self}{beginningbit}.${$self}{id}; delete ${$self}{beginningbit}; } diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/OptionalArgument.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/OptionalArgument.pm index a44ca52a51d..2b18f3c966b 100644 --- a/Master/texmf-dist/scripts/latexindent/LatexIndent/OptionalArgument.pm +++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/OptionalArgument.pm @@ -19,6 +19,7 @@ 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::LogFile qw/$logger/; use Exporter qw/import/; our @ISA = "LatexIndent::Document"; # class inheritance, Programming Perl, pg 321 our @EXPORT_OK = qw/find_optional_arguments/; @@ -46,8 +47,8 @@ sub find_optional_arguments{ # pick out the optional arguments while(${$self}{body} =~ m/$optArgRegExp\h*($trailingCommentRegExp)*(.*)/s){ # log file output - $self->logger("Optional argument found, body in ${$self}{name}",'heading') if $is_t_switch_active; - $self->logger("(last argument)") if($9 eq '' and $is_t_switch_active); + $logger->trace("*Optional argument found, body in ${$self}{name}") if $is_t_switch_active; + $logger->trace("(last argument)") if($9 eq '' and $is_t_switch_active); ${$self}{body} =~ s/ $optArgRegExp(\h*)($trailingCommentRegExp)*(.*) diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/Preamble.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/Preamble.pm index 178bfe4ff7b..fea38af0b64 100644 --- a/Master/texmf-dist/scripts/latexindent/LatexIndent/Preamble.pm +++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/Preamble.pm @@ -19,6 +19,7 @@ use warnings; use LatexIndent::Tokens qw/%tokens/; use LatexIndent::Switches qw/$is_t_switch_active/; use LatexIndent::GetYamlSettings qw/%masterSettings/; +use LatexIndent::LogFile qw/$logger/; our @ISA = "LatexIndent::Document"; # class inheritance, Programming Perl, pg 321 our $preambleCounter; @@ -34,7 +35,7 @@ sub get_replacement_text{ my $self = shift; # the replacement text for preamble needs to put the \\begin{document} back in - $self->logger("Custom replacement text routine for preamble ${$self}{name}") if $is_t_switch_active; + $logger->trace("Custom replacement text routine for preamble ${$self}{name}") if $is_t_switch_active; ${$self}{replacementText} = ${$self}{id}.${$self}{afterbit}; delete ${$self}{afterbit}; } diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/Special.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/Special.pm index d5a751f9e0e..461c620e53f 100644 --- a/Master/texmf-dist/scripts/latexindent/LatexIndent/Special.pm +++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/Special.pm @@ -20,6 +20,7 @@ use LatexIndent::Tokens qw/%tokens/; use LatexIndent::TrailingComments qw/$trailingCommentRegExp/; use LatexIndent::GetYamlSettings qw/%masterSettings/; use LatexIndent::Switches qw/$is_t_switch_active $is_tt_switch_active/; +use LatexIndent::LogFile qw/$logger/; use Data::Dumper; use Exporter qw/import/; our @ISA = "LatexIndent::Document"; # class inheritance, Programming Perl, pg 321 @@ -83,7 +84,7 @@ sub construct_special_begin{ /sx } else { - $self->logger("The special regexps won't include anything from $specialName (see lookForThis)",'heading') if $is_t_switch_active ; + $logger->trace("*The special regexps won't include anything from $specialName (see lookForThis)") if $is_t_switch_active ; } } @@ -94,10 +95,12 @@ sub construct_special_begin{ } # info to the log file - $self->logger("The special beginnings regexp is: $specialBegins (see specialBeginEnd)",'heading') if $is_t_switch_active; + $logger->trace("*The special beginnings regexp is: (see specialBeginEnd)") if $is_tt_switch_active; + $logger->trace($specialBegins) if $is_tt_switch_active; # overall special regexp - $self->logger("The overall special regexp is: $specialAllMatchesRegExp(see specialBeginEnd)",'heading') if $is_t_switch_active; + $logger->trace("*The overall special regexp is: (see specialBeginEnd)") if $is_tt_switch_active; + $logger->trace($specialAllMatchesRegExp) if $is_tt_switch_active; } @@ -108,8 +111,8 @@ sub find_special{ return if($specialBegins eq ""); # otherwise loop through the special begin/end - $self->logger("Searching for special begin/end (see specialBeginEnd)") if $is_t_switch_active ; - $self->logger(Dumper(\%{$masterSettings{specialBeginEnd}})) if $is_tt_switch_active; + $logger->trace("*Searching ${$self}{name} for special begin/end (see specialBeginEnd)") if $is_t_switch_active ; + $logger->trace(Dumper(\%{$masterSettings{specialBeginEnd}})) if $is_tt_switch_active; # keep looping as long as there is a special match of some kind while(${$self}{body} =~ m/$specialAllMatchesRegExp/sx){ @@ -119,9 +122,9 @@ sub find_special{ # log file if((ref($BeginEnd) eq "HASH") and ${$BeginEnd}{lookForThis}){ - $self->logger("Looking for $specialName",'heading') if $is_t_switch_active ; + $logger->trace("Looking for $specialName") if $is_t_switch_active ; } else { - $self->logger("Not looking for $specialName (see lookForThis)",'heading') if ($is_t_switch_active and (ref($BeginEnd) eq "HASH")); + $logger->trace("Not looking for $specialName (see lookForThis)") if ($is_t_switch_active and (ref($BeginEnd) eq "HASH")); next; } @@ -134,9 +137,6 @@ sub find_special{ ${$self}{body} =~ s/ $specialRegExp(\h*)($trailingCommentRegExp)? / - # log file output - $self->logger("special found: $specialName",'heading') if $is_t_switch_active; - # create a new special object my $specialObject = LatexIndent::Special->new(begin=>$1, body=>$3, @@ -162,6 +162,9 @@ sub find_special{ horizontalTrailingSpace=>$6?$6:q(), ); + # log file output + $logger->trace("*Special found: $specialName",'heading') if $is_t_switch_active; + # the settings and storage of most objects has a lot in common $self->get_settings_and_store_new_object($specialObject); ${@{${$self}{children}}[-1]}{replacementText}.($8?$8:q()).($9?$9:q()); diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/Tokens.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/Tokens.pm index a106a09dcb1..2e358e0b62f 100644 --- a/Master/texmf-dist/scripts/latexindent/LatexIndent/Tokens.pm +++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/Tokens.pm @@ -18,6 +18,7 @@ use strict; use warnings; use Exporter qw/import/; use LatexIndent::Switches qw/$is_t_switch_active $is_tt_switch_active/; +use LatexIndent::LogFile qw/$logger/; our @EXPORT_OK = qw/token_check %tokens/; # each of the tokens begins the same way -- this is exploited during the hidden Children routine @@ -52,17 +53,18 @@ our %tokens = ( doubleBackSlash=>$beginningToken."DOUBLEBACKSLASH", alignmentBlock=>$beginningToken."ALIGNMENTBLOCK", paragraph=>$beginningToken."PARA", + sentence=>$beginningToken."SENTENCE", endOfToken=>"-END", ); sub token_check{ my $self = shift; - $self->logger("Token check",'heading') if $is_t_switch_active; + $logger->trace("*Token check") if $is_t_switch_active; # we use tokens for trailing comments, environments, commands, etc, so check that they're not in the body foreach( keys %tokens){ while(${$self}{body} =~ m/$tokens{$_}/si){ - $self->logger("Found $tokens{$_} within body, updating replacement token to $tokens{$_}-LIN") if($is_t_switch_active); + $logger->trace("Found $tokens{$_} within body, updating replacement token to $tokens{$_}-LIN") if($is_t_switch_active); $tokens{$_} .= "-LIN"; } } diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/TrailingComments.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/TrailingComments.pm index cbc35f6eee7..7f2b8e12738 100644 --- a/Master/texmf-dist/scripts/latexindent/LatexIndent/TrailingComments.pm +++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/TrailingComments.pm @@ -19,6 +19,7 @@ use warnings; use LatexIndent::Tokens qw/%tokens/; use LatexIndent::Switches qw/$is_t_switch_active $is_tt_switch_active $is_m_switch_active/; use LatexIndent::GetYamlSettings qw/%masterSettings/; +use LatexIndent::LogFile qw/$logger/; use Data::Dumper; use Exporter qw/import/; our @EXPORT_OK = qw/remove_trailing_comments put_trailing_comments_back_in $trailingCommentRegExp add_comment_symbol construct_trailing_comment_regexp/; @@ -42,8 +43,8 @@ sub add_comment_symbol{ push(@trailingComments,{id=>$tokens{trailingComment}.$commentCounter.$tokens{endOfToken},value=>q()}); # log file info - $self->logger("Updating trailing comment array",'heading')if $is_t_switch_active; - $self->logger(Dumper(\@trailingComments),'ttrace') if($is_tt_switch_active); + $logger->trace("*Updating trailing comment array")if $is_t_switch_active; + $logger->trace(Dumper(\@trailingComments),'ttrace') if($is_tt_switch_active); # the returned value return $tokens{trailingComment}.$commentCounter.$tokens{endOfToken}; @@ -51,7 +52,7 @@ sub add_comment_symbol{ sub remove_trailing_comments{ my $self = shift; - $self->logger("Storing trailing comments",'heading')if $is_t_switch_active; + $logger->trace("*Storing trailing comments")if $is_t_switch_active; # perform the substitution ${$self}{body} =~ s/ @@ -71,10 +72,10 @@ sub remove_trailing_comments{ "%".$tokens{trailingComment}.$commentCounter.$tokens{endOfToken}; /xsmeg; if(@trailingComments){ - $self->logger("Trailing comments stored in:") if($is_t_switch_active); - $self->logger(Dumper(\@trailingComments)) if($is_t_switch_active); + $logger->trace("Trailing comments stored in:") if($is_tt_switch_active); + $logger->trace(Dumper(\@trailingComments)) if($is_tt_switch_active); } else { - $self->logger("No trailing comments found") if($is_t_switch_active); + $logger->trace("No trailing comments found") if($is_t_switch_active); } return; } @@ -83,7 +84,7 @@ sub put_trailing_comments_back_in{ my $self = shift; return unless( @trailingComments > 0 ); - $self->logger("Returning trailing comments to body",'heading')if $is_t_switch_active; + $logger->trace("*Returning trailing comments to body")if $is_t_switch_active; # loop through trailing comments in reverse so that, for example, # latexindenttrailingcomment1 doesn't match the first @@ -95,7 +96,7 @@ sub put_trailing_comments_back_in{ # the -m switch can modify max characters per line, and trailing comment IDs can # be split across lines if($is_m_switch_active and ${$self}{body} !~ m/%$trailingcommentID/m){ - $self->logger("$trailingcommentID not found in body using /m matching, assuming it has been split across line (see modifyLineBreaks: textWrapOptions)") if($is_t_switch_active); + $logger->trace("$trailingcommentID not found in body using /m matching, assuming it has been split across line (see modifyLineBreaks: textWrapOptions)") if($is_t_switch_active); my $trailingcommentIDwithLineBreaks; # construct a reg exp that contains possible line breaks in between each character @@ -107,7 +108,7 @@ sub put_trailing_comments_back_in{ my $trailingcommentIDwithLineBreaksRegExp = qr/$trailingcommentIDwithLineBreaks/s; # replace the line-broken trailing comment ID with a non-broken trailing comment ID - ${$self}{body} =~ s/%$trailingcommentIDwithLineBreaksRegExp/%$trailingcommentID/s; + ${$self}{body} =~ s/%\R?$trailingcommentIDwithLineBreaksRegExp/%$trailingcommentID/s; } if(${$self}{body} =~ m/%$trailingcommentID ( @@ -118,12 +119,12 @@ sub put_trailing_comments_back_in{ ) # captured into $1 (\h*)?$ /mx and $1 ne ''){ - $self->logger("Comment not at end of line $trailingcommentID, moving it to end of line")if $is_t_switch_active; + $logger->trace("Comment not at end of line $trailingcommentID, moving it to end of line")if $is_t_switch_active; ${$self}{body} =~ s/%$trailingcommentID(.*)$/$1%$trailingcommentValue/m; } else { ${$self}{body} =~ s/%$trailingcommentID/%$trailingcommentValue/; } - $self->logger("replace %$trailingcommentID with %$trailingcommentValue") if($is_t_switch_active); + $logger->trace("replace %$trailingcommentID with %$trailingcommentValue") if($is_tt_switch_active); } return; } diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/UnNamedGroupingBracesBrackets.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/UnNamedGroupingBracesBrackets.pm index 30c969076c7..0c18484649a 100644 --- a/Master/texmf-dist/scripts/latexindent/LatexIndent/UnNamedGroupingBracesBrackets.pm +++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/UnNamedGroupingBracesBrackets.pm @@ -19,6 +19,7 @@ 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::LogFile qw/$logger/; use Exporter qw/import/; our @ISA = "LatexIndent::Command"; # class inheritance, Programming Perl, pg 321 our @EXPORT_OK = qw/construct_unnamed_grouping_braces_brackets_regexp $un_named_grouping_braces_RegExp $un_named_grouping_braces_RegExp_trailing_comment/; @@ -76,7 +77,7 @@ sub get_replacement_text{ my $self = shift; # the replacement text for a key = {value} needes to accomodate the leading [ OR { OR % OR , OR any combination thereof - $self->logger("Custom replacement text routine for ${$self}{name}") if $is_t_switch_active; + $logger->trace("Custom replacement text routine for ${$self}{name}") if $is_t_switch_active; # the un-named object is a little special, as it doesn't have a name; as such, if there are blank lines before # the braces/brackets, we have to insert them @@ -89,7 +90,7 @@ sub get_replacement_text{ # but now turn off the switch for linebreaksAtEnd{begin}, otherwise the first brace gets too much indentation # (see, for example, test-cases/namedGroupingBracesBrackets/special-characters-minimal.tex) ${${$self}{linebreaksAtEnd}}{begin} = 0; - $self->logger("Beginning bit is: ${$self}{beginningbit}") if($is_t_switch_active); + $logger->trace("Beginning bit is: ${$self}{beginningbit}") if($is_t_switch_active); delete ${$self}{beginningbit}; } diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/Verbatim.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/Verbatim.pm index 909b33cfc1b..c79d9604715 100644 --- a/Master/texmf-dist/scripts/latexindent/LatexIndent/Verbatim.pm +++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/Verbatim.pm @@ -16,11 +16,12 @@ package LatexIndent::Verbatim; # For all communication, please visit: https://github.com/cmhughes/latexindent.pl use strict; use warnings; +use Data::Dumper; +use Exporter qw/import/; use LatexIndent::Tokens qw/%tokens/; use LatexIndent::GetYamlSettings qw/%masterSettings/; use LatexIndent::Switches qw/$is_t_switch_active $is_tt_switch_active $is_m_switch_active/; -use Data::Dumper; -use Exporter qw/import/; +use LatexIndent::LogFile qw/$logger/; our @EXPORT_OK = qw/put_verbatim_back_in find_verbatim_environments find_noindent_block find_verbatim_commands put_verbatim_commands_back_in/; our @ISA = "LatexIndent::Document"; # class inheritance, Programming Perl, pg 321 our $verbatimCounter; @@ -29,11 +30,11 @@ sub find_noindent_block{ my $self = shift; # noindent block - $self->logger('looking for NOINDENTBLOCk environments (see noIndentBlock)','heading') if $is_t_switch_active; - $self->logger(Dumper(\%{$masterSettings{noIndentBlock}})) if($is_t_switch_active); + $logger->trace('*Searching for NOINDENTBLOCk environments (see noIndentBlock)') if $is_t_switch_active; + $logger->trace(Dumper(\%{$masterSettings{noIndentBlock}})) if($is_tt_switch_active); while( my ($noIndentBlock,$yesno)= each %{$masterSettings{noIndentBlock}}){ if($yesno){ - $self->logger("looking for $noIndentBlock:$yesno environments") if $is_t_switch_active; + $logger->trace("looking for $noIndentBlock:$yesno environments") if $is_t_switch_active; my $noIndentRegExp = qr/ ( @@ -58,28 +59,31 @@ sub find_noindent_block{ while( ${$self}{body} =~ m/$noIndentRegExp/sx){ # create a new Environment object - my $noIndentBlock = LatexIndent::Verbatim->new( begin=>$1, + my $noIndentBlockObj = LatexIndent::Verbatim->new( begin=>$1, body=>$2, end=>$3, name=>$noIndentBlock, ); # give unique id - $noIndentBlock->create_unique_id; + $noIndentBlockObj->create_unique_id; # verbatim children go in special hash - ${$self}{verbatim}{${$noIndentBlock}{id}}=$noIndentBlock; + ${$self}{verbatim}{${$noIndentBlockObj}{id}}=$noIndentBlockObj; # log file output - $self->logger("NOINDENTBLOCK environment found: $noIndentBlock") if $is_t_switch_active; + $logger->trace("*NOINDENTBLOCK environment found: $noIndentBlock") if $is_t_switch_active; # remove the environment block, and replace with unique ID - ${$self}{body} =~ s/$noIndentRegExp/${$noIndentBlock}{id}/sx; + ${$self}{body} =~ s/$noIndentRegExp/${$noIndentBlockObj}{id}/sx; - $self->logger("replaced with ID: ${$noIndentBlock}{id}") if $is_t_switch_active; + $logger->trace("replaced with ID: ${$noIndentBlockObj}{id}") if $is_t_switch_active; + + # possible decoration in log file + $logger->trace(${$masterSettings{logFilePreferences}}{showDecorationFinishCodeBlockTrace}) if ${$masterSettings{logFilePreferences}}{showDecorationFinishCodeBlockTrace}; } } else { - $self->logger("*not* looking for $noIndentBlock as $noIndentBlock:$yesno") if $is_t_switch_active; + $logger->trace("*not* looking for $noIndentBlock as $noIndentBlock:$yesno") if $is_t_switch_active; } } return; @@ -89,11 +93,11 @@ sub find_verbatim_environments{ my $self = shift; # verbatim environments - $self->logger('looking for VERBATIM environments (see verbatimEnvironments)','heading') if $is_t_switch_active; - $self->logger(Dumper(\%{$masterSettings{verbatimEnvironments}})) if($is_t_switch_active); + $logger->trace('*Searching for VERBATIM environments (see verbatimEnvironments)') if $is_t_switch_active; + $logger->trace(Dumper(\%{$masterSettings{verbatimEnvironments}})) if($is_tt_switch_active); while( my ($verbEnv,$yesno)= each %{$masterSettings{verbatimEnvironments}}){ if($yesno){ - $self->logger("looking for $verbEnv:$yesno environments") if $is_t_switch_active; + $logger->trace("looking for $verbEnv:$yesno environments") if $is_t_switch_active; my $verbatimRegExp = qr/ ( @@ -124,15 +128,18 @@ sub find_verbatim_environments{ ${$self}{verbatim}{${$verbatimBlock}{id}}=$verbatimBlock; # log file output - $self->logger("VERBATIM environment found: $verbEnv") if $is_t_switch_active; + $logger->trace("*VERBATIM environment found: $verbEnv") if $is_t_switch_active; # remove the environment block, and replace with unique ID ${$self}{body} =~ s/$verbatimRegExp/${$verbatimBlock}{id}/sx; - $self->logger("replaced with ID: ${$verbatimBlock}{id}") if $is_t_switch_active; + $logger->trace("replaced with ID: ${$verbatimBlock}{id}") if $is_t_switch_active; + + # possible decoration in log file + $logger->trace(${$masterSettings{logFilePreferences}}{showDecorationFinishCodeBlockTrace}) if ${$masterSettings{logFilePreferences}}{showDecorationFinishCodeBlockTrace}; } } else { - $self->logger("*not* looking for $verbEnv as $verbEnv:$yesno") if $is_t_switch_active; + $logger->trace("*not* looking for $verbEnv as $verbEnv:$yesno") if $is_t_switch_active; } } return; @@ -146,11 +153,11 @@ sub find_verbatim_commands{ # would need to be found *before* trailing comments have been removed. Similarly, # verbatim commands need to be put back in *after* trailing comments have been put # back in - $self->logger('looking for VERBATIM commands (see verbatimCommands)','heading') if $is_t_switch_active; - $self->logger(Dumper(\%{$masterSettings{verbatimCommands}})) if($is_tt_switch_active); + $logger->trace('*Searching for VERBATIM commands (see verbatimCommands)') if $is_t_switch_active; + $logger->trace(Dumper(\%{$masterSettings{verbatimCommands}})) if($is_tt_switch_active); while( my ($verbCommand,$yesno)= each %{$masterSettings{verbatimCommands}}){ if($yesno){ - $self->logger("looking for $verbCommand:$yesno Commands") if $is_t_switch_active; + $logger->trace("looking for $verbCommand:$yesno Commands") if $is_t_switch_active; my $verbatimCommandRegExp = qr/ ( @@ -190,21 +197,24 @@ sub find_verbatim_commands{ $verbatimCommand->create_unique_id; # output, if desired - $self->logger(Dumper($verbatimCommand),'ttrace') if($is_tt_switch_active); + $logger->trace(Dumper($verbatimCommand),'ttrace') if($is_tt_switch_active); # verbatim children go in special hash ${$self}{verbatimCommands}{${$verbatimCommand}{id}}=$verbatimCommand; # log file output - $self->logger("VERBATIM command found: $verbCommand") if $is_t_switch_active; + $logger->trace("*VERBATIM command found: $verbCommand") if $is_t_switch_active; # remove the environment block, and replace with unique ID ${$self}{body} =~ s/$verbatimCommandRegExp/${$verbatimCommand}{id}/sx; - $self->logger("replaced with ID: ${$verbatimCommand}{id}") if $is_t_switch_active; + $logger->trace("replaced with ID: ${$verbatimCommand}{id}") if $is_t_switch_active; + + # possible decoration in log file + $logger->trace(${$masterSettings{logFilePreferences}}{showDecorationFinishCodeBlockTrace}) if ${$masterSettings{logFilePreferences}}{showDecorationFinishCodeBlockTrace}; } } else { - $self->logger("*not* looking for $verbCommand as $verbCommand:$yesno") if $is_t_switch_active; + $logger->trace("*not* looking for $verbCommand as $verbCommand:$yesno") if $is_t_switch_active; } } return; @@ -218,8 +228,8 @@ sub put_verbatim_back_in { return unless(${$self}{verbatim}); # search for environments/commands - $self->logger('Putting verbatim back in, here is the pre-processed body:','heading') if $is_t_switch_active; - $self->logger(${$self}{body}) if($is_t_switch_active); + $logger->trace('*Putting verbatim back in, here is the pre-processed body:') if $is_tt_switch_active; + $logger->trace(${$self}{body}) if($is_tt_switch_active); # loop through document children hash while( (scalar keys %{${$self}{verbatim}})>0 ){ @@ -230,14 +240,13 @@ sub put_verbatim_back_in { ${$self}{body} =~ s/${$child}{id}/${$child}{begin}${$child}{body}${$child}{end}/; # log file info - $self->logger('Body now looks like:','heading') if $is_tt_switch_active; - $self->logger(${$self}{body},'ttrace') if($is_tt_switch_active); + $logger->trace('Body now looks like:') if $is_tt_switch_active; + $logger->trace(${$self}{body},'ttrace') if($is_tt_switch_active); # delete the hash so it won't be operated upon again delete ${$self}{verbatim}{${$child}{id}}; - $self->logger("deleted key") if $is_t_switch_active; } elsif ($is_m_switch_active and ${$masterSettings{modifyLineBreaks}{textWrapOptions}}{columns}>1 and ${$self}{body} !~ m/${$child}{id}/){ - $self->logger("${$child}{id} not found in body using /m matching, it may have been split across line (see modifyLineBreaks: textWrapOptions)") if($is_t_switch_active); + $logger->trace("${$child}{id} not found in body using /m matching, it may have been split across line (see modifyLineBreaks: textWrapOptions)") if($is_t_switch_active); # search for a version of the verbatim ID that may have line breaks my $verbatimIDwithLineBreaks = join("\\R?",split(//,${$child}{id})); @@ -250,10 +259,8 @@ sub put_verbatim_back_in { } # logfile info - $self->logger("Number of children:",'heading') if $is_t_switch_active; - $self->logger(scalar keys %{${$self}{verbatim}}) if $is_t_switch_active; - $self->logger('Post-processed body:','heading') if $is_t_switch_active; - $self->logger(${$self}{body}) if($is_t_switch_active); + $logger->trace('*Post-processed body:') if $is_tt_switch_active; + $logger->trace(${$self}{body}) if($is_tt_switch_active); return; } @@ -264,8 +271,8 @@ sub put_verbatim_commands_back_in { return unless(${$self}{verbatimCommands}); # search for environments/commands - $self->logger('Putting verbatim commands back in, here is the pre-processed body:','heading') if $is_t_switch_active; - $self->logger(${$self}{body}) if($is_t_switch_active); + $logger->trace('*Putting verbatim commands back in, here is the pre-processed body:') if $is_tt_switch_active; + $logger->trace(${$self}{body}) if($is_tt_switch_active); # loop through document children hash while( (scalar keys %{${$self}{verbatimCommands}})>0 ){ @@ -276,14 +283,13 @@ sub put_verbatim_commands_back_in { ${$self}{body} =~ s/${$child}{id}/${$child}{begin}${$child}{body}${$child}{end}/; # log file info - $self->logger('Body now looks like:','heading') if $is_tt_switch_active; - $self->logger(${$self}{body},'ttrace') if($is_tt_switch_active); + $logger->trace('Body now looks like:') if $is_tt_switch_active; + $logger->trace(${$self}{body},'ttrace') if($is_tt_switch_active); # delete the hash so it won't be operated upon again delete ${$self}{verbatimCommands}{${$child}{id}}; - $self->logger("deleted key") if $is_t_switch_active; } elsif ($is_m_switch_active and ${$masterSettings{modifyLineBreaks}{textWrapOptions}}{columns}>1 and ${$self}{body} !~ m/${$child}{id}/){ - $self->logger("${$child}{id} not found in body using /m matching, it may have been split across line (see modifyLineBreaks: textWrapOptions)") if($is_t_switch_active); + $logger->trace("${$child}{id} not found in body using /m matching, it may have been split across line (see modifyLineBreaks: textWrapOptions)") if($is_t_switch_active); # search for a version of the verbatim ID that may have line breaks my $verbatimIDwithLineBreaks = join("\\R?",split(//,${$child}{id})); @@ -296,10 +302,8 @@ sub put_verbatim_commands_back_in { } # logfile info - $self->logger("Number of children:",'heading'); - $self->logger(scalar keys %{${$self}{verbatimCommands}}); - $self->logger('Post-processed body:','heading') if $is_t_switch_active; - $self->logger(${$self}{body}) if($is_t_switch_active); + $logger->trace('*Post-processed body:') if $is_tt_switch_active; + $logger->trace(${$self}{body}) if($is_tt_switch_active); return; } diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/Version.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/Version.pm index 260f1f124a4..8a8c41b7fca 100644 --- a/Master/texmf-dist/scripts/latexindent/LatexIndent/Version.pm +++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/Version.pm @@ -19,6 +19,6 @@ use warnings; use Exporter qw/import/; our @EXPORT_OK = qw/$versionNumber $versionDate/; -our $versionNumber = '3.3'; -our $versionDate = '2017-08-21'; +our $versionNumber = '3.4'; +our $versionDate = '2018-01-13'; 1 |