Submitter | Jordi Gutiérrez Hermoso |
---|---|
Date | Aug. 20, 2014, 7:24 p.m. |
Message ID | <b58e6a9a966a2ae349db.1408562668@Iris> |
Download | mbox | patch |
Permalink | /patch/5533/ |
State | Superseded |
Commit | c343557a84423215d47af9bdefaed62d32de0d9a |
Headers | show |
Comments
On 08/20/2014 12:24 PM, Jordi Gutiérrez Hermoso wrote: > # HG changeset patch > # User Jordi Gutiérrez Hermoso <jordigh@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 consider something more generic than "showtabs" like "diff line" or "touched line" > + > 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') you regexp match multiple tab. you conditional does not. Not super fan of the regexp approach but I've not good idea for now. I wonder what is the performance of it. > + else: > + yield (token, label) > + else: > + yield (stripline, label) > break > else: > yield (line, '') This patch want a test to convince people it actually works.
Patch
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, '')