Submitter | Sean Farley |
---|---|
Date | Jan. 9, 2013, 6:12 p.m. |
Message ID | <f8098885faa0fa09c8a9.1357755160@laptop.local> |
Download | mbox | patch |
Permalink | /patch/512/ |
State | Rejected |
Headers | show |
Comments
On Wed, 2013-01-09 at 12:12 -0600, Sean Farley wrote: > # HG changeset patch > # User Sean Farley <sean.michael.farley@gmail.com> > # Date 1357671975 21600 > # Node ID f8098885faa0fa09c8a9cfc887d807fa3c140cf4 > # Parent e9a1700097f2e520b5b0773f902cb92fe7af99ae > templaterfilters: add 'newline' filter We've got things like if() and sub() now, so we shouldn't need to add more special-purpose filters like this. $ hg tip --template '{if(author, "{author}\n")}' Matt Mackall <mpm@selenic.com>
On Wed, Jan 9, 2013 at 2:09 PM, Matt Mackall <mpm@selenic.com> wrote: > On Wed, 2013-01-09 at 12:12 -0600, Sean Farley wrote: >> # HG changeset patch >> # User Sean Farley <sean.michael.farley@gmail.com> >> # Date 1357671975 21600 >> # Node ID f8098885faa0fa09c8a9cfc887d807fa3c140cf4 >> # Parent e9a1700097f2e520b5b0773f902cb92fe7af99ae >> templaterfilters: add 'newline' filter > > We've got things like if() and sub() now, so we shouldn't need to add > more special-purpose filters like this. > > $ hg tip --template '{if(author, "{author}\n")}' > Matt Mackall <mpm@selenic.com> That's true. I'll drop this patch series. Also, I just figured out how to do 'notfirstname' with sub(). For those wondering, I was able to use sub(r'^.*\n?\n?', '', desc).
On Thu, 2013-01-17 at 12:36 -0600, Sean Farley wrote: > On Wed, Jan 9, 2013 at 2:09 PM, Matt Mackall <mpm@selenic.com> wrote: > > On Wed, 2013-01-09 at 12:12 -0600, Sean Farley wrote: > >> # HG changeset patch > >> # User Sean Farley <sean.michael.farley@gmail.com> > >> # Date 1357671975 21600 > >> # Node ID f8098885faa0fa09c8a9cfc887d807fa3c140cf4 > >> # Parent e9a1700097f2e520b5b0773f902cb92fe7af99ae > >> templaterfilters: add 'newline' filter > > > > We've got things like if() and sub() now, so we shouldn't need to add > > more special-purpose filters like this. > > > > $ hg tip --template '{if(author, "{author}\n")}' > > Matt Mackall <mpm@selenic.com> > > That's true. I'll drop this patch series. Also, I just figured out how > to do 'notfirstname' with sub(). For those wondering, I was able to > use sub(r'^.*\n?\n?', '', desc). Feel free to add examples to the template page.
On Thu, Jan 17, 2013 at 12:41 PM, Matt Mackall <mpm@selenic.com> wrote: > On Thu, 2013-01-17 at 12:36 -0600, Sean Farley wrote: >> On Wed, Jan 9, 2013 at 2:09 PM, Matt Mackall <mpm@selenic.com> wrote: >> > On Wed, 2013-01-09 at 12:12 -0600, Sean Farley wrote: >> >> # HG changeset patch >> >> # User Sean Farley <sean.michael.farley@gmail.com> >> >> # Date 1357671975 21600 >> >> # Node ID f8098885faa0fa09c8a9cfc887d807fa3c140cf4 >> >> # Parent e9a1700097f2e520b5b0773f902cb92fe7af99ae >> >> templaterfilters: add 'newline' filter >> > >> > We've got things like if() and sub() now, so we shouldn't need to add >> > more special-purpose filters like this. >> > >> > $ hg tip --template '{if(author, "{author}\n")}' >> > Matt Mackall <mpm@selenic.com> >> >> That's true. I'll drop this patch series. Also, I just figured out how >> to do 'notfirstname' with sub(). For those wondering, I was able to >> use sub(r'^.*\n?\n?', '', desc). > > Feel free to add examples to the template page. Brilliant!
On Thu, Jan 17, 2013 at 12:41 PM, Matt Mackall <mpm@selenic.com> wrote: > On Thu, 2013-01-17 at 12:36 -0600, Sean Farley wrote: >> On Wed, Jan 9, 2013 at 2:09 PM, Matt Mackall <mpm@selenic.com> wrote: >> > On Wed, 2013-01-09 at 12:12 -0600, Sean Farley wrote: >> >> # HG changeset patch >> >> # User Sean Farley <sean.michael.farley@gmail.com> >> >> # Date 1357671975 21600 >> >> # Node ID f8098885faa0fa09c8a9cfc887d807fa3c140cf4 >> >> # Parent e9a1700097f2e520b5b0773f902cb92fe7af99ae >> >> templaterfilters: add 'newline' filter >> > >> > We've got things like if() and sub() now, so we shouldn't need to add >> > more special-purpose filters like this. >> > >> > $ hg tip --template '{if(author, "{author}\n")}' >> > Matt Mackall <mpm@selenic.com> >> >> That's true. I'll drop this patch series. Also, I just figured out how >> to do 'notfirstname' with sub(). For those wondering, I was able to >> use sub(r'^.*\n?\n?', '', desc). > > Feel free to add examples to the template page. Just to make sure, you're talking about this page, http://mercurial.selenic.com/wiki/TemplateFilters correct?
On Thu, 2013-01-17 at 21:11 -0600, Sean Farley wrote: > On Thu, Jan 17, 2013 at 12:41 PM, Matt Mackall <mpm@selenic.com> wrote: > > On Thu, 2013-01-17 at 12:36 -0600, Sean Farley wrote: > >> On Wed, Jan 9, 2013 at 2:09 PM, Matt Mackall <mpm@selenic.com> wrote: > >> > On Wed, 2013-01-09 at 12:12 -0600, Sean Farley wrote: > >> >> # HG changeset patch > >> >> # User Sean Farley <sean.michael.farley@gmail.com> > >> >> # Date 1357671975 21600 > >> >> # Node ID f8098885faa0fa09c8a9cfc887d807fa3c140cf4 > >> >> # Parent e9a1700097f2e520b5b0773f902cb92fe7af99ae > >> >> templaterfilters: add 'newline' filter > >> > > >> > We've got things like if() and sub() now, so we shouldn't need to add > >> > more special-purpose filters like this. > >> > > >> > $ hg tip --template '{if(author, "{author}\n")}' > >> > Matt Mackall <mpm@selenic.com> > >> > >> That's true. I'll drop this patch series. Also, I just figured out how > >> to do 'notfirstname' with sub(). For those wondering, I was able to > >> use sub(r'^.*\n?\n?', '', desc). > > > > Feel free to add examples to the template page. > > Just to make sure, you're talking about this page, > > http://mercurial.selenic.com/wiki/TemplateFilters > > correct? Actually, I was talking about 'hg help templates'. Things that are as yet undocumented: if(expr, then[, else]) ifeq(expr, expr, then[, else]) sub(pat, repl, expr) join(list, sep) label(label, expr) date(date[, fmt]) fill(text[, width]) expr % "{template}" expr|filter -> filter(expr) The most frequently asked question is how to format lists like files. Previously, this required writing a style file, but can now be done with something like: $ hg log --template "{files % '{rev}: {file}\n'}"
On Fri, Jan 18, 2013 at 12:12 PM, Matt Mackall <mpm@selenic.com> wrote: > On Thu, 2013-01-17 at 21:11 -0600, Sean Farley wrote: >> On Thu, Jan 17, 2013 at 12:41 PM, Matt Mackall <mpm@selenic.com> wrote: >> > On Thu, 2013-01-17 at 12:36 -0600, Sean Farley wrote: >> >> On Wed, Jan 9, 2013 at 2:09 PM, Matt Mackall <mpm@selenic.com> wrote: >> >> > On Wed, 2013-01-09 at 12:12 -0600, Sean Farley wrote: >> >> >> # HG changeset patch >> >> >> # User Sean Farley <sean.michael.farley@gmail.com> >> >> >> # Date 1357671975 21600 >> >> >> # Node ID f8098885faa0fa09c8a9cfc887d807fa3c140cf4 >> >> >> # Parent e9a1700097f2e520b5b0773f902cb92fe7af99ae >> >> >> templaterfilters: add 'newline' filter >> >> > >> >> > We've got things like if() and sub() now, so we shouldn't need to add >> >> > more special-purpose filters like this. >> >> > >> >> > $ hg tip --template '{if(author, "{author}\n")}' >> >> > Matt Mackall <mpm@selenic.com> >> >> >> >> That's true. I'll drop this patch series. Also, I just figured out how >> >> to do 'notfirstname' with sub(). For those wondering, I was able to >> >> use sub(r'^.*\n?\n?', '', desc). >> > >> > Feel free to add examples to the template page. >> >> Just to make sure, you're talking about this page, >> >> http://mercurial.selenic.com/wiki/TemplateFilters >> >> correct? > > Actually, I was talking about 'hg help templates'. > > Things that are as yet undocumented: > > if(expr, then[, else]) > ifeq(expr, expr, then[, else]) > sub(pat, repl, expr) > join(list, sep) > label(label, expr) > date(date[, fmt]) > fill(text[, width]) > > expr % "{template}" > expr|filter -> filter(expr) > > > The most frequently asked question is how to format lists like files. > Previously, this required writing a style file, but can now be done with > something like: > > $ hg log --template "{files % '{rev}: {file}\n'}" Aha, I was confused by the use of "page," but I'm with you now. I'll try to whip up some documentation patches this afternoon.
Patch
diff --git a/mercurial/templatefilters.py b/mercurial/templatefilters.py --- a/mercurial/templatefilters.py +++ b/mercurial/templatefilters.py @@ -130,10 +130,16 @@ def fill76(text): """:fill76: Any text. Wraps the text to fit in 76 columns.""" return fill(text, 76) +def newline(text): + """:newline: Any text. If text is not empty, append \r\n.""" + if text: + text += '\r\n' + return text + def firstline(text): """:firstline: Any text. Returns the first line of text.""" try: return text.splitlines(True)[0].rstrip('\r\n') except IndexError: @@ -374,10 +380,11 @@ "isodate": isodate, "isodatesec": isodatesec, "json": json, "jsonescape": jsonescape, "localdate": localdate, + "newline": newline, "nonempty": nonempty, "notfirstline": notfirstline, "obfuscate": obfuscate, "permissions": permissions, "person": person,