blob: ba24257b02dcb3df6602ab5243e1e02f2c62dbcb [file] [log] [blame]
Bram Moolenaarf9132812015-07-21 19:19:13 +02001" Vim indent file
2" Language: Tera Term Language (TTL)
3" Based on Tera Term Version 4.86
4" Maintainer: Ken Takata
5" URL: https://github.com/k-takata/vim-teraterm
6" Last Change: 2015 Jun 4
7" Filenames: *.ttl
8" License: VIM License
9
10if exists("b:did_indent")
11 finish
12endif
13let b:did_indent = 1
14
15setlocal nosmartindent
16setlocal noautoindent
17setlocal indentexpr=GetTeraTermIndent(v:lnum)
18setlocal indentkeys=!^F,o,O,e
19setlocal indentkeys+==elseif,=endif,=loop,=next,=enduntil,=endwhile
20
21if exists("*GetTeraTermIndent")
22 finish
23endif
24
25" The shiftwidth() function is relatively new.
26" Don't require it to exist.
27if exists('*shiftwidth')
28 function s:sw() abort
29 return shiftwidth()
30 endfunction
31else
32 function s:sw() abort
33 return &shiftwidth
34 endfunction
35endif
36
37function! GetTeraTermIndent(lnum)
38 let l:prevlnum = prevnonblank(a:lnum-1)
39 if l:prevlnum == 0
40 " top of file
41 return 0
42 endif
43
44 " grab the previous and current line, stripping comments.
45 let l:prevl = substitute(getline(l:prevlnum), ';.*$', '', '')
46 let l:thisl = substitute(getline(a:lnum), ';.*$', '', '')
47 let l:previ = indent(l:prevlnum)
48
49 let l:ind = l:previ
50
51 if l:prevl =~ '^\s*if\>.*\<then\s*$'
52 " previous line opened a block
53 let l:ind += s:sw()
54 endif
55 if l:prevl =~ '^\s*\%(elseif\|else\|do\|until\|while\|for\)\>'
56 " previous line opened a block
57 let l:ind += s:sw()
58 endif
59 if l:thisl =~ '^\s*\%(elseif\|else\|endif\|enduntil\|endwhile\|loop\|next\)\>'
60 " this line closed a block
61 let l:ind -= s:sw()
62 endif
63
64 return l:ind
65endfunction
66
67" vim: ts=8 sw=2 sts=2