scala.vim 19 KB

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