blob: 8467cefcc01fcad8c8c9d3bce8fecd30dbf8e1fe [file] [log] [blame]
Bram Moolenaarf9132812015-07-21 19:19:13 +02001" Vim indent file
2" Language: Tera Term Language (TTL)
Bram Moolenaar7571d552016-08-18 22:54:46 +02003" Based on Tera Term Version 4.92
Bram Moolenaarf9132812015-07-21 19:19:13 +02004" Maintainer: Ken Takata
5" URL: https://github.com/k-takata/vim-teraterm
Bram Moolenaar7571d552016-08-18 22:54:46 +02006" Last Change: 2016 Aug 17
Bram Moolenaarf9132812015-07-21 19:19:13 +02007" 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')
Bram Moolenaar7571d552016-08-18 22:54:46 +020028 let s:sw = function('shiftwidth')
Bram Moolenaarf9132812015-07-21 19:19:13 +020029else
30 function s:sw() abort
31 return &shiftwidth
32 endfunction
33endif
34
35function! GetTeraTermIndent(lnum)
36 let l:prevlnum = prevnonblank(a:lnum-1)
37 if l:prevlnum == 0
38 " top of file
39 return 0
40 endif
41
42 " grab the previous and current line, stripping comments.
43 let l:prevl = substitute(getline(l:prevlnum), ';.*$', '', '')
44 let l:thisl = substitute(getline(a:lnum), ';.*$', '', '')
45 let l:previ = indent(l:prevlnum)
46
47 let l:ind = l:previ
48
Bram Moolenaar7571d552016-08-18 22:54:46 +020049 if l:prevl =~ '^\s*if\>.*\<then\>'
Bram Moolenaarf9132812015-07-21 19:19:13 +020050 " previous line opened a block
51 let l:ind += s:sw()
52 endif
53 if l:prevl =~ '^\s*\%(elseif\|else\|do\|until\|while\|for\)\>'
54 " previous line opened a block
55 let l:ind += s:sw()
56 endif
57 if l:thisl =~ '^\s*\%(elseif\|else\|endif\|enduntil\|endwhile\|loop\|next\)\>'
58 " this line closed a block
59 let l:ind -= s:sw()
60 endif
61
62 return l:ind
63endfunction
64
65" vim: ts=8 sw=2 sts=2