diff options
author | Karl Berry <karl@freefriends.org> | 2023-05-20 20:19:20 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2023-05-20 20:19:20 +0000 |
commit | 966f5266f47369fceb572fa736ea9a975c86d8bd (patch) | |
tree | accd6c93996e158d896d2d6b733f3322231e3e13 /Master/texmf-dist/scripts/latexindent | |
parent | 06cccdee5db849d30c6de6e7981c6015b7772342 (diff) |
latexindent (20may23)
git-svn-id: svn://tug.org/texlive/trunk@67174 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/scripts/latexindent')
6 files changed, 119 insertions, 12 deletions
diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/Document.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/Document.pm index 16a01bf2092..59188a7234a 100644 --- a/Master/texmf-dist/scripts/latexindent/LatexIndent/Document.pm +++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/Document.pm @@ -187,12 +187,12 @@ sub operate_on_file { $self->remove_leading_space; $self->process_body_of_text; ${$self}{body} =~ s/\r\n/\n/sg if $mainSettings{dos2unixlinebreaks}; - $self->remove_trailing_whitespace( when => "after" ); $self->condense_blank_lines if ( $is_m_switch_active and ${ $mainSettings{modifyLineBreaks} }{condenseMultipleBlankLinesInto} ); $self->unprotect_blank_lines if ( $is_m_switch_active and ${ $mainSettings{modifyLineBreaks} }{preserveBlankLines} ); $self->un_dodge_double_backslash; + $self->remove_trailing_whitespace( when => "after" ); $self->make_replacements( when => "after" ) if $is_rv_switch_active; $self->put_verbatim_back_in( match => "everything-except-commands" ); $self->put_trailing_comments_back_in; diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/GetYamlSettings.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/GetYamlSettings.pm index c46d0c5164d..6b97e617375 100644 --- a/Master/texmf-dist/scripts/latexindent/LatexIndent/GetYamlSettings.pm +++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/GetYamlSettings.pm @@ -26,7 +26,7 @@ use Cwd; use Exporter qw/import/; use LatexIndent::LogFile qw/$logger/; 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 %mainSettings/; + = 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 %mainSettings %previouslyFoundSettings/; # Read in defaultSettings.YAML file our $defaultSettings; @@ -818,6 +818,14 @@ sub yaml_get_indentation_settings_for_this_object { columns => ${$self}{columns}, ); + # text wrap 'after' information + if ( $is_m_switch_active + and ${ $mainSettings{modifyLineBreaks}{textWrapOptions} }{when} eq 'after' + and defined ${$self}{indentRule} ) + { + ${ ${previouslyFoundSettings}{textWrapAfter} }{$name} = $indentation; + } + # don't forget alignment settings! foreach (@alignAtAmpersandInformation) { ${ ${previouslyFoundSettings}{$storageName} }{ ${$_}{name} } = ${$self}{ ${$_}{name} } @@ -1091,11 +1099,27 @@ sub yaml_get_indentation_information { if ( defined $indentationInformation ) { if ( $indentationAbout eq "noAdditionalIndent" and $indentationInformation == 1 ) { $logger->trace("Found! Using '' (see $indentationAbout)") if $is_t_switch_active; + + # text wrapping 'after' requires knowledge of indent rules + # + if ( $is_m_switch_active + and ${ $mainSettings{modifyLineBreaks}{textWrapOptions} }{when} eq 'after' ) + { + ${$self}{indentRule} = $indentationInformation; + } return q(); } elsif ( $indentationAbout eq "indentRules" and $indentationInformation =~ m/^\h*$/ ) { $logger->trace("Found! Using '$indentationInformation' (see $indentationAbout)") if $is_t_switch_active; + + # text wrapping 'after' requires knowledge of indent rules + # + if ( $is_m_switch_active + and ${ $mainSettings{modifyLineBreaks}{textWrapOptions} }{when} eq 'after' ) + { + ${$self}{indentRule} = $indentationInformation; + } return $indentationInformation; } } @@ -1115,12 +1139,28 @@ sub yaml_get_indentation_information { { $logger->trace("$globalInformation specified for $YamlName (see $globalInformation)") if $is_t_switch_active; + + # text wrapping 'after' requires knowledge of indent rules + # + if ( $is_m_switch_active + and ${ $mainSettings{modifyLineBreaks}{textWrapOptions} }{when} eq 'after' ) + { + ${$self}{indentRule} = $indentationInformation; + } return q(); } elsif ( $globalInformation eq "indentRulesGlobal" ) { if ( ${ $mainSettings{$globalInformation} }{$YamlName} =~ m/^\h*$/ ) { $logger->trace("$globalInformation specified for $YamlName (see $globalInformation)") if $is_t_switch_active; + + # text wrapping 'after' requires knowledge of indent rules + # + if ( $is_m_switch_active + and ${ $mainSettings{modifyLineBreaks}{textWrapOptions} }{when} eq 'after' ) + { + ${$self}{indentRule} = $indentationInformation; + } return ${ $mainSettings{$globalInformation} }{$YamlName}; } elsif ( ${ $mainSettings{$globalInformation} }{$YamlName} ne '0' ) { diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/Version.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/Version.pm index c20ea7afb19..59ed17e3e02 100644 --- a/Master/texmf-dist/scripts/latexindent/LatexIndent/Version.pm +++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/Version.pm @@ -20,6 +20,6 @@ use warnings; use Exporter qw/import/; our @EXPORT_OK = qw/$versionNumber $versionDate/; -our $versionNumber = '3.21'; -our $versionDate = '2023-05-01'; +our $versionNumber = '3.21.1'; +our $versionDate = '2023-05-20'; 1 diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/Wrap.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/Wrap.pm index 9185459dae7..dc99170452f 100644 --- a/Master/texmf-dist/scripts/latexindent/LatexIndent/Wrap.pm +++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/Wrap.pm @@ -21,7 +21,7 @@ use Text::Wrap; use LatexIndent::Tokens qw/%tokens/; use LatexIndent::AlignmentAtAmpersand qw/get_column_width/; use LatexIndent::TrailingComments qw/$trailingCommentRegExp @trailingComments/; -use LatexIndent::GetYamlSettings qw/%mainSettings/; +use LatexIndent::GetYamlSettings qw/%mainSettings %previouslyFoundSettings/; use LatexIndent::Switches qw/$is_t_switch_active $is_tt_switch_active $is_m_switch_active/; use LatexIndent::LogFile qw/$logger/; use LatexIndent::Verbatim qw/%verbatimStorage/; @@ -207,7 +207,7 @@ sub text_wrap { # store the text wrap blocks my @textWrapBlockStorage = split( /($blocksFollow)/, ${$self}{body} ); - @textWrapBlockStorage = split( /(\s*$blocksFollow)/, ${$self}{body} ) + @textWrapBlockStorage = split( /(\s*$blocksFollow+)/, ${$self}{body} ) if ${ $mainSettings{modifyLineBreaks}{textWrapOptions} }{when} eq 'after'; # sentences need special treatment @@ -273,6 +273,7 @@ sub text_wrap { # # see also: test-cases/text-wrap/issue-359*.tex # + my $firstLineColumns = 0; if ( ${ $mainSettings{modifyLineBreaks}{textWrapOptions} }{when} eq 'after' ) { # reset columns @@ -288,7 +289,7 @@ sub text_wrap { my $thingToMeasure = ( split( /\R/, ${$self}{follows} ) )[-1]; $subsequentSpace - = ( ${$self}{follows} ? " " x length($thingToMeasure) : q() ); + = ( ${$self}{follows} ? " " x &get_column_width($thingToMeasure) : q() ); # possible tab adjustments $thingToMeasure = q() if ( not defined $thingToMeasure ); @@ -329,7 +330,7 @@ sub text_wrap { $subsequentSpace = ( $textWrapBlockCount == 0 ? q() - : " " x length($thingToMeasure) + : " " x &get_column_width($thingToMeasure) ); # possible tab adjustments @@ -337,8 +338,45 @@ sub text_wrap { for ( my $i = 1; $i <= $numberOfTABS; $i++ ) { $subsequentSpace =~ s/ / /; } + + # check for custom indentRules see + # + # test-cases/text-wrap/issue-444.tex and friends + # + # https://github.com/cmhughes/latexindent.pl/issues/444 + # + # WARNING: this routine isn't perfect, it's *VERY DIFFICULT* + # to figure out what a code block is without actually + # finding the code block + # + # **known issue** with textWrap: after and indentRules + # + # the below will likely need to be built upon + # + my $name = $thingToMeasure; + $name =~ s/\\begin//sg; + $name =~ s/[^a-zA-Z\@0-9]//sg; + + # check that $name is within indentRules + if ( $textWrapBlockCount > 0 + and $name !~ m/^\h*$/ + and defined $previouslyFoundSettings{textWrapAfter} + and defined ${ $previouslyFoundSettings{textWrapAfter} }{$name} + and ${ $previouslyFoundSettings{textWrapAfter} }{$name} =~ m/^\h*$/ ) + { + + $firstLineColumns = $columns - length($subsequentSpace); + + $thingToMeasure =~ s/^\h*//; + for ( my $i = 0; $i < &get_column_width($thingToMeasure); $i++ ) { + $subsequentSpace =~ s/ //; + } + $subsequentSpace .= ${ $previouslyFoundSettings{textWrapAfter} }{$name}; + } + } } + $Text::Wrap::columns = $columns - length($subsequentSpace); # possible tab adjustments @@ -470,8 +508,37 @@ sub text_wrap { } # perform the text wrap routine - $textWrapBlockStorageValue = wrap( '', '', $textWrapBlockStorageValue ) - if ${ $mainSettings{modifyLineBreaks}{textWrapOptions} }{columns} > 0; + if ( $firstLineColumns > 0 ) { + + # when 'after' is active, and indentation rules specified, they need attention + # + # noAdditionalIndent *per-name* basis + # indentRules *per-name* basis + # noAdditionalIndentGlobal + # indentRulesGlobal + # + # see + # + # test-cases/text-wrap/issue-444.tex + # + my $secondLineOnwardsColumns = $Text::Wrap::columns; + + # wrap the *first* line + $Text::Wrap::columns = $firstLineColumns; + $textWrapBlockStorageValue = wrap( '', '', $textWrapBlockStorageValue ); + my @tmpBlock = split( /\R/, $textWrapBlockStorageValue ); + my $firstLine = shift(@tmpBlock); + + # wrap the *subsequent* lines + my $secondLineOnwards = join( " ", @tmpBlock ); + $Text::Wrap::columns = $secondLineOnwardsColumns; + $secondLineOnwards = wrap( '', '', $secondLineOnwards ); + $textWrapBlockStorageValue = $firstLine . "\n" . $secondLineOnwards; + } + else { + $textWrapBlockStorageValue = wrap( '', '', $textWrapBlockStorageValue ) + if ${ $mainSettings{modifyLineBreaks}{textWrapOptions} }{columns} > 0; + } # if text wrap has happened *AFTER* indentation, # then we need to add the leading indentation diff --git a/Master/texmf-dist/scripts/latexindent/defaultSettings.yaml b/Master/texmf-dist/scripts/latexindent/defaultSettings.yaml index 698ef09c118..a3582b934b2 100755 --- a/Master/texmf-dist/scripts/latexindent/defaultSettings.yaml +++ b/Master/texmf-dist/scripts/latexindent/defaultSettings.yaml @@ -1,5 +1,5 @@ # -# latexindent.pl, version 3.21, 2023-05-01 +# latexindent.pl, version 3.21.1, 2023-05-20 # # defaultSettings.yaml, the default settings for latexindent.pl # diff --git a/Master/texmf-dist/scripts/latexindent/latexindent.pl b/Master/texmf-dist/scripts/latexindent/latexindent.pl index e9f37442d24..4b8e2b75278 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.21, 2023-05-01 +# latexindent.pl, version 3.21.1, 2023-05-20 # # 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 |