From patchwork Wed Aug 20 19:24:28 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [1,of,2] patch: enable diff.tab markup for the color extension From: =?utf-8?q?Jordi_Guti=C3=A9rrez_Hermoso?= X-Patchwork-Id: 5533 Message-Id: To: mercurial-devel@selenic.com Date: Wed, 20 Aug 2014 15:24:28 -0400 # HG changeset patch # User Jordi GutiƩrrez Hermoso # 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, '')