Second version of my diff.tab color extension patches

Jordi Gutiérrez Hermoso jordigh at octave.org
Mon Aug 25 08:28:01 CDT 2014


On Mon, 2014-08-25 at 11:16 +0200, Martin Geisler wrote:
> Jordi Gutiérrez Hermoso <jordigh at octave.org> writes:

> > 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.

I'm not sure what the "i > 0" block is checking for. This seems like a
bug. It's not like at this point I'm already sure that the line starts
with tabs.

At any rate, there's a deeper problem with this. You will get a single
empty string no matter how many adjacent tabs there are, i.e. you lose
some information in the split. I also wonder what could str.split
possibly be doing that could be faster than a compiled regexp.

- Jordi G. H.




More information about the Mercurial-devel mailing list