diff options
author | Karl Berry <karl@freefriends.org> | 2021-08-01 20:35:09 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2021-08-01 20:35:09 +0000 |
commit | 07a6550aa7f741c870ad36d20f966bc13b0772c1 (patch) | |
tree | bd6cc9efc5df807a68e2b242058af6c586a78781 /Master/texmf-dist/scripts/latexindent/LatexIndent | |
parent | 124368ae4f0ebc3a7736c703764ab1555997e214 (diff) |
latexindent (1aug21)
git-svn-id: svn://tug.org/texlive/trunk@60132 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/scripts/latexindent/LatexIndent')
4 files changed, 115 insertions, 18 deletions
diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/Document.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/Document.pm index 85a05579503..4098d018137 100644 --- a/Master/texmf-dist/scripts/latexindent/LatexIndent/Document.pm +++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/Document.pm @@ -222,6 +222,21 @@ sub find_objects{ # one sentence per line: sentences are objects, as of V3.5.1 $self->one_sentence_per_line if ($is_m_switch_active and ${$masterSettings{modifyLineBreaks}{oneSentencePerLine}}{manipulateSentences}); + if ($is_m_switch_active and !${$self}{preamblePresent}){ + $self->yaml_get_textwrap_removeparagraphline_breaks; + } + + if( $is_m_switch_active and ${$masterSettings{modifyLineBreaks}{textWrapOptions}}{beforeFindingChildCodeBlocks} == 1){ + # 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}; + } + } + # search for environments $logger->trace('looking for ENVIRONMENTS') if $is_t_switch_active; $self->find_environments if ${$self}{body} =~ m/$environmentBasicRegExp/s; @@ -238,17 +253,15 @@ sub find_objects{ $self->find_commands_or_key_equals_values_braces_and_special if ${$self}{body} =~ m/$specialBeginAndBracesBracketsBasicRegExp/s; # documents without preamble need a manual call to the paragraph_one_line routine - if ($is_m_switch_active and !${$self}{preamblePresent}){ - $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 ($is_m_switch_active and ${$masterSettings{modifyLineBreaks}{textWrapOptions}}{beforeFindingChildCodeBlocks} == 0 ){ + # 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 @@ -303,12 +316,15 @@ sub get_settings_and_store_new_object{ # there are a number of tasks common to each object $latexIndentObject->tasks_common_to_each_object(%{$self}); + + # removeParagraphLineBreaks and textWrapping fun! + $latexIndentObject->text_wrap_remove_paragraph_line_breaks if( $is_m_switch_active and ${$masterSettings{modifyLineBreaks}{textWrapOptions}}{beforeFindingChildCodeBlocks} ); # 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); + $latexIndentObject->text_wrap_remove_paragraph_line_breaks if($is_m_switch_active and !${$masterSettings{modifyLineBreaks}{textWrapOptions}}{beforeFindingChildCodeBlocks} ); # store children in special hash push(@{${$self}{children}},$latexIndentObject); diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/GetYamlSettings.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/GetYamlSettings.pm index f28fdd6525c..1529493d4f9 100644 --- a/Master/texmf-dist/scripts/latexindent/LatexIndent/GetYamlSettings.pm +++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/GetYamlSettings.pm @@ -570,6 +570,27 @@ sub yaml_read_settings{ $logger->info(Dumper(\%masterSettings)); } + if( $is_m_switch_active + and ${$masterSettings{modifyLineBreaks}{textWrapOptions}}{beforeFindingChildCodeBlocks} + and !${$masterSettings{modifyLineBreaks}{textWrapOptions}}{perCodeBlockBasis} ){ + + # the following settings don't make sense, so we change + # + # modifyLineBreaks: + # textWrapOptions: + # perCodeBlockBasis: 0 + # beforeFindingChildCodeBlocks: 1 + # into + # + # modifyLineBreaks: + # textWrapOptions: + # perCodeBlockBasis: 0 + # beforeFindingChildCodeBlocks: 0 + $logger->warn("*textWrapOptions:beforeFindingChildCodeBlocks:1 with textWrapOptions:perCodeBlockBasis:0"); + $logger->warn("turning off beforeFindingChildCodeBlocks by changing textWrapOptions:beforeFindingOtherCodeBlocks to be 0"); + $logger->warn("you need to set *both* values to be 1 to use the beforeFindingChildCodeBlocks feature"); + ${$masterSettings{modifyLineBreaks}{textWrapOptions}}{beforeFindingChildCodeBlocks} = 0; + } return; } diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/ModifyLineBreaks.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/ModifyLineBreaks.pm index 1b3f9486459..f11221e25bd 100644 --- a/Master/texmf-dist/scripts/latexindent/LatexIndent/ModifyLineBreaks.pm +++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/ModifyLineBreaks.pm @@ -274,6 +274,7 @@ sub verbatim_modify_line_breaks{ } } } + sub text_wrap_remove_paragraph_line_breaks{ my $self = shift; @@ -293,6 +294,60 @@ sub text_wrap{ # alignment at ampersand can take priority return if(${$self}{lookForAlignDelims} and ${$masterSettings{modifyLineBreaks}{textWrapOptions}}{alignAtAmpersandTakesPriority}); + # goal: get an accurate measurement of verbatim objects; + # + # example: + # Lorem \verb!x+y! ipsum dolor sit amet + # + # is represented as + # + # Lorem LTXIN-TK-VERBATIM1-END ipsum dolor sit amet + # + # so we *measure* the verbatim token and replace it with + # an appropriate-length string + # + # Lorem a2A41233rt ipsum dolor sit amet + # + # and then put the body back to + # + # Lorem LTXIN-TK-VERBATIM1-END ipsum dolor sit amet + # + # following the text wrapping + my @putVerbatimBackIn; + + # check body for verbatim and get measurements + if (${$self}{body} =~ m/$tokens{verbatim}/s and ${$masterSettings{modifyLineBreaks}{textWrapOptions}}{huge} eq "overflow"){ + + # reference: https://stackoverflow.com/questions/10336660/in-perl-how-can-i-generate-random-strings-consisting-of-eight-hex-digits + my @set = ('0' ..'9', 'A' .. 'Z', 'a' .. 'z'); + + # loop through verbatim objects + while( my ($verbatimID,$child)= each %verbatimStorage){ + my $verbatimThing = ${$child}{begin}.${$child}{body}.${$child}{end}; + + # if the object has line breaks, don't measure it + next if $verbatimThing =~ m/\R/s; + + if(${$self}{body} =~m/$verbatimID/s){ + + # measure length + my $verbatimLength = Unicode::GCString->new($verbatimThing)->columns(); + + # create temporary ID, and check that it is not contained in the body + my $verbatimTmpID = join '' => map $set[rand @set], 1 .. $verbatimLength; + while(${$self}{body} =~m/$verbatimTmpID/s){ + $verbatimTmpID = join '' => map $set[rand @set], 1 .. $verbatimLength; + } + + # store for use after the text wrapping + push(@putVerbatimBackIn,{origVerbatimID=>$verbatimID,tmpVerbatimID=>$verbatimTmpID}); + + # make the substitution + ${$self}{body} =~ s/$verbatimID/$verbatimTmpID/s; + } + } + } + # call the text wrapping routine my $columns; @@ -311,15 +366,20 @@ sub text_wrap{ $columns = 80; } + # vital Text::Wrap options $Text::Wrap::columns=$columns; - if(${$masterSettings{modifyLineBreaks}{textWrapOptions}}{separator} ne ''){ - $Text::Wrap::separator=${$masterSettings{modifyLineBreaks}{textWrapOptions}}{separator}; - } - $Text::Wrap::huge = ${$masterSettings{modifyLineBreaks}{textWrapOptions}}{huge} if ${$masterSettings{modifyLineBreaks}{textWrapOptions}}{huge}; + $Text::Wrap::huge = ${$masterSettings{modifyLineBreaks}{textWrapOptions}}{huge}; + + # all other Text::Wrap options not usually needed/helpful, but available + $Text::Wrap::separator=${$masterSettings{modifyLineBreaks}{textWrapOptions}}{separator} if(${$masterSettings{modifyLineBreaks}{textWrapOptions}}{separator} ne ''); $Text::Wrap::break = ${$masterSettings{modifyLineBreaks}{textWrapOptions}}{break} if ${$masterSettings{modifyLineBreaks}{textWrapOptions}}{break}; $Text::Wrap::unexpand = ${$masterSettings{modifyLineBreaks}{textWrapOptions}}{unexpand} if ${$masterSettings{modifyLineBreaks}{textWrapOptions}}{unexpand}; $Text::Wrap::tabstop = ${$masterSettings{modifyLineBreaks}{textWrapOptions}}{tabstop} if ${$masterSettings{modifyLineBreaks}{textWrapOptions}}{tabstop}; + + # perform the text wrapping ${$self}{body} = wrap('','',${$self}{body}); + + ${$self}{body} =~ s/${$_}{tmpVerbatimID}/${$_}{origVerbatimID}/s foreach (@putVerbatimBackIn); } sub construct_paragraph_reg_exp{ diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/Version.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/Version.pm index 41ff54c12be..81a37b49c0f 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.10.1'; -our $versionDate = '2021-07-23'; +our $versionNumber = '3.11'; +our $versionDate = '2021-07-31'; 1 |