Second version of my diff.tab color extension patches

Martin Geisler martin at geisler.net
Mon Aug 25 04:16:41 CDT 2014


Jordi Gutiérrez Hermoso <jordigh at octave.org> writes:

>> >   gitre = re.compile('diff --git a/(.*) b/(.*)')
>> > +tabsplitter = re.compile(r'(\t+|[^\t]+)')
> [snip]
>> > +
>> >               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.
>
> Oops, that was dumb. Thanks for catching that. I've fixed it.
>
>> Not super fan of the regexp approach but I've not good idea for now.
>> I wonder what is the performance of it.
>
> I don't know what alternatives there are, nor do I think we can do
> much better than a regexp. Fundamentally, I think we have to split up
> a line into tab and non-tab blocks. I don't think this can be avoided.

I think you can just split on a single '\t'. You'll get a list of
strings -- empty strings when there are adjacent tabs. So you iterate
over that list and output a tab before every string, except for the
first. Like this:

  for i, token in enumerate(stripline.split('\t')):
      if i > 0:
          yield ('\t', 'diff.tab')
      yield (token, label)

Unlike your solution, you'll end up with multiple yields when there are
adjacent tabs.

-- 
Martin Geisler

http://google.com/+MartinGeisler
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 818 bytes
Desc: not available
URL: <http://selenic.com/pipermail/mercurial-devel/attachments/20140825/df296c0c/attachment.pgp>


More information about the Mercurial-devel mailing list