From 746ec82646554d70d165549450f6e676d9a8c3df Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Sat, 9 Jan 2021 06:59:53 -0800 Subject: [PATCH] code cleanups; remove unused subs --- bin/perltidy | 8 ++- dev-bin/RandomTesting.md | 6 +- lib/Perl/Tidy.pm | 26 ++++----- lib/Perl/Tidy/Formatter.pm | 113 +++---------------------------------- 4 files changed, 30 insertions(+), 123 deletions(-) diff --git a/bin/perltidy b/bin/perltidy index f4c2c833..ed90fa18 100755 --- a/bin/perltidy +++ b/bin/perltidy @@ -416,7 +416,13 @@ Use n columns per indentation level (default n=4). The default maximum line length is n=80 characters. Perltidy will try to find line break points to keep lines below this length. However, long quotes and side comments may cause lines to exceed this length. -Setting B<-l=0> is equivalent to setting B<-l=(a large number)>. + +The default length of 80 comes from the past when this was the standard CRT +screen width. Many programmers prefer to increase this to something like 120. + +Setting B<-l=0> is equivalent to setting B<-l=(a very large number)>. But this is +not recommended because, for example, a very long list will be formatted in a +single long line. =item B<-vmll>, B<--variable-maximum-line-length> diff --git a/dev-bin/RandomTesting.md b/dev-bin/RandomTesting.md index c2b221be..77e09597 100644 --- a/dev-bin/RandomTesting.md +++ b/dev-bin/RandomTesting.md @@ -11,7 +11,7 @@ through the results. When this type of testing was begun, several dozen problems were quickly identified and fixed. The most common problem was that an uninitialized variable was referenced in some way. It has been some time since a new problem -was detected with these scripts, but it is important to periodically run these +was detected with these scripts, but it is important to run these tests periodically, and always before a release, because new coding and new parameters may introduce bugs. @@ -28,7 +28,7 @@ personal bin directory. ## Prepare a temporary directory First collect a large number (say 50 or more) of arbitrary perl scripts in a -single directory. These files can also contain arbitrary other files, such as +single directory. You may also include other arbitrary files, such as text or html files. Then create a temporary sub directory and enter it, say @@ -86,7 +86,7 @@ menu. You will be generating profiles here (a profile being a file with a random set of perltidy parameters). The number of random profiles is set to 50 but I sometimes increase it to 100 or 200. Every input file will be run against every random profile, so this can significantly increase the total run -time. The main menu looks like this (I am not sure if this will format correctly): +time. The main menu looks like this: ``` R - Read a config file diff --git a/lib/Perl/Tidy.pm b/lib/Perl/Tidy.pm index 0ef55091..d2184f17 100644 --- a/lib/Perl/Tidy.pm +++ b/lib/Perl/Tidy.pm @@ -2427,19 +2427,19 @@ sub generate_options { ######################################## $category = 13; # Debugging ######################################## -## $add_option->( 'DIAGNOSTICS', 'I', '!' ); - $add_option->( 'DEBUG', 'D', '!' ); - $add_option->( 'dump-cuddled-block-list', 'dcbl', '!' ); - $add_option->( 'dump-defaults', 'ddf', '!' ); - $add_option->( 'dump-long-names', 'dln', '!' ); - $add_option->( 'dump-options', 'dop', '!' ); - $add_option->( 'dump-profile', 'dpro', '!' ); - $add_option->( 'dump-short-names', 'dsn', '!' ); - $add_option->( 'dump-token-types', 'dtt', '!' ); - $add_option->( 'dump-want-left-space', 'dwls', '!' ); - $add_option->( 'dump-want-right-space', 'dwrs', '!' ); - $add_option->( 'fuzzy-line-length', 'fll', '!' ); - $add_option->( 'help', 'h', '' ); + $add_option->( 'DIAGNOSTICS', 'I', '!' ) if (DEVEL_MODE); + $add_option->( 'DEBUG', 'D', '!' ); + $add_option->( 'dump-cuddled-block-list', 'dcbl', '!' ); + $add_option->( 'dump-defaults', 'ddf', '!' ); + $add_option->( 'dump-long-names', 'dln', '!' ); + $add_option->( 'dump-options', 'dop', '!' ); + $add_option->( 'dump-profile', 'dpro', '!' ); + $add_option->( 'dump-short-names', 'dsn', '!' ); + $add_option->( 'dump-token-types', 'dtt', '!' ); + $add_option->( 'dump-want-left-space', 'dwls', '!' ); + $add_option->( 'dump-want-right-space', 'dwrs', '!' ); + $add_option->( 'fuzzy-line-length', 'fll', '!' ); + $add_option->( 'help', 'h', '' ); $add_option->( 'short-concatenation-item-length', 'scl', '=i' ); $add_option->( 'show-options', 'opt', '!' ); $add_option->( 'timestamp', 'ts', '!' ); diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index 9016df9e..2e9bf525 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -769,40 +769,6 @@ sub new { # CODE SECTION 2: Some Basic Utilities ###################################### -sub check_keys { - my ( $rtest, $rvalid, $msg, $exact_match ) = @_; - - # Check the keys of a hash: - # $rtest = ref to hash to test - # $rvalid = ref to hash with valid keys - - # $msg = a message to write in case of error - # $exact_match defines the type of check: - # = false: test hash must not have unknown key - # = true: test hash must have exactly same keys as known hash - my @unknown_keys = - grep { !exists $rvalid->{$_} } keys %{$rtest}; - my @missing_keys = - grep { !exists $rtest->{$_} } keys %{$rvalid}; - my $error = @unknown_keys; - if ($exact_match) { $error ||= @missing_keys } - if ($error) { - local $" = ')('; - my @expected_keys = sort keys %{$rvalid}; - @unknown_keys = sort @unknown_keys; - Die(<[$Kfirst]->[_TYPE_]; - if ( $keep_break_before_type{$typeb} ) { + my $type_first = $rLL->[$Kfirst]->[_TYPE_]; + if ( $keep_break_before_type{$type_first} ) { $rbreak_before_Kfirst->{$Kfirst} = 1; } - my $typee = $rLL->[$Klast]->[_TYPE_]; - if ( $keep_break_after_type{$typee} ) { + my $type_last = $rLL->[$Klast]->[_TYPE_]; + if ( $keep_break_after_type{$type_last} ) { $rbreak_after_Klast->{$Klast} = 1; } } @@ -6160,7 +6126,7 @@ sub weld_containers { # Note that weld_nested_containers() changes the _LEVEL_ values, so # weld_cuddled_blocks must use the _TRUE_LEVEL_ values instead. - # Here is a good test case to Be sure that both cuddling and welding + # Here is a good test case to be sure that both cuddling and welding # are working and not interfering with each other: <> # perltidy -wn -ce @@ -6202,6 +6168,8 @@ sub cumulative_length_before_K { } sub cumulative_length_after_K { + + # NOTE: This routine not currently called; could be deleted my ( $self, $KK ) = @_; my $rLL = $self->[_rLL_]; return $rLL->[$KK]->[_CUMULATIVE_LENGTH_]; @@ -10897,11 +10865,6 @@ EOM @unmatched_closing_indexes_in_this_batch; } - sub comma_arrow_count { - my $seqno = shift; - return $comma_arrow_count{$seqno}; - } - sub match_opening_and_closing_tokens { # Match up indexes of opening and closing braces, etc, in this batch. @@ -18354,68 +18317,6 @@ sub pad_token { return; } -sub mate_index_to_go { - my ( $self, $i ) = @_; - - # NOTE: This works but is too inefficient, but is retained for info. - - # Return the matching index of a container or ternary pair - # This is equivalent to the array @mate_index_to_go - my $K = $K_to_go[$i]; - my $K_mate = $self->K_mate_index($K); - my $i_mate = -1; - if ( defined($K_mate) ) { - $i_mate = $i + ( $K_mate - $K ); - if ( $i_mate < 0 || $i_mate > $max_index_to_go ) { - $i_mate = -1; - } - } - my $i_mate_alt = $mate_index_to_go[$i]; - - # FIXME: Old Debug code which can be removed eventually - if ( 0 && $i_mate_alt != $i_mate ) { - my $tok = $tokens_to_go[$i]; - my $type = $types_to_go[$i]; - my $tok_mate = '*'; - my $type_mate = '*'; - if ( $i_mate >= 0 && $i_mate <= $max_index_to_go ) { - $tok_mate = $tokens_to_go[$i_mate]; - $type_mate = $types_to_go[$i_mate]; - } - my $seq = $type_sequence_to_go[$i]; - my $file = get_input_stream_name(); - - Warn( -"mate_index: file '$file': i=$i, imate=$i_mate, should be $i_mate_alt, K=$K, K_mate=$K_mate\ntype=$type, tok=$tok, seq=$seq, max=$max_index_to_go, tok_mate=$tok_mate, type_mate=$type_mate" - ); - } - return $i_mate; -} - -sub K_mate_index { - - # Given the index K of an opening or closing container, or ?/: ternary pair, - # return the index K of the other member of the pair. - my ( $self, $K ) = @_; - return unless defined($K); - my $rLL = $self->[_rLL_]; - my $seqno = $rLL->[$K]->[_TYPE_SEQUENCE_]; - return unless ($seqno); - - my $K_opening = $self->[_K_opening_container_]->{$seqno}; - if ( defined($K_opening) ) { - if ( $K != $K_opening ) { return $K_opening } - return $self->[_K_closing_container_]->{$seqno}; - } - - $K_opening = $self->[_K_opening_ternary_]->{$seqno}; - if ( defined($K_opening) ) { - if ( $K != $K_opening ) { return $K_opening } - return $self->[_K_closing_ternary_]->{$seqno}; - } - return; -} - { ## begin closure make_alignment_patterns my %block_type_map; -- 2.39.5