summaryrefslogtreecommitdiff
path: root/support/latexindent/LatexIndent/KeyEqualsValuesBraces.pm
diff options
context:
space:
mode:
Diffstat (limited to 'support/latexindent/LatexIndent/KeyEqualsValuesBraces.pm')
-rw-r--r--support/latexindent/LatexIndent/KeyEqualsValuesBraces.pm65
1 files changed, 38 insertions, 27 deletions
diff --git a/support/latexindent/LatexIndent/KeyEqualsValuesBraces.pm b/support/latexindent/LatexIndent/KeyEqualsValuesBraces.pm
index f7090c3d71..684146e2f4 100644
--- a/support/latexindent/LatexIndent/KeyEqualsValuesBraces.pm
+++ b/support/latexindent/LatexIndent/KeyEqualsValuesBraces.pm
@@ -1,4 +1,5 @@
package LatexIndent::KeyEqualsValuesBraces;
+
# 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_m_switch_active $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_key_equals_values_regexp $key_equals_values_bracesRegExp $key_equals_values_bracesRegExpTrailingComment/;
+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/;
our $key_equals_values_braces_Counter;
-our $key_equals_values_bracesRegExp;
-our $key_equals_values_bracesRegExpTrailingComment;
+our $key_equals_values_bracesRegExp;
+our $key_equals_values_bracesRegExpTrailingComment;
-sub construct_key_equals_values_regexp{
+sub construct_key_equals_values_regexp {
my $self = shift;
# grab the arguments regexp
@@ -38,10 +40,11 @@ sub construct_key_equals_values_regexp{
my $blankLineToken = $tokens{blanklines};
# read from fine tuning
- my $keyEqualsValuesBracesBrackets = qr/${${$mainSettings{fineTuning}}{keyEqualsValuesBracesBrackets}}{name}/;
- my $keyEqualsValuesBracesBracketsFollow = qr/${${$mainSettings{fineTuning}}{keyEqualsValuesBracesBrackets}}{follow}/;
+ my $keyEqualsValuesBracesBrackets = qr/${${$mainSettings{fineTuning}}{keyEqualsValuesBracesBrackets}}{name}/;
+ my $keyEqualsValuesBracesBracketsFollow
+ = qr/${${$mainSettings{fineTuning}}{keyEqualsValuesBracesBrackets}}{follow}/;
- # store the regular expresssion for matching and replacing
+ # store the regular expresssion for matching and replacing
$key_equals_values_bracesRegExp = qr/
(
(?:$keyEqualsValuesBracesBracketsFollow)
@@ -61,46 +64,54 @@ sub construct_key_equals_values_regexp{
(\R)? # $9 linebreak at end
/sx;
- $key_equals_values_bracesRegExpTrailingComment = qr/$key_equals_values_bracesRegExp(\h*)((?:$trailingCommentRegExp\h*)*)?/;
+ $key_equals_values_bracesRegExpTrailingComment
+ = qr/$key_equals_values_bracesRegExp(\h*)((?:$trailingCommentRegExp\h*)*)?/;
}
-sub indent_begin{
+sub indent_begin {
my $self = shift;
# blank line token
my $blankLineToken = $tokens{blanklines};
- if(${$self}{begin} =~ /\R=/s or ${$self}{begin} =~ /$blankLineToken\h*=/s ){
+ if ( ${$self}{begin} =~ /\R=/s or ${$self}{begin} =~ /$blankLineToken\h*=/s ) {
$logger->trace("= found on own line in ${$self}{name}, adding indentation") if $is_t_switch_active;
${$self}{begin} =~ s/=/${$self}{indentation}=/s;
}
}
-sub check_linebreaks_before_equals{
+sub check_linebreaks_before_equals {
+
# check if -m switch is active
return unless $is_m_switch_active;
-
+
my $self = shift;
# linebreaks *infront* of = symbol
- if(${$self}{begin} =~ /\R\h*=/s){
- if(defined ${$self}{EqualsStartsOnOwnLine} and ${$self}{EqualsStartsOnOwnLine}==-1){
- $logger->trace("Removing linebreak before = symbol in ${$self}{name} (see EqualsStartsOnOwnLine)") if $is_t_switch_active;
+ if ( ${$self}{begin} =~ /\R\h*=/s ) {
+ if ( defined ${$self}{EqualsStartsOnOwnLine} and ${$self}{EqualsStartsOnOwnLine} == -1 ) {
+ $logger->trace("Removing linebreak before = symbol in ${$self}{name} (see EqualsStartsOnOwnLine)")
+ if $is_t_switch_active;
${$self}{begin} =~ s/(\R|\h)*=/=/s;
- }
- } else {
- if(defined ${$self}{EqualsStartsOnOwnLine} and ${$self}{EqualsStartsOnOwnLine}==1){
- $logger->trace("Adding a linebreak before = symbol for ${$self}{name} (see EqualsStartsOnOwnLine)") if $is_t_switch_active;
+ }
+ }
+ else {
+ if ( defined ${$self}{EqualsStartsOnOwnLine} and ${$self}{EqualsStartsOnOwnLine} == 1 ) {
+ $logger->trace("Adding a linebreak before = symbol for ${$self}{name} (see EqualsStartsOnOwnLine)")
+ if $is_t_switch_active;
${$self}{begin} =~ s/=/\n=/s;
- } elsif(defined ${$self}{EqualsStartsOnOwnLine} and ${$self}{EqualsStartsOnOwnLine}==2){
- $logger->trace("Adding a % linebreak immediately before = symbol for ${$self}{name} (see EqualsStartsOnOwnLine)") if $is_t_switch_active;
+ }
+ elsif ( defined ${$self}{EqualsStartsOnOwnLine} and ${$self}{EqualsStartsOnOwnLine} == 2 ) {
+ $logger->trace(
+ "Adding a % linebreak immediately before = symbol for ${$self}{name} (see EqualsStartsOnOwnLine)")
+ if $is_t_switch_active;
${$self}{begin} =~ s/\h*=/%\n=/s;
- }
+ }
}
return;
}
-sub create_unique_id{
+sub create_unique_id {
my $self = shift;
$key_equals_values_braces_Counter++;
@@ -108,12 +119,12 @@ 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;
- ${$self}{replacementText} = ${$self}{beginningbit}.${$self}{id};
+ ${$self}{replacementText} = ${$self}{beginningbit} . ${$self}{id};
delete ${$self}{beginningbit};
}