[PATCH 1 of 2] templater: sort functions alphabetically, as filters are

Alexander Plavin me at aplavin.ru
Sat Jun 29 09:02:57 CDT 2013


# HG changeset patch
# User Alexander Plavin <me at aplavin.ru>
# Date 1372501673 -14400
#      Sat Jun 29 14:27:53 2013 +0400
# Node ID 7b9b339fa1ccb512aa220dbdf0c651c28d469317
# Parent  acf2c4e871322dee1f5eb05405ae17400148a95d
templater: sort functions alphabetically, as filters are

diff -r acf2c4e87132 -r 7b9b339fa1cc mercurial/help/templates.txt
--- a/mercurial/help/templates.txt	Tue Jun 25 21:02:22 2013 +0400
+++ b/mercurial/help/templates.txt	Sat Jun 29 14:27:53 2013 +0400
@@ -58,12 +58,12 @@
 
 - label(label, expr)
 
-- sub(pat, repl, expr)
-
 - rstdoc(text, style)
 
 - strip(text[, chars])
 
+- sub(pat, repl, expr)
+
 Also, for any expression that returns a list, there is a list operator:
 
 - expr % "{template}"
diff -r acf2c4e87132 -r 7b9b339fa1cc mercurial/templater.py
--- a/mercurial/templater.py	Tue Jun 25 21:02:22 2013 +0400
+++ b/mercurial/templater.py	Sat Jun 29 14:27:53 2013 +0400
@@ -205,6 +205,51 @@
         f = context._filters[n]
         return (runfilter, (args[0][0], args[0][1], f))
 
+methods = {
+    "string": lambda e, c: (runstring, e[1]),
+    "symbol": lambda e, c: (runsymbol, e[1]),
+    "group": lambda e, c: compileexp(e[1], c),
+#    ".": buildmember,
+    "|": buildfilter,
+    "%": buildmap,
+    "func": buildfunc,
+    }
+
+def date(context, mapping, args):
+    if not (1 <= len(args) <= 2):
+        raise error.ParseError(_("date expects one or two arguments"))
+
+    date = args[0][0](context, mapping, args[0][1])
+    if len(args) == 2:
+        fmt = stringify(args[1][0](context, mapping, args[1][1]))
+        return util.datestr(date, fmt)
+    return util.datestr(date)
+
+def fill(context, mapping, args):
+    if not (1 <= len(args) <= 4):
+        raise error.ParseError(_("fill expects one to four arguments"))
+
+    text = stringify(args[0][0](context, mapping, args[0][1]))
+    width = 76
+    initindent = ''
+    hangindent = ''
+    if 2 <= len(args) <= 4:
+        try:
+            width = int(stringify(args[1][0](context, mapping, args[1][1])))
+        except ValueError:
+            raise error.ParseError(_("fill expects an integer width"))
+        try:
+            initindent = stringify(args[2][0](context, mapping, args[2][1]))
+            initindent = stringify(runtemplate(context, mapping,
+                                     compiletemplate(initindent, context)))
+            hangindent = stringify(args[3][0](context, mapping, args[3][1]))
+            hangindent = stringify(runtemplate(context, mapping,
+                                     compiletemplate(hangindent, context)))
+        except IndexError:
+            pass
+
+    return templatefilters.fill(text, width, initindent, hangindent)
+
 def get(context, mapping, args):
     if len(args) != 2:
         # i18n: "get" is a keyword
@@ -218,40 +263,6 @@
     key = args[1][0](context, mapping, args[1][1])
     yield dictarg.get(key)
 
-def join(context, mapping, args):
-    if not (1 <= len(args) <= 2):
-        # i18n: "join" is a keyword
-        raise error.ParseError(_("join expects one or two arguments"))
-
-    joinset = args[0][0](context, mapping, args[0][1])
-    if util.safehasattr(joinset, '__call__'):
-        jf = joinset.joinfmt
-        joinset = [jf(x) for x in joinset()]
-
-    joiner = " "
-    if len(args) > 1:
-        joiner = args[1][0](context, mapping, args[1][1])
-
-    first = True
-    for x in joinset:
-        if first:
-            first = False
-        else:
-            yield joiner
-        yield x
-
-def sub(context, mapping, args):
-    if len(args) != 3:
-        # i18n: "sub" is a keyword
-        raise error.ParseError(_("sub expects three arguments"))
-
-    pat = stringify(args[0][0](context, mapping, args[0][1]))
-    rpl = stringify(args[1][0](context, mapping, args[1][1]))
-    src = stringify(args[2][0](context, mapping, args[2][1]))
-    src = stringify(runtemplate(context, mapping,
-                                compiletemplate(src, context)))
-    yield re.sub(pat, rpl, src)
-
 def if_(context, mapping, args):
     if not (2 <= len(args) <= 3):
         # i18n: "if" is a keyword
@@ -279,6 +290,28 @@
         t = stringify(args[3][0](context, mapping, args[3][1]))
         yield runtemplate(context, mapping, compiletemplate(t, context))
 
+def join(context, mapping, args):
+    if not (1 <= len(args) <= 2):
+        # i18n: "join" is a keyword
+        raise error.ParseError(_("join expects one or two arguments"))
+
+    joinset = args[0][0](context, mapping, args[0][1])
+    if util.safehasattr(joinset, '__call__'):
+        jf = joinset.joinfmt
+        joinset = [jf(x) for x in joinset()]
+
+    joiner = " "
+    if len(args) > 1:
+        joiner = args[1][0](context, mapping, args[1][1])
+
+    first = True
+    for x in joinset:
+        if first:
+            first = False
+        else:
+            yield joiner
+        yield x
+
 def label(context, mapping, args):
     if len(args) != 2:
         # i18n: "label" is a keyword
@@ -298,41 +331,6 @@
 
     return minirst.format(text, style=style, keep=['verbose'])
 
-def fill(context, mapping, args):
-    if not (1 <= len(args) <= 4):
-        raise error.ParseError(_("fill expects one to four arguments"))
-
-    text = stringify(args[0][0](context, mapping, args[0][1]))
-    width = 76
-    initindent = ''
-    hangindent = ''
-    if 2 <= len(args) <= 4:
-        try:
-            width = int(stringify(args[1][0](context, mapping, args[1][1])))
-        except ValueError:
-            raise error.ParseError(_("fill expects an integer width"))
-        try:
-            initindent = stringify(args[2][0](context, mapping, args[2][1]))
-            initindent = stringify(runtemplate(context, mapping,
-                                     compiletemplate(initindent, context)))
-            hangindent = stringify(args[3][0](context, mapping, args[3][1]))
-            hangindent = stringify(runtemplate(context, mapping,
-                                     compiletemplate(hangindent, context)))
-        except IndexError:
-            pass
-
-    return templatefilters.fill(text, width, initindent, hangindent)
-
-def date(context, mapping, args):
-    if not (1 <= len(args) <= 2):
-        raise error.ParseError(_("date expects one or two arguments"))
-
-    date = args[0][0](context, mapping, args[0][1])
-    if len(args) == 2:
-        fmt = stringify(args[1][0](context, mapping, args[1][1]))
-        return util.datestr(date, fmt)
-    return util.datestr(date)
-
 def strip(context, mapping, args):
     if not (1 <= len(args) <= 2):
         raise error.ParseError(_("strip expects one or two arguments"))
@@ -343,27 +341,29 @@
         return text.strip(chars)
     return text.strip()
 
-methods = {
-    "string": lambda e, c: (runstring, e[1]),
-    "symbol": lambda e, c: (runsymbol, e[1]),
-    "group": lambda e, c: compileexp(e[1], c),
-#    ".": buildmember,
-    "|": buildfilter,
-    "%": buildmap,
-    "func": buildfunc,
-    }
+def sub(context, mapping, args):
+    if len(args) != 3:
+        # i18n: "sub" is a keyword
+        raise error.ParseError(_("sub expects three arguments"))
+
+    pat = stringify(args[0][0](context, mapping, args[0][1]))
+    rpl = stringify(args[1][0](context, mapping, args[1][1]))
+    src = stringify(args[2][0](context, mapping, args[2][1]))
+    src = stringify(runtemplate(context, mapping,
+                                compiletemplate(src, context)))
+    yield re.sub(pat, rpl, src)
 
 funcs = {
+    "date": date,
+    "fill": fill,
     "get": get,
     "if": if_,
     "ifeq": ifeq,
     "join": join,
     "label": label,
     "rstdoc": rstdoc,
+    "strip": strip,
     "sub": sub,
-    "fill": fill,
-    "date": date,
-    "strip": strip,
 }
 
 # template engine


More information about the Mercurial-devel mailing list