[PATCH 2 of 2 STABLE] Consistent help text formatting (indentation)

Matt Mackall mpm at selenic.com
Mon Jan 9 20:45:00 CST 2012


On Mon, 2012-01-09 at 17:31 +0100, Olav Reinert wrote:
> # HG changeset patch
> # User Olav Reinert <seroton10 at gmail.com>
> # Date 1326126555 -3600
> # Node ID dcd680d8410b6a1b4c9f6ef67271ec4789f5e34c
> # Parent  c9f8671b5081abd8891dd8d78ded241ae1c491db
> Consistent help text formatting (indentation)

(FYI, I think it's great that you're furthering the job I started of
doiing more RSTification of the built-in help)

> diff -r c9f8671b5081 -r dcd680d8410b mercurial/commands.py
> --- a/mercurial/commands.py	Mon Jan 09 17:28:49 2012 +0100
> +++ b/mercurial/commands.py	Mon Jan 09 17:29:15 2012 +0100
> @@ -3145,27 +3145,29 @@
>          ui.status(header)
>          fns = sorted(h)
>          m = max(map(len, fns))
> +        topics = []
>          for f in fns:
>              if ui.verbose:
>                  commands = cmds[f].replace("|",", ")
> -                ui.write(" %s:\n      %s\n"%(commands, h[f]))
> +                topics.append(commands+':')

Spaces around operators, please.

> +                topics.append('     '+h[f])
>              else:
> -                ui.write('%s\n' % (util.wrap(h[f], textwidth,
> -                                             initindent=' %-*s   ' % (m, f),
> -                                             hangindent=' ' * (m + 4))))
> +                topics.append(":%s: %s" % (f, h[f]))
> +        rstopt = { 'fieldshrink':False, 'fieldwidth':13, 'definitionmargin':False }

Where did 13 come from?

What's wrong with the output without these formatting hints?

> +        ui.write(minirst.format("\n".join(topics), textwidth, 1, **rstopt))
>  
>          if not name:
> -            text = help.listexts(_('enabled extensions:'), extensions.enabled())
> -            if text:
> -                ui.write("\n%s" % minirst.format(text, textwidth))
> +            extlist = help.listexts(extensions.enabled())
> +            if extlist:
> +                ui.write('\n%s\n\n' % _('enabled extensions:'))
> +                ui.write(minirst.format(extlist, textwidth, 1, **rstopt))

Ideally we generate the output by generating one large RST text and
doing one large format + write. That way when we finally implement 'hg
help --html/--rst', it just works. Also, this is what the web interface
will eventually want.

-- 
Mathematics is the supreme nostalgia of our time.




More information about the Mercurial-devel mailing list