blob: cd18f06189c500c5d0b2de61dd99f09cc9275d3a [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001" Vim indent file
2" Language: C-shell (tcsh)
Bram Moolenaard042c562005-06-30 22:04:15 +00003" Maintainer: Gautam Iyer <gautam@math.uchicago.edu>
Bram Moolenaar8c8de832008-06-24 22:58:06 +00004" Last Modified: Sat 16 Jun 2007 04:27:45 PM PDT
Bram Moolenaar071d4272004-06-13 20:20:40 +00005
6" Only load this indent file when no other was loaded.
7if exists("b:did_indent")
8 finish
9endif
10
11let b:did_indent = 1
12
13setlocal indentexpr=TcshGetIndent()
Bram Moolenaar8c8de832008-06-24 22:58:06 +000014setlocal indentkeys+=e,0=end,0=endsw indentkeys-=0{,0},0),:,0#
Bram Moolenaar071d4272004-06-13 20:20:40 +000015
16" Only define the function once.
17if exists("*TcshGetIndent")
18 finish
19endif
20
21set cpoptions-=C
22
23function TcshGetIndent()
24 " Find a non-blank line above the current line.
25 let lnum = prevnonblank(v:lnum - 1)
26
27 " Hit the start of the file, use zero indent.
28 if lnum == 0
29 return 0
30 endif
31
32 " Add indent if previous line begins with while or foreach
33 " OR line ends with case <str>:, default:, else, then or \
34 let ind = indent(lnum)
35 let line = getline(lnum)
36 if line =~ '\v^\s*%(while|foreach)>|^\s*%(case\s.*:|default:|else)\s*$|%(<then|\\)$'
37 let ind = ind + &sw
38 endif
39
40 if line =~ '\v^\s*breaksw>'
41 let ind = ind - &sw
42 endif
43
44 " Subtract indent if current line has on end, endif, case commands
45 let line = getline(v:lnum)
46 if line =~ '\v^\s*%(else|end|endif)\s*$'
47 let ind = ind - &sw
48 endif
49
50 return ind
51endfunction