[PATCH] templater: introduce indent function

Yuya Nishihara yuya at tcha.org
Sat Apr 4 08:23:23 CDT 2015


On Sat, 4 Apr 2015 01:19:52 -0700, Ryan McElroy wrote:
> # HG changeset patch
> # User Ryan McElroy <rmcelroy at fb.com>
> # Date 1428134632 25200
> #      Sat Apr 04 01:03:52 2015 -0700
> # Node ID e2af17e4887916089a49b2d3331a725c840fbce6
> # Parent  4a4018831d2ebc3c9cae9c6613e6a2497b4f0993
> templater: introduce indent function
> 
> diff --git a/mercurial/templater.py b/mercurial/templater.py
> --- a/mercurial/templater.py
> +++ b/mercurial/templater.py
> @@ -301,6 +301,20 @@ def pad(context, mapping, args):
>      else:
>          return text.ljust(width, fillchar)
>  
> +def indent(context, mapping, args):
> +    """:indent(text, indentchars): Indents all non-empty lines except the first
> +    with the characters given in the indentchars string.
> +    Example: indent('hello\\nworld', '    ') == "hello\\n    world"
> +    """
> +    if len(args) != 2:
> +        # i18n: "indent" is a keyword
> +        raise error.ParseError(_("indent() expects two arguments"))
> +
> +    text = args[0][0](context, mapping, args[0][1])
> +    indent = args[1][0](context, mapping, args[1][1])

They'll need stringify() to evaluate generator and avoid TypeError.

  {indent(sub(desc, "foo", "bar"), "  ")}
  {indent(date, "  ")}

Regards,


More information about the Mercurial-devel mailing list