blob: ed08e6c6e2371cbd6c4baab471a14aa493e4fc03 [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001" Vim indent file
2" Language: C-shell (tcsh)
Bram Moolenaarf1568ec2011-12-14 21:17:39 +01003" Maintainer: GI <a@b.c>, where a='gi1242+vim', b='gmail', c='com'
4" Last Modified: Sat 10 Dec 2011 09:23:00 AM EST
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
Bram Moolenaar071d4272004-06-13 20:20:40 +000021function TcshGetIndent()
22 " Find a non-blank line above the current line.
23 let lnum = prevnonblank(v:lnum - 1)
24
25 " Hit the start of the file, use zero indent.
26 if lnum == 0
27 return 0
28 endif
29
30 " Add indent if previous line begins with while or foreach
31 " OR line ends with case <str>:, default:, else, then or \
32 let ind = indent(lnum)
33 let line = getline(lnum)
34 if line =~ '\v^\s*%(while|foreach)>|^\s*%(case\s.*:|default:|else)\s*$|%(<then|\\)$'
Bram Moolenaar036986f2017-03-16 17:41:02 +010035 let ind = ind + shiftwidth()
Bram Moolenaar071d4272004-06-13 20:20:40 +000036 endif
37
38 if line =~ '\v^\s*breaksw>'
Bram Moolenaar036986f2017-03-16 17:41:02 +010039 let ind = ind - shiftwidth()
Bram Moolenaar071d4272004-06-13 20:20:40 +000040 endif
41
42 " Subtract indent if current line has on end, endif, case commands
43 let line = getline(v:lnum)
44 if line =~ '\v^\s*%(else|end|endif)\s*$'
Bram Moolenaar036986f2017-03-16 17:41:02 +010045 let ind = ind - shiftwidth()
Bram Moolenaar071d4272004-06-13 20:20:40 +000046 endif
47
48 return ind
49endfunction