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

Yuya Nishihara yuya at tcha.org
Thu May 5 03:22:51 EDT 2016


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}


More information about the Mercurial-devel mailing list