robin/laufey

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

Christian Clasonvim-patch:ce001a337e28 (#18287)521e91e1c4

master
1.3 KiB58 linesraw
1" Vim indent file
2" Language:		xinetd.conf(5) configuration file
3" Maintainer:		Doug Kearns <dougkearns@gmail.com>
4" Previous Maintainer:	Nikolai Weibull <now@bitwi.se>
5" Last Change:		2022 April 25
6
7if exists("b:did_indent")
8  finish
9endif
10let b:did_indent = 1
11
12setlocal indentexpr=GetXinetdIndent()
13setlocal indentkeys=0{,0},!^F,o,O
14setlocal nosmartindent
15
16let b:undo_indent = "setl inde< indk< si<"
17
18if exists("*GetXinetdIndent")
19  finish
20endif
21let s:keepcpo= &cpo
22set cpo&vim
23
24function s:count_braces(lnum, count_open)
25  let n_open = 0
26  let n_close = 0
27  let line = getline(a:lnum)
28  let pattern = '[{}]'
29  let i = match(line, pattern)
30  while i != -1
31    if synIDattr(synID(a:lnum, i + 1, 0), 'name') !~ 'ld\%(Comment\|String\)'
32      if line[i] == '{'
33        let n_open += 1
34      elseif line[i] == '}'
35        if n_open > 0
36          let n_open -= 1
37        else
38          let n_close += 1
39        endif
40      endif
41    endif
42    let i = match(line, pattern, i + 1)
43  endwhile
44  return a:count_open ? n_open : n_close
45endfunction
46
47function GetXinetdIndent()
48  let pnum = prevnonblank(v:lnum - 1)
49  if pnum == 0
50    return 0
51  endif
52
53  return indent(pnum) + s:count_braces(pnum, 1) * shiftwidth()
54        \ - s:count_braces(v:lnum, 0) * shiftwidth()
55endfunction
56
57let &cpo = s:keepcpo
58unlet s:keepcpo