blob: 025d9c805dcdc3d1df7e58f6b9d444064970edf3 [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001" Vim indent file
2" Language: C-shell (tcsh)
Bram Moolenaar6e649222021-10-04 21:32:54 +01003" Maintainer: Doug Kearns <a@b.com> where a=dougkearns, b=gmail
4" Last Modified: Sun 26 Sep 2021 12:38:38 PM EDT
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 Moolenaar6e649222021-10-04 21:32:54 +010015let b:undo_indent = "setl inde< indk<"
Bram Moolenaar071d4272004-06-13 20:20:40 +000016
17" Only define the function once.
18if exists("*TcshGetIndent")
19 finish
20endif
21
Bram Moolenaar071d4272004-06-13 20:20:40 +000022function TcshGetIndent()
23 " Find a non-blank line above the current line.
24 let lnum = prevnonblank(v:lnum - 1)
25
26 " Hit the start of the file, use zero indent.
27 if lnum == 0
28 return 0
29 endif
30
31 " Add indent if previous line begins with while or foreach
32 " OR line ends with case <str>:, default:, else, then or \
33 let ind = indent(lnum)
34 let line = getline(lnum)
35 if line =~ '\v^\s*%(while|foreach)>|^\s*%(case\s.*:|default:|else)\s*$|%(<then|\\)$'
Bram Moolenaar036986f2017-03-16 17:41:02 +010036 let ind = ind + shiftwidth()
Bram Moolenaar071d4272004-06-13 20:20:40 +000037 endif
38
39 if line =~ '\v^\s*breaksw>'
Bram Moolenaar036986f2017-03-16 17:41:02 +010040 let ind = ind - shiftwidth()
Bram Moolenaar071d4272004-06-13 20:20:40 +000041 endif
42
43 " Subtract indent if current line has on end, endif, case commands
44 let line = getline(v:lnum)
45 if line =~ '\v^\s*%(else|end|endif)\s*$'
Bram Moolenaar036986f2017-03-16 17:41:02 +010046 let ind = ind - shiftwidth()
Bram Moolenaar071d4272004-06-13 20:20:40 +000047 endif
48
49 return ind
50endfunction