vim

Fork of vim, an acceptable text editor
git clone git://git.laack.co/vim.git
Log | Files | Refs | README | LICENSE

j.vim (1812B)


      1 " Vim indent file
      2 " Language:	J
      3 " Maintainer:	David Bürgin <dbuergin@gluet.ch>
      4 " URL:		https://gitlab.com/glts/vim-j
      5 " Last Change:	2015-01-11
      6 
      7 if exists('b:did_indent')
      8   finish
      9 endif
     10 let b:did_indent = 1
     11 
     12 setlocal indentexpr=GetJIndent()
     13 setlocal indentkeys-=0{,0},:,0#
     14 setlocal indentkeys+=0),0<:>,=case.,=catch.,=catchd.,=catcht.,=do.,=else.,=elseif.,=end.,=fcase.
     15 
     16 let b:undo_indent = 'setlocal indentkeys< indentexpr<'
     17 
     18 if exists('*GetJIndent')
     19   finish
     20 endif
     21 
     22 " If g:j_indent_definitions is true, the bodies of explicit definitions of
     23 " adverbs, conjunctions, and verbs will be indented. Default is false (0).
     24 if !exists('g:j_indent_definitions')
     25   let g:j_indent_definitions = 0
     26 endif
     27 
     28 function GetJIndent() abort
     29   let l:prevlnum = prevnonblank(v:lnum - 1)
     30   if l:prevlnum == 0
     31     return 0
     32   endif
     33   let l:indent = indent(l:prevlnum)
     34   let l:prevline = getline(l:prevlnum)
     35   if l:prevline =~# '^\s*\%(case\|catch[dt]\=\|do\|else\%(if\)\=\|fcase\|for\%(_\a\k*\)\=\|if\|select\|try\|whil\%(e\|st\)\)\.\%(\%(\<end\.\)\@!.\)*$'
     36     " Increase indentation after an initial control word that starts or
     37     " continues a block and is not terminated by "end."
     38     let l:indent += shiftwidth()
     39   elseif g:j_indent_definitions && (l:prevline =~# '\<\%([1-4]\|13\|adverb\|conjunction\|verb\|monad\|dyad\)\s\+\%(:\s*0\|def\s\+0\|define\)\>' || l:prevline =~# '^\s*:\s*$')
     40     " Increase indentation in explicit definitions of adverbs, conjunctions,
     41     " and verbs
     42     let l:indent += shiftwidth()
     43   endif
     44   " Decrease indentation in lines that start with either control words that
     45   " continue or end a block, or the special items ")" and ":"
     46   if getline(v:lnum) =~# '^\s*\%()\|:\|\%(case\|catch[dt]\=\|do\|else\%(if\)\=\|end\|fcase\)\.\)'
     47     let l:indent -= shiftwidth()
     48   endif
     49   return l:indent
     50 endfunction