vim

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

chaiscript.vim (1204B)


      1 " Vim indent file
      2 " Language:     ChaiScript
      3 " Maintainer:	Jason Turner <lefticus 'at' gmail com>
      4 " Last Change: 	2022 Apr 06
      5 
      6 " Only load this indent file when no other was loaded.
      7 if exists("b:did_indent")
      8   finish
      9 endif
     10 let b:did_indent = 1
     11 
     12 setlocal indentexpr=GetChaiScriptIndent()
     13 setlocal autoindent
     14 
     15 let b:undo_indent = "setl ai< inde<"
     16 
     17 " Only define the function once.
     18 if exists("*GetChaiScriptIndent")
     19   finish
     20 endif
     21 
     22 function! GetChaiScriptIndent()
     23   " Find a non-blank line above the current line.
     24   let lnum = prevnonblank(v:lnum - 1)
     25 
     26   " Hit the start of the file, use zero indent.
     27   if lnum == 0
     28     return 0
     29   endif
     30 
     31   " Add a 'shiftwidth' after lines that start a block:
     32   " lines containing a {
     33   let ind = indent(lnum)
     34   let flag = 0
     35   let prevline = getline(lnum)
     36   if prevline =~ '^.*{.*'
     37     let ind = ind + shiftwidth()
     38     let flag = 1
     39   endif
     40 
     41   " Subtract a 'shiftwidth' after lines containing a { followed by a }
     42   " to keep it balanced
     43   if flag == 1 && prevline =~ '.*{.*}.*'
     44     let ind = ind - shiftwidth()
     45   endif
     46 
     47   " Subtract a 'shiftwidth' on lines ending with }
     48   if getline(v:lnum) =~ '^\s*\%(}\)'
     49     let ind = ind - shiftwidth()
     50   endif
     51 
     52   return ind
     53 endfunction