neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

teraterm.vim (1413B)


      1 " Vim indent file
      2 " Language:	Tera Term Language (TTL)
      3 "		Based on Tera Term Version 4.100
      4 " Maintainer:	Ken Takata
      5 " URL:		https://github.com/k-takata/vim-teraterm
      6 " Last Change:	2021-10-18
      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 let b:undo_indent = "setl ai< inde< indk< si<"
     22 
     23 if exists("*GetTeraTermIndent")
     24  finish
     25 endif
     26 
     27 function! GetTeraTermIndent(lnum)
     28  let l:prevlnum = prevnonblank(a:lnum-1)
     29  if l:prevlnum == 0
     30    " top of file
     31    return 0
     32  endif
     33 
     34  " grab the previous and current line, stripping comments.
     35  let l:prevl = substitute(getline(l:prevlnum), ';.*$', '', '')
     36  let l:thisl = substitute(getline(a:lnum), ';.*$', '', '')
     37  let l:previ = indent(l:prevlnum)
     38 
     39  let l:ind = l:previ
     40 
     41  if l:prevl =~ '^\s*if\>.*\<then\>'
     42    " previous line opened a block
     43    let l:ind += shiftwidth()
     44  endif
     45  if l:prevl =~ '^\s*\%(elseif\|else\|do\|until\|while\|for\)\>'
     46    " previous line opened a block
     47    let l:ind += shiftwidth()
     48  endif
     49  if l:thisl =~ '^\s*\%(elseif\|else\|endif\|enduntil\|endwhile\|loop\|next\)\>'
     50    " this line closed a block
     51    let l:ind -= shiftwidth()
     52  endif
     53 
     54  return l:ind
     55 endfunction
     56 
     57 " vim: ts=8 sw=2 sts=2