Skip to content

Commit

Permalink
poly-switch for verbatim code blocks updated to work for value 4
Browse files Browse the repository at this point in the history
  • Loading branch information
cmhughes committed Dec 2, 2022
1 parent 2f402d6 commit 28a3756
Show file tree
Hide file tree
Showing 66 changed files with 762 additions and 41 deletions.
59 changes: 33 additions & 26 deletions LatexIndent/ModifyLineBreaks.pm
Original file line number Diff line number Diff line change
Expand Up @@ -317,36 +317,43 @@ sub verbatim_modify_line_breaks {
my $BeginStringLogFile = ${$child}{aliases}{BeginStartsOnOwnLine};
$logger->trace("*$BeginStringLogFile is ${$child}{BeginStartsOnOwnLine} for ${$child}{name}")
if $is_t_switch_active;
if ( ${$child}{BeginStartsOnOwnLine} == -1 ) {

# VerbatimStartsOnOwnLine = -1
if ( ${$self}{body} =~ m/^\h*${$child}{id}/m ) {
$logger->trace("${$child}{name} begins on its own line, removing leading line break")
if $is_t_switch_active;
${$self}{body} =~ s/(\R|\h)*${$child}{id}/${$child}{id}/s;
}
}
elsif ( ${$child}{BeginStartsOnOwnLine} >= 1 and ${$self}{body} !~ m/^\h*${$child}{id}/m ) {
my @polySwitchValues
= ( ${$child}{BeginStartsOnOwnLine} == 4 ) ? ( -1, 3 ) : ( ${$child}{BeginStartsOnOwnLine} );

# VerbatimStartsOnOwnLine = 1, 2 or 3
my $trailingCharacterToken = q();
if ( ${$child}{BeginStartsOnOwnLine} == 1 ) {
$logger->trace("Adding a linebreak at the beginning of ${$child}{begin} (see $BeginStringLogFile)")
if $is_t_switch_active;
}
elsif ( ${$child}{BeginStartsOnOwnLine} == 2 ) {
$logger->trace(
"Adding a % at the end of the line that ${$child}{begin} is on, then a linebreak ($BeginStringLogFile == 2)"
) if $is_t_switch_active;
$trailingCharacterToken = "%" . $self->add_comment_symbol;
foreach (@polySwitchValues) {
if ( $_ == -1 ) {

# VerbatimStartsOnOwnLine = -1
if ( ${$self}{body} =~ m/^\h*${$child}{id}/m ) {
$logger->trace("${$child}{name} begins on its own line, removing leading line break")
if $is_t_switch_active;
${$self}{body} =~ s/(\R|\h)*${$child}{id}/${$child}{id}/s;
}
}
elsif ( ${$child}{BeginStartsOnOwnLine} == 3 ) {
$logger->trace(
"Adding a blank line at the end of the line that ${$child}{begin} is on, then a linebreak ($BeginStringLogFile == 3)"
) if $is_t_switch_active;
$trailingCharacterToken = "\n";
elsif ( $_ >= 1 and ${$self}{body} !~ m/^\h*${$child}{id}/m ) {

# VerbatimStartsOnOwnLine = 1, 2 or 3
my $trailingCharacterToken = q();
if ( $_ == 1 ) {
$logger->trace(
"Adding a linebreak at the beginning of ${$child}{begin} (see $BeginStringLogFile)")
if $is_t_switch_active;
}
elsif ( $_ == 2 ) {
$logger->trace(
"Adding a % at the end of the line that ${$child}{begin} is on, then a linebreak ($BeginStringLogFile == 2)"
) if $is_t_switch_active;
$trailingCharacterToken = "%" . $self->add_comment_symbol;
}
elsif ( $_ == 3 ) {
$logger->trace(
"Adding a blank line at the end of the line that ${$child}{begin} is on, then a linebreak ($BeginStringLogFile == 3)"
) if $is_t_switch_active;
$trailingCharacterToken = "\n";
}
${$self}{body} =~ s/\h*${$child}{id}/$trailingCharacterToken\n${$child}{id}/s;
}
${$self}{body} =~ s/\h*${$child}{id}/$trailingCharacterToken\n${$child}{id}/s;
}
}

Expand Down
4 changes: 2 additions & 2 deletions documentation/localSettings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ modifyLineBreaks:
other: '\\cmhlistingsfromfile|\\begin\{|\\\[|\\end\{' # regex
verbatim:
commandshell:
VerbatimBeginStartsOnOwnLine: 3
VerbatimEndFinishesWithLineBreak: 3
VerbatimBeginStartsOnOwnLine: 4
VerbatimEndFinishesWithLineBreak: 4
mandatoryArguments:
cmhlistingsfromfile*:
RCuBFinishesWithLineBreak: 1
Expand Down

0 comments on commit 28a3756

Please sign in to comment.