summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/scripts
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2018-04-28 21:57:31 +0000
committerKarl Berry <karl@freefriends.org>2018-04-28 21:57:31 +0000
commit1d47aeb4b6825139fc0f32c3549fbdf3fef6bb5c (patch)
tree13c5e17fc806f1d51e1d1a91c14b16e6a30b4fbb /Master/texmf-dist/scripts
parentb14146667f4cd6cbc5d5821c88e47096df3c78b5 (diff)
latexindent (28apr18)
git-svn-id: svn://tug.org/texlive/trunk@47471 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/scripts')
-rw-r--r--Master/texmf-dist/scripts/latexindent/LatexIndent/Arguments.pm17
-rwxr-xr-xMaster/texmf-dist/scripts/latexindent/LatexIndent/Command.pm23
-rw-r--r--Master/texmf-dist/scripts/latexindent/LatexIndent/Else.pm99
-rw-r--r--Master/texmf-dist/scripts/latexindent/LatexIndent/FileContents.pm2
-rw-r--r--Master/texmf-dist/scripts/latexindent/LatexIndent/GetYamlSettings.pm27
-rw-r--r--Master/texmf-dist/scripts/latexindent/LatexIndent/HiddenChildren.pm82
-rwxr-xr-xMaster/texmf-dist/scripts/latexindent/LatexIndent/IfElseFi.pm44
-rwxr-xr-xMaster/texmf-dist/scripts/latexindent/LatexIndent/NamedGroupingBracesBrackets.pm2
-rw-r--r--Master/texmf-dist/scripts/latexindent/LatexIndent/Special.pm67
-rw-r--r--Master/texmf-dist/scripts/latexindent/LatexIndent/Version.pm4
-rwxr-xr-xMaster/texmf-dist/scripts/latexindent/defaultSettings.yaml24
-rwxr-xr-xMaster/texmf-dist/scripts/latexindent/latexindent.pl2
12 files changed, 272 insertions, 121 deletions
diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/Arguments.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/Arguments.pm
index fc6cab0c33a..8c8b5af38f1 100644
--- a/Master/texmf-dist/scripts/latexindent/LatexIndent/Arguments.pm
+++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/Arguments.pm
@@ -235,19 +235,20 @@ sub get_arguments_regexp{
# commands are allowed strings between arguments, e.g node, decoration, etc, specified in stringsAllowedBetweenArguments
my $stringsBetweenArguments = q();
- if(defined ${input}{stringBetweenArguments} and ${input}{stringBetweenArguments}==1){
+ if(defined ${input}{stringBetweenArguments} and ${input}{stringBetweenArguments}==1
+ and ref(${$masterSettings{commandCodeBlocks}}{stringsAllowedBetweenArguments}) eq "ARRAY"){
# grab the strings allowed between arguments
- my %stringsAllowedBetweenArguments = %{${$masterSettings{commandCodeBlocks}}{stringsAllowedBetweenArguments}};
+ my @stringsAllowedBetweenArguments = @{${$masterSettings{commandCodeBlocks}}{stringsAllowedBetweenArguments}};
- while( my ($allowedStringName,$allowedStringValue)= each %stringsAllowedBetweenArguments){
- # change + and - to escaped characters
- $allowedStringName =~ s/\+/\\+/g;
- $allowedStringName =~ s/\-/\\-/g;
+ $logger->trace("*Looping through array for commandCodeBlocks->stringsAllowedBetweenArguments") if $is_t_switch_active ;
- # form the regexp
- $stringsBetweenArguments .= ($stringsBetweenArguments eq '' ? q() : "|").$allowedStringName if $allowedStringValue;
+ # note that the zero'th element in this array contains the amalgamate switch, which we don't want!
+ foreach (@stringsAllowedBetweenArguments[1 .. $#stringsAllowedBetweenArguments]) {
+ $logger->trace("$_") if $is_t_switch_active ;
+ $stringsBetweenArguments .= ($stringsBetweenArguments eq ""?q():"|").$_;
}
+ $stringsBetweenArguments = qr/$stringsBetweenArguments/;
# report to log file
$logger->trace("*Strings allowed between arguments: $stringsBetweenArguments (see stringsAllowedBetweenArguments)") if $is_t_switch_active;
}
diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/Command.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/Command.pm
index acd118ecf6d..2ba44bd5a62 100755
--- a/Master/texmf-dist/scripts/latexindent/LatexIndent/Command.pm
+++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/Command.pm
@@ -45,17 +45,20 @@ sub construct_command_regexp{
stringBetweenArguments=>1);
# put together a list of the special command names (this was mostly motivated by the \@ifnextchar[ issue)
- my %commandNameSpecial = %{${$masterSettings{commandCodeBlocks}}{commandNameSpecial}};
-
my $commandNameSpecialRegExp = q();
- while( my ($commandName,$yesNo)= each %commandNameSpecial){
- # change + and - to escaped characters
- $commandName =~ s/\+/\\+/g;
- $commandName =~ s/\-/\\-/g;
- $commandName =~ s/\[/\\[/g;
-
- # form the regexp
- $commandNameSpecialRegExp .= ($commandNameSpecialRegExp eq '' ? q() : "|").$commandName if $yesNo;
+ if(ref(${$masterSettings{commandCodeBlocks}}{commandNameSpecial}) eq "ARRAY"){
+
+ my @commandNameSpecial = @{${$masterSettings{commandCodeBlocks}}{commandNameSpecial}};
+ $logger->trace("*Looping through array for commandCodeBlocks->commandNameSpecial") if $is_t_switch_active ;
+
+ # note that the zero'th element in this array contains the amalgamate switch, which we don't want!
+ foreach (@commandNameSpecial[1 .. $#commandNameSpecial]) {
+ $logger->trace("$_") if $is_t_switch_active ;
+ $commandNameSpecialRegExp .= ($commandNameSpecialRegExp eq ""?q():"|").$_;
+ }
+
+ # turn the above into a regexp
+ $commandNameSpecialRegExp = qr/$commandNameSpecialRegExp/;
}
# details to log file
diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/Else.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/Else.pm
index fe2664cf1dd..0403de6adb2 100644
--- a/Master/texmf-dist/scripts/latexindent/LatexIndent/Else.pm
+++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/Else.pm
@@ -26,51 +26,62 @@ our @ISA = "LatexIndent::Document"; # class inheritance, Programming Perl, pg 32
our @EXPORT_OK = qw/check_for_else_statement/;
our $elseCounter;
-# store the regular expresssion for matching and replacing the \else statements
-our $elseRegExp = qr/
- (
- \\else
- \h* # possible horizontal space
- (\R*) # possible line breaks after \else statement
- )
- (.*?)$
- /sx;
-
sub check_for_else_statement{
my $self = shift;
- $logger->trace("*Looking for \\else statement (${$self}{name})") if $is_t_switch_active;
- ${$self}{body} =~ s/$elseRegExp(\h*)($trailingCommentRegExp)?
- /
- # create a new IfElseFi object
- my $else = LatexIndent::Else->new(begin=>$1,
- name=>${$self}{name},
- storageNameAppend=>"else",
- body=>$3,
- end=>q(),
- linebreaksAtEnd=>{
- begin=>$2?1:0,
- body=>0,
- end=>0,
- },
- aliases=>{
- # begin statements
- BeginStartsOnOwnLine=>"ElseStartsOnOwnLine",
- # end statements
- BodyStartsOnOwnLine=>"ElseFinishesWithLineBreak",
- },
- modifyLineBreaksYamlName=>"ifElseFi",
- 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};
- /xse;
- return;
+ # we call the else routine from different places; see IfElseFi.pm and Special.pm
+ my %input = @_;
+
+ # store the regular expresssion for matching and replacing the \else statements
+ my $elseRegExp = qr/
+ (
+ $input{elseNameRegExp}
+ \h* # possible horizontal space
+ (\R*) # possible line breaks after \else statement
+ )
+ (
+ (?:
+ (?!$input{elseNameRegExp}).
+ )*? # body, which can't include another \else
+ )
+ $
+ /sx;
+
+ $logger->trace("*Looking for $input{elseNameRegExp} statement (${$self}{name})") if $is_t_switch_active;
+
+ while(${$self}{body} =~ m/$elseRegExp(\h*)($trailingCommentRegExp)?/){
+ ${$self}{body} =~ s/$elseRegExp(\h*)($trailingCommentRegExp)?
+ /
+ # create a new IfElseFi object
+ my $else = LatexIndent::Else->new(begin=>$1,
+ name=>${$self}{name},
+ storageNameAppend=>$input{storageNameAppend},
+ body=>$3,
+ end=>q(),
+ linebreaksAtEnd=>{
+ begin=>$2?1:0,
+ body=>0,
+ end=>0,
+ },
+ aliases=>{
+ # begin statements
+ BeginStartsOnOwnLine=>$input{ElseStartsOnOwnLine},
+ # end statements
+ BodyStartsOnOwnLine=>$input{ElseFinishesWithLineBreak},
+ },
+ modifyLineBreaksYamlName=>${$self}{modifyLineBreaksYamlName},
+ endImmediatelyFollowedByComment=>0,
+ horizontalTrailingSpace=>q(),
+ );
+ # log file output
+ $logger->trace("*$input{logName} 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};
+ /xse;
+ }
+ return;
}
sub remove_line_breaks_begin{
@@ -92,6 +103,10 @@ sub tasks_particular_to_each_object{
# search for commands and special code blocks
$self->find_commands_or_key_equals_values_braces_and_special;
+
+ # search for arguments
+ $self->find_opt_mand_arguments;
+
return;
}
diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/FileContents.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/FileContents.pm
index 4ad2623fe0d..5ef487f9866 100644
--- a/Master/texmf-dist/scripts/latexindent/LatexIndent/FileContents.pm
+++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/FileContents.pm
@@ -120,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}}){
- $logger->trace("\\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") if $is_t_switch_active ;
# create a preamble object
$preamble = LatexIndent::Preamble->new( begin=>q(),
diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/GetYamlSettings.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/GetYamlSettings.pm
index b5a9037a907..8fb07087c35 100644
--- a/Master/texmf-dist/scripts/latexindent/LatexIndent/GetYamlSettings.pm
+++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/GetYamlSettings.pm
@@ -223,7 +223,32 @@ sub readSettings{
}
}
} else {
- $masterSettings{$firstLevelKey}{$secondLevelKey} = $secondLevelValue;
+ # settings such as commandCodeBlocks can have arrays, which may wish
+ # to be amalgamated, rather than overwritten
+ if(ref($secondLevelValue) eq "ARRAY"
+ and
+ ${${$masterSettings{$firstLevelKey}{$secondLevelKey}}[0]}{amalgamate}
+ and
+ !(ref(${$secondLevelValue}[0]) eq "HASH" and defined ${$secondLevelValue}[0]{amalgamate} and !${$secondLevelValue}[0]{amalgamate})
+ ){
+ $logger->trace("*$firstLevelKey -> $secondLevelKey, amalgamate: 1") if($is_t_switch_active);
+ foreach (@{$secondLevelValue}){
+ $logger->trace("$_") if($is_t_switch_active);
+ push (@{$masterSettings{$firstLevelKey}{$secondLevelKey}},$_) unless(ref($_) eq "HASH");
+ }
+
+ # remove duplicated entries, https://stackoverflow.com/questions/7651/how-do-i-remove-duplicate-items-from-an-array-in-perl
+ my %seen = ();
+ my @unique = grep { ! $seen{ $_ }++ } @{$masterSettings{$firstLevelKey}{$secondLevelKey}};
+ @{$masterSettings{$firstLevelKey}{$secondLevelKey}} = @unique;
+
+ $logger->trace("*master settings for $firstLevelKey -> $secondLevelKey now look like:") if $is_t_switch_active;
+ foreach (@{$masterSettings{$firstLevelKey}{$secondLevelKey}}){
+ $logger->trace("$_") if($is_t_switch_active);
+ }
+ } else {
+ $masterSettings{$firstLevelKey}{$secondLevelKey} = $secondLevelValue;
+ }
}
}
} else {
diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/HiddenChildren.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/HiddenChildren.pm
index af7d513809d..768ec1651f9 100644
--- a/Master/texmf-dist/scripts/latexindent/LatexIndent/HiddenChildren.pm
+++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/HiddenChildren.pm
@@ -101,48 +101,52 @@ sub update_family_tree{
# loop through the hash
$logger->trace("*Updating FamilyTree...") if $is_t_switch_active;
while( my ($idToSearch,$ancestorToSearch)= each %familyTree){
+ $logger->trace("*current ID: $idToSearch") if($is_t_switch_active);
foreach(@{${$ancestorToSearch}{ancestors}}){
my $ancestorID = ${$_}{ancestorID};
- $logger->trace("current ID: $idToSearch, ancestor: $ancestorID") if($is_t_switch_active);
- if($familyTree{$ancestorID}){
- $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}}){
- $logger->trace("ancestor of *hidden* child: ${$_}{ancestorID}") if($is_t_switch_active);
- my $newAncestorId = ${$_}{ancestorID};
- my $type;
- if($naturalAncestors =~ m/$ancestorID/){
- $type = "natural";
- } else {
- $type = "adopted";
- }
- my $matched = grep { $_->{ancestorID} eq $newAncestorId } @{${$familyTree{$idToSearch}}{ancestors}};
- push(@{${$familyTree{$idToSearch}}{ancestors}},{ancestorID=>${$_}{ancestorID},ancestorIndentation=>${$_}{ancestorIndentation},type=>$type}) unless($matched);
- }
- } else {
- my $naturalAncestors = q();
- foreach(@{${$familyTree{$idToSearch}}{ancestors}}){
- $naturalAncestors .= "---".${$_}{ancestorID} if(${$_}{type} eq "natural");
- }
- $logger->trace("natural ancestors of $ancestorID: $naturalAncestors") if($is_t_switch_active);
- foreach(@{${$allChildren{$ancestorID}}{ancestors}}){
- my $newAncestorId = ${$_}{ancestorID};
- my $type;
- if($naturalAncestors =~ m/$newAncestorId/){
- $type = "natural";
- } else {
- $type = "adopted";
- }
- my $matched = grep { $_->{ancestorID} eq $newAncestorId } @{${$familyTree{$idToSearch}}{ancestors}};
- unless($matched){
- $logger->trace("ancestor of UNHIDDEN child: ${$_}{ancestorID}") if($is_t_switch_active);
- push(@{${$familyTree{$idToSearch}}{ancestors}},{ancestorID=>${$_}{ancestorID},ancestorIndentation=>${$_}{ancestorIndentation},type=>$type});
+
+ # construct the natural ancestors
+ my $naturalAncestors = q();
+ foreach(@{${$familyTree{$idToSearch}}{ancestors}}){
+ $naturalAncestors .= "---".${$_}{ancestorID} if(${$_}{type} eq "natural");
+ }
+
+ # we only need to update the family tree if the $ancestorID is *not* a natural
+ # ancestor, otherwise everything will be taken care of by the natural ancestor
+ if($naturalAncestors !~ m/$ancestorID/){
+ $logger->trace("ancestor: $ancestorID") if($is_t_switch_active);
+ if($familyTree{$ancestorID}){
+ $logger->trace("$ancestorID is a key within familyTree, grabbing its ancestors") if($is_t_switch_active);
+ foreach(@{${$familyTree{$ancestorID}}{ancestors}}){
+ $logger->trace("ancestor of *hidden* child: ${$_}{ancestorID}") if($is_t_switch_active);
+ my $newAncestorId = ${$_}{ancestorID};
+ my $type;
+ if($naturalAncestors =~ m/$ancestorID/){
+ $type = "natural";
+ } else {
+ $type = "adopted";
+ }
+ my $matched = grep { $_->{ancestorID} eq $newAncestorId } @{${$familyTree{$idToSearch}}{ancestors}};
+ push(@{${$familyTree{$idToSearch}}{ancestors}},{ancestorID=>${$_}{ancestorID},ancestorIndentation=>${$_}{ancestorIndentation},type=>$type}) unless($matched);
}
- }
- }
+ } else {
+ $logger->trace("natural ancestors of $ancestorID: $naturalAncestors") if($is_t_switch_active);
+ foreach(@{${$allChildren{$ancestorID}}{ancestors}}){
+ my $newAncestorId = ${$_}{ancestorID};
+ my $type;
+ if($naturalAncestors =~ m/$newAncestorId/){
+ $type = "natural";
+ } else {
+ $type = "adopted";
+ }
+ my $matched = grep { $_->{ancestorID} eq $newAncestorId } @{${$familyTree{$idToSearch}}{ancestors}};
+ unless($matched){
+ $logger->trace("ancestor of UNHIDDEN child: ${$_}{ancestorID}") if($is_t_switch_active);
+ push(@{${$familyTree{$idToSearch}}{ancestors}},{ancestorID=>${$_}{ancestorID},ancestorIndentation=>${$_}{ancestorIndentation},type=>$type});
+ }
+ }
+ }
+ }
}
}
diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/IfElseFi.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/IfElseFi.pm
index 1a0529d3aac..ecceb00fec6 100755
--- a/Master/texmf-dist/scripts/latexindent/LatexIndent/IfElseFi.pm
+++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/IfElseFi.pm
@@ -101,12 +101,17 @@ sub find_ifelsefi{
sub post_indentation_check{
# needed to remove leading horizontal space before \else
my $self = shift;
- if(${$self}{body} =~ m/^\h*\\else/sm
- and
- !(${$self}{body} =~ m/^\h*\\else/s and ${$self}{linebreaksAtEnd}{begin}==0)
- ){
- $logger->trace("*Adding surrounding indentation to \\else statement ('${$self}{surroundingIndentation}')") if $is_t_switch_active;
- ${$self}{body} =~ s/^\h*\\else/${$self}{surroundingIndentation}\\else/sm;
+
+ # loop through \else and \or
+ foreach ({regExp=>qr/\\else/},{regExp=>qr/\\or/}){
+ my %else = %{$_};
+ if(${$self}{body} =~ m/^\h*$else{regExp}/sm
+ and
+ !(${$self}{body} =~ m/^\h*$else{regExp}/s and ${$self}{linebreaksAtEnd}{begin}==0)
+ ){
+ $logger->trace("*Adding surrounding indentation to $else{regExp} statement(s) ('${$self}{surroundingIndentation}')") if $is_t_switch_active;
+ ${$self}{body} =~ s/^\h*($else{regExp})/${$self}{surroundingIndentation}$1/smg;
+ }
}
return;
}
@@ -115,7 +120,32 @@ sub tasks_particular_to_each_object{
my $self = shift;
# check for existence of \else statement, and associated line break information
- $self->check_for_else_statement;
+ $self->check_for_else_statement(
+ # else name regexp
+ elseNameRegExp=>qr|\\else|,
+ # else statements name
+ ElseStartsOnOwnLine=>"ElseStartsOnOwnLine",
+ # end statements
+ ElseFinishesWithLineBreak=>"ElseFinishesWithLineBreak",
+ # for the YAML settings storage
+ storageNameAppend=>"else",
+ # logfile information
+ logName=>"else",
+ );
+
+ # check for existence of \or statement, and associated line break information
+ $self->check_for_else_statement(
+ # else name regexp
+ elseNameRegExp=>qr|\\or|,
+ # else statements name
+ ElseStartsOnOwnLine=>"OrStartsOnOwnLine",
+ # end statements
+ ElseFinishesWithLineBreak=>"OrFinishesWithLineBreak",
+ # for the YAML settings storage
+ storageNameAppend=>"or",
+ # logfile information
+ logName=>"or",
+ );
# search for headings (important to do this before looking for commands!)
$self->find_heading;
diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/NamedGroupingBracesBrackets.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/NamedGroupingBracesBrackets.pm
index 22429677894..4508943ddfa 100755
--- a/Master/texmf-dist/scripts/latexindent/LatexIndent/NamedGroupingBracesBrackets.pm
+++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/NamedGroupingBracesBrackets.pm
@@ -39,7 +39,7 @@ sub construct_grouping_braces_brackets_regexp{
\h|\R|\{|\[|\$|\)|\(
)
(
- [0-9a-zA-Z@\*><]+? # lowercase|uppercase letters, @, *, numbers, forward slash, dots
+ [0-9\.a-zA-Z@\*><]+? # lowercase|uppercase letters, @, *, numbers, forward slash, dots
) # $2 name
(\h*) # $3 h-space
(\R*) # $4 linebreaks
diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/Special.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/Special.pm
index 461c620e53f..45dd4c3ec16 100644
--- a/Master/texmf-dist/scripts/latexindent/LatexIndent/Special.pm
+++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/Special.pm
@@ -130,6 +130,7 @@ sub find_special{
# the regexp
my $specialRegExp = $individualSpecialRegExps{$specialName};
+ $logger->trace("$specialName regexp: \n$specialRegExp") if $is_tt_switch_active ;
while(${$self}{body} =~ m/$specialRegExp(\h*)($trailingCommentRegExp)?/){
@@ -163,7 +164,7 @@ sub find_special{
);
# log file output
- $logger->trace("*Special found: $specialName",'heading') if $is_t_switch_active;
+ $logger->trace("*Special found: $specialName") 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);
@@ -179,16 +180,80 @@ sub find_special{
sub tasks_particular_to_each_object{
my $self = shift;
+ if( defined ${${$masterSettings{specialBeginEnd}}{${$self}{name}}}{middle}){
+ $logger->trace("middle specified for ${$self}{name} (see specialBeginEnd -> ${$self}{name} -> middle)") if $is_t_switch_active ;
+
+ # initiate the middle regexp
+ my $specialMiddle = q();
+
+ # we can specify middle as either an array or a hash
+ if(ref(${${$masterSettings{specialBeginEnd}}{${$self}{name}}}{middle}) eq "ARRAY"){
+ $logger->trace("looping through middle array for ${$self}{name}") if $is_t_switch_active ;
+ foreach(@{${${$masterSettings{specialBeginEnd}}{${$self}{name}}}{middle}}){
+ $specialMiddle .= ($specialMiddle eq ""?q():"|").$_;
+ }
+ $specialMiddle = qr/$specialMiddle/;
+ } else {
+ $specialMiddle = qr/${${$masterSettings{specialBeginEnd}}{${$self}{name}}}{middle}/;
+ }
+
+ $logger->trace("overall middle regexp for ${$self}{name}: $specialMiddle") if $is_t_switch_active ;
+
+ # store the middle regexp for later
+ ${$self}{middleRegExp} = $specialMiddle;
+
+ # check for existence of a 'middle' statement, and associated line break information
+ $self->check_for_else_statement(
+ # else name regexp
+ elseNameRegExp=>$specialMiddle,
+ # else statements name
+ ElseStartsOnOwnLine=>"SpecialMiddleStartsOnOwnLine",
+ # end statements
+ ElseFinishesWithLineBreak=>"SpecialMiddleFinishesWithLineBreak",
+ # for the YAML settings storage
+ storageNameAppend=>"middle",
+ # logfile information
+ logName=>"special middle",
+ );
+
+
+ }
+
return unless(${$masterSettings{specialBeginEnd}}{specialBeforeCommand});
# search for commands with arguments
$self->find_commands_or_key_equals_values_braces;
+
+ # search for arguments
+ $self->find_opt_mand_arguments;
# search for ifElseFi blocks
$self->find_ifelsefi;
}
+sub post_indentation_check{
+ # needed to remove leading horizontal space before \else
+ my $self = shift;
+
+ return unless ( defined ${${$masterSettings{specialBeginEnd}}{${$self}{name}}}{middle});
+
+ $logger->trace("post indentation check for ${$self}{name} to account for middle") if $is_t_switch_active ;
+
+ # loop through \else and \or
+ foreach ({regExp=>${$self}{middleRegExp}}){
+ my %else = %{$_};
+ if(${$self}{body} =~ m/^\h*$else{regExp}/sm
+ and
+ !(${$self}{body} =~ m/^\h*$else{regExp}/s and ${$self}{linebreaksAtEnd}{begin}==0)
+ ){
+ $logger->trace("*Adding surrounding indentation to $else{regExp} statement(s) ('${$self}{surroundingIndentation}')") if $is_t_switch_active;
+ ${$self}{body} =~ s/^\h*($else{regExp})/${$self}{surroundingIndentation}$1/smg;
+ }
+ }
+ return;
+}
+
sub create_unique_id{
my $self = shift;
diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/Version.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/Version.pm
index 945841208c7..c048b649a66 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.4.1';
-our $versionDate = '2018-01-18';
+our $versionNumber = '3.4.2';
+our $versionDate = '2018-04-27';
1
diff --git a/Master/texmf-dist/scripts/latexindent/defaultSettings.yaml b/Master/texmf-dist/scripts/latexindent/defaultSettings.yaml
index 5f733c2ca23..4fa5eed5cc1 100755
--- a/Master/texmf-dist/scripts/latexindent/defaultSettings.yaml
+++ b/Master/texmf-dist/scripts/latexindent/defaultSettings.yaml
@@ -1,4 +1,4 @@
-# defaultSettings.yaml for latexindent.pl, version 3.4.1, 2018-01-18
+# defaultSettings.yaml for latexindent.pl, version 3.4.2, 2018-04-27
# a script that aims to
# beautify .tex, .sty, .cls files
#
@@ -311,14 +311,18 @@ indentRulesGlobal:
commandCodeBlocks:
roundParenthesesAllowed: 1
stringsAllowedBetweenArguments:
- node: 1
- at: 1
- to: 1
- decoration: 1
- ++: 1
- --: 1
+ -
+ amalgamate: 1
+ - 'node'
+ - 'at'
+ - 'to'
+ - 'decoration'
+ - '\+\+'
+ - '\-\-'
commandNameSpecial:
- @ifnextchar[: 1
+ -
+ amalgamate: 1
+ - '@ifnextchar\['
# modifyLineBreaks will only be searched if the -m
# switch is active
@@ -451,6 +455,8 @@ modifyLineBreaks:
ifElseFi:
IfStartsOnOwnLine: 0
BodyStartsOnOwnLine: 0
+ OrStartsOnOwnLine: 0
+ OrFinishesWithLineBreak: 0
ElseStartsOnOwnLine: 0
ElseFinishesWithLineBreak: 0
FiStartsOnOwnLine: 0
@@ -458,6 +464,8 @@ modifyLineBreaks:
ifnum:
IfStartsOnOwnLine: 0
BodyStartsOnOwnLine: 0
+ OrStartsOnOwnLine: 0
+ OrFinishesWithLineBreak: 0
ElseStartsOnOwnLine: 0
ElseFinishesWithLineBreak: 0
FiStartsOnOwnLine: 0
diff --git a/Master/texmf-dist/scripts/latexindent/latexindent.pl b/Master/texmf-dist/scripts/latexindent/latexindent.pl
index 97f8269ab88..b49b2a009cc 100755
--- a/Master/texmf-dist/scripts/latexindent/latexindent.pl
+++ b/Master/texmf-dist/scripts/latexindent/latexindent.pl
@@ -1,5 +1,5 @@
#!/usr/bin/env perl
-# latexindent.pl, version 3.4.1, 2018-01-18
+# latexindent.pl, version 3.4.2, 2018-04-27
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by