Fwd: [PATCH] Added template filter for converting white spaces to a newline

Doug Simon Doug.Simon at sun.com
Fri Oct 10 12:05:11 CDT 2008


I'm sending this to the mercurial-devel list upon request.

To address an issue raised on the mercurial at selenic list,
I'm aware that this patch has the downside of not dealing with
embedded spaces in file names very well. However, the output of the
{files} template keyword has already lost the distinction between
a space separator between file names and spaces embedded in file
names. That is, somewhat contrary to the documentation in hgbook.pdf,
{files} generates a single string of space separated file names,
*not* a list of strings. Given that (and my lack of knowledge about  
Python),
I can't see a way to handle file names with embedded spaces.

Begin forwarded message:

From: Doug Simon <Doug.Simon at sun.com>
Date: October 9, 2008 3:34:08 PM PDT
To: mercurial at selenic.com
Subject: [PATCH] Added template filter for converting white spaces to  
a newline


# HG changeset patch
# User Doug Simon <doug.simon at sun.com>
# Date 1223590072 25200
# Node ID 51dcd360b16d8eca3f54e147f6ac5c96f2c2091c
# Parent  643c751e60b248e4672f53633e040929f8041dc0
Added template filter for converting white spaces to a newline.

This patch adds a 'ws2nl' template filter that converts one or more
adjacent white spaces characters to a single newline character. This
makes it possible to apply newline based filters to template keywords
that generate a list of strings. For example, to show each file modified
in a changeset, one line per file, the following can be used in a
template:

     \t{files|stringify|ws2nl|tabindent}\n

diff -r 643c751e60b2 -r 51dcd360b16d mercurial/templatefilters.py
--- a/mercurial/templatefilters.py	Wed Oct 08 19:58:35 2008 -0500
+++ b/mercurial/templatefilters.py	Thu Oct 09 15:07:52 2008 -0700
@@ -175,6 +175,7 @@
     "short": lambda x: x[:12],
     "shortdate": util.shortdate,
     "stringify": templater.stringify,
+    "ws2nl": lambda x: re.sub('\s+', '\n', x),
     "strip": lambda x: x.strip(),
     "urlescape": lambda x: urllib.quote(x),
     "user": lambda x: util.shortuser(x),

_______________________________________________
Mercurial mailing list
Mercurial at selenic.com
http://selenic.com/mailman/listinfo/mercurial



More information about the Mercurial-devel mailing list