7
|
1 " Vim indent file
|
|
2 " Language: C-shell (tcsh)
|
25973
|
3 " Maintainer: Doug Kearns <dougkearns@gmail.com>
|
|
4 " Previous Maintainer: Gautam Iyer <gi1242+vim@NoSpam.com> where NoSpam=gmail (Original Author)
|
|
5 " Last Change: 2021 Oct 15
|
7
|
6
|
|
7 " Only load this indent file when no other was loaded.
|
|
8 if exists("b:did_indent")
|
|
9 finish
|
|
10 endif
|
|
11
|
|
12 let b:did_indent = 1
|
|
13
|
|
14 setlocal indentexpr=TcshGetIndent()
|
25973
|
15 setlocal indentkeys+=e,0=end
|
|
16 setlocal indentkeys-=0{,0},0),:,0#
|
|
17
|
25880
|
18 let b:undo_indent = "setl inde< indk<"
|
7
|
19
|
|
20 " Only define the function once.
|
|
21 if exists("*TcshGetIndent")
|
|
22 finish
|
|
23 endif
|
|
24
|
|
25 function TcshGetIndent()
|
|
26 " Find a non-blank line above the current line.
|
|
27 let lnum = prevnonblank(v:lnum - 1)
|
|
28
|
|
29 " Hit the start of the file, use zero indent.
|
|
30 if lnum == 0
|
|
31 return 0
|
|
32 endif
|
|
33
|
|
34 " Add indent if previous line begins with while or foreach
|
|
35 " OR line ends with case <str>:, default:, else, then or \
|
|
36 let ind = indent(lnum)
|
|
37 let line = getline(lnum)
|
|
38 if line =~ '\v^\s*%(while|foreach)>|^\s*%(case\s.*:|default:|else)\s*$|%(<then|\\)$'
|
11160
|
39 let ind = ind + shiftwidth()
|
7
|
40 endif
|
|
41
|
|
42 if line =~ '\v^\s*breaksw>'
|
11160
|
43 let ind = ind - shiftwidth()
|
7
|
44 endif
|
|
45
|
25973
|
46 " Subtract indent if current line has on end, endif, endsw, case commands
|
7
|
47 let line = getline(v:lnum)
|
25973
|
48 if line =~ '\v^\s*%(else|end|endif|endsw)\s*$'
|
11160
|
49 let ind = ind - shiftwidth()
|
7
|
50 endif
|
|
51
|
|
52 return ind
|
|
53 endfunction
|