[PATCH v2] templater: add separate() template function

Martin von Zweigbergk martinvonz at google.com
Thu May 5 14:23:12 UTC 2016


Sorry, s/do support/drop support/

On Thu, May 5, 2016, 07:22 Martin von Zweigbergk <martinvonz at google.com>
wrote:

> I'm tempted to just do support for list arguments and let the user use
> join() for those. What do others think? Matt?
>
> On Thu, May 5, 2016, 00:24 Yuya Nishihara <yuya at tcha.org> wrote:
>
>> On Thu, 05 May 2016 04:36:14 +0000, Martin von Zweigbergk wrote:
>> > On Wed, May 4, 2016 at 8:51 PM Yuya Nishihara <yuya at tcha.org> wrote:
>> > > On Thu, 05 May 2016 03:19:35 +0000, Martin von Zweigbergk wrote:
>> > > > Perhaps we can extend join() after all. When given at least 3
>> arguments,
>> > > > the last one can still be the separator and the ones before it are
>> the
>> > > > items to separate. It's a little weird to have the separator last,
>> but it
>> > > > does avoid the need for a new name. Thoughts?
>> > >
>> > > or introduce a list constructor?
>> > >
>> > >   join(items(node, bookmarks, tags), " ")
>> > >   items(node, bookmarks, tags) % "{item} "
>> > >
>> > > No idea if it should implicitly drop empty items.
>> >
>> > Right, I just remembered that point too. So a new function is probably
>> best.
>> >
>> > So the difference between your proposal and Matt's is when two arguments
>> > are given and the second one is not a list, for example:
>> >
>> > separate(" ", rev)
>> > separate(" ", branch)
>> >
>> > With Matt's proposal, they would be allowed (and pointless) and with
>> your
>> > proposal they would be disallowed. Although pointless, I think it's a
>> small
>> > win that separate(" ", rev, branch) can be simplified into one of the
>> above
>> > and still work without forcing the user to clean it up by dropping the
>> call
>> > to separate. Perhaps the user has a group of similar calls and wants to
>> > keep the separate() for consistency.
>> >
>> > Also note that, with either proposal, these two behave quite
>> differently:
>> >
>> > separate(":", node, branches)
>> > separate(":", branches)
>>
>> Yeah, that's one reason I insist that separate(":", rev) should be
>> disallowed.
>> If both separate(":", rev) and separate(":", branches) are allowed, I
>> would
>> expect that separate() is the function to flatten lists.
>>
>>   separate(":", rev)             # {rev}
>>   separate(":", branches)        # {branch0}:{branch1}
>>   separate(":", branches, tags)  # {branch0}:{branch1}:{tag0}:{tag1}
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurial-scm.org/pipermail/mercurial-devel/attachments/20160505/48650411/attachment-0002.html>


More information about the Mercurial-devel mailing list