From 4841af990664e40ab2f20099d8b39dabacf5ad0f Mon Sep 17 00:00:00 2001 From: Norbert Preining Date: Mon, 2 Jan 2023 03:04:24 +0000 Subject: CTAN sync 202301020304 --- support/latexindent/LatexIndent/Document.pm | 50 +- support/latexindent/LatexIndent/GetYamlSettings.pm | 118 +- support/latexindent/LatexIndent/Sentence.pm | 42 +- .../latexindent/LatexIndent/TrailingComments.pm | 12 +- support/latexindent/LatexIndent/Version.pm | 4 +- support/latexindent/LatexIndent/Wrap.pm | 354 ++- support/latexindent/README | 2 +- support/latexindent/bin/linux/latexindent | Bin 6159918 -> 6163349 bytes support/latexindent/bin/macos/latexindent | Bin 6389449 -> 6392841 bytes support/latexindent/defaultSettings.yaml | 296 +-- support/latexindent/documentation/contributors.bib | 8 + .../documentation/latexindent-yaml-schema.json | 2 +- support/latexindent/documentation/latexindent.pdf | Bin 1166672 -> 1240112 bytes support/latexindent/documentation/latexindent.tex | 2514 ++++++++++++-------- support/latexindent/latexindent.pl | 2 +- 15 files changed, 2216 insertions(+), 1188 deletions(-) (limited to 'support/latexindent') diff --git a/support/latexindent/LatexIndent/Document.pm b/support/latexindent/LatexIndent/Document.pm index 6a45320fe7..8982509445 100644 --- a/support/latexindent/LatexIndent/Document.pm +++ b/support/latexindent/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/; @@ -297,6 +297,31 @@ sub process_body_of_text { $logger->info('*Phase 4: final indentation check'); $self->final_indentation_check; + # one sentence per line: sentences are objects, as of V3.5.1 + if ( $is_m_switch_active + 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 ); + } + + # option for text wrap + if ( $is_m_switch_active + and !${ $mainSettings{modifyLineBreaks}{oneSentencePerLine} }{manipulateSentences} + and !${ $mainSettings{modifyLineBreaks}{oneSentencePerLine} }{textWrapSentences} + and ${ $mainSettings{modifyLineBreaks}{textWrapOptions} }{columns} != 0 + and ${ $mainSettings{modifyLineBreaks}{textWrapOptions} }{when} eq 'after' ) + { + $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; } @@ -304,8 +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 - 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 # @@ -319,7 +346,8 @@ sub find_objects { if ( $is_m_switch_active and !${ $mainSettings{modifyLineBreaks}{oneSentencePerLine} }{manipulateSentences} and !${ $mainSettings{modifyLineBreaks}{oneSentencePerLine} }{textWrapSentences} - and ${ $mainSettings{modifyLineBreaks}{textWrapOptions} }{columns} != 0 ) + and ${ $mainSettings{modifyLineBreaks}{textWrapOptions} }{columns} != 0 + and ${ $mainSettings{modifyLineBreaks}{textWrapOptions} }{when} eq 'before' ) { $self->text_wrap(); @@ -327,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; @@ -496,7 +530,13 @@ sub tasks_common_to_each_object { $self->check_for_hidden_children if ${$self}{body} =~ m/$tokens{beginOfToken}/; # double back slash poly-switch check - $self->double_back_slash_else if ( $is_m_switch_active and ${$self}{lookForAlignDelims} ); + $self->double_back_slash_else + if ( + $is_m_switch_active + and ( ${$self}{lookForAlignDelims} + or ( defined ${$self}{DBSStartsOnOwnLine} and ${$self}{DBSStartsOnOwnLine} != 0 ) + or ( defined ${$self}{DBSFinishesWithLineBreak} and ${$self}{DBSFinishesWithLineBreak} != 0 ) ) + ); # some objects can format their body to align at the & character $self->align_at_ampersand if ( ${$self}{lookForAlignDelims} and !${$self}{measureHiddenChildren} ); diff --git a/support/latexindent/LatexIndent/GetYamlSettings.pm b/support/latexindent/LatexIndent/GetYamlSettings.pm index 23f5a70d85..a5931d17f7 100644 --- a/support/latexindent/LatexIndent/GetYamlSettings.pm +++ b/support/latexindent/LatexIndent/GetYamlSettings.pm @@ -117,16 +117,75 @@ sub yaml_read_settings { # we'll need the home directory a lot in what follows my $homeDir = File::HomeDir->my_home; - $logger->info("*YAML settings read: indentconfig.yaml or .indentconfig.yaml") 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} ) { + $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->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} . '"' ); + } + } + 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" ) { + $indentconfig = "$homeDir/.config/latexindent/indentconfig.yaml"; + $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" ) { + $indentconfig = "$homeDir/Library/Preferences/latexindent/indentconfig.yaml"; + $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" ) { + $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" ) { + $indentconfig = "$homeDir/AppData/Local/latexindent/indentconfig.yaml"; + $logger->info( 'The config file in "' + . "$homeDir" + . '\AppData\Local\latexindent\indentconfig.yaml" was recognized' ); + } + } - # get information about user settings- first check if indentconfig.yaml exists - my $indentconfig = "$homeDir/indentconfig.yaml"; + # if $indentconfig is still not defined, fallback to the location in $homeDir + if ( !defined $indentconfig ) { - # if indentconfig.yaml doesn't exist, check for the hidden file, .indentconfig.yaml - $indentconfig = "$homeDir/.indentconfig.yaml" if ( !-e $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; + + # 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; + } + } # messages for indentconfig.yaml and/or .indentconfig.yaml - if ( -e $indentconfig and !$switches{onlyDefault} ) { + if ( defined $indentconfig && -f $indentconfig && !$switches{onlyDefault} ) { # read the absolute paths from indentconfig.yaml $userSettings = YAML::Tiny->read("$indentconfig"); @@ -135,19 +194,6 @@ sub yaml_read_settings { if ( $userSettings and ( ref( $userSettings->[0] ) eq 'HASH' ) and $userSettings->[0]->{paths} ) { $logger->info("Reading path information from $indentconfig"); - # if both indentconfig.yaml and .indentconfig.yaml exist - if ( -e File::HomeDir->my_home . "/indentconfig.yaml" - and -e File::HomeDir->my_home . "/.indentconfig.yaml" ) - { - $logger->info("$homeDir/.indentconfig.yaml has been found, but $indentconfig takes priority"); - } - elsif ( -e File::HomeDir->my_home . "/indentconfig.yaml" ) { - $logger->info("(Alternatively $homeDir/.indentconfig.yaml can be used)"); - } - elsif ( -e File::HomeDir->my_home . "/.indentconfig.yaml" ) { - $logger->info("(Alternatively $homeDir/indentconfig.yaml can be used)"); - } - # output the contents of indentconfig to the log file $logger->info( Dump \%{ $userSettings->[0] } ); @@ -190,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 ( -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} ); @@ -198,9 +245,9 @@ sub yaml_read_settings { $switches{yaml} = 0; } else { - # give the user instructions on where to put indentconfig.yaml or .indentconfig.yaml + # give the user instructions on where to put the config file $logger->info( - "Home directory is $homeDir (didn't find either indentconfig.yaml or .indentconfig.yaml)\nTo specify user settings you would put indentconfig.yaml here: $homeDir/indentconfig.yaml\nAlternatively, you can use the hidden file .indentconfig.yaml as: $homeDir/.indentconfig.yaml" + "Home directory is $homeDir (didn't find a config file, see all posible locations here: https://latexindentpl.readthedocs.io/en/latest/sec-appendices.html#indentconfig-options)" ); } } @@ -693,6 +740,25 @@ sub yaml_read_settings { } + # the following are incompatible: + # + # modifyLineBreaks: + # oneSentencePerLine: + # manipulateSentences: 1 + # textWrapSentences: 1 + # sentenceIndent: " "