idlang.vim 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. " 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. setlocal indentkeys=o,O,0=endif,0=ENDIF,0=endelse,0=ENDELSE,0=endwhile,0=ENDWHILE,0=endfor,0=ENDFOR,0=endrep,0=ENDREP
  12. setlocal indentexpr=GetIdlangIndent(v:lnum)
  13. let b:undo_indent = "setl inde< indk<"
  14. " Only define the function once.
  15. if exists("*GetIdlangIndent")
  16. finish
  17. endif
  18. function GetIdlangIndent(lnum)
  19. " First non-empty line above the current line.
  20. let pnum = prevnonblank(v:lnum-1)
  21. " v:lnum is the first non-empty line -- zero indent.
  22. if pnum == 0
  23. return 0
  24. endif
  25. " Second non-empty line above the current line.
  26. let pnum2 = prevnonblank(pnum-1)
  27. " Current indent.
  28. let curind = indent(pnum)
  29. " Indenting of continued lines.
  30. if getline(pnum) =~ '\$\s*\(;.*\)\=$'
  31. if getline(pnum2) !~ '\$\s*\(;.*\)\=$'
  32. let curind = curind+shiftwidth()
  33. endif
  34. else
  35. if getline(pnum2) =~ '\$\s*\(;.*\)\=$'
  36. let curind = curind-shiftwidth()
  37. endif
  38. endif
  39. " Indenting blocks of statements.
  40. if getline(v:lnum) =~? '^\s*\(endif\|endelse\|endwhile\|endfor\|endrep\)\>'
  41. if getline(pnum) =~? 'begin\>'
  42. elseif indent(v:lnum) > curind-shiftwidth()
  43. let curind = curind-shiftwidth()
  44. else
  45. return -1
  46. endif
  47. elseif getline(pnum) =~? 'begin\>'
  48. if indent(v:lnum) < curind+shiftwidth()
  49. let curind = curind+shiftwidth()
  50. else
  51. return -1
  52. endif
  53. endif
  54. return curind
  55. endfunction