blob: 35d7354290d8f3879ef8bf697096b8539e976a2b [file] [log] [blame]
Bram Moolenaarf9132812015-07-21 19:19:13 +02001" Vim indent file
2" Language: Tera Term Language (TTL)
Bram Moolenaar20aac6c2018-09-02 21:07:30 +02003" Based on Tera Term Version 4.100
Bram Moolenaarf9132812015-07-21 19:19:13 +02004" Maintainer: Ken Takata
5" URL: https://github.com/k-takata/vim-teraterm
Bram Moolenaar20aac6c2018-09-02 21:07:30 +02006" Last Change: 2018-08-31
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
Bram Moolenaarf9132812015-07-21 19:19:13 +020025function! GetTeraTermIndent(lnum)
26 let l:prevlnum = prevnonblank(a:lnum-1)
27 if l:prevlnum == 0
28 " top of file
29 return 0
30 endif
31
32 " grab the previous and current line, stripping comments.
33 let l:prevl = substitute(getline(l:prevlnum), ';.*$', '', '')
34 let l:thisl = substitute(getline(a:lnum), ';.*$', '', '')
35 let l:previ = indent(l:prevlnum)
36
37 let l:ind = l:previ
38
Bram Moolenaar7571d552016-08-18 22:54:46 +020039 if l:prevl =~ '^\s*if\>.*\<then\>'
Bram Moolenaarf9132812015-07-21 19:19:13 +020040 " previous line opened a block
Bram Moolenaar3ec574f2017-06-13 18:12:01 +020041 let l:ind += shiftwidth()
Bram Moolenaarf9132812015-07-21 19:19:13 +020042 endif
43 if l:prevl =~ '^\s*\%(elseif\|else\|do\|until\|while\|for\)\>'
44 " previous line opened a block
Bram Moolenaar3ec574f2017-06-13 18:12:01 +020045 let l:ind += shiftwidth()
Bram Moolenaarf9132812015-07-21 19:19:13 +020046 endif
47 if l:thisl =~ '^\s*\%(elseif\|else\|endif\|enduntil\|endwhile\|loop\|next\)\>'
48 " this line closed a block
Bram Moolenaar3ec574f2017-06-13 18:12:01 +020049 let l:ind -= shiftwidth()
Bram Moolenaarf9132812015-07-21 19:19:13 +020050 endif
51
52 return l:ind
53endfunction
54
55" vim: ts=8 sw=2 sts=2