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

Pierre-Yves David pierre-yves.david at ens-lyon.org
Wed Sep 17 18:54:14 CDT 2014



On 08/24/2014 03:22 PM, Jordi Gutiérrez Hermoso wrote:
> # 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 a028ddacb2daea2b4fe1db75f76f5ca0305f41c6
> # Parent  9d81f3c34b9fa408901c1b0362dd3a891639dee7
> patch: enable diff.tab markup for the color extension

pushed to the clowncopter with a minor fix (see below)

> 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.
>
> I also provide corresponding tests.
>
> 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
> +            diffline = 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()
> +                diffline = True
> +
>               prefixes = textprefixes
>               if head:
>                   prefixes = headprefixes
>               for prefix, label in prefixes:
>                   if stripline.startswith(prefix):
> -                    yield (stripline, label)
> +                    if diffline:
> +                        for token in tabsplitter.findall(stripline):
> +                            if '\t' in token:

I changed this line:

-                            if '\t' in token:
+                            if '\t' == token[0]:


-- 
Pierre-Yves David


More information about the Mercurial-devel mailing list