All of lore.kernel.org
 help / color / mirror / Atom feed
From: Akira Yokosawa <akiyks@gmail.com>
To: "Paul E. McKenney" <paulmck@kernel.org>
Cc: perfbook@vger.kernel.org, Akira Yokosawa <akiyks@gmail.com>
Subject: [PATCH -perfbook 1/4] cleverefcheck.pl: Add test of listing next to heading
Date: Wed, 8 Dec 2021 16:39:38 +0900	[thread overview]
Message-ID: <3747024b-f3df-09a3-a5a2-33808e5fa42c@gmail.com> (raw)
In-Reply-To: <4350078f-4054-cb28-157b-305d6df087ea@gmail.com>

There is a side effect of fancyvrb, or the Verbatim{L|N|U}
environments derived from Verbatim, in that floating "listing"
environments placed just next to chapter/section headings are
treated as page/column-break candidates, and results in a widowed
heading.

Other floating objects such as "figure" and "table" do not
have this issue as long as they are free of fancyvrb.

Add tests to detect "listing" environments who come next to
\chapter/\section/\subsection/... commands.

Signed-off-by: Akira Yokosawa <akiyks@gmail.com>
---
 utilities/cleverefcheck.pl | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/utilities/cleverefcheck.pl b/utilities/cleverefcheck.pl
index 0085fdb5..f46cd89f 100755
--- a/utilities/cleverefcheck.pl
+++ b/utilities/cleverefcheck.pl
@@ -25,8 +25,11 @@ my $IX_ptn = qr/(^|\s+)IX[^\s\{]*{/ ;
 my $api_ptn = qr/(^|\s+)api[^\s\{]*{/ ;
 my $ppl_ptn = qr/(^|\s+)ppl[^\s\{]*{/ ;
 my $acr_ptn = qr/(^|\s+)[aA]cr[^\s\{]*{/ ;
+my $heading_ptn = qr/(\\chapter|\\section|\\subsection|\\subsubsection)/ ;
+my $listing_ptn = qr/\\begin\{(listing|Verbatim)/ ;
 my $in_footnote = 0 ;
 my $footnote_save = 0;
+my $after_heading = 0;
 
 sub check_line {
     my $raw_line = $line;
@@ -102,6 +105,18 @@ sub check_line {
 	    print $ARGV[0], ':', $line_num, ':', $raw_line;
 	}
     }
+    if ($after_heading) {
+	if ($line =~ /^\s*$/) {
+	    # ignore empty/blank line
+	}
+	if ($line =~ /^\s*\{*[A-Za-z0-9]/) {
+	    $after_heading = 0 ;  # normal line, OK
+	}
+	if ($line =~ /$listing_ptn/) {
+	    print $ARGV[0], ':', $line_num, ':', $raw_line, "^^^ listing next to heading ^^^\n";
+	    $after_heading = 0 ;
+	}
+    }
     if ($line =~ /$Verbatim_end/) {
 	$skip = 0;
     } else {
@@ -135,6 +150,9 @@ sub check_line {
 	    }
 	}
     }
+    if ($line =~ /$heading_ptn/) {
+	$after_heading = 1 ;
+    }
 }
 
 open(my $fh, '<:encoding(UTF-8)', $ARGV[0])
-- 
2.17.1



  reply	other threads:[~2021-12-08  7:39 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-08  7:37 [PATCH -perfbook 0/4] Address potential widowing of headings Akira Yokosawa
2021-12-08  7:39 ` Akira Yokosawa [this message]
2021-12-08  7:41 ` [PATCH -perfbook 2/4] cleverefcheck.pl: Add test of \begin{...} at head of QQA Akira Yokosawa
2021-12-08  7:49 ` [PATCH -perfbook 3/4] cleverefcheck.pl: Add test of \begin{...} next to epigraph Akira Yokosawa
2021-12-08  7:52 ` [PATCH -perfbook 4/4] treewide: Address potential widowing of headings Akira Yokosawa
2021-12-08 19:55 ` [PATCH -perfbook 0/4] " Paul E. McKenney
2021-12-08 22:20   ` Akira Yokosawa
2021-12-08 23:58     ` Paul E. McKenney
2021-12-09  0:03       ` Akira Yokosawa
2021-12-09  6:28         ` Zhouyi Zhou

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3747024b-f3df-09a3-a5a2-33808e5fa42c@gmail.com \
    --to=akiyks@gmail.com \
    --cc=paulmck@kernel.org \
    --cc=perfbook@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.