diff --git a/LatexIndent/Document.pm b/LatexIndent/Document.pm index 0894295f..41a2cf6e 100644 --- a/LatexIndent/Document.pm +++ b/LatexIndent/Document.pm @@ -37,7 +37,7 @@ use LatexIndent::BlankLines qw/protect_blank_lines unprotect_blank_lines condens use LatexIndent::ModifyLineBreaks qw/modify_line_breaks_body modify_line_breaks_end modify_line_breaks_end_after remove_line_breaks_begin adjust_line_breaks_end_parent verbatim_modify_line_breaks/; use LatexIndent::Sentence qw/one_sentence_per_line/; -use LatexIndent::Wrap qw/text_wrap/; +use LatexIndent::Wrap qw/text_wrap text_wrap_comment_blocks/; 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/; @@ -302,8 +302,9 @@ sub process_body_of_text { and ${ $mainSettings{modifyLineBreaks}{oneSentencePerLine} }{manipulateSentences} and ${ $mainSettings{modifyLineBreaks}{textWrapOptions} }{when} eq 'after' ) { - $logger->trace("*one-sentence-per-line text wrapping routine, textWrapOptions:when set to 'after'") if $is_tt_switch_active; - $self->one_sentence_per_line( textWrap => 1); + $logger->trace("*one-sentence-per-line text wrapping routine, textWrapOptions:when set to 'after'") + if $is_tt_switch_active; + $self->one_sentence_per_line( textWrap => 1 ); } # option for text wrap @@ -315,6 +316,12 @@ sub process_body_of_text { { $self->text_wrap(); } + + # option for comment text wrap + $self->text_wrap_comment_blocks() + if ($is_m_switch_active + and ${ ${ $mainSettings{modifyLineBreaks}{textWrapOptions} }{comments} }{wrap} + and ${ $mainSettings{modifyLineBreaks}{textWrapOptions} }{when} eq 'after' ); return; } @@ -322,9 +329,10 @@ sub find_objects { my $self = shift; # one sentence per line: sentences are objects, as of V3.5.1 - $self->one_sentence_per_line( textWrap => (${ $mainSettings{modifyLineBreaks}{textWrapOptions} }{when} eq 'before')) - if ($is_m_switch_active - and ${ $mainSettings{modifyLineBreaks}{oneSentencePerLine} }{manipulateSentences}); + $self->one_sentence_per_line( + textWrap => ( ${ $mainSettings{modifyLineBreaks}{textWrapOptions} }{when} eq 'before' ) ) + if ( $is_m_switch_active + and ${ $mainSettings{modifyLineBreaks}{oneSentencePerLine} }{manipulateSentences} ); # text wrapping # @@ -347,6 +355,12 @@ sub find_objects { $self->verbatim_modify_line_breaks( when => "afterTextWrap" ); } + # option for comment text wrap + $self->text_wrap_comment_blocks() + if ($is_m_switch_active + and ${ ${ $mainSettings{modifyLineBreaks}{textWrapOptions} }{comments} }{wrap} + and ${ $mainSettings{modifyLineBreaks}{textWrapOptions} }{when} eq 'before' ); + # search for environments $logger->trace('*looking for ENVIRONMENTS') if $is_t_switch_active; $self->find_environments if ${$self}{body} =~ m/$environmentBasicRegExp/s; diff --git a/LatexIndent/GetYamlSettings.pm b/LatexIndent/GetYamlSettings.pm index a3617c33..630ef3f3 100644 --- a/LatexIndent/GetYamlSettings.pm +++ b/LatexIndent/GetYamlSettings.pm @@ -117,56 +117,73 @@ sub yaml_read_settings { # we'll need the home directory a lot in what follows my $homeDir = File::HomeDir->my_home; - $logger->info("*YAML reading settings") unless $switches{onlyDefault}; + $logger->info("*YAML reading settings") unless $switches{onlyDefault}; my $indentconfig = undef; - if (defined $ENV{LATEXINDENT_CONFIG} && !$switches{onlyDefault}) { - if(-f $ENV{LATEXINDENT_CONFIG}) { + if ( defined $ENV{LATEXINDENT_CONFIG} && !$switches{onlyDefault} ) { + if ( -f $ENV{LATEXINDENT_CONFIG} ) { $indentconfig = $ENV{LATEXINDENT_CONFIG}; $logger->info('The $LATEXINDENT_CONFIG variable was detected.'); - $logger->info('The value of $LATEXINDENT_CONFIG is: "' . $ENV{LATEXINDENT_CONFIG} . '"'); - } else { + $logger->info( 'The value of $LATEXINDENT_CONFIG is: "' . $ENV{LATEXINDENT_CONFIG} . '"' ); + } + else { $logger->warn('*The $LATEXINDENT_CONFIG variable is assigned, but does not point to a file!'); - $logger->warn('The value of $LATEXINDENT_CONFIG is: "' . $ENV{LATEXINDENT_CONFIG} . '"'); + $logger->warn( 'The value of $LATEXINDENT_CONFIG is: "' . $ENV{LATEXINDENT_CONFIG} . '"' ); } } - if (!defined $indentconfig && !$switches{onlyDefault}) { - # see all possible values of $^O here: https://perldoc.perl.org/perlport#Unix and https://perldoc.perl.org/perlport#DOS-and-Derivatives - if ($^O eq "linux") { - if (defined $ENV{XDG_CONFIG_HOME} && -f "$ENV{XDG_CONFIG_HOME}/latexindent/indentconfig.yaml") { + if ( !defined $indentconfig && !$switches{onlyDefault} ) { + +# see all possible values of $^O here: https://perldoc.perl.org/perlport#Unix and https://perldoc.perl.org/perlport#DOS-and-Derivatives + if ( $^O eq "linux" ) { + if ( defined $ENV{XDG_CONFIG_HOME} && -f "$ENV{XDG_CONFIG_HOME}/latexindent/indentconfig.yaml" ) { $indentconfig = "$ENV{XDG_CONFIG_HOME}/latexindent/indentconfig.yaml"; - $logger->info('The $XDG_CONFIG_HOME variable and the config file in "' . "$ENV{XDG_CONFIG_HOME}/latexindent/indentconfig.yaml" . '" were recognized'); - $logger->info('The value of $XDG_CONFIG_HOME is: "' . $ENV{XDG_CONFIG_HOME} . '"'); - } elsif (-f "$homeDir/.config/latexindent/indentconfig.yaml") { + $logger->info( 'The $XDG_CONFIG_HOME variable and the config file in "' + . "$ENV{XDG_CONFIG_HOME}/latexindent/indentconfig.yaml" + . '" were recognized' ); + $logger->info( 'The value of $XDG_CONFIG_HOME is: "' . $ENV{XDG_CONFIG_HOME} . '"' ); + } + elsif ( -f "$homeDir/.config/latexindent/indentconfig.yaml" ) { $indentconfig = "$homeDir/.config/latexindent/indentconfig.yaml"; - $logger->info('The config file in "' . "$homeDir/.config/latexindent/indentconfig.yaml" . '" was recognized'); + $logger->info( + 'The config file in "' . "$homeDir/.config/latexindent/indentconfig.yaml" . '" was recognized' ); } - } elsif ($^O eq "darwin") { - if (-f "$homeDir/Library/Preferences/latexindent/indentconfig.yaml") { + } + elsif ( $^O eq "darwin" ) { + if ( -f "$homeDir/Library/Preferences/latexindent/indentconfig.yaml" ) { $indentconfig = "$homeDir/Library/Preferences/latexindent/indentconfig.yaml"; - $logger->info('The config file in "' . "$homeDir/Library/Preferences/latexindent/indentconfig.yaml" . '" was recognized'); + $logger->info( 'The config file in "' + . "$homeDir/Library/Preferences/latexindent/indentconfig.yaml" + . '" was recognized' ); } - } elsif ($^O eq "MSWin32" || $^O eq "cygwin") { - if (defined $ENV{LOCALAPPDATA} && -f "$ENV{LOCALAPPDATA}/latexindent/indentconfig.yaml") { + } + elsif ( $^O eq "MSWin32" || $^O eq "cygwin" ) { + if ( defined $ENV{LOCALAPPDATA} && -f "$ENV{LOCALAPPDATA}/latexindent/indentconfig.yaml" ) { $indentconfig = "$ENV{LOCALAPPDATA}/latexindent/indentconfig.yaml"; - $logger->info('The $LOCALAPPDATA variable and the config file in "' . "$ENV{LOCALAPPDATA}" . '\latexindent\indentconfig.yaml" were recognized'); - $logger->info('The value of $LOCALAPPDATA is: "' . $ENV{LOCALAPPDATA} . '"'); - } elsif (-f "$homeDir/AppData/Local/latexindent/indentconfig.yaml") { + $logger->info( 'The $LOCALAPPDATA variable and the config file in "' + . "$ENV{LOCALAPPDATA}" + . '\latexindent\indentconfig.yaml" were recognized' ); + $logger->info( 'The value of $LOCALAPPDATA is: "' . $ENV{LOCALAPPDATA} . '"' ); + } + elsif ( -f "$homeDir/AppData/Local/latexindent/indentconfig.yaml" ) { $indentconfig = "$homeDir/AppData/Local/latexindent/indentconfig.yaml"; - $logger->info('The config file in "' . "$homeDir" . '\AppData\Local\latexindent\indentconfig.yaml" was recognized'); + $logger->info( 'The config file in "' + . "$homeDir" + . '\AppData\Local\latexindent\indentconfig.yaml" was recognized' ); } } + # if $indentconfig is still not defined, fallback to the location in $homeDir if ( !defined $indentconfig ) { + # if all of these don't exist check home directly, with the non hidden file - $indentconfig = (-f "$homeDir/indentconfig.yaml") ? "$homeDir/indentconfig.yaml" : undef; + $indentconfig = ( -f "$homeDir/indentconfig.yaml" ) ? "$homeDir/indentconfig.yaml" : undef; + # if indentconfig.yaml doesn't exist, check for the hidden file, .indentconfig.yaml - $indentconfig = (-f "$homeDir/.indentconfig.yaml") ? "$homeDir/.indentconfig.yaml" : undef; - $logger->info('The config file in "' . "$indentconfig" . '" was recognized') if defined $indentconfig; + $indentconfig = ( -f "$homeDir/.indentconfig.yaml" ) ? "$homeDir/.indentconfig.yaml" : undef; + $logger->info( 'The config file in "' . "$indentconfig" . '" was recognized' ) if defined $indentconfig; } } - # messages for indentconfig.yaml and/or .indentconfig.yaml if ( defined $indentconfig && -f $indentconfig && !$switches{onlyDefault} ) { @@ -219,7 +236,8 @@ sub yaml_read_settings { else { if ( $switches{onlyDefault} ) { $logger->info("*-d switch active: only default settings requested"); - $logger->info("not reading USER settings from $indentconfig") if ( defined $indentconfig && -e $indentconfig ); + $logger->info("not reading USER settings from $indentconfig") + if ( defined $indentconfig && -e $indentconfig ); $logger->info("Ignoring the -l switch: $switches{readLocalSettings} (you used the -d switch)") if ( $switches{readLocalSettings} ); $logger->info("Ignoring the -y switch: $switches{yaml} (you used the -d switch)") if ( $switches{yaml} ); @@ -733,9 +751,11 @@ sub yaml_read_settings { # columns: 100 # when: after