When there is a regular expression that contains interpolation which contains a regular expression, the /s are incorrectly matched and thus the syntax highlighting is thrown off. For example:
is highlighted as:
Works for me.
Really? I'm seeing this in both vanilla Vim 7.3.390 and when loading the current git head of vim-ruby as the only addition to vanilla Vim. Obviously it also appears in my own configuration.
I'm seeing the same problem on my setup. My knowledge of syntax highlighting is pretty limited, though. I poked around a bit and found out that removing keepend from the rubyRegexp syntax group fixes the issue. From what I understood of Vim's help on this, keepend is meant to allow ending a nested pattern with a match for the outer one, which pretty much describes the issue.
The commit that adds the keepend there was made in 2008 by @tpope: 88a38fc. Not sure if there's anything more recent dealing with this, it has a fairly long history.
@tpope, do you remember the reason for the keepend there? This problem a bit of an edge case, so breaking something else to fix it wouldn't be a very good idea...
I can reproduce it now. I guess that's what happens when you make me type out a screenshot.
I don't remember the specifics of why I added keepend. But it's a safe guess that it was to fix one of those "the entire rest of the file highlights as a regex" bugs. Which is much worse than this bug.
@amarshall, please try reverting that change and seeing if things work better for you. Though I'm really hesitant to do that globablly without putting a lot of miles on it first.
Sorry about that. I've updated the description to include the plain text as well for future reference.
I've removed the keepend from ruby.vim:127 (there were some other changes in that commit that I've left in) and that fixes this issue, though I'm unsure of what other repercussions it may have. I'll let you know if I encounter any.
Correctly highlight regexp within interpolated regexp (Fixes #63)
It's been quite a while since we last talked about the issue. @amarshall, have you noticed any regressions with the keepend removal?
I've been using vim-ruby with the patch since I wrote it (so about 9 months) and haven't noticed any problems—though I could have just not run into whatever odd edge case that its removal exposes.
@tpope, what do you think? This really is quite an edge case, so if you don't feel comfortable removing the keepend in master, I don't intend to argue. I'm just poking you to get some closure on this issue.
Nuke it. We can always add it back.
On Nov 13, 2012, at 15:26, Andrew Radev email@example.com wrote:
@tpope https://github.com/tpope, what do you think? This really is quite
an edge case, so if you don't feel comfortable removing the keepend in
master, I don't intend to argue. I'm just poking you to get some closure on
Reply to this email directly or view it on
Nuked and closed.
Remove "keepend" from regex syntax highlighting
This fixes an issue with highlighting a regex with interpolation in it
with a regex within.
See vim-ruby#63 for details