Mercurial > vim
comparison runtime/indent/teraterm.vim @ 6951:b2673982c625
Updated and new runtime files.
author | Bram Moolenaar <bram@vim.org> |
---|---|
date | Tue, 21 Jul 2015 19:19:13 +0200 |
parents | |
children | 2b6654519a7c |
comparison
equal
deleted
inserted
replaced
6950:21cbf1529a71 | 6951:b2673982c625 |
---|---|
1 " 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 | |
10 if exists("b:did_indent") | |
11 finish | |
12 endif | |
13 let b:did_indent = 1 | |
14 | |
15 setlocal nosmartindent | |
16 setlocal noautoindent | |
17 setlocal indentexpr=GetTeraTermIndent(v:lnum) | |
18 setlocal indentkeys=!^F,o,O,e | |
19 setlocal indentkeys+==elseif,=endif,=loop,=next,=enduntil,=endwhile | |
20 | |
21 if exists("*GetTeraTermIndent") | |
22 finish | |
23 endif | |
24 | |
25 " The shiftwidth() function is relatively new. | |
26 " Don't require it to exist. | |
27 if exists('*shiftwidth') | |
28 function s:sw() abort | |
29 return shiftwidth() | |
30 endfunction | |
31 else | |
32 function s:sw() abort | |
33 return &shiftwidth | |
34 endfunction | |
35 endif | |
36 | |
37 function! 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 | |
65 endfunction | |
66 | |
67 " vim: ts=8 sw=2 sts=2 |