summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/scripts/latexindent
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2018-08-14 22:01:47 +0000
committerKarl Berry <karl@freefriends.org>2018-08-14 22:01:47 +0000
commita54d196b0fc4715e3d2dbcfe62cfccea6aae57fe (patch)
tree40ebe5b6f9da50b68cd6ae2546a9e32124cb46ed /Master/texmf-dist/scripts/latexindent
parent2feb602ca10b928ee4cba97b3ae95a8ef6b853d4 (diff)
latexindent (15aug18)
git-svn-id: svn://tug.org/texlive/trunk@48402 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/scripts/latexindent')
-rw-r--r--Master/texmf-dist/scripts/latexindent/LatexIndent/AlignmentAtAmpersand.pm2
-rw-r--r--Master/texmf-dist/scripts/latexindent/LatexIndent/Arguments.pm14
-rw-r--r--Master/texmf-dist/scripts/latexindent/LatexIndent/BlankLines.pm20
-rw-r--r--Master/texmf-dist/scripts/latexindent/LatexIndent/Document.pm36
-rw-r--r--Master/texmf-dist/scripts/latexindent/LatexIndent/Else.pm2
-rwxr-xr-xMaster/texmf-dist/scripts/latexindent/LatexIndent/Environment.pm4
-rw-r--r--Master/texmf-dist/scripts/latexindent/LatexIndent/FileContents.pm34
-rw-r--r--Master/texmf-dist/scripts/latexindent/LatexIndent/GetYamlSettings.pm233
-rw-r--r--Master/texmf-dist/scripts/latexindent/LatexIndent/Heading.pm2
-rw-r--r--Master/texmf-dist/scripts/latexindent/LatexIndent/HiddenChildren.pm17
-rw-r--r--Master/texmf-dist/scripts/latexindent/LatexIndent/Indent.pm20
-rw-r--r--Master/texmf-dist/scripts/latexindent/LatexIndent/LogFile.pm6
-rw-r--r--Master/texmf-dist/scripts/latexindent/LatexIndent/MandatoryArgument.pm2
-rw-r--r--Master/texmf-dist/scripts/latexindent/LatexIndent/ModifyLineBreaks.pm78
-rw-r--r--Master/texmf-dist/scripts/latexindent/LatexIndent/OptionalArgument.pm2
-rw-r--r--Master/texmf-dist/scripts/latexindent/LatexIndent/Preamble.pm18
-rw-r--r--Master/texmf-dist/scripts/latexindent/LatexIndent/RoundBrackets.pm2
-rw-r--r--Master/texmf-dist/scripts/latexindent/LatexIndent/Special.pm8
-rw-r--r--Master/texmf-dist/scripts/latexindent/LatexIndent/TrailingComments.pm2
-rw-r--r--Master/texmf-dist/scripts/latexindent/LatexIndent/Verbatim.pm53
-rw-r--r--Master/texmf-dist/scripts/latexindent/LatexIndent/Version.pm4
-rwxr-xr-xMaster/texmf-dist/scripts/latexindent/defaultSettings.yaml27
-rwxr-xr-xMaster/texmf-dist/scripts/latexindent/latexindent.pl4
23 files changed, 492 insertions, 98 deletions
diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/AlignmentAtAmpersand.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/AlignmentAtAmpersand.pm
index 50fe2410141..7a4a9727c89 100644
--- a/Master/texmf-dist/scripts/latexindent/LatexIndent/AlignmentAtAmpersand.pm
+++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/AlignmentAtAmpersand.pm
@@ -107,7 +107,7 @@ sub find_aligned_block{
return;
}
-sub modify_line_breaks_settings{
+sub yaml_modify_line_breaks_settings{
return;
}
diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/Arguments.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/Arguments.pm
index 8c8b5af38f1..7c84a0e65f3 100644
--- a/Master/texmf-dist/scripts/latexindent/LatexIndent/Arguments.pm
+++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/Arguments.pm
@@ -78,6 +78,14 @@ sub find_opt_mand_arguments{
# give unique id
$arguments->create_unique_id;
+
+ # text wrapping can make the ID split across lines
+ ${$arguments}{idRegExp} = ${$arguments}{id};
+
+ if($is_m_switch_active){
+ my $IDwithLineBreaks = join("\\R?\\h*",split(//,${$arguments}{id}));
+ ${$arguments}{idRegExp} = qr/$IDwithLineBreaks/s;
+ }
# determine which comes first, optional or mandatory
if(${$arguments}{body} =~ m/.*?((?<!\\)\{|\[)/s){
@@ -98,6 +106,12 @@ sub find_opt_mand_arguments{
$arguments->find_optional_arguments;
}
+ # it's possible not to have any mandatory or optional arguments, see
+ # https://github.com/cmhughes/latexindent.pl/issues/123
+ if( !(defined ${$arguments}{children}) ){
+ $logger->trace("No optional or mandatory arguments found; searching for matching round parenthesis") if $is_t_switch_active;
+ $arguments->find_round_brackets;
+ }
} else {
$logger->trace("Searching for round brackets ONLY") if $is_t_switch_active;
# look for round brackets
diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/BlankLines.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/BlankLines.pm
index e4041ce26d5..abd1ed73a3c 100644
--- a/Master/texmf-dist/scripts/latexindent/LatexIndent/BlankLines.pm
+++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/BlankLines.pm
@@ -26,6 +26,18 @@ our @EXPORT_OK = qw/protect_blank_lines unprotect_blank_lines condense_blank_lin
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;
@@ -43,7 +55,7 @@ sub condense_blank_lines{
return unless ${$masterSettings{modifyLineBreaks}}{condenseMultipleBlankLinesInto}>0;
my $self = shift;
-
+
$logger->trace("*condense blank lines routine") if $is_t_switch_active;
# if preserveBlankLines is set to 0, then the blank-line-token will not be present
# in the document -- we change that here
@@ -84,9 +96,13 @@ sub unprotect_blank_lines{
return unless ${$masterSettings{modifyLineBreaks}}{preserveBlankLines};
my $self = shift;
+
+ # remove any empty lines that might have been added by the text_wrap routine; see, for example,
+ # test-cases/maxLineChars/multi-object-all.tex -l=multi-object2.yaml -m
+ ${$self}{body} =~ s/^\h*\R//mg;
$logger->trace("Unprotecting blank lines (see preserveBlankLines)") if $is_t_switch_active;
- my $blankLineToken = $tokens{blanklines};
+ my $blankLineToken = join("(?:\\h|\\R)*",split(//,$tokens{blanklines}));
# loop through the body, looking for the blank line token
while(${$self}{body} =~ m/$blankLineToken/s){
diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/Document.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/Document.pm
index 48d93c622d5..1b9d3811fb9 100644
--- a/Master/texmf-dist/scripts/latexindent/LatexIndent/Document.pm
+++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/Document.pm
@@ -23,11 +23,11 @@ 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/;
use LatexIndent::LogFile qw/processSwitches $logger/;
-use LatexIndent::GetYamlSettings qw/readSettings modify_line_breaks_settings get_indentation_settings_for_this_object get_every_or_custom_value get_indentation_information get_object_attribute_for_indentation_settings alignment_at_ampersand_settings %masterSettings/;
+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/;
use LatexIndent::FileExtension qw/file_extension_check/;
use LatexIndent::BackUpFileProcedure qw/create_back_up_file/;
use LatexIndent::BlankLines qw/protect_blank_lines unprotect_blank_lines condense_blank_lines/;
-use LatexIndent::ModifyLineBreaks qw/modify_line_breaks_body modify_line_breaks_end remove_line_breaks_begin adjust_line_breaks_end_parent max_char_per_line paragraphs_on_one_line construct_paragraph_reg_exp one_sentence_per_line/;
+use LatexIndent::ModifyLineBreaks qw/modify_line_breaks_body modify_line_breaks_end remove_line_breaks_begin adjust_line_breaks_end_parent text_wrap remove_paragraph_line_breaks construct_paragraph_reg_exp one_sentence_per_line text_wrap_remove_paragraph_line_breaks/;
use LatexIndent::TrailingComments qw/remove_trailing_comments put_trailing_comments_back_in add_comment_symbol construct_trailing_comment_regexp/;
use LatexIndent::HorizontalWhiteSpace qw/remove_trailing_whitespace remove_leading_space/;
use LatexIndent::Indent qw/indent wrap_up_statement determine_total_indentation indent_begin indent_body indent_end_statement final_indentation_check get_surrounding_indentation indent_children_recursively check_for_blank_lines_at_beginning put_blank_lines_back_in_at_beginning add_surrounding_indentation_to_begin_statement post_indentation_check/;
@@ -37,7 +37,7 @@ use LatexIndent::AlignmentAtAmpersand qw/align_at_ampersand find_aligned_block/;
use LatexIndent::DoubleBackSlash qw/dodge_double_backslash un_dodge_double_backslash/;
# code blocks
-use LatexIndent::Verbatim qw/put_verbatim_back_in find_verbatim_environments find_noindent_block find_verbatim_commands put_verbatim_commands_back_in/;
+use LatexIndent::Verbatim qw/put_verbatim_back_in find_verbatim_environments find_noindent_block find_verbatim_commands put_verbatim_commands_back_in find_verbatim_special/;
use LatexIndent::Environment qw/find_environments $environmentBasicRegExp/;
use LatexIndent::IfElseFi qw/find_ifelsefi construct_ifelsefi_regexp $ifElseFiBasicRegExp/;
use LatexIndent::Else qw/check_for_else_statement/;
@@ -88,7 +88,8 @@ sub operate_on_file{
$self->find_aligned_block;
$self->remove_trailing_comments;
$self->find_verbatim_environments;
- $self->max_char_per_line;
+ $self->find_verbatim_special;
+ $self->text_wrap if ($is_m_switch_active and !${$masterSettings{modifyLineBreaks}{textWrapOptions}}{perCodeBlockBasis} and ${$masterSettings{modifyLineBreaks}{textWrapOptions}}{columns}>1);
$self->protect_blank_lines;
$self->remove_trailing_whitespace(when=>"before");
$self->find_file_contents_environments_and_preamble;
@@ -196,8 +197,16 @@ sub find_objects{
# documents without preamble need a manual call to the paragraph_one_line routine
if ($is_m_switch_active and !${$self}{preamblePresent}){
- ${$self}{removeParagraphLineBreaks} = ${$masterSettings{modifyLineBreaks}{removeParagraphLineBreaks}}{all}||${$masterSettings{modifyLineBreaks}{removeParagraphLineBreaks}}{masterDocument}||0;
- $self->paragraphs_on_one_line ;
+ $self->yaml_get_textwrap_removeparagraphline_breaks;
+
+ # call the remove_paragraph_line_breaks and text_wrap routines
+ if(${$masterSettings{modifyLineBreaks}{removeParagraphLineBreaks}}{beforeTextWrap}){
+ $self->remove_paragraph_line_breaks if ${$self}{removeParagraphLineBreaks};
+ $self->text_wrap if (${$self}{textWrapOptions} and ${$masterSettings{modifyLineBreaks}{textWrapOptions}}{perCodeBlockBasis});
+ } else {
+ $self->text_wrap if (${$self}{textWrapOptions} and ${$masterSettings{modifyLineBreaks}{textWrapOptions}}{perCodeBlockBasis});
+ $self->remove_paragraph_line_breaks if ${$self}{removeParagraphLineBreaks};
+ }
}
# if there are no children, return
@@ -255,6 +264,9 @@ sub get_settings_and_store_new_object{
# tasks particular to each object
$latexIndentObject->tasks_particular_to_each_object;
+
+ # removeParagraphLineBreaks and textWrapping fun!
+ $latexIndentObject->text_wrap_remove_paragraph_line_breaks if($is_m_switch_active);
# store children in special hash
push(@{${$self}{children}},$latexIndentObject);
@@ -295,7 +307,7 @@ sub tasks_common_to_each_object{
${$self}{bodyLineBreaks} = $bodyLineBreaks;
# get settings for this object
- $self->get_indentation_settings_for_this_object;
+ $self->yaml_get_indentation_settings_for_this_object;
# give unique id
$self->create_unique_id;
@@ -303,6 +315,14 @@ sub tasks_common_to_each_object{
# add trailing text to the id to stop, e.g LATEX-INDENT-ENVIRONMENT1 matching LATEX-INDENT-ENVIRONMENT10
${$self}{id} .= $tokens{endOfToken};
+ # text wrapping can make the ID split across lines
+ ${$self}{idRegExp} = ${$self}{id};
+
+ if($is_m_switch_active){
+ my $IDwithLineBreaks = join("\\R?\\h*",split(//,${$self}{id}));
+ ${$self}{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
$self->get_replacement_text;
@@ -362,7 +382,7 @@ sub wrap_up_tasks{
my $child = @{${$self}{children}}[-1];
# check if the last object was the last thing in the body, and if it has adjusted linebreaks
- $self->adjust_line_breaks_end_parent;
+ $self->adjust_line_breaks_end_parent if $is_m_switch_active;
$logger->trace(Dumper(\%{$child})) if($is_tt_switch_active);
$logger->trace("replaced with ID: ${$child}{id}") if $is_t_switch_active;
diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/Else.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/Else.pm
index 698fc6c1b90..10b1cc4d41b 100644
--- a/Master/texmf-dist/scripts/latexindent/LatexIndent/Else.pm
+++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/Else.pm
@@ -113,7 +113,7 @@ sub tasks_particular_to_each_object{
return;
}
-sub get_indentation_information{
+sub yaml_get_indentation_information{
return q();
}
diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/Environment.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/Environment.pm
index 2ecaf6d4e36..2c74f47554e 100755
--- a/Master/texmf-dist/scripts/latexindent/LatexIndent/Environment.pm
+++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/Environment.pm
@@ -19,7 +19,7 @@ use warnings;
use LatexIndent::Tokens qw/%tokens/;
use LatexIndent::TrailingComments qw/$trailingCommentRegExp/;
use LatexIndent::GetYamlSettings qw/%masterSettings/;
-use LatexIndent::Switches qw/$is_t_switch_active $is_tt_switch_active/;
+use LatexIndent::Switches qw/$is_t_switch_active $is_tt_switch_active $is_m_switch_active/;
use LatexIndent::LogFile qw/$logger/;
use LatexIndent::Braces qw/$braceBracketRegExpBasic/;
use LatexIndent::IfElseFi qw/$ifElseFiBasicRegExp/;
@@ -90,7 +90,7 @@ sub find_environments{
$self->get_settings_and_store_new_object($env);
${@{${$self}{children}}[-1]}{replacementText}.($9?$9:q()).($10?$10:q());
/xseg;
- $self->adjust_line_breaks_end_parent;
+ $self->adjust_line_breaks_end_parent if $is_m_switch_active;
}
return;
}
diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/FileContents.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/FileContents.pm
index f3fba5fab75..cbb20e51483 100644
--- a/Master/texmf-dist/scripts/latexindent/LatexIndent/FileContents.pm
+++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/FileContents.pm
@@ -18,7 +18,7 @@ use strict;
use warnings;
use LatexIndent::Tokens qw/%tokens/;
use LatexIndent::GetYamlSettings qw/%masterSettings/;
-use LatexIndent::Switches qw/$is_t_switch_active $is_tt_switch_active/;
+use LatexIndent::Switches qw/$is_t_switch_active $is_tt_switch_active $is_m_switch_active/;
use LatexIndent::LogFile qw/$logger/;
use LatexIndent::Environment qw/$environmentBasicRegExp/;
use LatexIndent::IfElseFi qw/$ifElseFiBasicRegExp/;
@@ -83,6 +83,14 @@ sub find_file_contents_environments_and_preamble{
);
# 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;
@@ -142,6 +150,14 @@ sub find_file_contents_environments_and_preamble{
# give unique id
$preamble->create_unique_id;
+
+ # text wrapping can make the ID split across lines
+ ${$preamble}{idRegExp} = ${$preamble}{id};
+
+ if($is_m_switch_active){
+ my $IDwithLineBreaks = join("\\R?\\h*",split(//,${$preamble}{id}));
+ ${$preamble}{idRegExp} = qr/$IDwithLineBreaks/s;
+ }
# get the replacement_text
$preamble->get_replacement_text;
@@ -189,7 +205,7 @@ sub find_file_contents_environments_and_preamble{
# store the child, if necessary
if($indentThisChild){
$_->remove_leading_space;
- $_->get_indentation_settings_for_this_object;
+ $_->yaml_get_indentation_settings_for_this_object;
$_->tasks_particular_to_each_object;
push(@{${$self}{children}},$_);
@@ -230,6 +246,20 @@ sub tasks_particular_to_each_object{
# search for commands and special code blocks
$self->find_commands_or_key_equals_values_braces_and_special if ${$self}{body} =~ m/$specialBeginAndBracesBracketsBasicRegExp/s;
+
+ # text wrapping, remove paragraph line breaks
+ if ($is_m_switch_active){
+ $self->yaml_get_textwrap_removeparagraphline_breaks;
+
+ # call the remove_paragraph_line_breaks and text_wrap routines
+ if(${$masterSettings{modifyLineBreaks}{removeParagraphLineBreaks}}{beforeTextWrap}){
+ $self->remove_paragraph_line_breaks if ${$self}{removeParagraphLineBreaks};
+ $self->text_wrap if (${$self}{textWrapOptions} and ${$masterSettings{modifyLineBreaks}{textWrapOptions}}{perCodeBlockBasis});
+ } else {
+ $self->text_wrap if (${$self}{textWrapOptions} and ${$masterSettings{modifyLineBreaks}{textWrapOptions}}{perCodeBlockBasis});
+ $self->remove_paragraph_line_breaks if ${$self}{removeParagraphLineBreaks};
+ }
+ }
}
1;
diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/GetYamlSettings.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/GetYamlSettings.pm
index 00af6ab2ae4..84558485951 100644
--- a/Master/texmf-dist/scripts/latexindent/LatexIndent/GetYamlSettings.pm
+++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/GetYamlSettings.pm
@@ -22,7 +22,7 @@ use File::Basename; # to get the filename and directory path
use File::HomeDir;
use Log::Log4perl qw(get_logger :levels);
use Exporter qw/import/;
-our @EXPORT_OK = qw/readSettings modify_line_breaks_settings get_indentation_settings_for_this_object get_every_or_custom_value get_indentation_information get_object_attribute_for_indentation_settings alignment_at_ampersand_settings %masterSettings/;
+our @EXPORT_OK = 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/;
# Read in defaultSettings.YAML file
our $defaultSettings;
@@ -44,7 +44,7 @@ our @alignAtAmpersandInformation = ( {name=>"lookForAlignDelims",yamlname=>"de
{name=>"justification",default=>"left"},
);
-sub readSettings{
+sub yaml_read_settings{
my $self = shift;
# read the default settings
@@ -431,7 +431,7 @@ sub readSettings{
return;
}
-sub get_indentation_settings_for_this_object{
+sub yaml_get_indentation_settings_for_this_object{
my $self = shift;
# create a name for previously found settings
@@ -449,13 +449,13 @@ sub get_indentation_settings_for_this_object{
# check for noAdditionalIndent and indentRules
# otherwise use defaultIndent
- my $indentation = $self->get_indentation_information;
+ my $indentation = $self->yaml_get_indentation_information;
# check for alignment at ampersand settings
- $self->alignment_at_ampersand_settings;
+ $self->yaml_alignment_at_ampersand_settings;
# check for line break settings
- $self->modify_line_breaks_settings if $is_m_switch_active;
+ $self->yaml_modify_line_breaks_settings if $is_m_switch_active;
# store the settings
%{${previouslyFoundSettings}{$storageName}} = (
@@ -465,6 +465,8 @@ sub get_indentation_settings_for_this_object{
EndStartsOnOwnLine=>${$self}{EndStartsOnOwnLine},
EndFinishesWithLineBreak=>${$self}{EndFinishesWithLineBreak},
removeParagraphLineBreaks=>${$self}{removeParagraphLineBreaks},
+ textWrapOptions=>${$self}{textWrapOptions},
+ columns=>${$self}{columns},
);
# don't forget alignment settings!
@@ -492,7 +494,7 @@ sub get_indentation_settings_for_this_object{
return;
}
-sub alignment_at_ampersand_settings{
+sub yaml_alignment_at_ampersand_settings{
my $self = shift;
# if the YamlName is, for example, optionalArguments, mandatoryArguments, heading, then we'll be looking for information about the *parent*
@@ -534,14 +536,15 @@ sub alignment_at_ampersand_settings{
return;
}
-sub modify_line_breaks_settings{
+sub yaml_modify_line_breaks_settings{
my $self = shift;
# grab the logging object
my $logger = get_logger("Document");
# details to the log file
- $logger->trace("*-m modifylinebreaks switch active, looking for settings for ${$self}{name} ") if $is_t_switch_active;
+ $logger->trace("*-m modifylinebreaks switch active") if $is_t_switch_active;
+ $logger->trace("looking for polyswitch, textWrapOptions, removeParagraphLineBreaks, oneSentencePerLine settings for ${$self}{name} ") if $is_t_switch_active;
# some objects, e.g ifElseFi, can have extra assignments, e.g ElseStartsOnOwnLine
my @toBeAssignedTo = ${$self}{additionalAssignments} ? @{${$self}{additionalAssignments}} : ();
@@ -551,47 +554,201 @@ sub modify_line_breaks_settings{
# we can efficiently loop through the following
foreach (@toBeAssignedTo){
- $self->get_every_or_custom_value(
+ $self->yaml_poly_switch_get_every_or_custom_value(
toBeAssignedTo=>$_,
toBeAssignedToAlias=> ${$self}{aliases}{$_} ? ${$self}{aliases}{$_} : $_,
);
- }
+ };
- # paragraph line break settings
- ${$self}{removeParagraphLineBreaks} = ${$masterSettings{modifyLineBreaks}{removeParagraphLineBreaks}}{all};
+ $self->yaml_get_textwrap_removeparagraphline_breaks;
+ return;
+}
- return if(${$self}{removeParagraphLineBreaks});
+sub yaml_get_textwrap_removeparagraphline_breaks{
+ my $self = shift;
+
+ # grab the logging object
+ my $logger = get_logger("Document");
- # the removeParagraphLineBreaks can contain fields that are hashes or scalar, for example:
- #
- # removeParagraphLineBreaks:
- # all: 0
- # environments: 0
- # or
- # removeParagraphLineBreaks:
- # all: 0
- # environments:
- # quotation: 0
+ # textWrap and removeParagraphLineBreaks settings
+ foreach ("textWrapOptions","removeParagraphLineBreaks"){
+
+ # first check for either
+ #
+ # textWrapOptions:
+ # all: 0
+ #
+ # or
+ #
+ # removeParagraphLineBreaks:
+ # all: 0
+ #
+ # *IMPORTANT*
+ # even if all is set to 1, then it can still be disabled on either a
+ #
+ # per-object:
+ #
+ # for example
+ #
+ # textWrapOptions:
+ # all:
+ # except:
+ # - environments
+ #
+ # will disable textWrapOptions for *all* environments
+ #
+ # per-name
+ #
+ # for example
+ #
+ # textWrapOptions:
+ # all:
+ # except:
+ # - itemize
+ #
+ # will disable textWrapOptions for itemize
+
+ # if 'all' is set as a hash, then the default value is 1, to be turned off (possibly) later
+ ${$self}{$_} = ( ref ${$masterSettings{modifyLineBreaks}{$_}}{all} eq "HASH" ? 1 : ${$masterSettings{modifyLineBreaks}{$_}}{all});
+
+ # get the columns
+ if($_ eq "textWrapOptions" and ${$masterSettings{modifyLineBreaks}{textWrapOptions}}{perCodeBlockBasis}){
+ $self->yaml_get_columns;
+ }
+
+ # name of the object in the modifyLineBreaks yaml (e.g environments, ifElseFi, etc)
+ my $YamlName = ${$self}{modifyLineBreaksYamlName};
+
+ # if the YamlName is either optionalArguments or mandatoryArguments, then we'll be looking for information about the *parent*
+ my $name = ($YamlName =~ m/Arguments/) ? ${$self}{parent} : ${$self}{name};
+
+ # move to the next <thing> if
+ #
+ # textWrapOptions/removeParagraphLineBreaks::
+ # all: 1
+ #
+ if(${$self}{$_}
+ and
+ ref ${$masterSettings{modifyLineBreaks}{$_}}{all} ne "HASH"
+ and
+ ${$masterSettings{modifyLineBreaks}{$_}}{all}){
+ $logger->trace("$_ for $name is ${$self}{$_}") if $is_t_switch_active;
+ next;
+ };
+
+ # otherwise, look for exceptions, either through
+ #
+ # textWrapOptions/removeParagraphLineBreaks:
+ # all:
+ # except:
+ # - <*type* of thing or *name* of thing>
+ #
+ # so, for example, the following (per code-block) is acceptable
+ # which makes an exception for all *environments*
+ #
+ # all:
+ # except:
+ # - 'environments'
+ #
+ # the following (per-name) is acceptable
+ # which only makes an exception for things called itemize
+ #
+ # all:
+ # except:
+ # - 'itemize'
+ #
+ if(${$self}{$_}
+ and
+ defined ${${$masterSettings{modifyLineBreaks}{$_}}{all}}{except}
+ and
+ ref ${${$masterSettings{modifyLineBreaks}{$_}}{all}}{except} eq "ARRAY"
+ ){
+ my %except = map { $_ => 1 } @{${${$masterSettings{modifyLineBreaks}}{$_}}{all}{except}};
+ if( $except{$name} or $except{$YamlName}){
+ ${$self}{$_} = 0;
+ my $detail = ($except{$name} ? "per-name" : "per-code-block-type");
+ $logger->trace("$_ for $name is ${$self}{$_} (found as exception $detail, see $_:all:except)") if $is_t_switch_active;
+ next;
+ }
+ } else {
+ # or otherwise through, for example
+ #
+ # all: 0
+ # ifElseFi: 1
+ #
+ # the textWrapOptions/removeParagraphLineBreaks can contain fields that are hashes or scalar
+ #
+ if(ref ${$masterSettings{modifyLineBreaks}{$_}}{$YamlName} eq "HASH"){
+ # textWrapOptions/removeParagraphLineBreaks:
+ # all: 0
+ # environments:
+ # quotation: 0
+ $logger->trace("*$YamlName specified with fields in $_, looking for $name") if $is_t_switch_active;
+ ${$self}{$_} = ${${$masterSettings{modifyLineBreaks}{$_}}{$YamlName}}{$name} if (defined ${${$masterSettings{modifyLineBreaks}{$_}}{$YamlName}}{$name});
+ } elsif(defined ${$masterSettings{modifyLineBreaks}{$_}}{$YamlName}){
+ # textWrapOptions/removeParagraphLineBreaks:
+ # all: 0
+ # environments: 0
+ $logger->trace("*$YamlName specified with just a number in $_ ${$masterSettings{modifyLineBreaks}{$_}}{$YamlName}") if $is_t_switch_active;
+ ${$self}{$_} = ${$masterSettings{modifyLineBreaks}{$_}}{$YamlName} if (defined ${$masterSettings{modifyLineBreaks}{$_}}{$YamlName});
+ }
+ }
+
+ # summary to log file
+ $logger->trace("$_ for $name is ${$self}{$_}") if $is_t_switch_active;
+ }
+
+ return;
+}
+
+sub yaml_get_columns{
+ my $self = shift;
- # name of the object in the modifyLineBreaks yaml (e.g environments, ifElseFi, etc)
my $YamlName = ${$self}{modifyLineBreaksYamlName};
- # if the YamlName is either optionalArguments or mandatoryArguments, then we'll be looking for information about the *parent*
- my $name = ($YamlName =~ m/Arguments/) ? ${$self}{parent} : ${$self}{name};
+ # the columns settings can have a variety of different ways of being specified
+ if(ref ${$masterSettings{modifyLineBreaks}{textWrapOptions}}{columns} eq "HASH"){
+ # assign default value of $columns
+ my $columns;
+ if(defined ${${$masterSettings{modifyLineBreaks}{textWrapOptions}}{columns}}{default}){
+ $columns = ${${$masterSettings{modifyLineBreaks}{textWrapOptions}}{columns}}{default};
+ } else {
+ $columns = 80;
+ }
- if(ref ${$masterSettings{modifyLineBreaks}{removeParagraphLineBreaks}}{$YamlName} eq "HASH"){
- $logger->trace("*$YamlName specified with fields in removeParagraphLineBreaks, looking for $name") if $is_t_switch_active;
- ${$self}{removeParagraphLineBreaks} = ${${$masterSettings{modifyLineBreaks}{removeParagraphLineBreaks}}{$YamlName}}{$name}||0;
- } else {
- if(defined ${$masterSettings{modifyLineBreaks}{removeParagraphLineBreaks}}{$YamlName}){
- $logger->trace("*$YamlName specified with just a number in removeParagraphLineBreaks ${$masterSettings{modifyLineBreaks}{removeParagraphLineBreaks}}{$YamlName}") if $is_t_switch_active;
- ${$self}{removeParagraphLineBreaks} = ${$masterSettings{modifyLineBreaks}{removeParagraphLineBreaks}}{$YamlName};
+ # possibly specify object wrapping on a per-name basis
+ if(ref ${${$masterSettings{modifyLineBreaks}{textWrapOptions}}{columns}}{$YamlName} eq "HASH"){
+ # for example:
+ # modifyLineBreaks:
+ # textWrapOptions:
+ # columns:
+ # default: 80
+ # environments:
+ # default: 80
+ # something: 10
+ # another: 20
+ if(defined ${${${$masterSettings{modifyLineBreaks}{textWrapOptions}}{columns}}{$YamlName}}{${$self}{name}}){
+ $columns = ${${${$masterSettings{modifyLineBreaks}{textWrapOptions}}{columns}}{$YamlName}}{${$self}{name}};
+ } elsif (${${${$masterSettings{modifyLineBreaks}{textWrapOptions}}{columns}}{$YamlName}}{default}){
+ $columns = ${${${$masterSettings{modifyLineBreaks}{textWrapOptions}}{columns}}{$YamlName}}{default};
+ }
+ } else {
+ # for example:
+ # modifyLineBreaks:
+ # textWrapOptions:
+ # columns:
+ # default: 80
+ # environments: 10
+ $columns = ${${$masterSettings{modifyLineBreaks}{textWrapOptions}}{columns}}{$YamlName};
}
+ ${$self}{columns} = $columns;
+ } else {
+ ${$self}{columns} = ${$masterSettings{modifyLineBreaks}{textWrapOptions}}{columns};
}
return;
}
-sub get_every_or_custom_value{
+sub yaml_poly_switch_get_every_or_custom_value{
my $self = shift;
my %input = @_;
@@ -630,7 +787,7 @@ sub get_every_or_custom_value{
return;
}
-sub get_indentation_information{
+sub yaml_get_indentation_information{
my $self = shift;
#**************************************
@@ -678,7 +835,7 @@ sub get_indentation_information{
my $name = (defined ${$self}{nameForIndentationSettings}) ? ${$self}{nameForIndentationSettings} : ${$self}{name};
# if the YamlName is not optionalArguments, mandatoryArguments, heading (possibly others) then assume we're looking for 'body'
- my $YamlName = $self->get_object_attribute_for_indentation_settings;
+ my $YamlName = $self->yaml_get_object_attribute_for_indentation_settings;
# grab the logging object
my $logger = get_logger("Document");
@@ -732,7 +889,7 @@ sub get_indentation_information{
return $masterSettings{defaultIndent};
}
-sub get_object_attribute_for_indentation_settings{
+sub yaml_get_object_attribute_for_indentation_settings{
# when looking for noAdditionalIndent or indentRules, we may need to determine
# which thing we're looking for, e.g
#
diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/Heading.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/Heading.pm
index 82957e182f1..208dfa9715e 100644
--- a/Master/texmf-dist/scripts/latexindent/LatexIndent/Heading.pm
+++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/Heading.pm
@@ -174,7 +174,7 @@ sub adjust_replacement_text_line_breaks_at_end{
return;
}
-sub get_object_attribute_for_indentation_settings{
+sub yaml_get_object_attribute_for_indentation_settings{
# when looking for noAdditionalIndent or indentRules, we may need to determine
# which thing we're looking for, e.g
#
diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/HiddenChildren.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/HiddenChildren.pm
index 1ddfa1bb537..878939fd41a 100644
--- a/Master/texmf-dist/scripts/latexindent/LatexIndent/HiddenChildren.pm
+++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/HiddenChildren.pm
@@ -16,7 +16,7 @@ package LatexIndent::HiddenChildren;
# For all communication, please visit: https://github.com/cmhughes/latexindent.pl
use strict;
use warnings;
-use LatexIndent::Switches qw/$is_t_switch_active $is_tt_switch_active/;
+use LatexIndent::Switches qw/$is_t_switch_active $is_tt_switch_active $is_m_switch_active /;
use LatexIndent::Tokens qw/%tokens/;
use LatexIndent::LogFile qw/$logger/;
use Data::Dumper;
@@ -156,8 +156,21 @@ sub check_for_hidden_children{
my $self = shift;
+ my @matched;
# grab the matches
- my @matched = (${$self}{body} =~ /((?:$tokens{ifelsefiSpecial})?$tokens{beginOfToken}.[-a-z0-9]+?$tokens{endOfToken})/ig);
+ if($is_m_switch_active){
+ # if modifyLineBreaks is active, then the IDS can be split across lines
+ my $ifElseFiSpecialBegin = join("\\R?\\h*",split(//,$tokens{ifelsefiSpecial}));
+ my $BeginwithLineBreaks = join("\\R?\\h*",split(//,$tokens{beginOfToken}));
+ my $EndwithLineBreaks = join("\\R?\\h*",split(//,$tokens{endOfToken}));
+ my $BlankLinesWithLineBreaks = join("\\R?\\h*",split(//,$tokens{blanklines}));
+ @matched = (${$self}{body} =~ /(?!$BlankLinesWithLineBreaks)((?:$ifElseFiSpecialBegin)?$BeginwithLineBreaks[-a-z0-9\n]+?$EndwithLineBreaks)/ig);
+
+ # remove line breaks and horizontal space from matches
+ $_ =~ s/\R|\h//gs foreach (@matched);
+ } else {
+ @matched = (${$self}{body} =~ /((?:$tokens{ifelsefiSpecial})?$tokens{beginOfToken}.[-a-z0-9]+?$tokens{endOfToken})/igs);
+ }
# log file
$logger->trace("*Hidden children check") if $is_t_switch_active;
diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/Indent.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/Indent.pm
index 57bcd225add..fce49e2c660 100644
--- a/Master/texmf-dist/scripts/latexindent/LatexIndent/Indent.pm
+++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/Indent.pm
@@ -124,7 +124,7 @@ sub indent_body{
$self->align_at_ampersand if ${$self}{lookForAlignDelims};
# possibly remove paragraph line breaks
- $self->paragraphs_on_one_line if $is_m_switch_active;
+ $self->remove_paragraph_line_breaks if ($is_m_switch_active and ${$self}{removeParagraphLineBreaks} and !${$masterSettings{modifyLineBreaks}{removeParagraphLineBreaks}}{beforeTextWrap});
# body indendation
if(${$self}{linebreaksAtEnd}{begin}==1){
@@ -279,7 +279,7 @@ sub indent_children_recursively{
# we work through the array *in order*
foreach my $child (@{${$self}{children}}){
$logger->trace("Searching ${$self}{name} for ${$child}{id}...") if $is_t_switch_active;
- if(${$self}{body} =~ m/${$child}{id}/s){
+ if(${$self}{body} =~ m/${$child}{idRegExp}/s){
# we only care if id is first non-white space character
# and if followed by line break
# if m switch is active
@@ -288,11 +288,11 @@ sub indent_children_recursively{
# update the above two, if necessary
if ($is_m_switch_active){
- $IDFirstNonWhiteSpaceCharacter = (${$self}{body} =~ m/^${$child}{id}/m
+ $IDFirstNonWhiteSpaceCharacter = (${$self}{body} =~ m/^${$child}{idRegExp}/m
or
- ${$self}{body} =~ m/^\h\h*${$child}{id}/m
+ ${$self}{body} =~ m/^\h\h*${$child}{idRegExp}/m
) ?1:0;
- $IDFollowedImmediatelyByLineBreak = (${$self}{body} =~ m/${$child}{id}\h*\R+/m) ?1:0;
+ $IDFollowedImmediatelyByLineBreak = (${$self}{body} =~ m/${$child}{idRegExp}\h*\R+/m) ?1:0;
${$child}{IDFollowedImmediatelyByLineBreak} = $IDFollowedImmediatelyByLineBreak;
}
@@ -308,7 +308,7 @@ sub indent_children_recursively{
# remove line break *after* <end statement>, if appropriate
my $EndStringLogFile = ${$child}{aliases}{EndFinishesWithLineBreak}||"EndFinishesWithLineBreak";
$logger->trace("Removing linebreak after ${$child}{end} (see $EndStringLogFile)") if $is_t_switch_active;
- ${$self}{body} =~ s/${$child}{id}(\h*)?(\R|\h)*/${$child}{id}$1/s;
+ ${$self}{body} =~ s/${$child}{idRegExp}(\h*)?(\R|\h)*/${$child}{id}$1/s;
${$child}{linebreaksAtEnd}{end} = 0;
}
@@ -332,7 +332,7 @@ sub indent_children_recursively{
my $trailingCharacterToken = q();
if(${$child}{BeginStartsOnOwnLine}==2){
$logger->trace("Removing space immediately before ${$child}{id}, in preparation for adding % ($BeginStringLogFile == 2)") if $is_t_switch_active;
- ${$self}{body} =~ s/\h*${$child}{id}/${$child}{id}/s;
+ ${$self}{body} =~ s/\h*${$child}{idRegExp}/${$child}{id}/s;
$logger->trace("Adding a % at the end of the line that ${$child}{begin} is on, then a linebreak ($BeginStringLogFile == 2)") if $is_t_switch_active;
$trailingCharacterToken = "%".$self->add_comment_symbol;
} elsif (${$child}{BeginStartsOnOwnLine}==3){
@@ -352,9 +352,9 @@ sub indent_children_recursively{
# finally, if BeginStartsOnOwnLine == -1 then we might need to *remove* a blank line(s)
# important to check we don't move the begin statement next to a blank-line-token
my $blankLineToken = $tokens{blanklines};
- if(${$self}{body} !~ m/$blankLineToken\R*\h*${$child}{id}/s){
+ if(${$self}{body} !~ m/$blankLineToken\R*\h*${$child}{idRegExp}/s){
$logger->trace("Removing linebreak before ${$child}{begin} (see $BeginStringLogFile in ${$child}{modifyLineBreaksYamlName} YAML)") if $is_t_switch_active;
- ${$self}{body} =~ s/(\h*)(?:\R*|\h*)+${$child}{id}/$1${$child}{id}/s;
+ ${$self}{body} =~ s/(\h*)(?:\R*|\h*)+${$child}{idRegExp}/$1${$child}{id}/s;
} else {
$logger->trace("Not removing linebreak ahead of ${$child}{begin}, as blank-line-token present (see preserveBlankLines)") if $is_t_switch_active;
}
@@ -364,7 +364,7 @@ sub indent_children_recursively{
$logger->trace(Dumper(\%{$child})) if($is_tt_switch_active);
# replace ids with body
- ${$self}{body} =~ s/${$child}{id}/${$child}{begin}${$child}{body}${$child}{end}/;
+ ${$self}{body} =~ s/${$child}{idRegExp}/${$child}{begin}${$child}{body}${$child}{end}/;
# log file info
$logger->trace("Body (${$self}{name}) now looks like:") if $is_tt_switch_active;
diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/LogFile.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/LogFile.pm
index 8f3dee24066..b8ebc034b3a 100644
--- a/Master/texmf-dist/scripts/latexindent/LatexIndent/LogFile.pm
+++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/LogFile.pm
@@ -140,7 +140,7 @@ ENDQUOTE
if($switches{screenlog}){
$appender_screen = Log::Log4perl::Appender->new(
"Log::Log4perl::Appender::Screen",
- stderr => 0,
+ stderr => 1,
utf8 => 1,
);
@@ -160,7 +160,7 @@ ENDQUOTE
} else {
$logger->info("Reading input from STDIN");
my $buttonText = ($FindBin::Script eq 'latexindent.exe') ? 'CTRL+Z followed by ENTER':'CTRL+D';
- print "Please enter text to be indented: (press $buttonText when finished)\n";
+ print STDERR "Please enter text to be indented: (press $buttonText when finished)\n";
}
# log the switches from the user
@@ -205,7 +205,7 @@ ENDQUOTE
}
# read the YAML settings
- $self->readSettings;
+ $self->yaml_read_settings;
# the user may have specified their own settings for the rest of the log file,
# for example:
diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/MandatoryArgument.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/MandatoryArgument.pm
index ba6e220d09e..0b641231f2a 100644
--- a/Master/texmf-dist/scripts/latexindent/LatexIndent/MandatoryArgument.pm
+++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/MandatoryArgument.pm
@@ -113,7 +113,7 @@ sub get_mand_arg_reg_exp{
return $mandArgRegExp;
}
-sub get_object_attribute_for_indentation_settings{
+sub yaml_get_object_attribute_for_indentation_settings{
my $self = shift;
return ${$self}{modifyLineBreaksYamlName};
diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/ModifyLineBreaks.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/ModifyLineBreaks.pm
index 7b704736c02..afa1360369d 100644
--- a/Master/texmf-dist/scripts/latexindent/LatexIndent/ModifyLineBreaks.pm
+++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/ModifyLineBreaks.pm
@@ -25,13 +25,13 @@ use LatexIndent::TrailingComments qw/$trailingCommentRegExp/;
use LatexIndent::Switches qw/$is_m_switch_active $is_t_switch_active $is_tt_switch_active/;
use LatexIndent::Item qw/$listOfItems/;
use LatexIndent::LogFile qw/$logger/;
-our @EXPORT_OK = qw/modify_line_breaks_body modify_line_breaks_end adjust_line_breaks_end_parent remove_line_breaks_begin max_char_per_line paragraphs_on_one_line construct_paragraph_reg_exp one_sentence_per_line/;
+our @EXPORT_OK = qw/modify_line_breaks_body modify_line_breaks_end adjust_line_breaks_end_parent remove_line_breaks_begin text_wrap remove_paragraph_line_breaks construct_paragraph_reg_exp one_sentence_per_line text_wrap_remove_paragraph_line_breaks/;
our $paragraphRegExp = q();
sub modify_line_breaks_body{
my $self = shift;
-
+
# add a line break after \begin{statement} if appropriate
if(defined ${$self}{BodyStartsOnOwnLine}){
my $BodyStringLogFile = ${$self}{aliases}{BodyStartsOnOwnLine}||"BodyStartsOnOwnLine";
@@ -177,7 +177,6 @@ sub modify_line_breaks_end{
sub adjust_line_breaks_end_parent{
# when a parent object contains a child object, the line break
# at the end of the parent object can become messy
- return unless $is_m_switch_active;
my $self = shift;
@@ -208,14 +207,44 @@ sub adjust_line_breaks_end_parent{
}
-sub max_char_per_line{
- return unless $is_m_switch_active;
+sub text_wrap_remove_paragraph_line_breaks{
+ my $self = shift;
+
+ if(${$masterSettings{modifyLineBreaks}{removeParagraphLineBreaks}}{beforeTextWrap}){
+ $self->remove_paragraph_line_breaks if ${$self}{removeParagraphLineBreaks};
+ $self->text_wrap if (${$self}{textWrapOptions} and ${$masterSettings{modifyLineBreaks}{textWrapOptions}}{perCodeBlockBasis});
+ } else {
+ $self->text_wrap if (${$self}{textWrapOptions} and ${$masterSettings{modifyLineBreaks}{textWrapOptions}}{perCodeBlockBasis});
+ }
+
+}
+
+sub text_wrap{
my $self = shift;
- return unless ${$masterSettings{modifyLineBreaks}{textWrapOptions}}{columns}>1;
+
+ # alignment at ampersand can take priority
+ return if(${$self}{lookForAlignDelims} and ${$masterSettings{modifyLineBreaks}{textWrapOptions}}{alignAtAmpersandTakesPriority});
# call the text wrapping routine
- $Text::Wrap::columns=${$masterSettings{modifyLineBreaks}{textWrapOptions}}{columns};
+ my $columns;
+
+ # columns might have been defined by the user
+ if(defined ${$self}{columns}){
+ $columns = ${$self}{columns};
+ } elsif(ref ${$masterSettings{modifyLineBreaks}{textWrapOptions}}{columns} eq "HASH"){
+ if(defined ${${$masterSettings{modifyLineBreaks}{textWrapOptions}}{columns}}{default}){
+ $columns = ${${$masterSettings{modifyLineBreaks}{textWrapOptions}}{columns}}{default};
+ } else {
+ $columns = 80;
+ }
+ } elsif (defined ${$masterSettings{modifyLineBreaks}{textWrapOptions}}{columns}){
+ $columns = ${$masterSettings{modifyLineBreaks}{textWrapOptions}}{columns} ;
+ } else {
+ $columns = 80;
+ }
+
+ $Text::Wrap::columns=$columns;
if(${$masterSettings{modifyLineBreaks}{textWrapOptions}}{separator} ne ''){
$Text::Wrap::separator=${$masterSettings{modifyLineBreaks}{textWrapOptions}}{separator};
}
@@ -271,7 +300,7 @@ sub construct_paragraph_reg_exp{
$logger->trace($paragraphRegExp) if $is_tt_switch_active ;
}
-sub paragraphs_on_one_line{
+sub remove_paragraph_line_breaks{
my $self = shift;
return unless ${$self}{removeParagraphLineBreaks};
@@ -481,6 +510,39 @@ sub one_sentence_per_line{
while( my $sentence = pop @sentenceStorage){
my $sentenceStorageID = ${$sentence}{id};
my $sentenceStorageValue = ${$sentence}{value};
+
+ # option to text wrap (and option to indent) sentences
+ if(${$masterSettings{modifyLineBreaks}{oneSentencePerLine}}{textWrapSentences}){
+ my $sentenceObj = LatexIndent::Document->new(body=>$sentenceStorageValue,
+ name=>"sentence",
+ modifyLineBreaksYamlName=>"sentence",
+ );
+
+ # text wrapping
+ $sentenceObj->yaml_get_columns;
+ $sentenceObj->text_wrap;
+
+ # indentation of sentences
+ if(${$sentenceObj}{body} =~ m/
+ (.*?) # content of first line
+ \R # first line break
+ (.*$) # rest of body
+ /sx){
+ my $bodyFirstLine = $1;
+ my $remainingBody = $2;
+ my $indentation = ${$masterSettings{modifyLineBreaks}{oneSentencePerLine}}{sentenceIndent};
+ $logger->trace("first line of sencent: $bodyFirstLine") if $is_tt_switch_active;
+ $logger->trace("remaining body (before indentation):\n'$remainingBody'") if($is_tt_switch_active);
+
+ # add the indentation to all the body except first line
+ $remainingBody =~ s/^/$indentation/mg unless($remainingBody eq ''); # add indentation
+ $logger->trace("remaining body (after indentation):\n$remainingBody'") if($is_tt_switch_active);
+
+ # put the body back together
+ ${$sentenceObj}{body} = $bodyFirstLine."\n".$remainingBody;
+ }
+ $sentenceStorageValue = ${$sentenceObj}{body};
+ };
# sentence at the very END
${$self}{body} =~ s/\h*$sentenceStorageID\h*$/$sentenceStorageValue/s;
# sentence at the very BEGINNING
diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/OptionalArgument.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/OptionalArgument.pm
index f98acac4874..60e03ca91d4 100644
--- a/Master/texmf-dist/scripts/latexindent/LatexIndent/OptionalArgument.pm
+++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/OptionalArgument.pm
@@ -90,7 +90,7 @@ sub find_optional_arguments{
}
}
-sub get_object_attribute_for_indentation_settings{
+sub yaml_get_object_attribute_for_indentation_settings{
my $self = shift;
return ${$self}{modifyLineBreaksYamlName};
diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/Preamble.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/Preamble.pm
index 306b423e5a9..a31efd1a49e 100644
--- a/Master/texmf-dist/scripts/latexindent/LatexIndent/Preamble.pm
+++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/Preamble.pm
@@ -17,7 +17,7 @@ package LatexIndent::Preamble;
use strict;
use warnings;
use LatexIndent::Tokens qw/%tokens/;
-use LatexIndent::Switches qw/$is_t_switch_active/;
+use LatexIndent::Switches qw/$is_t_switch_active $is_m_switch_active/;
use LatexIndent::GetYamlSettings qw/%masterSettings/;
use LatexIndent::LogFile qw/$logger/;
use LatexIndent::Environment qw/$environmentBasicRegExp/;
@@ -69,7 +69,21 @@ sub tasks_particular_to_each_object{
# search for special begin/end
$self->find_special if ${$self}{body} =~ m/$specialBeginBasicRegExp/s;
- }
+ }
+
+ # text wrapping, remove paragraph line breaks
+ if ($is_m_switch_active){
+ $self->yaml_get_textwrap_removeparagraphline_breaks;
+
+ # call the remove_paragraph_line_breaks and text_wrap routines
+ if(${$masterSettings{modifyLineBreaks}{removeParagraphLineBreaks}}{beforeTextWrap}){
+ $self->remove_paragraph_line_breaks if ${$self}{removeParagraphLineBreaks};
+ $self->text_wrap if (${$self}{textWrapOptions} and ${$masterSettings{modifyLineBreaks}{textWrapOptions}}{perCodeBlockBasis});
+ } else {
+ $self->text_wrap if (${$self}{textWrapOptions} and ${$masterSettings{modifyLineBreaks}{textWrapOptions}}{perCodeBlockBasis});
+ $self->remove_paragraph_line_breaks if ${$self}{removeParagraphLineBreaks};
+ }
+ }
}
diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/RoundBrackets.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/RoundBrackets.pm
index f320d007fa2..fff5efedd00 100644
--- a/Master/texmf-dist/scripts/latexindent/LatexIndent/RoundBrackets.pm
+++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/RoundBrackets.pm
@@ -79,7 +79,7 @@ sub find_round_brackets{
}
}
-sub get_object_attribute_for_indentation_settings{
+sub yaml_get_object_attribute_for_indentation_settings{
my $self = shift;
return ${$self}{modifyLineBreaksYamlName};
diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/Special.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/Special.pm
index aa17f24df13..8898697d0f3 100644
--- a/Master/texmf-dist/scripts/latexindent/LatexIndent/Special.pm
+++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/Special.pm
@@ -40,7 +40,7 @@ sub construct_special_begin{
while( my ($specialName,$BeginEnd)= each %{$masterSettings{specialBeginEnd}}){
if(ref($BeginEnd) eq "HASH"){
# only append the regexps if lookForThis is 1
- $specialBegins .= ($specialBegins eq ""?q():"|").${$BeginEnd}{begin} if(${$BeginEnd}{lookForThis});
+ $specialBegins .= ($specialBegins eq ""?q():"|").${$BeginEnd}{begin} if(${$BeginEnd}{lookForThis}=~m/\d/s and ${$BeginEnd}{lookForThis} == 1);
}
}
@@ -48,9 +48,7 @@ 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}){
- # the beginning parts
- $specialBegins .= ($specialBegins eq ""?q():"|").${$BeginEnd}{begin};
+ if( (ref($BeginEnd) eq "HASH") and ${$BeginEnd}{lookForThis}=~m/\d/s and ${$BeginEnd}{lookForThis} == 1){
# the overall regexp
$specialAllMatchesRegExp .= ($specialAllMatchesRegExp eq ""?q():"|")
@@ -128,7 +126,7 @@ sub find_special{
while( my ($specialName,$BeginEnd)= each %{$masterSettings{specialBeginEnd}}){
# log file
- if((ref($BeginEnd) eq "HASH") and ${$BeginEnd}{lookForThis}){
+ if((ref($BeginEnd) eq "HASH") and ${$BeginEnd}{lookForThis}=~m/\d/s and ${$BeginEnd}{lookForThis} == 1){
$logger->trace("Looking for $specialName") if $is_t_switch_active ;
} else {
$logger->trace("Not looking for $specialName (see lookForThis)") if ($is_t_switch_active and (ref($BeginEnd) eq "HASH"));
diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/TrailingComments.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/TrailingComments.pm
index 7f2b8e12738..6ec052a0f3b 100644
--- a/Master/texmf-dist/scripts/latexindent/LatexIndent/TrailingComments.pm
+++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/TrailingComments.pm
@@ -103,7 +103,7 @@ sub put_trailing_comments_back_in{
if(${$masterSettings{modifyLineBreaks}{textWrapOptions}}{separator} ne ''){
$trailingcommentIDwithLineBreaks = join("\\".${$masterSettings{modifyLineBreaks}{textWrapOptions}}{separator}."?",split(//,$trailingcommentID));
} else {
- $trailingcommentIDwithLineBreaks = join("\\R?",split(//,$trailingcommentID));
+ $trailingcommentIDwithLineBreaks = join("(?:\\h|\\R)*",split(//,$trailingcommentID));
}
my $trailingcommentIDwithLineBreaksRegExp = qr/$trailingcommentIDwithLineBreaks/s;
diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/Verbatim.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/Verbatim.pm
index c79d9604715..836e7ccd88d 100644
--- a/Master/texmf-dist/scripts/latexindent/LatexIndent/Verbatim.pm
+++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/Verbatim.pm
@@ -22,7 +22,7 @@ use LatexIndent::Tokens qw/%tokens/;
use LatexIndent::GetYamlSettings qw/%masterSettings/;
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 put_verbatim_commands_back_in/;
+our @EXPORT_OK = qw/put_verbatim_back_in find_verbatim_environments find_noindent_block find_verbatim_commands put_verbatim_commands_back_in find_verbatim_special/;
our @ISA = "LatexIndent::Document"; # class inheritance, Programming Perl, pg 321
our $verbatimCounter;
@@ -307,6 +307,57 @@ sub put_verbatim_commands_back_in {
return;
}
+sub find_verbatim_special{
+ my $self = shift;
+
+ # loop through specialBeginEnd
+ while( my ($specialName,$BeginEnd)= each %{$masterSettings{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'){
+ $logger->trace('*Searching for VERBATIM special (see specialBeginEnd)') if $is_t_switch_active;
+
+ my $verbatimRegExp = qr/
+ (
+ ${$BeginEnd}{begin}
+ )
+ (
+ .*?
+ )
+ (
+ ${$BeginEnd}{end}
+ )
+ /sx;
+
+ while( ${$self}{body} =~ m/$verbatimRegExp/sx){
+
+ # create a new Environment object
+ my $verbatimBlock = LatexIndent::Verbatim->new( begin=>$1,
+ body=>$2,
+ end=>$3,
+ name=>$specialName,
+ );
+ # give unique id
+ $verbatimBlock->create_unique_id;
+
+ # verbatim children go in special hash
+ ${$self}{verbatim}{${$verbatimBlock}{id}}=$verbatimBlock;
+
+ # log file output
+ $logger->trace("*VERBATIM special found: $specialName") if $is_t_switch_active;
+
+ # remove the special block, and replace with unique ID
+ ${$self}{body} =~ s/$verbatimRegExp/${$verbatimBlock}{id}/sx;
+
+ $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};
+ }
+ }
+ }
+}
+
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 bfec70b7942..989d4f73fb1 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.3';
-our $versionDate = '2018-06-08';
+our $versionNumber = '3.5';
+our $versionDate = '2018-08-13';
1
diff --git a/Master/texmf-dist/scripts/latexindent/defaultSettings.yaml b/Master/texmf-dist/scripts/latexindent/defaultSettings.yaml
index 785b805eed7..a1ef1172aca 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.3, 2018-06-08
+# defaultSettings.yaml for latexindent.pl, version 3.5, 2018-08-13
# a script that aims to
# beautify .tex, .sty, .cls files
#
@@ -394,12 +394,11 @@ commandCodeBlocks:
modifyLineBreaks:
preserveBlankLines: 1
condenseMultipleBlankLinesInto: 1
- textWrapOptions:
- columns: 0
- separator: ""
oneSentencePerLine:
manipulateSentences: 0
removeSentenceLineBreaks: 1
+ textWrapSentences: 0
+ sentenceIndent: ""
sentencesFollow:
par: 1
blankLine: 1
@@ -419,8 +418,26 @@ modifyLineBreaks:
exclamationMark: 1
questionMark: 1
other: 0
+ textWrapOptions:
+ columns: 0
+ separator: ""
+ perCodeBlockBasis: 0
+ all: 0
+ alignAtAmpersandTakesPriority: 1
+ environments:
+ quotation: 0
+ ifElseFi: 0
+ optionalArguments: 0
+ mandatoryArguments: 0
+ items: 0
+ specialBeginEnd: 0
+ afterHeading: 0
+ preamble: 0
+ filecontents: 0
+ masterDocument: 0
removeParagraphLineBreaks:
all: 0
+ beforeTextWrap: 0
alignAtAmpersandTakesPriority: 1
environments:
quotation: 0
@@ -430,10 +447,12 @@ modifyLineBreaks:
items: 0
specialBeginEnd: 0
afterHeading: 0
+ preamble: 0
filecontents: 0
masterDocument: 0
paragraphsStopAt:
environments: 1
+ verbatim: 1
commands: 0
ifElseFi: 0
items: 0
diff --git a/Master/texmf-dist/scripts/latexindent/latexindent.pl b/Master/texmf-dist/scripts/latexindent/latexindent.pl
index c9835ccbe37..0945273d857 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.3, 2018-06-08
+# latexindent.pl, version 3.5, 2018-08-13
#
# 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
@@ -73,6 +73,6 @@ if(defined($switches{readLocalSettings}) and ($switches{readLocalSettings} eq ''
# allow STDIN as input, if a filename is not present
unshift( @ARGV, '-' ) unless @ARGV;
-my $document = bless ({name=>"masterDocument",fileName=>$ARGV[0],switches=>\%switches},"LatexIndent::Document");
+my $document = bless ({name=>"masterDocument",modifyLineBreaksYamlName=>"masterDocument",fileName=>$ARGV[0],switches=>\%switches},"LatexIndent::Document");
$document->latexindent;
exit(0);