robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

Christian Clasonvim-patch:partial:cbaff5e06ec5 (#18042)d3068d34cc

master
1.2 KiB53 linesraw
1" Vim indent file
2" Language:     ChaiScript
3" Maintainer:	Jason Turner <lefticus 'at' gmail com>
4" Last Change: 	2022 Apr 06
5
6" Only load this indent file when no other was loaded.
7if exists("b:did_indent")
8  finish
9endif
10let b:did_indent = 1
11
12setlocal indentexpr=GetChaiScriptIndent()
13setlocal autoindent
14
15let b:undo_indent = "setl ai< inde<"
16
17" Only define the function once.
18if exists("*GetChaiScriptIndent")
19  finish
20endif
21
22function! GetChaiScriptIndent()
23  " Find a non-blank line above the current line.
24  let lnum = prevnonblank(v:lnum - 1)
25
26  " Hit the start of the file, use zero indent.
27  if lnum == 0
28    return 0
29  endif
30
31  " Add a 'shiftwidth' after lines that start a block:
32  " lines containing a {
33  let ind = indent(lnum)
34  let flag = 0
35  let prevline = getline(lnum)
36  if prevline =~ '^.*{.*'
37    let ind = ind + shiftwidth()
38    let flag = 1
39  endif
40
41  " Subtract a 'shiftwidth' after lines containing a { followed by a }
42  " to keep it balanced
43  if flag == 1 && prevline =~ '.*{.*}.*'
44    let ind = ind - shiftwidth()
45  endif
46
47  " Subtract a 'shiftwidth' on lines ending with }
48  if getline(v:lnum) =~ '^\s*\%(}\)'
49    let ind = ind - shiftwidth()
50  endif
51
52  return ind
53endfunction