blob: bb40bf6f01c0dab96e4b44ad7b8209b4355ad52b [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
Bram Moolenaarce001a32022-04-27 15:25:03 +01005" Last Change: 2022 Apr 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
Bram Moolenaarce001a32022-04-27 15:25:03 +010017let b:undo_indent = "setlocal indentexpr< indentkeys<"
18
Bram Moolenaar8c8de832008-06-24 22:58:06 +000019" Only define the function once:
20if exists("*GetTFIndent")
21 finish
22endif
23
24function GetTFIndent()
25 " Find a non-blank line above the current line:
26 let lnum = prevnonblank(v:lnum - 1)
27
28 " No indent for the start of the file:
29 if lnum == 0
30 return 0
31 endif
32
33 let ind = indent(lnum)
34 let line = getline(lnum)
35
36 " No indentation if the previous line didn't end with "\":
37 " (Could be annoying, but it lets you know if you made a mistake.)
38 if line !~ '\\$'
39 return 0
40 endif
41
42 if line =~ '\(/def.*\\\|/for.*\(%;\s*\)\@\<!\\\)$'
Bram Moolenaar214641f2017-03-05 17:04:09 +010043 let ind = ind + shiftwidth()
Bram Moolenaar8c8de832008-06-24 22:58:06 +000044 elseif line =~ '\(/if\|/else\|/then\)'
45 if line !~ '/endif'
Bram Moolenaar214641f2017-03-05 17:04:09 +010046 let ind = ind + shiftwidth()
Bram Moolenaar8c8de832008-06-24 22:58:06 +000047 endif
48 elseif line =~ '/while'
49 if line !~ '/done'
Bram Moolenaar214641f2017-03-05 17:04:09 +010050 let ind = ind + shiftwidth()
Bram Moolenaar8c8de832008-06-24 22:58:06 +000051 endif
52 endif
53
54 let line = getline(v:lnum)
55
56 if line =~ '\(/else\|/endif\|/then\)'
57 if line !~ '/if'
Bram Moolenaar214641f2017-03-05 17:04:09 +010058 let ind = ind - shiftwidth()
Bram Moolenaar8c8de832008-06-24 22:58:06 +000059 endif
60 elseif line =~ '/done'
61 if line !~ '/while'
Bram Moolenaar214641f2017-03-05 17:04:09 +010062 let ind = ind - shiftwidth()
Bram Moolenaar8c8de832008-06-24 22:58:06 +000063 endif
64 endif
65
66 " Comments at the beginning of a line:
67 if line =~ '^\s*;'
68 let ind = 0
69 endif
70
71
72 return ind
73
74endfunction