neovim

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

idlang.vim (1723B)


      1 " IDL (Interactive Data Language) indent file.
      2 " Language:	IDL (ft=idlang)
      3 " Maintainer:	Aleksandar Jelenak <ajelenak AT yahoo.com> (Invalid email address)
      4 " 		Doug Kearns <dougkearns@gmail.com>
      5 " Last change:	2022 Apr 06
      6 
      7 " Only load this indent file when no other was loaded.
      8 if exists("b:did_indent")
      9   finish
     10 endif
     11 let b:did_indent = 1
     12 
     13 setlocal indentkeys=o,O,0=endif,0=ENDIF,0=endelse,0=ENDELSE,0=endwhile,0=ENDWHILE,0=endfor,0=ENDFOR,0=endrep,0=ENDREP
     14 
     15 setlocal indentexpr=GetIdlangIndent(v:lnum)
     16 
     17 let b:undo_indent = "setl inde< indk<"
     18 
     19 " Only define the function once.
     20 if exists("*GetIdlangIndent")
     21   finish
     22 endif
     23 
     24 function GetIdlangIndent(lnum)
     25   " First non-empty line above the current line.
     26   let pnum = prevnonblank(v:lnum-1)
     27   " v:lnum is the first non-empty line -- zero indent.
     28   if pnum == 0
     29      return 0
     30   endif
     31   " Second non-empty line above the current line.
     32   let pnum2 = prevnonblank(pnum-1)
     33 
     34   " Current indent.
     35   let curind = indent(pnum)
     36 
     37   " Indenting of continued lines.
     38   if getline(pnum) =~ '\$\s*\(;.*\)\=$'
     39      if getline(pnum2) !~ '\$\s*\(;.*\)\=$'
     40  let curind = curind+shiftwidth()
     41      endif
     42   else
     43      if getline(pnum2) =~ '\$\s*\(;.*\)\=$'
     44  let curind = curind-shiftwidth()
     45      endif
     46   endif
     47 
     48   " Indenting blocks of statements.
     49   if getline(v:lnum) =~? '^\s*\(endif\|endelse\|endwhile\|endfor\|endrep\)\>'
     50      if getline(pnum) =~? 'begin\>'
     51      elseif indent(v:lnum) > curind-shiftwidth()
     52  let curind = curind-shiftwidth()
     53      else
     54  return -1
     55      endif
     56   elseif getline(pnum) =~? 'begin\>'
     57      if indent(v:lnum) < curind+shiftwidth()
     58  let curind = curind+shiftwidth()
     59      else
     60  return -1
     61      endif
     62   endif
     63   return curind
     64 endfunction