From: peter@bikeshed.quignogs.org.uk
To: Matthew Wilcox <willy@infradead.org>, linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
"Rafael J. Wysocki" <rafael@kernel.org>,
linux-doc@vger.kernel.org, Jonathan Corbet <corbet@lwn.net>,
Peter Lister <peter@bikeshed.quignogs.org.uk>
Subject: [PATCH v3 1/1] A compact idiom to add code examples in kerneldoc comments.
Date: Thu, 26 Mar 2020 19:51:56 +0000 [thread overview]
Message-ID: <20200326195156.11858-2-peter@bikeshed.quignogs.org.uk> (raw)
In-Reply-To: <20200326195156.11858-1-peter@bikeshed.quignogs.org.uk>
From: Peter Lister <peter@bikeshed.quignogs.org.uk>
scripts/kernel-doc - When a double colon follows a section heading
(e.g. Example::), write a double colon line to the ReST output to make
the following text (e.g. a code snippet) into a literal block.
drivers/base/platform.c - Changed Example: headings to Example:: to
literalise code snippets as above.
This patch also removes two kerneldoc build warnings:
./drivers/base/platform.c:134: WARNING: Unexpected indentation.
./drivers/base/platform.c:213: WARNING: Unexpected indentation.
Signed-off-by: Peter Lister <peter@bikeshed.quignogs.org.uk>
---
drivers/base/platform.c | 4 ++--
scripts/kernel-doc | 19 +++++++++++++++----
2 files changed, 17 insertions(+), 6 deletions(-)
diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index b5ce7b085795..47f4a9b410b2 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -128,7 +128,7 @@ EXPORT_SYMBOL_GPL(devm_platform_ioremap_resource_byname);
* request_irq() APIs. This is the same as platform_get_irq(), except that it
* does not print an error message if an IRQ can not be obtained.
*
- * Example:
+ * Example::
* int irq = platform_get_irq_optional(pdev, 0);
* if (irq < 0)
* return irq;
@@ -207,7 +207,7 @@ EXPORT_SYMBOL_GPL(platform_get_irq_optional);
* IRQ fails. Device drivers should check the return value for errors so as to
* not pass a negative integer value to the request_irq() APIs.
*
- * Example:
+ * Example::
* int irq = platform_get_irq(pdev, 0);
* if (irq < 0)
* return irq;
diff --git a/scripts/kernel-doc b/scripts/kernel-doc
index f2d73f04e71d..732db3dcc402 100755
--- a/scripts/kernel-doc
+++ b/scripts/kernel-doc
@@ -362,7 +362,7 @@ my $doc_com_body = '\s*\* ?';
my $doc_decl = $doc_com . '(\w+)';
# @params and a strictly limited set of supported section names
my $doc_sect = $doc_com .
- '\s*(\@[.\w]+|\@\.\.\.|description|context|returns?|notes?|examples?)\s*:(.*)';
+ '\s*(\@[.\w]+|\@\.\.\.|description|context|returns?|notes?|examples?)\s*:(:?)(.*)';
my $doc_content = $doc_com_body . '(.*)';
my $doc_block = $doc_com . 'DOC:\s*(.*)?';
my $doc_inline_start = '^\s*/\*\*\s*$';
@@ -1952,11 +1952,22 @@ sub process_body($$) {
++$warnings;
}
}
-
+ # $doc_sect is a regex which searches for section names.
+ # If it matches:
+ # $1 is the section name
+ # $2 is a colon if the section name was followed by a double colon.
+ # $3 is the rest of the content after the colon (or double colon).
if (/$doc_sect/i) { # case insensitive for supported section names
$newsection = $1;
- $newcontents = $2;
-
+ # If $2 is ':', the section name was followed by a double
+ # colon, so insert a line containing just '::' to make the
+ # following block into a ReST literal. This idiom is useful
+ # for an Example section introducing a code snippet.
+ if ($2 eq ':') {
+ $newcontents = "::\n" . $3;
+ } else {
+ $newcontents = $3;
+ }
# map the supported section names to the canonical names
if ($newsection =~ m/^description$/i) {
$newsection = $section_default;
--
2.25.1
next prev parent reply other threads:[~2020-03-26 19:52 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-11 19:22 [PATCH 0/1] Format kerneldoc code snippets as literal block peter
2020-03-11 19:22 ` [PATCH 1/1] Added double colons and blank lines within kerneldoc to format code snippets as ReST literal blocks peter
2020-03-11 19:30 ` Jonathan Corbet
2020-03-26 19:16 ` [PATCH v2 0/1] Compactly make code examples into " peter
2020-03-26 19:16 ` [PATCH v2 1/1] A compact idiom to add code examples in kerneldoc comments peter
2020-03-26 19:29 ` Matthew Wilcox
2020-03-26 19:36 ` Peter Lister
2020-03-26 19:51 ` [PATCH v3 0/1] Compactly make code examples into literal blocks peter
2020-03-26 19:51 ` peter [this message]
2020-03-26 19:54 ` [PATCH v3 1/1] A compact idiom to add code examples in kerneldoc comments Matthew Wilcox
2020-03-27 6:32 ` Greg Kroah-Hartman
2020-03-27 11:28 ` [PATCH v3 0/1] Compactly make code examples into literal blocks Jani Nikula
2020-03-27 16:41 ` Jonathan Corbet
2020-03-27 16:50 ` Matthew Wilcox
2020-03-27 17:11 ` Jonathan Corbet
2020-03-27 17:35 ` Matthew Wilcox
2020-03-31 11:22 ` Jani Nikula
2020-03-31 10:50 ` Jani Nikula
2020-03-30 22:29 ` Peter Lister
2020-03-30 22:32 ` Jonathan Corbet
2020-03-31 11:54 ` Jani Nikula
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=20200326195156.11858-2-peter@bikeshed.quignogs.org.uk \
--to=peter@bikeshed.quignogs.org.uk \
--cc=corbet@lwn.net \
--cc=gregkh@linuxfoundation.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rafael@kernel.org \
--cc=willy@infradead.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).