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
vim scala indent support fails on line containing single close parentheses #2699
Comments
Imported From: https://issues.scala-lang.org/browse/SI-2699?orig=1
|
bwaskiew said: |
bwaskiew said: I can be of help if anyone needs assistance. |
@stepancheg said: |
bwaskiew said: |
bwaskiew said: I didn't describe the problem correctly above, either. The problem doesn't occur after you type the parenthesis that I pointed out, but rather after you press enter after you've typed that paren. The CountParens tries to match parens, but only on that line. When it fails to match the paren, it dedents the next line even though you are still in the same scope. |
I don't know where vim support lives these days, but it isn't under scala/* |
Using the file indent scala.vim causes code like the following to fail. (This code is a snippet taken from the end of chapter 3 in Programming in Scala by Odersky, Spoon and Venners)
import scala.io.Source
def widthOfLength(s: String) = s.Length.toString.toString
if (args.length > 0) {
val lines = Source.fromFile(args(0)).getLines.toList
val longestLine = lines.reduceLeft(
(a, b) => if (a.length > b.length) a else b
) <<<<<< HERE
...
}
After typing the close parenthesis in the marked line, the scala.vim file sees mis-matched parens after calling CountParens, and thinks it must dedent.
I propose modifying the lines at and following 56 so that it looks as such:
" If parenthesis are unbalanced, indent or dedent
" but only if prevline contains more than a close
" parenthesis and (optionally) comments
if prevline !~ '^\s*)\s*(//.|/*.*/)*$$'
let c = CountParens(prevline)
echo c
if c > 0
let ind = ind + &shiftwidth
elseif c < 0
let ind = ind - &shiftwidth
endif
endif
Adding the extra if block to test if the line contains more than just a close parenthesis and (optionally) a comment will prevent it from errantly dedenting when the script thinks it has a mismatched paren (when really it does match, just not on the same line).
The text was updated successfully, but these errors were encountered: