[PATCH] templater: introduce indent function

Durham Goode durham at fb.com
Fri Apr 10 14:44:35 CDT 2015



On 4/9/15 11:18 PM, Ryan McElroy wrote:
> On 4/4/2015 1:31 PM, Durham Goode wrote:
>>
>>
>> On 4/4/15 1:19 AM, 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"
>>> +    """
>> Why doesn't it indent the first line?
> For consistency with tabindent, and because I call the same function 
> as tabindent, which works this way. The reasoning, I suppose, is that 
> one can always indent the first line without a function by simply 
> adding spaces or tabs inside the template.
Looks like the tabindent functionality was added in Mar 2006.  I'd vote 
to have indent() indent every line.  This is a chance to remove one more 
anachronism from the code base as we move away from template filters.

If people need the ability to skip only certain lines, we can add an 
optional arg to indent() later.


More information about the Mercurial-devel mailing list