[PATCH 1 of 2] patch: enable diff.tab markup for the color extension

Jordi Gutiérrez Hermoso jordigh at octave.org
Wed Aug 20 14:24:28 CDT 2014


# HG changeset patch
# User Jordi Gutiérrez Hermoso <jordigh at octave.org>
# Date 1408562150 14400
#      Wed Aug 20 15:15:50 2014 -0400
# Node ID b58e6a9a966a2ae349db1af92943d2bc8898aa06
# Parent  de783f2403c498ef1e20121acf178b32ec27199c
patch: enable diff.tab markup for the color extension

The following patch splits up changed lines along tabs (using
re.findall), and gives them a "diff.tab" label. This can be used by
the color extension for colorising tabs, like it does right now with
trailing whitespace.

diff --git a/mercurial/patch.py b/mercurial/patch.py
--- a/mercurial/patch.py
+++ b/mercurial/patch.py
@@ -18,6 +18,7 @@ from node import hex, short
 import base85, mdiff, scmutil, util, diffhelpers, copies, encoding, error
 
 gitre = re.compile('diff --git a/(.*) b/(.*)')
+tabsplitter = re.compile(r'(\t+|[^\t]+)')
 
 class PatchError(Exception):
     pass
@@ -1669,15 +1670,26 @@ def difflabel(func, *args, **kw):
                 if line and line[0] not in ' +-@\\':
                     head = True
             stripline = line
+            showtabs = False
             if not head and line and line[0] in '+-':
-                # highlight trailing whitespace, but only in changed lines
+                # highlight tabs and trailing whitespace, but only in
+                # changed lines
                 stripline = line.rstrip()
+                showtabs = True
+
             prefixes = textprefixes
             if head:
                 prefixes = headprefixes
             for prefix, label in prefixes:
                 if stripline.startswith(prefix):
-                    yield (stripline, label)
+                    if showtabs:
+                        for token in tabsplitter.findall(stripline):
+                            if token == '\t':
+                                yield (token, 'diff.tab')
+                            else:
+                                yield (token, label)
+                    else:
+                        yield (stripline, label)
                     break
             else:
                 yield (line, '')


More information about the Mercurial-devel mailing list