From patchwork Thu Feb 20 17:04:44 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [4, of, 4] doc: gendoc.py writes option descriptions with indentation after newlines From: Simon Heimberg X-Patchwork-Id: 3725 Message-Id: To: Mercurial-devel Date: Thu, 20 Feb 2014 18:04:44 +0100 # HG changeset patch # User Simon Heimberg # Date 1392884245 -3600 # Thu Feb 20 09:17:25 2014 +0100 # Node ID bb89d555d7d371d6d731f5a19e91a44d26cec744 # Parent 8e19fd0d5ec2a8dc9c361bcecab020fa400a1256 doc: gendoc.py writes option descriptions with indentation after newlines Alternative to the simple handling in the previous patch. The output now looks like this: -o, --option desc line 1 desc line 2 instead of: -o, --option desc line 1 desc line 2 But in the final output, this does not make any difference. A single line break is not a new paragraph, it is only for the writer. Breaking lines at the page limit is handled by html/man/... diff -r 8e19fd0d5ec2 -r bb89d555d7d3 doc/gendoc.py --- a/doc/gendoc.py Thu Feb 20 16:13:23 2014 +0100 +++ b/doc/gendoc.py Thu Feb 20 09:17:25 2014 +0100 @@ -50,9 +50,6 @@ allopts[-1] += " <%s[+]>" % optlabel elif (default is not None) and not isinstance(default, bool): allopts[-1] += " <%s>" % optlabel - if '\n' in desc: - # only remove line breaks and indentation - desc = ' '.join(l.lstrip() for l in desc.split('\n')) desc += default and _(" (default: %s)") % default or "" yield (", ".join(allopts), desc) @@ -91,7 +88,8 @@ desc for e -s, --some - a description on several lines (default: True) + a description + on several lines (default: True) Commands ... @@ -100,7 +98,14 @@ ui.write(minirst.section(_("Options"))) multioccur = False for optstr, desc in get_opts(globalopts): - ui.write("%s\n %s\n\n" % (optstr, desc)) + if '\n' in desc: # desc may have multiple lines + lines = desc.split('\n') + ui.write("%s\n %s\n" % (optstr, lines[0])) + for line in lines[1:]: + ui.write(" %s\n" % line) + ui.write("\n") + else: + ui.write("%s\n %s\n\n" % (optstr, desc)) if optstr.endswith("[+]>"): multioccur = True if multioccur: @@ -181,7 +186,8 @@ Options: - -o, --opt this is a long description with several lines (default: 3) + -o, --opt this is a long description + with several lines (default: 3) --p desc for p """ @@ -216,7 +222,12 @@ ui.write(_("Options:\n\n")) multioccur = False for optstr, desc in opt_output: - if desc: + if '\n' in desc: # desc may have multiple lines + lines = desc.split('\n') + s = "%-*s %s" % (opts_len, optstr, lines[0] + '\n') + for line in lines[1:]: + s += "%s %s" % (' ' * opts_len, line.lstrip(' ') + '\n') + elif desc: s = "%-*s %s" % (opts_len, optstr, desc) else: s = optstr