add vim conf files
[arrow.git] / conf_slk120 / vim / _vim / indent / viki.vim
blobaf1d60d6e0d11d13126daa482f8726d721e9d161
1 " viki.vim -- viki indentation
2 " @Author:      Thomas Link (samul AT web.de)
3 " @Website:     http://members.a1.net/t.link/
4 " @License:     GPL (see http://www.gnu.org/licenses/gpl.txt)
5 " @Created:     16-Jän-2004.
6 " @Last Change: 29-Okt-2005.
7 " @Revision: 0.222
9 if !g:vikiEnabled
10     finish
11 endif
13 if exists("b:did_indent") || exists("g:vikiNoIndent")
14     finish
15 endif
16 let b:did_indent = 1
18 " Possible values: 'sw', '::'
19 if !exists("g:vikiIndentDesc") | let g:vikiIndentDesc = 'sw' | endif "{{{2
21 setlocal indentexpr=VikiGetIndent()
22 setlocal indentkeys&
23 setlocal indentkeys=0=#\ ,0=?\ ,0=<*>\ ,0=-\ ,0=+\ ,0=@\ ,=::\ ,!^F,o,O,e
24 " setlocal indentkeys=0=#<space>,0=?<space>,0=<*><space>,0=-<space>,=::<space>,!^F,o,O,e
26 " Only define the function once.
27 if exists("*VikiGetIndent")
28     finish
29 endif
31 fun! VikiGetIndent()
32     " Find a non-blank line above the current line.
33     let lnum = prevnonblank(v:lnum - 1)
35     " At the start of the file use zero indent.
36     if lnum == 0
37         return 0
38     endif
40     let ind  = indent(lnum)
41     let line = getline(lnum)      " last line
42     
43     let cnum  = v:lnum
44     let cind  = indent(cnum)
45     let cline = getline(cnum)
46     
47     " Do not change indentation in regions
48     if VikiIsInRegion(cnum)
49         return cind
50     endif
51     
52     let cHeading = matchend(cline, '^\*\+\s\+')
53     if cHeading >= 0
54         return 0
55     endif
56         
57     let pnum   = v:lnum - 1
58     let pind   = indent(pnum)
59     
60     let pline  = getline(pnum) " last line
61     let plCont = matchend(pline, '\\$')
62     
63     if plCont >= 0
64         let plHeading = matchend(pline, '^\*\+\s\+')
65         " if plHeading >= 0
66         "     " echo "DBG continuation plHeading=". plHeading
67         "     return plHeading
68         " else
69         "     " echo "DBG continuation pind=". pind
70             return pind
71         " endif
72     end
73     
74     if cind > 0
75         " Do not change indentation of:
76         "   - commented lines
77         "   - headings
78         if cline =~ '^\(\s*%\|\*\)'
79             " echom "DBG comment or heading: ". cline
80             return ind
81         endif
83         let markRx = '^\s\+\([#?!+]\)\1\{2,2}\s\+'
84         let listRx = '^\s\+\([-+*#?@]\|[0-9#]\+\.\|[a-zA-Z?]\.\)\s\+'
85         let priRx  = '^\s\+#[A-F]\d\? \+[x_] \+'
86         let descRx = '^\s\+.\{-1,}\s::\s\+'
87         
88         let clMark = matchend(cline, markRx)
89         let clList = matchend(cline, listRx)
90         let clPri  = matchend(cline, priRx)
91         let clDesc = matchend(cline, descRx)
92         " let cln    = clList >= 0 ? clList : clDesc
94         if clList >= 0 || clDesc >= 0 || clMark >= 0 || clPri >= 0
95             let spaceEnd = matchend(cline, '^\s\+')
96             let rv = (spaceEnd / &sw) * &sw
97             " echom "DBG clList=". clList ." clDesc=". clDesc
98             return rv
99         else
100             let plMark = matchend(pline, markRx)
101             if plMark >= 0
102                 return plMark
103             endif
104             
105             let plList = matchend(pline, listRx)
106             if plList >= 0
107                 " echom "DBG plList ". plList ." ". pline
108                 return plList
109             endif
111             let plPri = matchend(pline, priRx)
112             " echom "DBG plPri=". plPri
113             if plPri >= 0
114                 return plPri
115             endif
117             let plDesc = matchend(pline, descRx)
118             if plDesc >= 0
119                 " echom "DBG plDesc ". pind + (&sw / 2)
120                 if plDesc >= 0 && g:vikiIndentDesc == '::'
121                     return plDesc
122                 else
123                     return pind + (&sw / 2)
124                 endif
125             endif
127             if cind < ind
128                 let rv = (cind / &sw) * &sw
129                 " echom "DBG cind < ind ". rv
130                 return rv
131             elseif cind >= ind
132                 if cind % &sw == 0
133                     " echom "DBG cind % &sw ". cind
134                     return cind
135                 else
136                     " echom "DBG cind >= ind ". ind
137                     return ind
138                 end
139             endif
140         endif
141     endif
143     " echom "DBG fallback"
144     return ind
145 endfun