scala.vim 19 KB

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