Mercurial > public > mercurial-scm > hg
comparison mercurial/patch.py @ 22460:c343557a8442
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.
I also provide corresponding tests.
author | Jordi Guti?rrez Hermoso <jordigh@octave.org> |
---|---|
date | Wed, 20 Aug 2014 15:15:50 -0400 |
parents | 650b5b6e75ed |
children | ac072c79bd9d |
comparison
equal
deleted
inserted
replaced
22459:0c7b018d3258 | 22460:c343557a8442 |
---|---|
16 from i18n import _ | 16 from i18n import _ |
17 from node import hex, short | 17 from node import hex, short |
18 import base85, mdiff, scmutil, util, diffhelpers, copies, encoding, error | 18 import base85, mdiff, scmutil, util, diffhelpers, copies, encoding, error |
19 | 19 |
20 gitre = re.compile('diff --git a/(.*) b/(.*)') | 20 gitre = re.compile('diff --git a/(.*) b/(.*)') |
21 tabsplitter = re.compile(r'(\t+|[^\t]+)') | |
21 | 22 |
22 class PatchError(Exception): | 23 class PatchError(Exception): |
23 pass | 24 pass |
24 | 25 |
25 | 26 |
1671 head = False | 1672 head = False |
1672 else: | 1673 else: |
1673 if line and line[0] not in ' +-@\\': | 1674 if line and line[0] not in ' +-@\\': |
1674 head = True | 1675 head = True |
1675 stripline = line | 1676 stripline = line |
1677 diffline = False | |
1676 if not head and line and line[0] in '+-': | 1678 if not head and line and line[0] in '+-': |
1677 # highlight trailing whitespace, but only in changed lines | 1679 # highlight tabs and trailing whitespace, but only in |
1680 # changed lines | |
1678 stripline = line.rstrip() | 1681 stripline = line.rstrip() |
1682 diffline = True | |
1683 | |
1679 prefixes = textprefixes | 1684 prefixes = textprefixes |
1680 if head: | 1685 if head: |
1681 prefixes = headprefixes | 1686 prefixes = headprefixes |
1682 for prefix, label in prefixes: | 1687 for prefix, label in prefixes: |
1683 if stripline.startswith(prefix): | 1688 if stripline.startswith(prefix): |
1684 yield (stripline, label) | 1689 if diffline: |
1690 for token in tabsplitter.findall(stripline): | |
1691 if '\t' == token[0]: | |
1692 yield (token, 'diff.tab') | |
1693 else: | |
1694 yield (token, label) | |
1695 else: | |
1696 yield (stripline, label) | |
1685 break | 1697 break |
1686 else: | 1698 else: |
1687 yield (line, '') | 1699 yield (line, '') |
1688 if line != stripline: | 1700 if line != stripline: |
1689 yield (line[len(stripline):], 'diff.trailingwhitespace') | 1701 yield (line[len(stripline):], 'diff.trailingwhitespace') |