scala.vim 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610
  1. " Vim indent file
  2. " Language: Scala (http://scala-lang.org/)
  3. " Original Author: Stefan Matthias Aust
  4. " Modifications By: Derek Wyatt
  5. " URL: https://github.com/derekwyatt/vim-scala
  6. " Last Change: 2016 Aug 26
  7. if exists("b:did_indent")
  8. finish
  9. endif
  10. let b:did_indent = 1
  11. setlocal autoindent
  12. setlocal indentexpr=GetScalaIndent()
  13. setlocal indentkeys=0{,0},0),!^F,<>>,o,O,e,=case,<CR>
  14. if exists("*GetScalaIndent")
  15. finish
  16. endif
  17. let s:keepcpo= &cpo
  18. set cpo&vim
  19. let s:defMatcher = '\%(\%(private\|protected\)\%(\[[^\]]*\]\)\?\s\+\|abstract\s\+\|override\s\+\)*\<def\>'
  20. let s:funcNameMatcher = '\w\+'
  21. let s:typeSpecMatcher = '\%(\s*\[\_[^\]]*\]\)'
  22. let s:defArgMatcher = '\%((\_.\{-})\)'
  23. let s:returnTypeMatcher = '\%(:\s*\w\+' . s:typeSpecMatcher . '\?\)'
  24. let g:fullDefMatcher = '^\s*' . s:defMatcher . '\s\+' . s:funcNameMatcher . '\s*' . s:typeSpecMatcher . '\?\s*' . s:defArgMatcher . '\?\s*' . s:returnTypeMatcher . '\?\s*[={]'
  25. function! scala#ConditionalConfirm(msg)
  26. if 0
  27. call confirm(a:msg)
  28. endif
  29. endfunction
  30. function! scala#GetLine(lnum)
  31. let line = substitute(getline(a:lnum), '//.*$', '', '')
  32. let line = substitute(line, '"\(.\|\\"\)\{-}"', '""', 'g')
  33. return line
  34. endfunction
  35. function! scala#CountBrackets(line, openBracket, closedBracket)
  36. let line = substitute(a:line, '"\(.\|\\"\)\{-}"', '', 'g')
  37. let open = substitute(line, '[^' . a:openBracket . ']', '', 'g')
  38. let close = substitute(line, '[^' . a:closedBracket . ']', '', 'g')
  39. return strlen(open) - strlen(close)
  40. endfunction
  41. function! scala#CountParens(line)
  42. return scala#CountBrackets(a:line, '(', ')')
  43. endfunction
  44. function! scala#CountCurlies(line)
  45. return scala#CountBrackets(a:line, '{', '}')
  46. endfunction
  47. function! scala#LineEndsInIncomplete(line)
  48. if a:line =~ '[.,]\s*$'
  49. return 1
  50. else
  51. return 0
  52. endif
  53. endfunction
  54. function! scala#LineIsAClosingXML(line)
  55. if a:line =~ '^\s*</\w'
  56. return 1
  57. else
  58. return 0
  59. endif
  60. endfunction
  61. function! scala#LineCompletesXML(lnum, line)
  62. let savedpos = getpos('.')
  63. call setpos('.', [savedpos[0], a:lnum, 0, savedpos[3]])
  64. let tag = substitute(a:line, '^.*</\([^>]*\)>.*$', '\1', '')
  65. let [lineNum, colnum] = searchpairpos('<' . tag . '>', '', '</' . tag . '>', 'Wbn')
  66. call setpos('.', savedpos)
  67. let pline = scala#GetLine(prevnonblank(lineNum - 1))
  68. if pline =~ '=\s*$'
  69. return 1
  70. else
  71. return 0
  72. endif
  73. endfunction
  74. function! scala#IsParentCase()
  75. let savedpos = getpos('.')
  76. call setpos('.', [savedpos[0], savedpos[1], 0, savedpos[3]])
  77. let [l, c] = searchpos('^\s*\%(' . s:defMatcher . '\|\%(\<case\>\)\)', 'bnW')
  78. let retvalue = -1
  79. if l != 0 && search('\%' . l . 'l\s*\<case\>', 'bnW')
  80. let retvalue = l
  81. endif
  82. call setpos('.', savedpos)
  83. return retvalue
  84. endfunction
  85. function! scala#CurlyMatcher()
  86. let matchline = scala#GetLineThatMatchesBracket('{', '}')
  87. if scala#CountParens(scala#GetLine(matchline)) < 0
  88. let savedpos = getpos('.')
  89. call setpos('.', [savedpos[0], matchline, 9999, savedpos[3]])
  90. call searchpos('{', 'Wbc')
  91. call searchpos(')', 'Wb')
  92. let [lnum, colnum] = searchpairpos('(', '', ')', 'Wbn')
  93. call setpos('.', savedpos)
  94. let line = scala#GetLine(lnum)
  95. if line =~ '^\s*' . s:defMatcher
  96. return lnum
  97. else
  98. return matchline
  99. endif
  100. else
  101. return matchline
  102. endif
  103. endfunction
  104. function! scala#GetLineAndColumnThatMatchesCurly()
  105. return scala#GetLineAndColumnThatMatchesBracket('{', '}')
  106. endfunction
  107. function! scala#GetLineAndColumnThatMatchesParen()
  108. return scala#GetLineAndColumnThatMatchesBracket('(', ')')
  109. endfunction
  110. function! scala#GetLineAndColumnThatMatchesBracket(openBracket, closedBracket)
  111. let savedpos = getpos('.')
  112. let curline = scala#GetLine(line('.'))
  113. if curline =~ a:closedBracket . '.*' . a:openBracket . '.*' . a:closedBracket
  114. call setpos('.', [savedpos[0], savedpos[1], 0, savedpos[3]])
  115. call searchpos(a:closedBracket . '\ze[^' . a:closedBracket . a:openBracket . ']*' . a:openBracket, 'W')
  116. else
  117. call setpos('.', [savedpos[0], savedpos[1], 9999, savedpos[3]])
  118. call searchpos(a:closedBracket, 'Wbc')
  119. endif
  120. let [lnum, colnum] = searchpairpos(a:openBracket, '', a:closedBracket, 'Wbn')
  121. call setpos('.', savedpos)
  122. return [lnum, colnum]
  123. endfunction
  124. function! scala#GetLineThatMatchesCurly()
  125. return scala#GetLineThatMatchesBracket('{', '}')
  126. endfunction
  127. function! scala#GetLineThatMatchesParen()
  128. return scala#GetLineThatMatchesBracket('(', ')')
  129. endfunction
  130. function! scala#GetLineThatMatchesBracket(openBracket, closedBracket)
  131. let [lnum, colnum] = scala#GetLineAndColumnThatMatchesBracket(a:openBracket, a:closedBracket)
  132. return lnum
  133. endfunction
  134. function! scala#NumberOfBraceGroups(line)
  135. let line = substitute(a:line, '[^()]', '', 'g')
  136. if strlen(line) == 0
  137. return 0
  138. endif
  139. let line = substitute(line, '^)*', '', 'g')
  140. if strlen(line) == 0
  141. return 0
  142. endif
  143. let line = substitute(line, '^(', '', 'g')
  144. if strlen(line) == 0
  145. return 0
  146. endif
  147. let c = 1
  148. let counter = 0
  149. let groupCount = 0
  150. while counter < strlen(line)
  151. let char = strpart(line, counter, 1)
  152. if char == '('
  153. let c = c + 1
  154. elseif char == ')'
  155. let c = c - 1
  156. endif
  157. if c == 0
  158. let groupCount = groupCount + 1
  159. endif
  160. let counter = counter + 1
  161. endwhile
  162. return groupCount
  163. endfunction
  164. function! scala#MatchesIncompleteDefValr(line)
  165. if a:line =~ '^\s*\%(' . s:defMatcher . '\|\<va[lr]\>\).*[=({]\s*$'
  166. return 1
  167. else
  168. return 0
  169. endif
  170. endfunction
  171. function! scala#LineIsCompleteIf(line)
  172. if scala#CountBrackets(a:line, '{', '}') == 0 &&
  173. \ scala#CountBrackets(a:line, '(', ')') == 0 &&
  174. \ a:line =~ '^\s*\<if\>\s*([^)]*)\s*\S.*$'
  175. return 1
  176. else
  177. return 0
  178. endif
  179. endfunction
  180. function! scala#LineCompletesIfElse(lnum, line)
  181. if a:line =~ '^\s*\%(\<if\>\|\%(}\s*\)\?\<else\>\)'
  182. return 0
  183. endif
  184. let result = search('^\%(\s*\<if\>\s*(.*).*\n\|\s*\<if\>\s*(.*)\s*\n.*\n\)\%(\s*\<else\>\s*\<if\>\s*(.*)\s*\n.*\n\)*\%(\s*\<else\>\s*\n\|\s*\<else\>[^{]*\n\)\?\%' . a:lnum . 'l', 'Wbn')
  185. if result != 0 && scala#GetLine(prevnonblank(a:lnum - 1)) !~ '{\s*$'
  186. return result
  187. endif
  188. return 0
  189. endfunction
  190. function! scala#GetPrevCodeLine(lnum)
  191. " This needs to skip comment lines
  192. return prevnonblank(a:lnum - 1)
  193. endfunction
  194. function! scala#InvertBracketType(openBracket, closedBracket)
  195. if a:openBracket == '('
  196. return [ '{', '}' ]
  197. else
  198. return [ '(', ')' ]
  199. endif
  200. endfunction
  201. function! scala#Testhelper(lnum, line, openBracket, closedBracket, iteration)
  202. let bracketCount = scala#CountBrackets(a:line, a:openBracket, a:closedBracket)
  203. " There are more '}' braces than '{' on this line so it may be completing the function definition
  204. if bracketCount < 0
  205. let [matchedLNum, matchedColNum] = scala#GetLineAndColumnThatMatchesBracket(a:openBracket, a:closedBracket)
  206. if matchedLNum == a:lnum
  207. return -1
  208. endif
  209. let matchedLine = scala#GetLine(matchedLNum)
  210. if ! scala#MatchesIncompleteDefValr(matchedLine)
  211. let bracketLine = substitute(substitute(matchedLine, '\%' . matchedColNum . 'c.*$', '', ''), '[^{}()]', '', 'g')
  212. if bracketLine =~ '}$'
  213. return scala#Testhelper(matchedLNum, matchedLine, '{', '}', a:iteration + 1)
  214. elseif bracketLine =~ ')$'
  215. return scala#Testhelper(matchedLNum, matchedLine, '(', ')', a:iteration + 1)
  216. else
  217. let prevCodeLNum = scala#GetPrevCodeLine(matchedLNum)
  218. if scala#MatchesIncompleteDefValr(scala#GetLine(prevCodeLNum))
  219. return prevCodeLNum
  220. else
  221. return -1
  222. endif
  223. endif
  224. else
  225. " return indent value instead
  226. return matchedLNum
  227. endif
  228. " There's an equal number of '{' and '}' on this line so it may be a single line function definition
  229. elseif bracketCount == 0
  230. if a:iteration == 0
  231. let otherBracketType = scala#InvertBracketType(a:openBracket, a:closedBracket)
  232. return scala#Testhelper(a:lnum, a:line, otherBracketType[0], otherBracketType[1], a:iteration + 1)
  233. else
  234. let prevCodeLNum = scala#GetPrevCodeLine(a:lnum)
  235. let prevCodeLine = scala#GetLine(prevCodeLNum)
  236. if scala#MatchesIncompleteDefValr(prevCodeLine) && prevCodeLine !~ '{\s*$'
  237. return prevCodeLNum
  238. else
  239. let possibleIfElse = scala#LineCompletesIfElse(a:lnum, a:line)
  240. if possibleIfElse != 0
  241. let defValrLine = prevnonblank(possibleIfElse - 1)
  242. let possibleDefValr = scala#GetLine(defValrLine)
  243. if scala#MatchesIncompleteDefValr(possibleDefValr) && possibleDefValr =~ '^.*=\s*$'
  244. return possibleDefValr
  245. else
  246. return -1
  247. endif
  248. else
  249. return -1
  250. endif
  251. endif
  252. endif
  253. else
  254. return -1
  255. endif
  256. endfunction
  257. function! scala#Test(lnum, line, openBracket, closedBracket)
  258. return scala#Testhelper(a:lnum, a:line, a:openBracket, a:closedBracket, 0)
  259. endfunction
  260. function! scala#LineCompletesDefValr(lnum, line)
  261. let bracketCount = scala#CountBrackets(a:line, '{', '}')
  262. if bracketCount < 0
  263. let matchedBracket = scala#GetLineThatMatchesBracket('{', '}')
  264. if ! scala#MatchesIncompleteDefValr(scala#GetLine(matchedBracket))
  265. let possibleDefValr = scala#GetLine(prevnonblank(matchedBracket - 1))
  266. if matchedBracket != -1 && scala#MatchesIncompleteDefValr(possibleDefValr)
  267. return 1
  268. else
  269. return 0
  270. endif
  271. else
  272. return 0
  273. endif
  274. elseif bracketCount == 0
  275. let bracketCount = scala#CountBrackets(a:line, '(', ')')
  276. if bracketCount < 0
  277. let matchedBracket = scala#GetLineThatMatchesBracket('(', ')')
  278. if ! scala#MatchesIncompleteDefValr(scala#GetLine(matchedBracket))
  279. let possibleDefValr = scala#GetLine(prevnonblank(matchedBracket - 1))
  280. if matchedBracket != -1 && scala#MatchesIncompleteDefValr(possibleDefValr)
  281. return 1
  282. else
  283. return 0
  284. endif
  285. else
  286. return 0
  287. endif
  288. elseif bracketCount == 0
  289. let possibleDefValr = scala#GetLine(prevnonblank(a:lnum - 1))
  290. if scala#MatchesIncompleteDefValr(possibleDefValr) && possibleDefValr =~ '^.*=\s*$'
  291. return 1
  292. else
  293. let possibleIfElse = scala#LineCompletesIfElse(a:lnum, a:line)
  294. if possibleIfElse != 0
  295. let possibleDefValr = scala#GetLine(prevnonblank(possibleIfElse - 1))
  296. if scala#MatchesIncompleteDefValr(possibleDefValr) && possibleDefValr =~ '^.*=\s*$'
  297. return 2
  298. else
  299. return 0
  300. endif
  301. else
  302. return 0
  303. endif
  304. endif
  305. else
  306. return 0
  307. endif
  308. endif
  309. endfunction
  310. function! scala#SpecificLineCompletesBrackets(lnum, openBracket, closedBracket)
  311. let savedpos = getpos('.')
  312. call setpos('.', [savedpos[0], a:lnum, 9999, savedpos[3]])
  313. let retv = scala#LineCompletesBrackets(a:openBracket, a:closedBracket)
  314. call setpos('.', savedpos)
  315. return retv
  316. endfunction
  317. function! scala#LineCompletesBrackets(openBracket, closedBracket)
  318. let savedpos = getpos('.')
  319. let offline = 0
  320. while offline == 0
  321. let [lnum, colnum] = searchpos(a:closedBracket, 'Wb')
  322. let [lnumA, colnumA] = searchpairpos(a:openBracket, '', a:closedBracket, 'Wbn')
  323. if lnum != lnumA
  324. let [lnumB, colnumB] = searchpairpos(a:openBracket, '', a:closedBracket, 'Wbnr')
  325. let offline = 1
  326. endif
  327. endwhile
  328. call setpos('.', savedpos)
  329. if lnumA == lnumB && colnumA == colnumB
  330. return lnumA
  331. else
  332. return -1
  333. endif
  334. endfunction
  335. function! GetScalaIndent()
  336. " Find a non-blank line above the current line.
  337. let prevlnum = prevnonblank(v:lnum - 1)
  338. " Hit the start of the file, use zero indent.
  339. if prevlnum == 0
  340. return 0
  341. endif
  342. let ind = indent(prevlnum)
  343. let originalIndentValue = ind
  344. let prevline = scala#GetLine(prevlnum)
  345. let curlnum = v:lnum
  346. let curline = scala#GetLine(curlnum)
  347. if get(g:, 'scala_scaladoc_indent', 0)
  348. let star_indent = 2
  349. else
  350. let star_indent = 1
  351. end
  352. if prevline =~ '^\s*/\*\*'
  353. if prevline =~ '\*/\s*$'
  354. return ind
  355. else
  356. return ind + star_indent
  357. endif
  358. endif
  359. if curline =~ '^\s*\*'
  360. return cindent(curlnum)
  361. endif
  362. " If this line starts with a { then make it indent the same as the previous line
  363. if curline =~ '^\s*{'
  364. call scala#ConditionalConfirm("1")
  365. " Unless, of course, the previous one is a { as well
  366. if prevline !~ '^\s*{'
  367. call scala#ConditionalConfirm("2")
  368. return indent(prevlnum)
  369. endif
  370. endif
  371. " '.' continuations
  372. if curline =~ '^\s*\.'
  373. if prevline =~ '^\s*\.'
  374. return ind
  375. else
  376. return ind + shiftwidth()
  377. endif
  378. endif
  379. " Indent html literals
  380. if prevline !~ '/>\s*$' && prevline =~ '^\s*<[a-zA-Z][^>]*>\s*$'
  381. call scala#ConditionalConfirm("3")
  382. return ind + shiftwidth()
  383. endif
  384. " assumes curly braces around try-block
  385. if curline =~ '^\s*}\s*\<catch\>'
  386. return ind - shiftwidth()
  387. elseif curline =~ '^\s*\<catch\>'
  388. return ind
  389. endif
  390. " Add a shiftwidth()' after lines that start a block
  391. " If 'if', 'for' or 'while' end with ), this is a one-line block
  392. " If 'val', 'var', 'def' end with =, this is a one-line block
  393. if (prevline =~ '^\s*\<\%(\%(}\?\s*else\s\+\)\?if\|for\|while\)\>.*[)=]\s*$' && scala#NumberOfBraceGroups(prevline) <= 1)
  394. \ || prevline =~ '^\s*' . s:defMatcher . '.*=\s*$'
  395. \ || prevline =~ '^\s*\<va[lr]\>.*[=]\s*$'
  396. \ || prevline =~ '^\s*\%(}\s*\)\?\<else\>\s*$'
  397. \ || prevline =~ '=\s*$'
  398. call scala#ConditionalConfirm("4")
  399. let ind = ind + shiftwidth()
  400. elseif prevline =~ '^\s*\<\%(}\?\s*else\s\+\)\?if\>' && curline =~ '^\s*}\?\s*\<else\>'
  401. return ind
  402. endif
  403. let lineCompletedBrackets = 0
  404. let bracketCount = scala#CountBrackets(prevline, '{', '}')
  405. if bracketCount > 0 || prevline =~ '.*{\s*$'
  406. call scala#ConditionalConfirm("5b")
  407. let ind = ind + shiftwidth()
  408. elseif bracketCount < 0
  409. call scala#ConditionalConfirm("6b")
  410. " if the closing brace actually completes the braces entirely, then we
  411. " have to indent to line that started the whole thing
  412. let completeLine = scala#LineCompletesBrackets('{', '}')
  413. if completeLine != -1
  414. call scala#ConditionalConfirm("8b")
  415. let prevCompleteLine = scala#GetLine(prevnonblank(completeLine - 1))
  416. " However, what actually started this part looks like it was a function
  417. " definition, so we need to indent to that line instead. This is
  418. " actually pretty weak at the moment.
  419. if prevCompleteLine =~ '=\s*$'
  420. call scala#ConditionalConfirm("9b")
  421. let ind = indent(prevnonblank(completeLine - 1))
  422. else
  423. call scala#ConditionalConfirm("10b")
  424. let ind = indent(completeLine)
  425. endif
  426. else
  427. let lineCompletedBrackets = 1
  428. endif
  429. endif
  430. if ind == originalIndentValue
  431. let bracketCount = scala#CountBrackets(prevline, '(', ')')
  432. if bracketCount > 0 || prevline =~ '.*(\s*$'
  433. call scala#ConditionalConfirm("5a")
  434. let ind = ind + shiftwidth()
  435. elseif bracketCount < 0
  436. call scala#ConditionalConfirm("6a")
  437. " if the closing brace actually completes the braces entirely, then we
  438. " have to indent to line that started the whole thing
  439. let completeLine = scala#LineCompletesBrackets('(', ')')
  440. if completeLine != -1 && prevline !~ '^.*{\s*$'
  441. call scala#ConditionalConfirm("8a")
  442. let prevCompleteLine = scala#GetLine(prevnonblank(completeLine - 1))
  443. " However, what actually started this part looks like it was a function
  444. " definition, so we need to indent to that line instead. This is
  445. " actually pretty weak at the moment.
  446. if prevCompleteLine =~ '=\s*$'
  447. call scala#ConditionalConfirm("9a")
  448. let ind = indent(prevnonblank(completeLine - 1))
  449. else
  450. call scala#ConditionalConfirm("10a")
  451. let ind = indent(completeLine)
  452. endif
  453. else
  454. " This is the only part that's different from from the '{', '}' one below
  455. " Yup... some refactoring is necessary at some point.
  456. let ind = ind + (bracketCount * shiftwidth())
  457. let lineCompletedBrackets = 1
  458. endif
  459. endif
  460. endif
  461. if curline =~ '^\s*}\?\s*\<else\>\%(\s\+\<if\>\s*(.*)\)\?\s*{\?\s*$' &&
  462. \ ! scala#LineIsCompleteIf(prevline) &&
  463. \ prevline !~ '^.*}\s*$'
  464. let ind = ind - shiftwidth()
  465. endif
  466. " Subtract a shiftwidth()' on '}' or html
  467. let curCurlyCount = scala#CountCurlies(curline)
  468. if curCurlyCount < 0
  469. call scala#ConditionalConfirm("14a")
  470. let matchline = scala#CurlyMatcher()
  471. return indent(matchline)
  472. elseif curline =~ '^\s*</[a-zA-Z][^>]*>'
  473. call scala#ConditionalConfirm("14c")
  474. return ind - shiftwidth()
  475. endif
  476. let prevParenCount = scala#CountParens(prevline)
  477. if prevline =~ '^\s*\<for\>.*$' && prevParenCount > 0
  478. call scala#ConditionalConfirm("15")
  479. let ind = indent(prevlnum) + 5
  480. endif
  481. let prevCurlyCount = scala#CountCurlies(prevline)
  482. if prevCurlyCount == 0 && prevline =~ '^.*\%(=>\|⇒\)\s*$' && prevline !~ '^\s*this\s*:.*\%(=>\|⇒\)\s*$' && curline !~ '^\s*\<case\>'
  483. call scala#ConditionalConfirm("16")
  484. let ind = ind + shiftwidth()
  485. endif
  486. if ind == originalIndentValue && curline =~ '^\s*\<case\>'
  487. call scala#ConditionalConfirm("17")
  488. let parentCase = scala#IsParentCase()
  489. if parentCase != -1
  490. call scala#ConditionalConfirm("17a")
  491. return indent(parentCase)
  492. endif
  493. endif
  494. if prevline =~ '^\s*\*/'
  495. \ || prevline =~ '*/\s*$'
  496. call scala#ConditionalConfirm("18")
  497. let ind = ind - star_indent
  498. endif
  499. if scala#LineEndsInIncomplete(prevline)
  500. call scala#ConditionalConfirm("19")
  501. return ind
  502. endif
  503. if scala#LineIsAClosingXML(prevline)
  504. if scala#LineCompletesXML(prevlnum, prevline)
  505. call scala#ConditionalConfirm("20a")
  506. return ind - shiftwidth()
  507. else
  508. call scala#ConditionalConfirm("20b")
  509. return ind
  510. endif
  511. endif
  512. if ind == originalIndentValue
  513. "let indentMultiplier = scala#LineCompletesDefValr(prevlnum, prevline)
  514. "if indentMultiplier != 0
  515. " call scala#ConditionalConfirm("19a")
  516. " let ind = ind - (indentMultiplier * shiftwidth())
  517. let defValrLine = scala#Test(prevlnum, prevline, '{', '}')
  518. if defValrLine != -1
  519. call scala#ConditionalConfirm("21a")
  520. let ind = indent(defValrLine)
  521. elseif lineCompletedBrackets == 0
  522. call scala#ConditionalConfirm("21b")
  523. if scala#GetLine(prevnonblank(prevlnum - 1)) =~ '^.*\<else\>\s*\%(//.*\)\?$'
  524. call scala#ConditionalConfirm("21c")
  525. let ind = ind - shiftwidth()
  526. elseif scala#LineCompletesIfElse(prevlnum, prevline)
  527. call scala#ConditionalConfirm("21d")
  528. let ind = ind - shiftwidth()
  529. elseif scala#CountParens(curline) < 0 && curline =~ '^\s*)' && scala#GetLine(scala#GetLineThatMatchesBracket('(', ')')) =~ '.*(\s*$'
  530. " Handles situations that look like this:
  531. "
  532. " val a = func(
  533. " 10
  534. " )
  535. "
  536. " or
  537. "
  538. " val a = func(
  539. " 10
  540. " ).somethingHere()
  541. call scala#ConditionalConfirm("21e")
  542. let ind = ind - shiftwidth()
  543. endif
  544. endif
  545. endif
  546. call scala#ConditionalConfirm("returning " . ind)
  547. return ind
  548. endfunction
  549. let &cpo = s:keepcpo
  550. unlet s:keepcpo
  551. " vim:set sw=2 sts=2 ts=8 et:
  552. " vim600:fdm=marker fdl=1 fdc=0: