diff options
Diffstat (limited to 'Master/texmf-dist/scripts/latexindent/LatexIndent/Document.pm')
-rw-r--r-- | Master/texmf-dist/scripts/latexindent/LatexIndent/Document.pm | 77 |
1 files changed, 42 insertions, 35 deletions
diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/Document.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/Document.pm index 8697c20e86c..03817c8d7cf 100644 --- a/Master/texmf-dist/scripts/latexindent/LatexIndent/Document.pm +++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/Document.pm @@ -22,12 +22,12 @@ 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/logger output_logfile processSwitches/; +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::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/; +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::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/; @@ -64,6 +64,7 @@ sub new{ my $invocant = shift; my $class = ref($invocant) || $invocant; my $self = {@_}; + $logger->trace(${$masterSettings{logFilePreferences}}{showDecorationStartCodeBlockTrace}) if ${$masterSettings{logFilePreferences}}{showDecorationStartCodeBlockTrace}; bless ($self,$class); return $self; } @@ -72,7 +73,6 @@ sub latexindent{ my $self = shift; $self->storeSwitches; $self->processSwitches; - $self->readSettings; $self->file_extension_check; $self->operate_on_file; } @@ -94,6 +94,7 @@ sub operate_on_file{ $self->find_file_contents_environments_and_preamble; $self->dodge_double_backslash; $self->remove_leading_space; + $self->one_sentence_per_line if $is_m_switch_active; $self->process_body_of_text; $self->remove_trailing_whitespace(when=>"after"); $self->condense_blank_lines; @@ -103,7 +104,6 @@ sub operate_on_file{ $self->put_trailing_comments_back_in; $self->put_verbatim_commands_back_in; $self->output_indented_text; - $self->output_logfile; return } @@ -125,25 +125,32 @@ sub construct_regular_expressions{ sub output_indented_text{ my $self = shift; - # output to screen, unless silent mode - print ${$self}{body} unless $switches{silentMode}; - - $self->logger("Output routine",'heading'); + $logger->info("*Output routine:"); # if -overwrite is active then output to original fileName if($switches{overwrite}) { - $self->logger("Overwriting file ${$self}{fileName}"); + $logger->info("Overwriting file ${$self}{fileName}"); open(OUTPUTFILE,">",${$self}{fileName}); print OUTPUTFILE ${$self}{body}; close(OUTPUTFILE); } elsif($switches{outputToFile}) { - $self->logger("Outputting to file $switches{outputToFile}"); + $logger->info("Outputting to file $switches{outputToFile}"); open(OUTPUTFILE,">",$switches{outputToFile}); print OUTPUTFILE ${$self}{body}; close(OUTPUTFILE); } else { - $self->logger("Not outputting to file; see -w and -o switches for more options."); + $logger->info("Not outputting to file; see -w and -o switches for more options."); } + + # put the final line in the logfile + $logger->info("${$masterSettings{logFilePreferences}}{endLogFileWith}") if ${$masterSettings{logFilePreferences}}{endLogFileWith}; + + # github info line + $logger->info("*Please direct all communication/issues to:\nhttps://github.com/cmhughes/latexindent.pl") if ${$masterSettings{logFilePreferences}}{showGitHubInfoFooter}; + + # output to screen, unless silent mode + print ${$self}{body} unless $switches{silentMode}; + return; } @@ -151,19 +158,19 @@ sub process_body_of_text{ my $self = shift; # find objects recursively - $self->logger('Phase 1: searching for objects','heading'); + $logger->info('*Phase 1: searching for objects'); $self->find_objects; # find all hidden child - $self->logger('Phase 2: finding surrounding indentation','heading'); + $logger->info('*Phase 2: finding surrounding indentation'); $self->find_surrounding_indentation_for_children; # indentation recursively - $self->logger('Phase 3: indenting objects','heading'); + $logger->info('*Phase 3: indenting objects'); $self->indent_children_recursively; # final indentation check - $self->logger('Phase 4: final indentation check','heading'); + $logger->info('*Phase 4: final indentation check'); $self->final_indentation_check; return; @@ -173,15 +180,15 @@ sub find_objects{ my $self = shift; # search for environments - $self->logger('looking for ENVIRONMENTS') if $is_t_switch_active; + $logger->trace('looking for ENVIRONMENTS') if $is_t_switch_active; $self->find_environments; # search for ifElseFi blocks - $self->logger('looking for IFELSEFI') if $is_t_switch_active; + $logger->trace('looking for IFELSEFI') if $is_t_switch_active; $self->find_ifelsefi; # search for headings (part, chapter, section, setc) - $self->logger('looking for HEADINGS (chapter, section, part, etc)') if $is_t_switch_active; + $logger->trace('looking for HEADINGS (chapter, section, part, etc)') if $is_t_switch_active; $self->find_heading; # the ordering of finding commands and special code blocks can change @@ -195,16 +202,14 @@ sub find_objects{ # if there are no children, return if(${$self}{children}){ - $self->logger("Objects have been found.",'heading') if $is_t_switch_active; + $logger->trace("*Objects have been found.") if $is_t_switch_active; } else { - $self->logger("No objects found."); + $logger->trace("No objects found."); return; } # logfile information - $self->logger(Dumper(\%{$self}),'ttrace') if($is_tt_switch_active); - $self->logger("Operating on: ${$self}{name}",'heading')if $is_t_switch_active; - $self->logger("Number of children: ".scalar (@{${$self}{children}})) if $is_t_switch_active; + $logger->trace(Dumper(\%{$self})) if($is_tt_switch_active); return; } @@ -216,19 +221,19 @@ sub find_commands_or_key_equals_values_braces_and_special{ # can change depending upon specialBeforeCommand if(${$masterSettings{specialBeginEnd}}{specialBeforeCommand}){ # search for special begin/end - $self->logger('looking for SPECIAL begin/end *before* looking for commands (see specialBeforeCommand)') if $is_t_switch_active; + $logger->trace('looking for SPECIAL begin/end *before* looking for commands (see specialBeforeCommand)') if $is_t_switch_active; $self->find_special; # search for commands with arguments - $self->logger('looking for COMMANDS and key = {value}') if $is_t_switch_active; + $logger->trace('looking for COMMANDS and key = {value}') if $is_t_switch_active; $self->find_commands_or_key_equals_values_braces; } else { # search for commands with arguments - $self->logger('looking for COMMANDS and key = {value}') if $is_t_switch_active; + $logger->trace('looking for COMMANDS and key = {value}') if $is_t_switch_active; $self->find_commands_or_key_equals_values_braces; # search for special begin/end - $self->logger('looking for SPECIAL begin/end') if $is_t_switch_active; + $logger->trace('looking for SPECIAL begin/end') if $is_t_switch_active; $self->find_special; } return; @@ -236,7 +241,7 @@ sub find_commands_or_key_equals_values_braces_and_special{ sub tasks_particular_to_each_object{ my $self = shift; - $self->logger("There are no tasks particular to ${$self}{name}") if $is_t_switch_active; + $logger->trace("There are no tasks particular to ${$self}{name}") if $is_t_switch_active; } sub get_settings_and_store_new_object{ @@ -254,6 +259,8 @@ sub get_settings_and_store_new_object{ # store children in special hash push(@{${$self}{children}},$latexIndentObject); + # possible decoration in log file + $logger->trace(${$masterSettings{logFilePreferences}}{showDecorationFinishCodeBlockTrace}) if ${$masterSettings{logFilePreferences}}{showDecorationFinishCodeBlockTrace}; } sub tasks_common_to_each_object{ @@ -264,12 +271,12 @@ sub tasks_common_to_each_object{ # update/create the ancestor information if($parent{ancestors}){ - $self->logger("Ancestors *have* been found for ${$self}{name}") if($is_t_switch_active); + $logger->trace("Ancestors *have* been found for ${$self}{name}") if($is_t_switch_active); push(@{${$self}{ancestors}},@{$parent{ancestors}}); } else { - $self->logger("No ancestors found for ${$self}{name}") if($is_t_switch_active); + $logger->trace("No ancestors found for ${$self}{name}") if($is_t_switch_active); if(defined $parent{id} and $parent{id} ne ''){ - $self->logger("Creating ancestors with $parent{id} as the first one") if($is_t_switch_active); + $logger->trace("Creating ancestors with $parent{id} as the first one") if($is_t_switch_active); push(@{${$self}{ancestors}},{ancestorID=>$parent{id},ancestorIndentation=>\$parent{indentation},type=>"natural",name=>${$self}{name}}); } } @@ -328,7 +335,7 @@ sub adjust_replacement_text_line_breaks_at_end{ # the above regexp, when used below, will remove the trailing linebreak in ${$self}{linebreaksAtEnd}{end} # so we compensate for it here - $self->logger("Putting linebreak after replacementText for ${$self}{name}") if($is_t_switch_active); + $logger->trace("Putting linebreak after replacementText for ${$self}{name}") if($is_t_switch_active); if(defined ${$self}{horizontalTrailingSpace}){ ${$self}{replacementText} .= ${$self}{horizontalTrailingSpace} unless(!${$self}{endImmediatelyFollowedByComment} and defined ${$self}{EndFinishesWithLineBreak} and ${$self}{EndFinishesWithLineBreak}==2); } @@ -345,7 +352,7 @@ sub count_body_line_breaks{ my $bodyLineBreaks = 0; $bodyLineBreaks++ while(${$self}{body} =~ m/\R/sxg); ${$self}{bodyLineBreaks} = $bodyLineBreaks; - $self->logger("bodyLineBreaks ${$self}{bodyLineBreaks}") if((${$self}{bodyLineBreaks} != $oldBodyLineBreaks) and $is_t_switch_active); + $logger->trace("bodyLineBreaks ${$self}{bodyLineBreaks}") if((${$self}{bodyLineBreaks} != $oldBodyLineBreaks) and $is_t_switch_active); } sub wrap_up_tasks{ @@ -357,8 +364,8 @@ sub wrap_up_tasks{ # 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->logger(Dumper(\%{$child})) if($is_tt_switch_active); - $self->logger("replaced with ID: ${$child}{id}") if $is_t_switch_active; + $logger->trace(Dumper(\%{$child})) if($is_tt_switch_active); + $logger->trace("replaced with ID: ${$child}{id}") if $is_t_switch_active; } |