summaryrefslogtreecommitdiff
path: root/support/latexindent/LatexIndent
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2021-06-20 03:01:22 +0000
committerNorbert Preining <norbert@preining.info>2021-06-20 03:01:22 +0000
commit0b024adf546cd484554e4de5bd1a9919a4fdd03d (patch)
treef688c8afa79d522868966c9c91e09088f28b5248 /support/latexindent/LatexIndent
parentdaa6873fe1d06863ffc2980970295b39071f02ba (diff)
CTAN sync 202106200301
Diffstat (limited to 'support/latexindent/LatexIndent')
-rw-r--r--support/latexindent/LatexIndent/AlignmentAtAmpersand.pm25
-rw-r--r--support/latexindent/LatexIndent/BlankLines.pm12
-rw-r--r--support/latexindent/LatexIndent/Document.pm11
-rw-r--r--support/latexindent/LatexIndent/Else.pm1
-rw-r--r--support/latexindent/LatexIndent/Environment.pm1
-rw-r--r--support/latexindent/LatexIndent/FileContents.pm152
-rw-r--r--support/latexindent/LatexIndent/GetYamlSettings.pm116
-rw-r--r--support/latexindent/LatexIndent/Heading.pm1
-rw-r--r--support/latexindent/LatexIndent/IfElseFi.pm1
-rw-r--r--support/latexindent/LatexIndent/KeyEqualsValuesBraces.pm1
-rw-r--r--support/latexindent/LatexIndent/LogFile.pm9
-rw-r--r--support/latexindent/LatexIndent/Replacement.pm1
-rw-r--r--support/latexindent/LatexIndent/Special.pm78
-rw-r--r--support/latexindent/LatexIndent/Switches.pm4
-rw-r--r--support/latexindent/LatexIndent/TrailingComments.pm17
-rw-r--r--support/latexindent/LatexIndent/Verbatim.pm116
-rw-r--r--support/latexindent/LatexIndent/Version.pm4
17 files changed, 355 insertions, 195 deletions
diff --git a/support/latexindent/LatexIndent/AlignmentAtAmpersand.pm b/support/latexindent/LatexIndent/AlignmentAtAmpersand.pm
index 993423ab2e..45307a90b6 100644
--- a/support/latexindent/LatexIndent/AlignmentAtAmpersand.pm
+++ b/support/latexindent/LatexIndent/AlignmentAtAmpersand.pm
@@ -388,7 +388,12 @@ sub align_at_ampersand{
){
${$_}{row} = (${$_}{unformattedRow} ne "" ? ${$_}{unformattedRow}:q()).(${$_}{trailingComment}?${$_}{trailingComment}:q());
}
-
+
+ # spaces for leadingBlankColumn in operation
+ if(${$self}{leadingBlankColumn}>-1){
+ $padding = " " x (${$self}{leadingBlankColumn});
+ ${$_}{row} =~ s/^\h*/$padding/s;
+ }
}
# delete the original body
@@ -738,6 +743,19 @@ sub individual_padding{
${$cell}{delimiterLength} = $maxDelimiterWidth[$j];
}
+ # to keep leadingBlankColumn on, we need to check:
+ #
+ # - are we in the first column?
+ # - is leadingBlankColumn 0 or more?
+ # - cell width of first column equal 0?
+ # - are we measuring this cell?
+ #
+ # see test-cases/alignment/issue-275a.tex and the associated logfile
+ #
+ if ($j==0 and ${$self}{leadingBlankColumn}>-1 and ${$cell}{width} > 0 and ${$cell}{measureThis}==1){
+ ${$self}{leadingBlankColumn} = -1;
+ }
+
# there are some cells that shouldn't be accounted for in measuring,
# for example {ccc}
next if !${$cell}{measureThis};
@@ -748,6 +766,7 @@ sub individual_padding{
max($maximumColumnWidths[$j],${$cell}{width})
:
${$cell}{width});
+
}
# update the maximum number of columns
@@ -1288,14 +1307,14 @@ sub pretty_print_cell_info{
$logger->trace("*cell information: $thingToPrint");
- $logger->trace("minimum multi col span: ",join(",",@minMultiColSpan)) if(@minMultiColSpan);
+ $logger->trace("minimum multi col span: ".join(",",@minMultiColSpan)) if(@minMultiColSpan);
foreach my $row (@cellStorage) {
my $tmpLogFileLine = q();
foreach my $cell (@$row) {
$tmpLogFileLine .= ${$cell}{$thingToPrint}."\t";
}
- $logger->trace(' ', $tmpLogFileLine) if($is_t_switch_active);
+ $logger->trace(' '. $tmpLogFileLine) if($is_t_switch_active);
}
if($thingToPrint eq "type"){
diff --git a/support/latexindent/LatexIndent/BlankLines.pm b/support/latexindent/LatexIndent/BlankLines.pm
index abd1ed73a3..2622e9ad90 100644
--- a/support/latexindent/LatexIndent/BlankLines.pm
+++ b/support/latexindent/LatexIndent/BlankLines.pm
@@ -27,18 +27,6 @@ sub protect_blank_lines{
return unless $is_m_switch_active;
my $self = shift;
- # the text wrap routine, under some circumstances, can
- # cause new blank lines that haven't been awarded a token; see, for example,
- # test-cases/maxLineChars/multi-object-all.tex -l=multi-object2.yaml -m
- # we can circumvent this by forcing blank lines to be protected if
- # the text wrap option is active, which allows us to remove blank
- # lines from wrapped text
- if(ref ${$masterSettings{modifyLineBreaks}{textWrapOptions}}{columns} eq "HASH"
- or ${$masterSettings{modifyLineBreaks}{textWrapOptions}}{columns}>0 ){
- ${$masterSettings{modifyLineBreaks}}{preserveBlankLines} = 1;
- }
-
-
unless(${$masterSettings{modifyLineBreaks}}{preserveBlankLines}){
$logger->trace("*Blank lines will not be protected (preserveBlankLines=0)") if $is_t_switch_active;
return
diff --git a/support/latexindent/LatexIndent/Document.pm b/support/latexindent/LatexIndent/Document.pm
index 863d4d7d00..b6e609edc0 100644
--- a/support/latexindent/LatexIndent/Document.pm
+++ b/support/latexindent/LatexIndent/Document.pm
@@ -21,8 +21,8 @@ use utf8;
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 $is_r_switch_active $is_rr_switch_active $is_rv_switch_active/;
-use LatexIndent::LogFile qw/processSwitches $logger/;
+use LatexIndent::Switches qw/store_switches %switches $is_m_switch_active $is_t_switch_active $is_tt_switch_active $is_r_switch_active $is_rr_switch_active $is_rv_switch_active/;
+use LatexIndent::LogFile qw/process_switches $logger/;
use LatexIndent::Logger qw/@logFileLines/;
use LatexIndent::Replacement qw/make_replacements/;
use LatexIndent::GetYamlSettings qw/yaml_read_settings yaml_modify_line_breaks_settings yaml_get_indentation_settings_for_this_object yaml_poly_switch_get_every_or_custom_value yaml_get_indentation_information yaml_get_object_attribute_for_indentation_settings yaml_alignment_at_ampersand_settings yaml_get_textwrap_removeparagraphline_breaks %masterSettings yaml_get_columns/;
@@ -74,8 +74,9 @@ sub new{
sub latexindent{
my $self = shift;
- $self->storeSwitches;
- $self->processSwitches;
+ $self->store_switches;
+ $self->process_switches;
+ $self->yaml_read_settings;
$self->file_extension_check;
$self->operate_on_file;
}
@@ -103,6 +104,7 @@ sub operate_on_file{
$self->dodge_double_backslash;
$self->remove_leading_space;
$self->process_body_of_text;
+ ${$self}{body} =~ s/\r\n/\n/sg if $masterSettings{dos2unixlinebreaks};
$self->remove_trailing_whitespace(when=>"after");
$self->condense_blank_lines;
$self->unprotect_blank_lines;
@@ -112,6 +114,7 @@ sub operate_on_file{
$self->put_trailing_comments_back_in;
$self->put_verbatim_back_in (match=>"just-commands");
$self->make_replacements(when=>"after") if ($is_r_switch_active and !$is_rv_switch_active);
+ ${$self}{body} =~ s/\r\n/\n/sg if $masterSettings{dos2unixlinebreaks};
}
$self->output_indented_text;
return
diff --git a/support/latexindent/LatexIndent/Else.pm b/support/latexindent/LatexIndent/Else.pm
index 5a367c784f..26d8014f5a 100644
--- a/support/latexindent/LatexIndent/Else.pm
+++ b/support/latexindent/LatexIndent/Else.pm
@@ -23,7 +23,6 @@ use LatexIndent::LogFile qw/$logger/;
use LatexIndent::Braces qw/$braceBracketRegExpBasic/;
use LatexIndent::Special qw/$specialBeginAndBracesBracketsBasicRegExp/;
use LatexIndent::Heading qw/$allHeadingsRegexp/;
-use Data::Dumper;
use Exporter qw/import/;
our @ISA = "LatexIndent::Document"; # class inheritance, Programming Perl, pg 321
our @EXPORT_OK = qw/check_for_else_statement/;
diff --git a/support/latexindent/LatexIndent/Environment.pm b/support/latexindent/LatexIndent/Environment.pm
index c658acedf2..44388abbf3 100644
--- a/support/latexindent/LatexIndent/Environment.pm
+++ b/support/latexindent/LatexIndent/Environment.pm
@@ -25,7 +25,6 @@ use LatexIndent::Braces qw/$braceBracketRegExpBasic/;
use LatexIndent::IfElseFi qw/$ifElseFiBasicRegExp/;
use LatexIndent::Heading qw/$allHeadingsRegexp/;
use LatexIndent::Special qw/$specialBeginAndBracesBracketsBasicRegExp/;
-use Data::Dumper;
use Exporter qw/import/;
our @ISA = "LatexIndent::Document"; # class inheritance, Programming Perl, pg 321
our @EXPORT_OK = qw/find_environments $environmentBasicRegExp construct_environments_regexp/;
diff --git a/support/latexindent/LatexIndent/FileContents.pm b/support/latexindent/LatexIndent/FileContents.pm
index cbb20e5148..d870f16c41 100644
--- a/support/latexindent/LatexIndent/FileContents.pm
+++ b/support/latexindent/LatexIndent/FileContents.pm
@@ -42,80 +42,82 @@ sub find_file_contents_environments_and_preamble{
$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){
- $logger->trace("looking for $fileContentsEnv environments") if $is_t_switch_active;
-
- # the trailing * needs some care
- if($fileContentsEnv =~ m/\*$/){
- $fileContentsEnv =~ s/\*$//;
- $fileContentsEnv .= '\*';
- }
-
- my $fileContentsRegExp = qr/
- (
- \\begin\{
- $fileContentsEnv
- \}
- )
- (
- .*?
- )
- (
- \\end\{$fileContentsEnv\}
- \h*
- )
- (\R)?
- /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,
- linebreaksAtEnd=>{
- begin=>0,
- body=>0,
- end=>$4?1:0,
- },
- modifyLineBreaksYamlName=>"filecontents",
- );
- # give unique id
- $fileContentsBlock->create_unique_id;
-
- # text wrapping can make the ID split across lines
- ${$fileContentsBlock}{idRegExp} = ${$fileContentsBlock}{id};
-
- if($is_m_switch_active){
- my $IDwithLineBreaks = join("\\R?\\h*",split(//,${$fileContentsBlock}{id}));
- ${$fileContentsBlock}{idRegExp} = qr/$IDwithLineBreaks/s;
- }
-
- # the replacement text can be just the ID, but the ID might have a line break at the end of it
- $fileContentsBlock->get_replacement_text;
- # count body line breaks
- $fileContentsBlock->count_body_line_breaks;
-
- # the above regexp, when used below, will remove the trailing linebreak in ${$self}{linebreaksAtEnd}{end}
- # so we compensate for it here
- $fileContentsBlock->adjust_replacement_text_line_breaks_at_end;
-
- # store the fileContentsBlock, and determine location afterwards
- push(@fileContentsStorageArray,$fileContentsBlock);
+ if(!$yesno){
+ $logger->trace(" *not* looking for $fileContentsEnv as $fileContentsEnv:$yesno");
+ next;
+ }
- # log file output
- $logger->trace("FILECONTENTS environment found: $fileContentsEnv");
+ $logger->trace("looking for $fileContentsEnv environments") if $is_t_switch_active;
- # remove the environment block, and replace with unique ID
- ${$self}{body} =~ s/$fileContentsRegExp/${$fileContentsBlock}{replacementText}/sx;
+ # the trailing * needs some care
+ if($fileContentsEnv =~ m/\*$/){
+ $fileContentsEnv =~ s/\*$//;
+ $fileContentsEnv .= '\*';
+ }
- $logger->trace("replaced with ID: ${$fileContentsBlock}{id}") if $is_tt_switch_active;
- }
- } else {
- $logger->trace("*not* looking for $fileContentsEnv as $fileContentsEnv:$yesno");
- }
+ my $fileContentsRegExp = qr/
+ (
+ \\begin\{
+ $fileContentsEnv
+ \}
+ )
+ (
+ .*?
+ )
+ (
+ \\end\{$fileContentsEnv\}
+ \h*
+ )
+ (\R)?
+ /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,
+ linebreaksAtEnd=>{
+ begin=>0,
+ body=>0,
+ end=>$4?1:0,
+ },
+ modifyLineBreaksYamlName=>"filecontents",
+ );
+ # give unique id
+ $fileContentsBlock->create_unique_id;
+
+ # text wrapping can make the ID split across lines
+ ${$fileContentsBlock}{idRegExp} = ${$fileContentsBlock}{id};
+
+ if($is_m_switch_active){
+ my $IDwithLineBreaks = join("\\R?\\h*",split(//,${$fileContentsBlock}{id}));
+ ${$fileContentsBlock}{idRegExp} = qr/$IDwithLineBreaks/s;
+ }
+
+ # the replacement text can be just the ID, but the ID might have a line break at the end of it
+ $fileContentsBlock->get_replacement_text;
+
+ # count body line breaks
+ $fileContentsBlock->count_body_line_breaks;
+
+ # the above regexp, when used below, will remove the trailing linebreak in ${$self}{linebreaksAtEnd}{end}
+ # so we compensate for it here
+ $fileContentsBlock->adjust_replacement_text_line_breaks_at_end;
+
+ # store the fileContentsBlock, and determine location afterwards
+ push(@fileContentsStorageArray,$fileContentsBlock);
+
+ # log file output
+ $logger->trace("FILECONTENTS environment found: $fileContentsEnv")if $is_t_switch_active;
+
+ # remove the environment block, and replace with unique ID
+ ${$self}{body} =~ s/$fileContentsRegExp/${$fileContentsBlock}{replacementText}/sx;
+
+ $logger->trace("replaced with ID: ${$fileContentsBlock}{id}") if $is_tt_switch_active;
+ }
}
# determine if body of document contains \begin{document} -- if it does, then assume
@@ -171,7 +173,7 @@ sub find_file_contents_environments_and_preamble{
$logger->trace("replaced with ID: ${$preamble}{replacementText}") if $is_tt_switch_active;
# indentPreamble set to 1
if($masterSettings{indentPreamble}){
- $logger->trace("storing ${$preamble}{id} for indentation (see indentPreamble)");
+ $logger->trace("storing ${$preamble}{id} for indentation (see indentPreamble)") if $is_tt_switch_active;
$needToStorePreamble = 1;
} else {
# indentPreamble set to 0
@@ -188,18 +190,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}/){
- $logger->trace("filecontents (${$_}{id}) is within preamble");
+ $logger->trace("filecontents (${$_}{id}) is within preamble") if $is_t_switch_active;
# indentPreamble set to 1
if($masterSettings{indentPreamble}){
- $logger->trace("storing ${$_}{id} for indentation (indentPreamble is 1)");
+ $logger->trace("storing ${$_}{id} for indentation (indentPreamble is 1)") if $is_t_switch_active;
$indentThisChild = 1;
} else {
# indentPreamble set to 0
- $logger->trace("Storing ${$_}{id} as a VERBATIM object (indentPreamble is 0)");
+ $logger->trace("Storing ${$_}{id} as a VERBATIM object (indentPreamble is 0)") if $is_t_switch_active;
${$self}{verbatim}{${$_}{id}}=$_;
}
} else {
- $logger->trace("storing ${$_}{id} for indentation (${$_}{name} found outside of preamble)");
+ $logger->trace("storing ${$_}{id} for indentation (${$_}{name} found outside of preamble)") if $is_t_switch_active;
$indentThisChild = 1;
}
# store the child, if necessary
diff --git a/support/latexindent/LatexIndent/GetYamlSettings.pm b/support/latexindent/LatexIndent/GetYamlSettings.pm
index 4be1d3a97b..f28fdd6525 100644
--- a/support/latexindent/LatexIndent/GetYamlSettings.pm
+++ b/support/latexindent/LatexIndent/GetYamlSettings.pm
@@ -16,6 +16,7 @@ package LatexIndent::GetYamlSettings;
# For all communication, please visit: https://github.com/cmhughes/latexindent.pl
use strict;
use warnings;
+use Data::Dumper;
use LatexIndent::Switches qw/%switches $is_m_switch_active $is_t_switch_active $is_tt_switch_active/;
use YAML::Tiny; # interpret defaultSettings.yaml and other potential settings files
use File::Basename; # to get the filename and directory path
@@ -47,6 +48,7 @@ our @alignAtAmpersandInformation = ( {name=>"lookForAlignDelims",yamlname=>"de
{name=>"dontMeasure",default=>0},
{name=>"delimiterRegEx",default=>"(?<!\\\\)(&)"},
{name=>"delimiterJustification",default=>"left"},
+ {name=>"leadingBlankColumn",default=>-1},
);
sub yaml_read_settings{
@@ -56,7 +58,8 @@ sub yaml_read_settings{
$defaultSettings = YAML::Tiny->read( "$FindBin::RealBin/defaultSettings.yaml" ) if ( -e "$FindBin::RealBin/defaultSettings.yaml" );
# grab the logger object
- $logger->info("*YAML settings read: defaultSettings.yaml\nReading defaultSettings.yaml from $FindBin::RealBin/defaultSettings.yaml");
+ $logger->info("*YAML settings read: defaultSettings.yaml");
+ $logger->info("Reading 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
@@ -71,6 +74,8 @@ sub yaml_read_settings{
# master yaml settings is a hash, global to this module
our %masterSettings = %{$defaultSettings->[0]};
+ &yaml_update_dumper_settings();
+
# scalar to read user settings
my $userSettings;
@@ -107,7 +112,34 @@ sub yaml_read_settings{
# output the contents of indentconfig to the log file
$logger->info(Dump \%{$userSettings->[0]});
- @absPaths = @{$userSettings->[0]->{paths}};
+ # change the encoding of the paths according to the field `encoding`
+ if($userSettings and (ref($userSettings->[0]) eq 'HASH') and $userSettings->[0]->{encoding}){
+ use Encode;
+ my $encoding = $userSettings->[0]->{encoding};
+ my $encodingObject = find_encoding($encoding);
+ # Check if the encoding is valid.
+ if (ref($encodingObject))
+ {
+ $logger->info("*Encoding of the paths is $encoding");
+ foreach (@{$userSettings->[0]->{paths}})
+ {
+ my $temp = $encodingObject->encode("$_");
+ $logger->info("Transform file encoding: $_ -> $temp");
+ push(@absPaths,$temp);
+ }
+ }
+ else
+ {
+ $logger->warn("*encoding \"$encoding\" not found");
+ $logger->warn("Ignore this setting and will take the default encoding.");
+ @absPaths = @{$userSettings->[0]->{paths}};
+ }
+ }
+ else # No such setting, and will take the default
+ {
+ # $logger->info("*Encoding of the paths takes the default.");
+ @absPaths = @{$userSettings->[0]->{paths}};
+ }
} else {
$logger->warn("*The paths field cannot be read from $indentconfig; this means it is either empty or contains invalid YAML");
$logger->warn("See https://latexindentpl.readthedocs.io/en/latest/sec-indent-config-and-settings.html for an example");
@@ -240,14 +272,16 @@ sub yaml_read_settings{
if (ref $secondLevelValue eq "HASH"){
# 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"){
+ if(defined $masterSettings{$firstLevelKey}{$secondLevelKey}
+ and ref $masterSettings{$firstLevelKey}{$secondLevelKey} ne "HASH"){
$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"){
+ if (defined $masterSettings{$firstLevelKey}{$secondLevelKey}{$thirdLevelKey}
+ and ref $masterSettings{$firstLevelKey}{$secondLevelKey}{$thirdLevelKey} ne "HASH"){
$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} ;
}
@@ -328,6 +362,9 @@ sub yaml_read_settings{
$logger->info("specifies $settings but this file does not exist - unable to read settings from this file");
}
}
+
+ &yaml_update_dumper_settings();
+
}
# read settings from -y|--yaml switch
@@ -519,7 +556,10 @@ sub yaml_read_settings{
$logger->info("Updating masterSettings with $parent: $child: $grandchild: $greatgrandchild: $value");
$masterSettings{$parent}{$child}{$grandchild}{$greatgrandchild} = $value;
}
+
+ &yaml_update_dumper_settings();
}
+
}
# some users may wish to see showAmalgamatedSettings
@@ -527,7 +567,7 @@ sub yaml_read_settings{
# from the default in various user files
if($masterSettings{logFilePreferences}{showAmalgamatedSettings}){
$logger->info("Amalgamated/overall settings to be used:");
- $logger->info(Dump \%masterSettings);
+ $logger->info(Dumper(\%masterSettings));
}
return;
@@ -611,6 +651,8 @@ sub yaml_alignment_at_ampersand_settings{
# spacesBeforeDoubleBackSlash: 2
return unless ${$masterSettings{lookForAlignDelims}}{$name};
+ $logger->trace("alignAtAmpersand settings for $name (see lookForAlignDelims)") if($is_t_switch_active);
+
if(ref ${$masterSettings{lookForAlignDelims}}{$name} eq "HASH"){
# specified as a hash, e.g
#
@@ -621,7 +663,57 @@ sub yaml_alignment_at_ampersand_settings{
# spacesBeforeDoubleBackSlash: 2
foreach (@alignAtAmpersandInformation){
my $yamlname = (defined ${$_}{yamlname} ? ${$_}{yamlname}: ${$_}{name});
- ${$self}{${$_}{name}} = (defined ${${$masterSettings{lookForAlignDelims}}{$name}}{$yamlname} ) ? ${${$masterSettings{lookForAlignDelims}}{$name}}{$yamlname} : ${$_}{default};
+
+ # each of the following cases need to be allowed:
+ #
+ # lookForAlignDelims:
+ # aligned:
+ # spacesBeforeAmpersand:
+ # default: 1
+ # leadingBlankColumn: 0
+ #
+ # lookForAlignDelims:
+ # aligned:
+ # spacesBeforeAmpersand:
+ # leadingBlankColumn: 0
+ #
+ # lookForAlignDelims:
+ # aligned:
+ # spacesBeforeAmpersand:
+ # default: 0
+ #
+ # approach:
+ # - update masterSettings to have the relevant information: leadingBlankColumn and/or default
+ # - delete the spacesBeforeAmpersand hash
+ #
+ if ($yamlname eq "spacesBeforeAmpersand"
+ and ref(${${$masterSettings{lookForAlignDelims}}{$name}}{spacesBeforeAmpersand}) eq "HASH"){
+ $logger->trace("spacesBeforeAmpersand settings for $name") if $is_t_switch_active;
+
+ # lookForAlignDelims:
+ # aligned:
+ # spacesBeforeAmpersand:
+ # leadingBlankColumn: 0
+ if(defined ${${${$masterSettings{lookForAlignDelims}}{$name}}{spacesBeforeAmpersand}}{leadingBlankColumn}){
+ $logger->trace("spacesBeforeAmpersand: leadingBlankColumn specified for $name") if $is_t_switch_active;
+ ${${$masterSettings{lookForAlignDelims}}{$name}}{leadingBlankColumn}
+ = ${${${$masterSettings{lookForAlignDelims}}{$name}}{spacesBeforeAmpersand}}{leadingBlankColumn};
+ }
+
+ # lookForAlignDelims:
+ # aligned:
+ # spacesBeforeAmpersand:
+ # default: 0
+ if(defined ${${${$masterSettings{lookForAlignDelims}}{$name}}{spacesBeforeAmpersand}}{default}){
+ ${${$masterSettings{lookForAlignDelims}}{$name}}{spacesBeforeAmpersand}
+ = ${${${$masterSettings{lookForAlignDelims}}{$name}}{spacesBeforeAmpersand}}{default};
+ } else {
+ # deleting spacesBeforeAmpersand hash allows spacesBeforeAmpersand
+ # to pull from the default values @alignAtAmpersandInformation
+ delete ${${$masterSettings{lookForAlignDelims}}{$name}}{spacesBeforeAmpersand};
+ }
+ }
+ ${$self}{ ${$_}{name} } = (defined ${${$masterSettings{lookForAlignDelims}}{$name}}{$yamlname} ) ? ${${$masterSettings{lookForAlignDelims}}{$name}}{$yamlname} : ${$_}{default};
}
} else {
# specified as a scalar, e.g
@@ -991,4 +1083,16 @@ sub yaml_get_object_attribute_for_indentation_settings{
return "body";
}
+sub yaml_update_dumper_settings{
+
+ # log file preferences
+ $Data::Dumper::Terse = ${$masterSettings{logFilePreferences}{Dumper}}{Terse};
+ $Data::Dumper::Indent = ${$masterSettings{logFilePreferences}{Dumper}}{Indent};
+ $Data::Dumper::Useqq = ${$masterSettings{logFilePreferences}{Dumper}}{Useqq};
+ $Data::Dumper::Deparse = ${$masterSettings{logFilePreferences}{Dumper}}{Deparse};
+ $Data::Dumper::Quotekeys = ${$masterSettings{logFilePreferences}{Dumper}}{Quotekeys};
+ $Data::Dumper::Sortkeys = ${$masterSettings{logFilePreferences}{Dumper}}{Sortkeys};
+ $Data::Dumper::Pair = ${$masterSettings{logFilePreferences}{Dumper}}{Pair};
+
+}
1;
diff --git a/support/latexindent/LatexIndent/Heading.pm b/support/latexindent/LatexIndent/Heading.pm
index 208dfa9715..0c42f166a6 100644
--- a/support/latexindent/LatexIndent/Heading.pm
+++ b/support/latexindent/LatexIndent/Heading.pm
@@ -22,7 +22,6 @@ use LatexIndent::TrailingComments qw/$trailingCommentRegExp/;
use LatexIndent::GetYamlSettings qw/%masterSettings/;
use LatexIndent::LogFile qw/$logger/;
use LatexIndent::Special qw/$specialBeginBasicRegExp/;
-use Data::Dumper;
use Exporter qw/import/;
our @ISA = "LatexIndent::Document"; # class inheritance, Programming Perl, pg 321
our @EXPORT_OK = qw/find_heading construct_headings_levels $allHeadingsRegexp/;
diff --git a/support/latexindent/LatexIndent/IfElseFi.pm b/support/latexindent/LatexIndent/IfElseFi.pm
index e7e363b04c..4cbab6efea 100644
--- a/support/latexindent/LatexIndent/IfElseFi.pm
+++ b/support/latexindent/LatexIndent/IfElseFi.pm
@@ -22,7 +22,6 @@ 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 LatexIndent::Heading qw/$allHeadingsRegexp/;
-use Data::Dumper;
use Exporter qw/import/;
our @ISA = "LatexIndent::Document"; # class inheritance, Programming Perl, pg 321
our @EXPORT_OK = qw/find_ifelsefi construct_ifelsefi_regexp $ifElseFiBasicRegExp/;
diff --git a/support/latexindent/LatexIndent/KeyEqualsValuesBraces.pm b/support/latexindent/LatexIndent/KeyEqualsValuesBraces.pm
index 590d9acb8c..6eb4f703dd 100644
--- a/support/latexindent/LatexIndent/KeyEqualsValuesBraces.pm
+++ b/support/latexindent/LatexIndent/KeyEqualsValuesBraces.pm
@@ -21,7 +21,6 @@ use LatexIndent::GetYamlSettings qw/%masterSettings/;
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::Command"; # class inheritance, Programming Perl, pg 321
our @EXPORT_OK = qw/construct_key_equals_values_regexp $key_equals_values_bracesRegExp $key_equals_values_bracesRegExpTrailingComment/;
diff --git a/support/latexindent/LatexIndent/LogFile.pm b/support/latexindent/LatexIndent/LogFile.pm
index ca8376daa9..5b44822829 100644
--- a/support/latexindent/LatexIndent/LogFile.pm
+++ b/support/latexindent/LatexIndent/LogFile.pm
@@ -21,10 +21,10 @@ use File::Basename; # to get the filename and directory path
use Exporter qw/import/;
use LatexIndent::Switches qw/%switches/;
use LatexIndent::Version qw/$versionNumber $versionDate/;
-our @EXPORT_OK = qw/processSwitches $logger/;
+our @EXPORT_OK = qw/process_switches $logger/;
our $logger;
-sub processSwitches{
+sub process_switches{
# -v switch is just to show the version number
if($switches{version}) {
print $versionNumber,", ",$versionDate,"\n";
@@ -152,14 +152,11 @@ ENDQUOTE
(my $file = $moduleName) =~ s|::|/|g;
$logger->info($INC{$file .'.pm'});
}
- $logger->info("*Latex Indent perl modules are being loaded from, for example:");
+ $logger->info("*LatexIndent perl modules are being loaded from, for example:");
(my $file = 'LatexIndent::Document') =~ s|::|/|g;
$logger->info($INC{$file .'.pm'});
}
- # read the YAML settings
- $self->yaml_read_settings;
-
return;
}
diff --git a/support/latexindent/LatexIndent/Replacement.pm b/support/latexindent/LatexIndent/Replacement.pm
index 1bc51caed2..0d79a39f0c 100644
--- a/support/latexindent/LatexIndent/Replacement.pm
+++ b/support/latexindent/LatexIndent/Replacement.pm
@@ -21,7 +21,6 @@ use LatexIndent::TrailingComments qw/$trailingCommentRegExp/;
use LatexIndent::GetYamlSettings qw/%masterSettings/;
use LatexIndent::Switches qw/$is_t_switch_active $is_tt_switch_active $is_rr_switch_active/;
use LatexIndent::LogFile qw/$logger/;
-use Data::Dumper;
use Exporter qw/import/;
our @ISA = "LatexIndent::Document"; # class inheritance, Programming Perl, pg 321
our @EXPORT_OK = qw/make_replacements/;
diff --git a/support/latexindent/LatexIndent/Special.pm b/support/latexindent/LatexIndent/Special.pm
index 8898697d0f..4e1a8020b3 100644
--- a/support/latexindent/LatexIndent/Special.pm
+++ b/support/latexindent/LatexIndent/Special.pm
@@ -36,9 +36,17 @@ our $specialBeginBasicRegExp;
sub construct_special_begin{
my $self = shift;
+ $logger->trace("*Constructing specialBeginEnd regex (see specialBeginEnd)") if $is_t_switch_active;
+
# put together a list of the begin terms in special
while( my ($specialName,$BeginEnd)= each %{$masterSettings{specialBeginEnd}}){
if(ref($BeginEnd) eq "HASH"){
+ if (not defined ${$BeginEnd}{lookForThis}){
+ ${$BeginEnd}{lookForThis} = 1;
+ ${${$masterSettings{specialBeginEnd}}{$specialName}}{lookForThis} = 1;
+ $logger->trace("setting lookForThis:1 for $specialName (lookForThis not specified)") if $is_t_switch_active;
+ }
+
# only append the regexps if lookForThis is 1
$specialBegins .= ($specialBegins eq ""?q():"|").${$BeginEnd}{begin} if(${$BeginEnd}{lookForThis}=~m/\d/s and ${$BeginEnd}{lookForThis} == 1);
}
@@ -48,45 +56,49 @@ sub construct_special_begin{
while( my ($specialName,$BeginEnd)= each %{$masterSettings{specialBeginEnd}}){
# only append the regexps if lookForThis is 1
- if( (ref($BeginEnd) eq "HASH") and ${$BeginEnd}{lookForThis}=~m/\d/s and ${$BeginEnd}{lookForThis} == 1){
+ if( ref($BeginEnd) eq "HASH" ){
+ if ( ${$BeginEnd}{lookForThis}=~m/\d/s and ${$BeginEnd}{lookForThis} == 0 ){
+ $logger->trace("The specialBeginEnd regexps won't include anything from $specialName (lookForThis: 0)") if $is_t_switch_active ;
+ next;
+ }
+ } else {
+ next;
+ }
- # the overall regexp
- $specialAllMatchesRegExp .= ($specialAllMatchesRegExp eq ""?q():"|")
- .qr/
+ # the overall regexp
+ $specialAllMatchesRegExp .= ($specialAllMatchesRegExp eq ""?q():"|")
+ .qr/
+ ${$BeginEnd}{begin}
+ (?: # cluster-only (), don't capture
+ (?!
+ (?:$specialBegins) # cluster-only (), don't capture
+ ). # any character, but not anything in $specialBegins
+ )*?
+ ${$BeginEnd}{end}
+ /sx;
+
+ # store the individual special regexp
+ $individualSpecialRegExps{$specialName} = qr/
+ (
${$BeginEnd}{begin}
+ \h*
+ (\R*)?
+ )
+ (
(?: # cluster-only (), don't capture
(?!
(?:$specialBegins) # cluster-only (), don't capture
). # any character, but not anything in $specialBegins
)*?
- ${$BeginEnd}{end}
- /sx;
-
- # store the individual special regexp
- $individualSpecialRegExps{$specialName} = qr/
- (
- ${$BeginEnd}{begin}
- \h*
- (\R*)?
- )
- (
- (?: # cluster-only (), don't capture
- (?!
- (?:$specialBegins) # cluster-only (), don't capture
- ). # any character, but not anything in $specialBegins
- )*?
- (\R*)?
- )
- (
- ${$BeginEnd}{end}
- )
- (\h*)
- (\R)?
- /sx
-
- } else {
- $logger->trace("*The special regexps won't include anything from $specialName (see lookForThis)") if $is_t_switch_active ;
- }
+ (\R*)?
+ )
+ (
+ ${$BeginEnd}{end}
+ )
+ (\h*)
+ (\R)?
+ /sx
+
}
# move $$ to the beginning
@@ -176,7 +188,7 @@ sub find_special{
${@{${$self}{children}}[-1]}{replacementText}.($8?$8:q()).($9?$9:q());
/xseg;
- $self->wrap_up_tasks;
+ $self->wrap_up_tasks;
}
}
}
diff --git a/support/latexindent/LatexIndent/Switches.pm b/support/latexindent/LatexIndent/Switches.pm
index d738a4b36b..e5e93b1de0 100644
--- a/support/latexindent/LatexIndent/Switches.pm
+++ b/support/latexindent/LatexIndent/Switches.pm
@@ -17,7 +17,7 @@ package LatexIndent::Switches;
use strict;
use warnings;
use Exporter qw/import/;
-our @EXPORT_OK = qw/%switches storeSwitches $is_m_switch_active $is_t_switch_active $is_tt_switch_active $is_r_switch_active $is_rr_switch_active $is_rv_switch_active/;
+our @EXPORT_OK = qw/%switches store_switches $is_m_switch_active $is_t_switch_active $is_tt_switch_active $is_r_switch_active $is_rr_switch_active $is_rv_switch_active/;
our %switches;
our $is_m_switch_active;
our $is_t_switch_active;
@@ -26,7 +26,7 @@ our $is_r_switch_active;
our $is_rr_switch_active;
our $is_rv_switch_active;
-sub storeSwitches{
+sub store_switches{
my $self = shift;
# copy document switches into hash local to this module
diff --git a/support/latexindent/LatexIndent/TrailingComments.pm b/support/latexindent/LatexIndent/TrailingComments.pm
index 6ec052a0f3..262201e76a 100644
--- a/support/latexindent/LatexIndent/TrailingComments.pm
+++ b/support/latexindent/LatexIndent/TrailingComments.pm
@@ -28,7 +28,9 @@ our $commentCounter = 0;
our $trailingCommentRegExp;
sub construct_trailing_comment_regexp{
- $trailingCommentRegExp = qr/(?<!\\)%$tokens{trailingComment}\d+$tokens{endOfToken}/;
+ my $notPreceededBy = qr/${${$masterSettings{fineTuning}}{trailingComments}}{notPreceededBy}/;
+
+ $trailingCommentRegExp = qr/$notPreceededBy%$tokens{trailingComment}\d+$tokens{endOfToken}/;
}
sub add_comment_symbol{
@@ -54,9 +56,11 @@ sub remove_trailing_comments{
my $self = shift;
$logger->trace("*Storing trailing comments")if $is_t_switch_active;
+ my $notPreceededBy = qr/${${$masterSettings{fineTuning}}{trailingComments}}{notPreceededBy}/;
+
# perform the substitution
${$self}{body} =~ s/
- (?<!\\) # not preceeded by a \
+ $notPreceededBy # not preceeded by a \
% # %
(
\h*? # followed by possible horizontal space
@@ -110,13 +114,14 @@ sub put_trailing_comments_back_in{
# replace the line-broken trailing comment ID with a non-broken trailing comment ID
${$self}{body} =~ s/%\R?$trailingcommentIDwithLineBreaksRegExp/%$trailingcommentID/s;
}
+ my $notPreceededBy = qr/${${$masterSettings{fineTuning}}{trailingComments}}{notPreceededBy}/;
if(${$self}{body} =~ m/%$trailingcommentID
(
- (?! # not immediately preceeded by
- (?<!\\) # \
- % # %
+ (?! # not immediately preceeded by
+ $notPreceededBy # \
+ % # %
).*?
- ) # captured into $1
+ ) # captured into $1
(\h*)?$
/mx and $1 ne ''){
$logger->trace("Comment not at end of line $trailingcommentID, moving it to end of line")if $is_t_switch_active;
diff --git a/support/latexindent/LatexIndent/Verbatim.pm b/support/latexindent/LatexIndent/Verbatim.pm
index 6149ca5236..1657f41521 100644
--- a/support/latexindent/LatexIndent/Verbatim.pm
+++ b/support/latexindent/LatexIndent/Verbatim.pm
@@ -30,64 +30,100 @@ sub find_noindent_block{
my $self = shift;
# noindent block
- $logger->trace('*Searching for NOINDENTBLOCk environments (see noIndentBlock)') if $is_t_switch_active;
+ $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}}){
- if($yesno){
- $logger->trace("looking for $noIndentBlock:$yesno environments") if $is_t_switch_active;
+
+ # 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;
+ }
+ } elsif( ref($yesno) ne "HASH" and !$yesno ){
+ $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;
+
+ if (ref($yesno) eq "HASH"){
+ # 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;
+ $logger->trace("body not specified for $noIndentBlock, setting default .*?") if $is_t_switch_active;
+ ${$yesno}{body} = qr/.*?/sx;
+ } else {
+ $logger->trace("looking for regex based $noIndentBlock") if $is_t_switch_active;
+ $logger->trace("begin: ${$yesno}{begin}") if $is_t_switch_active;
+ $logger->trace("body: ${$yesno}{body}") if $is_t_switch_active;
+ $logger->trace("end: ${$yesno}{end}") if $is_t_switch_active;
+ }
+
+ $noIndentRegExp = qr/
+ (${$yesno}{begin})
+ (${$yesno}{body})
+ (${$yesno}{end})
+ /sx;
+ } else {
+ $logger->trace("looking for $noIndentBlock:$yesno noIndentBlock") if $is_t_switch_active;
(my $noIndentBlockSpec = $noIndentBlock) =~ s/\*/\\*/sg;
- my $noIndentRegExp = qr/
+ $noIndentRegExp = qr/
(
(?!<\\)
%
(?:\h|(?!<\\)%)* # possible horizontal spaces
\\begin\{
- $noIndentBlockSpec # environment name captured into $2
+ $noIndentBlockSpec
\} # % \begin{noindentblock} statement
- )
+ ) # begin captured into $1
(
.*?
- ) # non-greedy match (body)
+ ) # non-greedy match (body) into $2
(
(?!<\\)
% # %
(?:\h|(?!<\\)%)* # possible horizontal spaces
\\end\{$noIndentBlockSpec\} # \end{noindentblock}
- ) # % \end{<something>} statement
+ ) # % \end{<something>} statement into $3
/sx;
-
- while( ${$self}{body} =~ m/$noIndentRegExp/sx){
-
- # create a new Verbatim object
- my $noIndentBlockObj = LatexIndent::Verbatim->new( begin=>$1,
- body=>$2,
- end=>$3,
- name=>$noIndentBlock,
- type=>"noindentblock",
- modifyLineBreaksYamlName=>"verbatim",
- );
-
- # give unique id
- $noIndentBlockObj->create_unique_id;
-
- # verbatim children go in special hash
- ${$self}{verbatim}{${$noIndentBlockObj}{id}}=$noIndentBlockObj;
-
- # log file output
- $logger->trace("*NOINDENTBLOCK environment found: $noIndentBlock") if $is_t_switch_active;
-
- # remove the environment block, and replace with unique ID
- ${$self}{body} =~ s/$noIndentRegExp/${$noIndentBlockObj}{id}/sx;
-
- $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 {
- $logger->trace("*not* looking for $noIndentBlock as $noIndentBlock:$yesno") if $is_t_switch_active;
- }
+ }
+ while( ${$self}{body} =~ m/$noIndentRegExp/sx){
+
+ # create a new Verbatim object
+ my $noIndentBlockObj = LatexIndent::Verbatim->new( begin=>$1,
+ body=>$2,
+ end=>$3,
+ name=>$noIndentBlock,
+ type=>"noindentblock",
+ modifyLineBreaksYamlName=>"verbatim",
+ );
+
+ # give unique id
+ $noIndentBlockObj->create_unique_id;
+
+ # verbatim children go in special hash
+ ${$self}{verbatim}{${$noIndentBlockObj}{id}}=$noIndentBlockObj;
+
+ # log file output
+ $logger->trace("NOINDENTBLOCK found: $noIndentBlock") if $is_t_switch_active;
+
+ # remove the environment block, and replace with unique ID
+ ${$self}{body} =~ s/$noIndentRegExp/${$noIndentBlockObj}{id}/sx;
+
+ $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};
+ }
}
return;
}
diff --git a/support/latexindent/LatexIndent/Version.pm b/support/latexindent/LatexIndent/Version.pm
index 20cbab2672..eb1b1226dc 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.9.3';
-our $versionDate = '2021-05-07';
+our $versionNumber = '3.10';
+our $versionDate = '2021-06-19';
1