summaryrefslogtreecommitdiff
path: root/vim/.vim/indent/gmsh.vim
blob: 845b668aad74c3055eeecc0794cac783f14e68cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
" Vim indent file

if exists("b:did_indent")
  finish
endif
let b:did_indent = 1

setlocal indentexpr=GetGeoIndent()
setlocal indentkeys&
setlocal autoindent
setlocal commentstring=//%s

if exists("*GetGeoIndent")
  finish
endif

let s:cpo_save = &cpo
set cpo&vim

let s:skip_syntax = '\%(Comment\|String\)$'

function! GetGeoIndent()

  let lnum = prevnonblank(v:lnum - 1)

  if lnum == 0
    return 0
  endif

      let ind          = indent(lnum)
      let last_line    = getline(lnum)
      let current_line = getline(v:lnum)

      if last_line =~ '\(^\/\/\|^\/\*\)'
          return ind
      endif

      if last_line =~ '\(\<If\>\|\<For\>\|\<Macro\>\)'
          let ind += &shiftwidth
      endif

      if last_line =~ '\({[^}]*$\)'
          let ind += &shiftwidth
      endif

      if current_line =~ '\(^[^{]*}\)'
          let ind -= &shiftwidth
      endif

      if current_line =~ '\(\<EndIf\>\|\<EndFor\>\|\<Return\>\)$'
          let ind -= &shiftwidth
      endif

      return ind

endfunction

let &cpo = s:cpo_save
unlet s:cpo_save