SublimeText / WordHighlight

Highlight all copies of the currently selected word.
MIT License
179 stars 24 forks source link

Arrays not covered by WordHighlight? #36

Closed 01-Scripts closed 11 years ago

01-Scripts commented 11 years ago

Hello,

I'm new to Sublime and have installed your Plugin. Now I ran into the following problem and I'm not sure if it is a bug or a feature:

I changed the sublime preference from word_separators": "./\\()\"'-:,.;<>~!@#$%^&*|+=[]{}~?", to: "word_separators": "./\()\"-:,.;<>~!@%^&*|+=}~?", in my user preferences

Now if I doubleclick on $array['name'] everything from $ until ] is selected bot the Highlighting of same Arrays isn't working.

Can you confirm this behaviour?

Regards, Michael

titoBouzout commented 11 years ago

Im unable to reproduce the problem you are describing.

01-Scripts commented 11 years ago

I made a short video that is illustrating the problem: http://screencast.com/t/qcj3ttq8YZ

titoBouzout commented 11 years ago

Thanks, that makes sense now to me.

This is a bug.Changing the line of the regular expression to:

    search = '(?<![\\w])'+re.escape(string).replace("\\'", "'")+'(?<![\w])'

makes the bug disappear, but I'm not sure if this is correct. Opinion please! @adzenith

Thanks!

adzenith commented 11 years ago

So change this: search = '(?<![\w])'+re.escape(string)+'\b' To this: search = '(?<![\w])'+re.escape(string).replace("\'", "'")+'(?<![\w])' ?

So re.escape doesn't work right with whatever regex library ST2 uses? That's sad :(

adzenith commented 11 years ago

Interestingly, when I first wrote this plugin, I wrote my own escape function. Someone asked me why I didn't use re.escape, and I vaguely remembered trying it and finding it to be broken, but I couldn't for the life of me remember why, so I moved over.

Maybe we should figure out all of the characters that get escaped that shouldn't be.

adzenith commented 11 years ago

\" works just like "... strange.

adzenith commented 11 years ago

whoops hit the wrong button.

titoBouzout commented 11 years ago

Hi, thanks, is not just the escaping of the RegExp, also the change at the end of \b to (?<![\w]) matters. I don't understand these regexp :O

titoBouzout commented 11 years ago

It was me that requested to change the string.replace for a re.escape, I was unable to find a situation on which some of these fail.

adzenith commented 11 years ago

Works when preceded with a backslash: !"#$%&()*+,-./:;=?@[]^_{|}~ Doesn't work in ST2, but works in Python: '<>` So that's four characters I guess we need to "unescape".

@tito I'll check out the ending change as well. And I do think that using re.escape is much better than whatever I was trying to do; I'm just sad that Sublime Text seems to be choking on these regexes.

adzenith commented 11 years ago

(?<![\w]) (which could probably be rewritten without the square brackets) is a negative lookbehind assertion:

(?<! # The preceding must not be \w # a word character. )

This prevents dub from matching inside of indubitably. We used to use \b instead of (?<!\w), but I believe we stopped because it sometimes broke when punctuation was involved; here we could be seeing the same problem.

adzenith commented 11 years ago

Tito, Could you look over this and pull if it looks good? I tried it out and it seems to work great. Thanks!

adzenith commented 11 years ago

P.S. Thanks for taking the time to figure out why it wasn't working!

titoBouzout commented 11 years ago

Have been testing, looks pretty good, Thanks to you!

adzenith commented 11 years ago

Sweet thanks! I'll pull it then.