Skip to content

Commit ddeaf8f

Browse files
committed
tools/format-changelog: Upgrade line-unwrapping to handle nested lists
The `fmt` tool from GNU coreutils is very simple, and doesn't have the needed configuration knobs to be able to handle the nested lists that we now routinely use in changelog entries; it ends up mangling them. As a result, for many recent releases I've been doing the reformatting semi-manually, in Emacs: M-q to unwrap lines (after setting the text width to 999), and then a regexp find-and-replace to turn references `#1234` into `#F1234`. It seems to be somewhat annoying to get Emacs to operate within a shell pipeline. But it's less annoying for Vim; and Vim's `gq` works just as well as Emacs's M-q, given the right config. So use that.
1 parent 690a0e5 commit ddeaf8f

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

tools/format-changelog

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,29 @@ extract_highlights() {
3131

3232
# Undo line-wrapping.
3333
unwrap() {
34-
fmt --tagged-paragraph --width=2000
34+
# Implemented by rewrapping paragraphs in Vim.
35+
# (Emacs works equally well, interactively; but seems more annoying
36+
# to integrate into a CLI pipeline.)
37+
38+
local vim_markdown_settings=/usr/share/vim/vim90/ftplugin/markdown.vim
39+
if [ ! -r "${vim_markdown_settings}" ]; then
40+
# On Debian, this file is installed by the package `vim-runtime`.
41+
# We can generalize this as needed to find where other systems put it.
42+
# Upstream is here:
43+
# https://github.com/tpope/vim-markdown/blob/f9f845f28/ftplugin/markdown.vim
44+
# The parts we actually use are the variables `comments`,
45+
# `formatoptions`, and `formatlistpat`.
46+
echo >&2 "error: Could not find spec for rewrapping Markdown."
47+
echo >&2 " See comments in the source code in tools/format-changelog."
48+
exit 1
49+
fi
50+
51+
# The Vim command "gq" rewraps paragraphs; "G" makes it do so
52+
# from the current point to the end, and "gg" first goes to the start.
53+
vim -es /dev/stdin \
54+
'+set textwidth=2000' \
55+
"+source ${vim_markdown_settings}" \
56+
'+normal gggqG' '+%print' '+:q!'
3557
}
3658

3759
# Print changelog entry, with line-wrapping removed.

0 commit comments

Comments
 (0)