summaryrefslogtreecommitdiff
path: root/support/latexindent/LatexIndent/Verbatim.pm
diff options
context:
space:
mode:
Diffstat (limited to 'support/latexindent/LatexIndent/Verbatim.pm')
-rw-r--r--support/latexindent/LatexIndent/Verbatim.pm54
1 files changed, 36 insertions, 18 deletions
diff --git a/support/latexindent/LatexIndent/Verbatim.pm b/support/latexindent/LatexIndent/Verbatim.pm
index 2d8fe0e2d8..3abe2e0d46 100644
--- a/support/latexindent/LatexIndent/Verbatim.pm
+++ b/support/latexindent/LatexIndent/Verbatim.pm
@@ -19,7 +19,7 @@ use warnings;
use Data::Dumper;
use Exporter qw/import/;
use LatexIndent::Tokens qw/%tokens/;
-use LatexIndent::GetYamlSettings qw/%masterSettings/;
+use LatexIndent::GetYamlSettings qw/%mainSettings/;
use LatexIndent::Switches qw/$is_t_switch_active $is_tt_switch_active $is_m_switch_active/;
use LatexIndent::LogFile qw/$logger/;
our @EXPORT_OK = qw/put_verbatim_back_in find_verbatim_environments find_noindent_block find_verbatim_commands find_verbatim_special verbatim_common_tasks %verbatimStorage/;
@@ -32,8 +32,8 @@ sub find_noindent_block{
# noindent block
$logger->trace('*Searching for NOINDENTBLOCk (see noIndentBlock)') if $is_t_switch_active;
- $logger->trace(Dumper(\%{$masterSettings{noIndentBlock}})) if($is_tt_switch_active);
- while( my ($noIndentBlock,$yesno)= each %{$masterSettings{noIndentBlock}}){
+ $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" ){
@@ -123,7 +123,7 @@ sub find_noindent_block{
$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};
+ $logger->trace(${$mainSettings{logFilePreferences}}{showDecorationFinishCodeBlockTrace}) if ${$mainSettings{logFilePreferences}}{showDecorationFinishCodeBlockTrace};
}
}
return;
@@ -134,8 +134,8 @@ sub find_verbatim_environments{
# verbatim environments
$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}}){
+ $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;
@@ -192,7 +192,7 @@ sub find_verbatim_environments{
$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};
+ $logger->trace(${$mainSettings{logFilePreferences}}{showDecorationFinishCodeBlockTrace}) if ${$mainSettings{logFilePreferences}}{showDecorationFinishCodeBlockTrace};
}
} else {
$logger->trace("*not* looking for $verbEnv as $verbEnv:$yesno") if $is_t_switch_active;
@@ -210,8 +210,8 @@ sub find_verbatim_commands{
# verbatim commands need to be put back in *after* trailing comments have been put
# back in
$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}}){
+ $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;
@@ -281,7 +281,7 @@ sub find_verbatim_commands{
$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};
+ $logger->trace(${$mainSettings{logFilePreferences}}{showDecorationFinishCodeBlockTrace}) if ${$mainSettings{logFilePreferences}}{showDecorationFinishCodeBlockTrace};
}
} else {
$logger->trace("*not* looking for $verbCommand as $verbCommand:$yesno") if $is_t_switch_active;
@@ -295,7 +295,7 @@ sub find_verbatim_special{
my $self = shift;
# loop through specialBeginEnd
- while( my ($specialName,$BeginEnd)= each %{$masterSettings{specialBeginEnd}}){
+ while( my ($specialName,$BeginEnd)= each %{$mainSettings{specialBeginEnd}}){
# only classify special Verbatim if lookForThis is 'verbatim'
if( (ref($BeginEnd) eq "HASH") and ${$BeginEnd}{lookForThis}=~m/v/s and ${$BeginEnd}{lookForThis} eq 'verbatim'){
@@ -350,7 +350,7 @@ sub find_verbatim_special{
$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};
+ $logger->trace(${$mainSettings{logFilePreferences}}{showDecorationFinishCodeBlockTrace}) if ${$mainSettings{logFilePreferences}}{showDecorationFinishCodeBlockTrace};
}
}
}
@@ -363,7 +363,7 @@ sub put_verbatim_back_in {
my $verbatimCount=0;
my $toMatch = q();
if($input{match} eq "everything-except-commands"){
- $toMatch = "noindentblockenvironmentspecial";
+ $toMatch = "noindentblockenvironmentspeciallinesprotect";
} else {
$toMatch = "command";
}
@@ -386,14 +386,32 @@ sub put_verbatim_back_in {
while($verbatimFound < $verbatimCount){
while( my ($verbatimID,$child)= each %verbatimStorage){
if($toMatch =~ m/${$child}{type}/){
- if(${$self}{body} =~ m/$verbatimID/mx){
+ if(${$self}{body} =~ m/$verbatimID/m){
# possibly remove trailing line break
- if(defined ${$child}{EndFinishesWithLineBreak}
+ if($is_m_switch_active
+ and defined ${$child}{EndFinishesWithLineBreak}
and ${$child}{EndFinishesWithLineBreak}==-1
and ${$self}{body} =~ m/$verbatimID\h*\R/s){
$logger->trace("m-switch active, removing trailing line breaks from ${$child}{name}") if $is_t_switch_active;
${$self}{body} =~ s/$verbatimID(\h*)?(\R|\h)*/$verbatimID /s;
}
+
+ # line protection mode can allow line breaks to be removed
+ # at end of verbatim; these need to be added back in
+ #
+ # see
+ #
+ # test-cases/line-switch-test-cases/environments-simple-nested-mod13.tex
+ #
+ if(${$child}{type} eq "linesprotect"){
+ # remove leading space ahead of verbatim ID
+ ${$self}{body} =~ s/^\h*$verbatimID/$verbatimID/m;
+
+ if($is_m_switch_active and ${$self}{body}=~ m/$verbatimID\h*\S/s){
+ ${$self}{body} =~ s/$verbatimID\h*(\S)/$verbatimID\n$1/s;
+ }
+ }
+
# replace ids with body
${$self}{body} =~ s/$verbatimID/${$child}{begin}${$child}{body}${$child}{end}/s;
@@ -405,8 +423,8 @@ sub put_verbatim_back_in {
delete $verbatimStorage{$verbatimID};
$verbatimFound++;
} elsif ($is_m_switch_active
- and ${$masterSettings{modifyLineBreaks}{textWrapOptions}}{columns}>1
- and ${$masterSettings{modifyLineBreaks}{textWrapOptions}}{huge} ne "overflow"
+ and ${$mainSettings{modifyLineBreaks}{textWrapOptions}}{columns}>1
+ and ${$mainSettings{modifyLineBreaks}{textWrapOptions}}{huge} ne "overflow"
and ${$self}{body} !~ m/${$child}{id}/){
$logger->trace("$verbatimID not found in body using /m matching, it may have been split across line (see modifyLineBreaks: textWrapOptions)") if($is_t_switch_active);
@@ -462,7 +480,7 @@ sub create_unique_id{
sub yaml_get_textwrap_removeparagraphline_breaks{
my $self = shift;
- $logger->trace("No text wrap or remove paragraph line breaks for verbatim code blocks, ${$self}{name}") if ${$masterSettings{logFilePreferences}}{showDecorationFinishCodeBlockTrace};
+ $logger->trace("No text wrap or remove paragraph line breaks for verbatim code blocks, ${$self}{name}") if ${$mainSettings{logFilePreferences}}{showDecorationFinishCodeBlockTrace};
}
1;