diff options
Diffstat (limited to 'support/latexindent/LatexIndent')
-rw-r--r-- | support/latexindent/LatexIndent/AlignmentAtAmpersand.pm | 29 | ||||
-rw-r--r-- | support/latexindent/LatexIndent/FileContents.pm | 22 | ||||
-rw-r--r-- | support/latexindent/LatexIndent/Verbatim.pm | 358 | ||||
-rw-r--r-- | support/latexindent/LatexIndent/Version.pm | 4 |
4 files changed, 236 insertions, 177 deletions
diff --git a/support/latexindent/LatexIndent/AlignmentAtAmpersand.pm b/support/latexindent/LatexIndent/AlignmentAtAmpersand.pm index c015e08a87..22de133bf1 100644 --- a/support/latexindent/LatexIndent/AlignmentAtAmpersand.pm +++ b/support/latexindent/LatexIndent/AlignmentAtAmpersand.pm @@ -61,23 +61,22 @@ sub find_aligned_block{ (?!<\\) % \* - \h* # possible horizontal spaces + \h* # possible horizontal spaces \\begin\{ - $alignmentBlock # environment name captured into $2 - \} # %* \begin{alignmentBlock} statement + ($alignmentBlock) # environment name captured into $2 + \} # \begin{alignmentBlock} statement captured into $1 ) ( - .*? + .*? # non-greedy match (body) into $3 ) - \R - \h* + \R # a line break + \h* # possible horizontal spaces ( (?!<\\) - %\* # % - \h* # possible horizontal spaces - \\end\{$alignmentBlock\} # \end{alignmentBlock} - ) # %* \end{<something>} statement - #\R + %\* # % + \h* # possible horizontal spaces + \\end\{\2\} # \end{alignmentBlock} statement captured into $4 + ) /sx; while( ${$self}{body} =~ m/$alignmentRegExp/sx){ @@ -87,9 +86,9 @@ sub find_aligned_block{ / # create a new Environment object my $alignmentBlockObj = LatexIndent::AlignmentAtAmpersand->new( begin=>$1, - body=>$2, - end=>$3, - name=>$alignmentBlock, + body=>$3, + end=>$4, + name=>$2, modifyLineBreaksYamlName=>"environments", linebreaksAtEnd=>{ begin=>1, @@ -99,7 +98,7 @@ sub find_aligned_block{ ); # log file output - $logger->trace("*Alignment block found: %*\\begin\{$alignmentBlock\}") if $is_t_switch_active; + $logger->trace("*Alignment block found: %*\\begin\{${$alignmentBlock}{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($alignmentBlockObj); diff --git a/support/latexindent/LatexIndent/FileContents.pm b/support/latexindent/LatexIndent/FileContents.pm index b18feae6bd..439e764b31 100644 --- a/support/latexindent/LatexIndent/FileContents.pm +++ b/support/latexindent/LatexIndent/FileContents.pm @@ -60,30 +60,30 @@ sub find_file_contents_environments_and_preamble{ my $fileContentsRegExp = qr/ ( \\begin\{ - $fileContentsEnv - \} + ($fileContentsEnv) # environment name captured into $2 + \} # begin statement captured into $1 ) ( - .*? + .*? # non-greedy match (body) into $3 ) ( - \\end\{$fileContentsEnv\} - \h* + \\end\{\2\} # end statement captured into $4 + \h* # possible horizontal spaces ) - (\R)? + (\R)? # possibly followed by a line break /sx; while( ${$self}{body} =~ m/$fileContentsRegExp/sx){ # create a new Environment object my $fileContentsBlock = LatexIndent::FileContents->new( begin=>$1, - body=>$2, - end=>$3, - name=>$fileContentsEnv, + body=>$3, + end=>$4, + name=>$2, linebreaksAtEnd=>{ begin=>0, body=>0, - end=>$4?1:0, + end=>$5?1:0, }, modifyLineBreaksYamlName=>"filecontents", ); @@ -112,7 +112,7 @@ sub find_file_contents_environments_and_preamble{ push(@fileContentsStorageArray,$fileContentsBlock); # log file output - $logger->trace("FILECONTENTS environment found: $fileContentsEnv")if $is_t_switch_active; + $logger->trace("FILECONTENTS environment found: ${$fileContentsEnv}{name}")if $is_t_switch_active; # remove the environment block, and replace with unique ID ${$self}{body} =~ s/$fileContentsRegExp/${$fileContentsBlock}{replacementText}/sx; diff --git a/support/latexindent/LatexIndent/Verbatim.pm b/support/latexindent/LatexIndent/Verbatim.pm index 3abe2e0d46..0bb41c5227 100644 --- a/support/latexindent/LatexIndent/Verbatim.pm +++ b/support/latexindent/LatexIndent/Verbatim.pm @@ -31,31 +31,46 @@ sub find_noindent_block{ my $self = shift; # noindent block - $logger->trace('*Searching for NOINDENTBLOCk (see noIndentBlock)') if $is_t_switch_active; + $logger->trace('*Searching for NOINDENTBLOCK (see noIndentBlock)') if $is_t_switch_active; $logger->trace(Dumper(\%{$mainSettings{noIndentBlock}})) if($is_tt_switch_active); while( my ($noIndentBlock,$yesno)= each %{$mainSettings{noIndentBlock}}){ # integrity check on the field for noIndentBlock if ( ref($yesno) eq "HASH" ){ - if (not defined ${$yesno}{begin}){ - $logger->trace(" *not* looking for $noIndentBlock as $noIndentBlock:begin not specified") if $is_t_switch_active; - next; - } elsif (not defined ${$yesno}{end}) { - $logger->trace(" *not* looking for $noIndentBlock as $noIndentBlock:end not specified") if $is_t_switch_active; - next; - } elsif (defined ${$yesno}{lookForThis} and !${$yesno}{lookForThis}){ - $logger->trace(" *not* looking for $noIndentBlock as lookForThis: 0") if $is_t_switch_active; - next; - } + if (defined ${$yesno}{lookForThis} and !${$yesno}{lookForThis}){ + $logger->trace(" *not* looking for $noIndentBlock as lookForThis: 0") if $is_t_switch_active; + next; + } + if (not defined ${$yesno}{name}) { + if (not defined ${$yesno}{begin}){ + $logger->trace(" *not* looking for $noIndentBlock as $noIndentBlock:begin not specified") if $is_t_switch_active; + next; + } elsif (not defined ${$yesno}{end}) { + $logger->trace(" *not* looking for $noIndentBlock as $noIndentBlock:end not specified") if $is_t_switch_active; + next; + } + } elsif (defined ${$yesno}{begin} or defined ${$yesno}{end}){ + $logger->trace(" *not* looking for $noIndentBlock as $noIndentBlock:name specified with begin and/or end") if $is_t_switch_active; + next; + } } elsif( ref($yesno) ne "HASH" and !$yesno ){ - $logger->trace(" *not* looking for $noIndentBlock as $noIndentBlock:$yesno") if $is_t_switch_active; - next; + $logger->trace(" *not* looking for $noIndentBlock as $noIndentBlock:$yesno") if $is_t_switch_active; + next; } # if we've made it this far, then we're good to go my $noIndentRegExp; + my $noIndentBlockObj; if (ref($yesno) eq "HASH"){ + # default value of begin and end + if (defined ${$yesno}{name} and not defined ${$yesno}{begin} and not defined ${$yesno}{end}){ + ${$yesno}{begin} = "\\\\begin\\{(${$yesno}{name})\\}"; + ${$yesno}{end} = "\\\\end\\{\\2\\}"; + $logger->trace("looking for regex based $noIndentBlock, name: ${$yesno}{name}") if $is_t_switch_active; + $logger->trace("begin not specified for $noIndentBlock, setting default ${$yesno}{begin}") if $is_t_switch_active; + $logger->trace("end not specified for $noIndentBlock, setting default ${$yesno}{end}") if $is_t_switch_active; + } # default value of body if (not defined ${$yesno}{body}){ $logger->trace("looking for regex based $noIndentBlock, begin: ${$yesno}{begin}, end: ${$yesno}{end}") if $is_t_switch_active; @@ -70,8 +85,8 @@ sub find_noindent_block{ $noIndentRegExp = qr/ (${$yesno}{begin}) - (${$yesno}{body}) - (${$yesno}{end}) + (${$yesno}{body}) + (${$yesno}{end}) /sx; } else { $logger->trace("looking for $noIndentBlock:$yesno noIndentBlock") if $is_t_switch_active; @@ -81,32 +96,44 @@ sub find_noindent_block{ ( (?!<\\) % - (?:\h|(?!<\\)%)* # possible horizontal spaces + (?:\h|(?!<\\)%)* # possible horizontal spaces \\begin\{ - $noIndentBlockSpec - \} # % \begin{noindentblock} statement - ) # begin captured into $1 + ($noIndentBlockSpec) # environment name captured into $2 + \} # % \begin{noindentblock} statement + ) # begin statement captured into $1 ( - .*? - ) # non-greedy match (body) into $2 + .*? # non-greedy match (body) into $3 + ) ( (?!<\\) - % # % - (?:\h|(?!<\\)%)* # possible horizontal spaces - \\end\{$noIndentBlockSpec\} # \end{noindentblock} - ) # % \end{<something>} statement into $3 + % # % + (?:\h|(?!<\\)%)* # possible horizontal spaces + \\end\{\2\} # % \end{noindentblock} statement + ) # end statement captured into $4 /sx; } while( ${$self}{body} =~ m/$noIndentRegExp/sx){ # create a new Verbatim object - my $noIndentBlockObj = LatexIndent::Verbatim->new( begin=>$1, + if (ref($yesno) eq "HASH" and not defined ${$yesno}{name}){ + # user defined begin and end statements + $noIndentBlockObj = LatexIndent::Verbatim->new( begin=>$1, body=>$2, end=>$3, name=>$noIndentBlock, type=>"noindentblock", modifyLineBreaksYamlName=>"verbatim", ); + } else { + # specified by name (entry:1 or entry: name: regex) + $noIndentBlockObj = LatexIndent::Verbatim->new( begin=>$1, + body=>$3, + end=>$4, + name=>$2, + type=>"noindentblock", + modifyLineBreaksYamlName=>"verbatim", + ); + } # give unique id $noIndentBlockObj->create_unique_id; @@ -115,7 +142,7 @@ sub find_noindent_block{ $verbatimStorage{${$noIndentBlockObj}{id}}=$noIndentBlockObj; # log file output - $logger->trace("NOINDENTBLOCK found: $noIndentBlock") if $is_t_switch_active; + $logger->trace("NOINDENTBLOCK found: ${$noIndentBlockObj}{name}") if $is_t_switch_active; # remove the environment block, and replace with unique ID ${$self}{body} =~ s/$noIndentRegExp/${$noIndentBlockObj}{id}/sx; @@ -136,67 +163,83 @@ sub find_verbatim_environments{ $logger->trace('*Searching for VERBATIM environments (see verbatimEnvironments)') if $is_t_switch_active; $logger->trace(Dumper(\%{$mainSettings{verbatimEnvironments}})) if($is_tt_switch_active); while( my ($verbEnv,$yesno)= each %{$mainSettings{verbatimEnvironments}}){ - if($yesno){ - $logger->trace("looking for $verbEnv:$yesno environments") if $is_t_switch_active; + my $verbEnvSpec; - (my $verbEnvSpec = $verbEnv) =~ s/\*/\\*/sg; - my $verbatimRegExp = qr/ - ( - \\begin\{ - $verbEnvSpec # environment name captured into $1 - \} # \begin{<something>} statement - ) - ( - .*? - ) # any character, but not \\begin - ( - \\end\{$verbEnvSpec\} # \end{<something>} statement - ) - (\h*)? # possibly followed by horizontal space - (\R)? # possibly followed by a line break - /sx; - - while( ${$self}{body} =~ m/$verbatimRegExp/sx){ + # integrity check on the field for noIndentBlock + if ( ref($yesno) eq "HASH" ){ + if (defined ${$yesno}{lookForThis} and !${$yesno}{lookForThis}){ + $logger->trace(" *not* looking for $verbEnv as lookForThis: 0") if $is_t_switch_active; + next; + } elsif (not defined ${$yesno}{name}){ + $logger->trace(" *not* looking for $verbEnv as $verbEnv:name not specified") if $is_t_switch_active; + next; + } else { + $logger->trace("looking for VERBATIM-environments $verbEnv, name: ${$yesno}{name}") if $is_t_switch_active; + $verbEnvSpec = ${$yesno}{name}; + } + } elsif( ref($yesno) ne "HASH" and $yesno ){ + $logger->trace("looking for $verbEnv:$yesno environments") if $is_t_switch_active; + ($verbEnvSpec = $verbEnv) =~ s/\*/\\*/sg; + } else { + $logger->trace(" *not* looking for $verbEnv as $verbEnv:$yesno") if $is_t_switch_active; + next; + } - # create a new Verbatim object - my $verbatimBlock = LatexIndent::Verbatim->new( begin=>$1, - body=>$2, - end=>$3, - name=>$verbEnv, - type=>"environment", - modifyLineBreaksYamlName=>"verbatim", - linebreaksAtEnd=>{ - end=>$5?1:0, - }, - horizontalTrailingSpace=>$4?$4:q(), - aliases=>{ - # begin statements - BeginStartsOnOwnLine=>"VerbatimBeginStartsOnOwnLine", - # after end statements - EndFinishesWithLineBreak=>"VerbatimEndFinishesWithLineBreak", - }, - ); + # if we've made it this far, then we're good to go + my $verbatimRegExp = qr/ + ( + \\begin\{ + ($verbEnvSpec) # environment name captured into $2 + \} # \begin{<something>} statement captured into $1 + ) + ( + .*? # non-greedy match (body) into $3 + ) # any character, but not \\begin + ( + \\end\{\2\} # \end{<something>} statement captured into $4 + ) + (\h*)? # possibly followed by horizontal space + (\R)? # possibly followed by a line break + /sx; + + while( ${$self}{body} =~ m/$verbatimRegExp/sx){ + + # create a new Verbatim object + my $verbatimBlock = LatexIndent::Verbatim->new( begin=>$1, + body=>$3, + end=>$4, + name=>$2, + type=>"environment", + modifyLineBreaksYamlName=>"verbatim", + linebreaksAtEnd=>{ + end=>$6?1:0, + }, + horizontalTrailingSpace=>$5?$5:q(), + aliases=>{ + # begin statements + BeginStartsOnOwnLine=>"VerbatimBeginStartsOnOwnLine", + # after end statements + EndFinishesWithLineBreak=>"VerbatimEndFinishesWithLineBreak", + }, + ); - # there are common tasks for each of the verbatim objects - $verbatimBlock->verbatim_common_tasks; - - # verbatim children go in special hash - $verbatimStorage{${$verbatimBlock}{id}}=$verbatimBlock; + # there are common tasks for each of the verbatim objects + $verbatimBlock->verbatim_common_tasks; + + # verbatim children go in special hash + $verbatimStorage{${$verbatimBlock}{id}}=$verbatimBlock; - # log file output - $logger->trace("*VERBATIM environment found: $verbEnv") if $is_t_switch_active; + # log file output + $logger->trace("*VERBATIM environment found: ${$verbatimBlock}{name}") if $is_t_switch_active; - # remove the environment block, and replace with unique ID - ${$self}{body} =~ s/$verbatimRegExp/${$verbatimBlock}{replacementText}/sx; + # remove the environment block, and replace with unique ID + ${$self}{body} =~ s/$verbatimRegExp/${$verbatimBlock}{replacementText}/sx; - $logger->trace("replaced with ID: ${$verbatimBlock}{id}") if $is_t_switch_active; - - # possible decoration in log file - $logger->trace(${$mainSettings{logFilePreferences}}{showDecorationFinishCodeBlockTrace}) if ${$mainSettings{logFilePreferences}}{showDecorationFinishCodeBlockTrace}; - } - } else { - $logger->trace("*not* looking for $verbEnv as $verbEnv:$yesno") if $is_t_switch_active; - } + $logger->trace("replaced with ID: ${$verbatimBlock}{id}") if $is_t_switch_active; + + # possible decoration in log file + $logger->trace(${$mainSettings{logFilePreferences}}{showDecorationFinishCodeBlockTrace}) if ${$mainSettings{logFilePreferences}}{showDecorationFinishCodeBlockTrace}; + } } return; } @@ -212,80 +255,97 @@ sub find_verbatim_commands{ $logger->trace('*Searching for VERBATIM commands (see verbatimCommands)') if $is_t_switch_active; $logger->trace(Dumper(\%{$mainSettings{verbatimCommands}})) if($is_tt_switch_active); while( my ($verbCommand,$yesno)= each %{$mainSettings{verbatimCommands}}){ - if($yesno){ - $logger->trace("looking for $verbCommand:$yesno Commands") if $is_t_switch_active; + my $verbCommandSpec; - my $verbatimRegExp = qr/ - ( - \\$verbCommand - \h* - ) # name of command into $1 - ( - \[ - (?: - (?! - (?:(?<!\\)\[) - ). - )*? # not including [, but \[ ok - (?<!\\) # not immediately pre-ceeded by \ - \] # [optional arguments] - \h* - )? # opt arg into $2 - ( - . - ) # delimiter into $3 - ( - .*? - ) # body into $4 - \3 - (\h*)? # possibly followed by horizontal space - (\R)? # possibly followed by a line break - /mx; - - while( ${$self}{body} =~ m/$verbatimRegExp/){ + # integrity check on the field for noIndentBlock + if ( ref($yesno) eq "HASH" ){ + if (defined ${$yesno}{lookForThis} and !${$yesno}{lookForThis}){ + $logger->trace(" *not* looking for $verbCommand as lookForThis: 0") if $is_t_switch_active; + next; + } elsif (not defined ${$yesno}{name}){ + $logger->trace(" *not* looking for $verbCommand as $verbCommand:name not specified") if $is_t_switch_active; + next; + } else { + $logger->trace("looking for regex based VERBATIM-commands $verbCommand, name: ${$yesno}{name}") if $is_t_switch_active; + $verbCommandSpec = ${$yesno}{name}; + } + } elsif( ref($yesno) ne "HASH" and $yesno ){ + $logger->trace("looking for $verbCommand:$yesno Commands") if $is_t_switch_active; + $verbCommandSpec = $verbCommand; + } else { + $logger->trace("*not* looking for $verbCommand as $verbCommand:$yesno") if $is_t_switch_active; + next; + } - # create a new Verbatim object - my $verbatimCommand = LatexIndent::Verbatim->new( begin=>$1.($2?$2:q()).$3, - body=>$4, - end=>$3, - name=>$verbCommand, - type=>"command", - modifyLineBreaksYamlName=>"verbatim", - linebreaksAtEnd=>{ - end=>$6?1:0, - }, - horizontalTrailingSpace=>$5?$5:q(), - aliases=>{ - # begin statements - BeginStartsOnOwnLine=>"VerbatimBeginStartsOnOwnLine", - # after end statements - EndFinishesWithLineBreak=>"VerbatimEndFinishesWithLineBreak", - }, - optArg=>$2?$2:q(), - ); - # there are common tasks for each of the verbatim objects - $verbatimCommand->verbatim_common_tasks; + # if we've made it this far, then we're good to go + my $verbatimRegExp = qr/ + ( + \\($verbCommandSpec) # name of command into $2 + \h* + ) + ( + \[ + (?: + (?! + (?:(?<!\\)\[) + ). + )*? # not including [, but \[ ok + (?<!\\) # not immediately pre-ceeded by \ + \] # [optional arguments] + \h* + )? # opt arg into $3 + ( + . + ) # delimiter into $4 + ( + .*? + ) # body into $5 + \4 + (\h*)? # possibly followed by horizontal space + (\R)? # possibly followed by a line break + /mx; + + while( ${$self}{body} =~ m/$verbatimRegExp/){ + + # create a new Verbatim object + my $verbatimCommand = LatexIndent::Verbatim->new( begin=>$1.($3?$3:q()).$4, + body=>$5, + end=>$4, + name=>$2, + type=>"command", + modifyLineBreaksYamlName=>"verbatim", + linebreaksAtEnd=>{ + end=>$7?1:0, + }, + horizontalTrailingSpace=>$6?$6:q(), + aliases=>{ + # begin statements + BeginStartsOnOwnLine=>"VerbatimBeginStartsOnOwnLine", + # after end statements + EndFinishesWithLineBreak=>"VerbatimEndFinishesWithLineBreak", + }, + optArg=>$3?$3:q(), + ); + # there are common tasks for each of the verbatim objects + $verbatimCommand->verbatim_common_tasks; - # output, if desired - $logger->trace(Dumper($verbatimCommand),'ttrace') if($is_tt_switch_active); + # output, if desired + $logger->trace(Dumper($verbatimCommand),'ttrace') if($is_tt_switch_active); - # verbatim children go in special hash - $verbatimStorage{${$verbatimCommand}{id}}=$verbatimCommand; + # verbatim children go in special hash + $verbatimStorage{${$verbatimCommand}{id}}=$verbatimCommand; - # log file output - $logger->trace("*VERBATIM command found: $verbCommand") if $is_t_switch_active; + # log file output + $logger->trace("*VERBATIM command found: ${$verbatimCommand}{name}") if $is_t_switch_active; - # remove the environment block, and replace with unique ID - ${$self}{body} =~ s/$verbatimRegExp/${$verbatimCommand}{replacementText}/sx; + # remove the environment block, and replace with unique ID + ${$self}{body} =~ s/$verbatimRegExp/${$verbatimCommand}{replacementText}/sx; - $logger->trace("replaced with ID: ${$verbatimCommand}{id}") if $is_t_switch_active; - - # possible decoration in log file - $logger->trace(${$mainSettings{logFilePreferences}}{showDecorationFinishCodeBlockTrace}) if ${$mainSettings{logFilePreferences}}{showDecorationFinishCodeBlockTrace}; - } - } else { - $logger->trace("*not* looking for $verbCommand as $verbCommand:$yesno") if $is_t_switch_active; - } + $logger->trace("replaced with ID: ${$verbatimCommand}{id}") if $is_t_switch_active; + + # possible decoration in log file + $logger->trace(${$mainSettings{logFilePreferences}}{showDecorationFinishCodeBlockTrace}) if ${$mainSettings{logFilePreferences}}{showDecorationFinishCodeBlockTrace}; + } } return; diff --git a/support/latexindent/LatexIndent/Version.pm b/support/latexindent/LatexIndent/Version.pm index cd4878cbaa..d25b4f55ab 100644 --- a/support/latexindent/LatexIndent/Version.pm +++ b/support/latexindent/LatexIndent/Version.pm @@ -19,6 +19,6 @@ use warnings; use Exporter qw/import/; our @EXPORT_OK = qw/$versionNumber $versionDate/; -our $versionNumber = '3.12'; -our $versionDate = '2021-09-16'; +our $versionNumber = '3.13'; +our $versionDate = '2021-10-30'; 1 |