New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Syntax highlighting error when \ used to put if/unless on a new line #195
Comments
The problem here is that we don't care for line continuations. When vim-ruby sees the if-clause with nothing but whitespace before it, it assumes it's a full if-clause with a matching "end". What I could do is squeeze a At this time, I'm strongly inclined to just not support line continuations. I believe they're not encountered so often in ruby code and they would complicate handling of both this case and possibly many others. A related issue is that your example also doesn't indent correctly, which means that should also be tackled. In this case, I'd personally just use a multiline if-clause: def foo
if call_some_function(args)
return false
end
end Is there some reason to prefer your variant as opposed to the multiline one? |
At the moment, my only real motive for supporting line continuations is that I work somewhere which treats it as preferred style (even though I personally do not). It can be frustrating to have closing If the possible negative effects of supporting the format are too significant, I can understand not supporting it. In a broader style sense, I dislike line continuations, but if I change existing ones in code at work, they'll get reverted or questioned. I may try dropping your suggestion into my local version of vim-ruby and look for any negative side effects. |
I see, this was what I was afraid of. It's much more likely to convince a person than a corporation :). Even so, I think we both agree this style is not particularly conventional, so I'm not keen on the idea of supporting it. For now, do try the change and see how it turns out. The relevant line is here: https://github.com/vim-ruby/vim-ruby/blob/master/syntax/ruby.vim#L229. The replacement for it would be: syn region rubyConditionalExpression matchgroup=rubyConditional start="\%(\%(\\\n\s*\)\<@!\%(^\|\.\.\.\=\|[{:,;([<>~\*/%&^|+=-]\|\%(\<[_[:lower:]][_[:alnum:]]*\)\@<![?!]\)\s*\)\@<=\%(if\|unless\)\>" end="\%(\%(\%(\.\@<!\.\)\|::\)\s*\)\@<!\<end\>" contains=ALLBUT,@rubyNotTop fold |
I think that if the I have created a pull request with the change: #267 |
The performance issue is not the big problem here, it's that we just don't support backslashes like this. As I said, that particular example breaks indentation as well (as far as I remember). Even if we fix this issue, we just don't have much of a plan for dealing with these kind of constructs. Most ruby codebases can just use a different syntax. Still, I won't close the PR out of fear of (unknown) bad consequences. I'll go ahead and merge it, but bear in mind that if we end up with related issues I may revert it. |
Example:
In the above case, the
end
will be correctly highlighted to match the defNow, with the
if
on the line below, theend
will be incorrectly highlighted as the match for theif
The code still performs correctly (the syntax is valid in Ruby) but the highlighting gets confused. This is more problematic when the block is nested further, and it is harder to visually detect the correct nesting without the help of the highlight.
May not present a problem in all color schemes, if the color is the same for
class
andif
. Problem presented when using the wombat256mod colorschemeThe text was updated successfully, but these errors were encountered: