From d82d72343a5dfcbc4ba14569fba7f9e34debdf71 Mon Sep 17 00:00:00 2001 From: Norbert Preining Date: Fri, 15 Apr 2022 03:00:41 +0000 Subject: CTAN sync 202204150300 --- .../LatexIndent/UnNamedGroupingBracesBrackets.pm | 62 ++++++++++++---------- 1 file changed, 33 insertions(+), 29 deletions(-) (limited to 'support/latexindent/LatexIndent/UnNamedGroupingBracesBrackets.pm') diff --git a/support/latexindent/LatexIndent/UnNamedGroupingBracesBrackets.pm b/support/latexindent/LatexIndent/UnNamedGroupingBracesBrackets.pm index 55f0d7fa27..b1d619fad6 100644 --- a/support/latexindent/LatexIndent/UnNamedGroupingBracesBrackets.pm +++ b/support/latexindent/LatexIndent/UnNamedGroupingBracesBrackets.pm @@ -1,4 +1,5 @@ package LatexIndent::UnNamedGroupingBracesBrackets; + # 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 # the Free Software Foundation, either version 3 of the License, or @@ -22,13 +23,14 @@ 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/; +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/; our $unNamedGroupingBracesCounter; our $un_named_grouping_braces_RegExp; -our $un_named_grouping_braces_RegExp_trailing_comment; +our $un_named_grouping_braces_RegExp_trailing_comment; -sub construct_unnamed_grouping_braces_brackets_regexp{ +sub construct_unnamed_grouping_braces_brackets_regexp { my $self = shift; # grab the arguments regexp @@ -38,10 +40,10 @@ sub construct_unnamed_grouping_braces_brackets_regexp{ my $blankLineToken = $tokens{blanklines}; # arguments Before, by default, includes beamer special and numbered arguments, for example #1 #2, etc - my $argumentsBefore = qr/${${$mainSettings{fineTuning}}{arguments}}{before}/; + my $argumentsBefore = qr/${${$mainSettings{fineTuning}}{arguments}}{before}/; my $UnNamedGroupingFollowRegExp = qr/${${$mainSettings{fineTuning}}{UnNamedGroupingBracesBrackets}}{follow}/; - # store the regular expresssion for matching and replacing + # store the regular expresssion for matching and replacing $un_named_grouping_braces_RegExp = qr/ # NOT (?! @@ -64,10 +66,11 @@ sub construct_unnamed_grouping_braces_brackets_regexp{ (\R)? # $6 linebreak /sx; - $un_named_grouping_braces_RegExp_trailing_comment = qr/$un_named_grouping_braces_RegExp(\h*)((?:$trailingCommentRegExp\h*)*)?/; + $un_named_grouping_braces_RegExp_trailing_comment + = qr/$un_named_grouping_braces_RegExp(\h*)((?:$trailingCommentRegExp\h*)*)?/; } -sub create_unique_id{ +sub create_unique_id { my $self = shift; $unNamedGroupingBracesCounter++; @@ -75,31 +78,32 @@ sub create_unique_id{ return; } -sub get_replacement_text{ +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 + # the replacement text for a key = {value} needes to accomodate the leading [ OR { OR % OR , OR any combination thereof $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 - # - # also, the argument reg-exp can pick up a leading comment (with line break), which needs to be put - # into the replacement text (see documentation/demonstrations/pstricks.tex and test-cases/unnamed-braces/unnamed.tex for example) +# 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 +# +# also, the argument reg-exp can pick up a leading comment (with line break), which needs to be put +# into the replacement text (see documentation/demonstrations/pstricks.tex and test-cases/unnamed-braces/unnamed.tex for example) ${$self}{body} =~ s/(.*?)(\{|\[)/$2/s; - ${$self}{replacementText} = ${$self}{beginningbit}.($1 ne ''?$1:q()).${$self}{id}; + ${$self}{replacementText} = ${$self}{beginningbit} . ( $1 ne '' ? $1 : q() ) . ${$self}{id}; # 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; - $logger->trace("Beginning bit is: ${$self}{beginningbit}") if($is_t_switch_active); + ${ ${$self}{linebreaksAtEnd} }{begin} = 0; + $logger->trace("Beginning bit is: ${$self}{beginningbit}") if ($is_t_switch_active); delete ${$self}{beginningbit}; } -sub check_for_blank_lines_at_beginning{ - # some examples can have blank line tokens at the beginning of the body, - # which can confuse the routine below - # See, for example, +sub check_for_blank_lines_at_beginning { + + # some examples can have blank line tokens at the beginning of the body, + # which can confuse the routine below + # See, for example, # test-cases/namedGroupingBracesBrackets/special-characters-minimal-blank-lines-m-switch.tex # compared to # test-cases/namedGroupingBracesBrackets/special-characters-minimal-blank-lines-default.tex @@ -109,7 +113,7 @@ sub check_for_blank_lines_at_beginning{ my $blankLineToken = $tokens{blanklines}; # if the body begins with 2 or more blank line tokens - if(${$self}{body} =~ m/^((?:$blankLineToken\R){2,})/s){ + if ( ${$self}{body} =~ m/^((?:$blankLineToken\R){2,})/s ) { # remove them ${$self}{body} =~ s/^((?:$blankLineToken\R)+)//s; @@ -118,21 +122,21 @@ sub check_for_blank_lines_at_beginning{ my $blank_line_tokens_at_beginning_of_body = $1; # and count them, for use after the indentation routine - ${$self}{blankLinesAtBeginning} = () = $blank_line_tokens_at_beginning_of_body =~ /$blankLineToken\R/sg + ${$self}{blankLinesAtBeginning} = () = $blank_line_tokens_at_beginning_of_body =~ /$blankLineToken\R/sg; } return; } -sub put_blank_lines_back_in_at_beginning{ +sub put_blank_lines_back_in_at_beginning { my $self = shift; # some bodies have blank lines at the beginning - if(${$self}{blankLinesAtBeginning}){ - for(my $i=0; $i<${$self}{blankLinesAtBeginning}; $i++){ - ${$self}{body} = $tokens{blanklines}.${$self}{body}; + if ( ${$self}{blankLinesAtBeginning} ) { + for ( my $i = 0; $i < ${$self}{blankLinesAtBeginning}; $i++ ) { + ${$self}{body} = $tokens{blanklines} . ${$self}{body}; } } - return + return; } 1; -- cgit v1.2.3