robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

Christian Clasonvim-patch:ce001a337e28 (#18287)521e91e1c4

master
1.6 KiB74 linesraw
1" Vim indent file
2" Language:     tf (TinyFugue)
3" Maintainer:   Christian J. Robinson <heptite@gmail.com>
4" URL:          http://www.vim.org/scripts/script.php?script_id=174
5" Last Change:  2022 Apr 25
6
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
17let b:undo_indent = "setlocal indentexpr< indentkeys<"
18
19" 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*\)\@\<!\\\)$'
43		let ind = ind + shiftwidth()
44	elseif line =~ '\(/if\|/else\|/then\)'
45		if line !~ '/endif'
46			let ind = ind + shiftwidth()
47		endif
48	elseif line =~ '/while'
49		if line !~ '/done'
50			let ind = ind + shiftwidth()
51		endif
52	endif
53
54	let line = getline(v:lnum)
55
56	if line =~ '\(/else\|/endif\|/then\)'
57		if line !~ '/if'
58			let ind = ind - shiftwidth()
59		endif
60	elseif line =~ '/done'
61		if line !~ '/while'
62			let ind = ind - shiftwidth()
63		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