Skip to content
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

Closed
scabug opened this issue Nov 24, 2009 · 8 comments
Closed
Labels
Milestone

Comments

@scabug
Copy link

scabug commented Nov 24, 2009

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

@scabug
Copy link
Author

scabug commented Nov 24, 2009

Imported From: https://issues.scala-lang.org/browse/SI-2699?orig=1
Reporter: bwaskiew
Attachments:

  • scala.diff (created on Feb 7, 2010 3:10:27 AM UTC, 478 bytes)
  • scala.vim (created on Nov 24, 2009 5:16:36 PM UTC, 2355 bytes)

@scabug
Copy link
Author

scabug commented Nov 24, 2009

bwaskiew said:
indent scala.vim

@scabug
Copy link
Author

scabug commented Dec 2, 2009

@cunei said:
Hello Stepan, I believe you usually take care of the vim support files. Could you please review the patch provided by bwaskiew in ticket #2699 and commit it if all is ok?
Thanks! Toni

@scabug
Copy link
Author

scabug commented Jan 28, 2010

bwaskiew said:
Is this not a defect after all? Or is there a problem identifying what exactly is wrong and/or how to patch it?

I can be of help if anyone needs assistance.

@scabug
Copy link
Author

scabug commented Jan 31, 2010

@stepancheg said:
@bwaskiew, I tried your version of script instead of SVN, and nothing changed, both SVN version and yours dedent when ")" pressed. But I think it is proper behaviour, because after pressing ")" indentation must be as you shown.

@scabug
Copy link
Author

scabug commented Feb 7, 2010

bwaskiew said:
diff of .vim/indent/scala.vim

@scabug
Copy link
Author

scabug commented Feb 7, 2010

bwaskiew said:
stepancheg: I have added a diff to be sure I didn't mess anything up locally when I was experimenting with my solution.

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.

@scabug scabug added the build label Apr 7, 2017
@scabug scabug added this to the Backlog milestone Apr 7, 2017
@SethTisue
Copy link
Member

I don't know where vim support lives these days, but it isn't under scala/*

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants