From: Steve Hancock Date: Thu, 22 Jul 2021 22:47:19 +0000 (-0700) Subject: minor code cleanups X-Git-Tag: 20210717.02~79 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=57c29e2816366026594564e5520c45948c984c7f;p=perltidy.git minor code cleanups --- diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index 1baf45ed..9132083d 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -4509,7 +4509,7 @@ sub make_closing_side_comment_prefix { # Sequence numbers are generated for opening tokens, so every opening # token should be sequenced. Closing tokens will be unsequenced - # if they do not have a matching opening toke. + # if they do not have a matching opening token. if ( $is_opening_sequence_token{$token} && $type ne 'q' && $type ne 'Q' ) @@ -9661,6 +9661,8 @@ sub process_all_lines { # HERE_END - last line of here-doc (target word) # FORMAT - format section # FORMAT_END - last line of format section, '.' + # SKIP - code skipping section + # SKIP_END - last line of code skipping section, '#>>V' # DATA_START - __DATA__ line # DATA - unidentified text following __DATA__ # END_START - __END__ line @@ -9766,10 +9768,8 @@ sub process_all_lines { } # Patch to avoid losing blank lines after a code-skipping block; - # fixes case c047. Note that the code for code-skipping is - # currently 'FORMAT'. If it changes, the next line would need to - # be changed. - elsif ( $line_type eq 'FORMAT' ) { + # fixes case c047. + elsif ( $line_type eq 'SKIP_END' ) { $file_writer_object->reset_consecutive_blank_lines(); } @@ -10078,7 +10078,7 @@ EOM # Find the parent container of the first token on the next line my $parent_seqno = $self->parent_seqno_by_K($Knext_nonblank); - goto RETURN unless defined($parent_seqno); + goto RETURN unless ( defined($parent_seqno) ); # Must not be a weld (can be unstable) goto RETURN @@ -12013,10 +12013,20 @@ sub compare_indentation_levels { sub set_forced_breakpoint { my ( $self, $i ) = @_; + # Set a breakpoint AFTER the token at index $i in the _to_go arrays. + + # Exceptions: + # - If the token at index $i is a blank, backup to $i-1 to + # get to the previous nonblank token. + # - For certain tokens, the break may be placed BEFORE the token + # at index $i, depending on user break preference settings. + # - If a break is made after an opening token, then a break will + # also be made before the corresponding closing token. + return unless defined $i && $i >= 0; - # Back up at a blank in case we need an = break. - # This is a backup fix for cases like b932. + # Back up at a blank so we have a token to examine. + # This was added to fix for cases like b932 involving an '=' break. if ( $i > 0 && $types_to_go[$i] eq 'b' ) { $i-- } # no breaks between welded tokens diff --git a/lib/Perl/Tidy/HtmlWriter.pm b/lib/Perl/Tidy/HtmlWriter.pm index d9e120b1..c5239c2e 100644 --- a/lib/Perl/Tidy/HtmlWriter.pm +++ b/lib/Perl/Tidy/HtmlWriter.pm @@ -1429,6 +1429,8 @@ sub write_line { elsif ( $line_type eq 'HERE_END' ) { $line_character = 'h' } elsif ( $line_type eq 'FORMAT' ) { $line_character = 'H' } elsif ( $line_type eq 'FORMAT_END' ) { $line_character = 'h' } + elsif ( $line_type eq 'SKIP' ) { $line_character = 'H' } + elsif ( $line_type eq 'SKIP_END' ) { $line_character = 'h' } elsif ( $line_type eq 'SYSTEM' ) { $line_character = 'c' } elsif ( $line_type eq 'END_START' ) { $line_character = 'k'; diff --git a/lib/Perl/Tidy/Tokenizer.pm b/lib/Perl/Tidy/Tokenizer.pm index 42915e5c..a5058483 100644 --- a/lib/Perl/Tidy/Tokenizer.pm +++ b/lib/Perl/Tidy/Tokenizer.pm @@ -748,6 +748,8 @@ sub get_line { # HERE_END - last line of here-doc (target word) # FORMAT - format section # FORMAT_END - last line of format section, '.' + # SKIP - code skipping section + # SKIP_END - last line of code skipping section, '#>>V' # DATA_START - __DATA__ line # DATA - unidentified text following __DATA__ # END_START - __END__ line @@ -885,9 +887,9 @@ sub get_line { # print line unchanged if in skipped section elsif ( $tokenizer_self->[_in_skipped_] ) { - # NOTE: marked as the existing type 'FORMAT' to keep html working - $line_of_tokens->{_line_type} = 'FORMAT'; + $line_of_tokens->{_line_type} = 'SKIP'; if ( $input_line =~ /$code_skipping_pattern_end/ ) { + $line_of_tokens->{_line_type} = 'SKIP_END'; $write_logfile_entry->("Exiting code-skipping section\n"); $tokenizer_self->[_in_skipped_] = 0; } @@ -1078,8 +1080,7 @@ sub get_line { # handle start of skipped section if ( $tokenizer_self->[_in_skipped_] ) { - # NOTE: marked as the existing type 'FORMAT' to keep html working - $line_of_tokens->{_line_type} = 'FORMAT'; + $line_of_tokens->{_line_type} = 'SKIP'; $write_logfile_entry->("Entering code-skipping section\n"); return $line_of_tokens; } @@ -8786,6 +8787,8 @@ The following additional token types are defined: HERE_END - last line of here-doc (target word) FORMAT - format section FORMAT_END - last line of format section, '.' + SKIP - code skipping section + SKIP_END - last line of code skipping section, '#>>V' DATA_START - __DATA__ line DATA - unidentified text following __DATA__ END_START - __END__ line