blob: a98053850611b37d2df031de2583cdd6dd4b8791 [file] [log] [blame]
Bram Moolenaar8c8de832008-06-24 22:58:06 +00001" Vim indent file
2" Language: tf (TinyFugue)
Bram Moolenaara3ff49f2010-05-30 22:48:02 +02003" Maintainer: Christian J. Robinson <heptite@gmail.com>
Bram Moolenaar214641f2017-03-05 17:04:09 +01004" URL: http://www.vim.org/scripts/script.php?script_id=174
5" Last Change: 2017 Feb 25
Bram Moolenaar8c8de832008-06-24 22:58:06 +00006
7" Only load this indent file when no other was loaded.
8if exists("b:did_indent")
9 finish
10endif
11let b:did_indent = 1
12
13setlocal indentexpr=GetTFIndent()
14setlocal indentkeys-=0{,0} indentkeys-=0# indentkeys-=:
15setlocal indentkeys+==/endif,=/then,=/else,=/done,0;
16
17" Only define the function once:
18if exists("*GetTFIndent")
19 finish
20endif
21
22function GetTFIndent()
23 " Find a non-blank line above the current line:
24 let lnum = prevnonblank(v:lnum - 1)
25
26 " No indent for the start of the file:
27 if lnum == 0
28 return 0
29 endif
30
31 let ind = indent(lnum)
32 let line = getline(lnum)
33
34 " No indentation if the previous line didn't end with "\":
35 " (Could be annoying, but it lets you know if you made a mistake.)
36 if line !~ '\\$'
37 return 0
38 endif
39
40 if line =~ '\(/def.*\\\|/for.*\(%;\s*\)\@\<!\\\)$'
Bram Moolenaar214641f2017-03-05 17:04:09 +010041 let ind = ind + shiftwidth()
Bram Moolenaar8c8de832008-06-24 22:58:06 +000042 elseif line =~ '\(/if\|/else\|/then\)'
43 if line !~ '/endif'
Bram Moolenaar214641f2017-03-05 17:04:09 +010044 let ind = ind + shiftwidth()
Bram Moolenaar8c8de832008-06-24 22:58:06 +000045 endif
46 elseif line =~ '/while'
47 if line !~ '/done'
Bram Moolenaar214641f2017-03-05 17:04:09 +010048 let ind = ind + shiftwidth()
Bram Moolenaar8c8de832008-06-24 22:58:06 +000049 endif
50 endif
51
52 let line = getline(v:lnum)
53
54 if line =~ '\(/else\|/endif\|/then\)'
55 if line !~ '/if'
Bram Moolenaar214641f2017-03-05 17:04:09 +010056 let ind = ind - shiftwidth()
Bram Moolenaar8c8de832008-06-24 22:58:06 +000057 endif
58 elseif line =~ '/done'
59 if line !~ '/while'
Bram Moolenaar214641f2017-03-05 17:04:09 +010060 let ind = ind - shiftwidth()
Bram Moolenaar8c8de832008-06-24 22:58:06 +000061 endif
62 endif
63
64 " Comments at the beginning of a line:
65 if line =~ '^\s*;'
66 let ind = 0
67 endif
68
69
70 return ind
71
72endfunction