prolog.vim 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. " vim: set sw=4 sts=4:
  2. " Maintainer : Gergely Kontra <kgergely@mcl.hu>
  3. " Revised on : 2002.02.18. 23:34:05
  4. " Language : Prolog
  5. " Last change by: Takuya Fujiwara, 2018 Sep 23
  6. " TODO:
  7. " checking with respect to syntax highlighting
  8. " ignoring multiline comments
  9. " detecting multiline strings
  10. " Only load this indent file when no other was loaded.
  11. if exists("b:did_indent")
  12. finish
  13. endif
  14. let b:did_indent = 1
  15. setlocal indentexpr=GetPrologIndent()
  16. setlocal indentkeys-=:,0#
  17. setlocal indentkeys+=0%,-,0;,>,0)
  18. " Only define the function once.
  19. "if exists("*GetPrologIndent")
  20. " finish
  21. "endif
  22. function! GetPrologIndent()
  23. " Find a non-blank line above the current line.
  24. let pnum = prevnonblank(v:lnum - 1)
  25. " Hit the start of the file, use zero indent.
  26. if pnum == 0
  27. return 0
  28. endif
  29. let line = getline(v:lnum)
  30. let pline = getline(pnum)
  31. let ind = indent(pnum)
  32. " Previous line was comment -> use previous line's indent
  33. if pline =~ '^\s*%'
  34. return ind
  35. endif
  36. " Previous line was the start of block comment -> +1 after '/*' comment
  37. if pline =~ '^\s*/\*'
  38. return ind + 1
  39. endif
  40. " Previous line was the end of block comment -> -1 after '*/' comment
  41. if pline =~ '^\s*\*/'
  42. return ind - 1
  43. endif
  44. " Check for clause head on previous line
  45. if pline =~ '\%(:-\|-->\)\s*\(%.*\)\?$'
  46. let ind = ind + shiftwidth()
  47. " Check for end of clause on previous line
  48. elseif pline =~ '\.\s*\(%.*\)\?$'
  49. let ind = ind - shiftwidth()
  50. endif
  51. " Check for opening conditional on previous line
  52. if pline =~ '^\s*\([(;]\|->\)'
  53. let ind = ind + shiftwidth()
  54. endif
  55. " Check for closing an unclosed paren, or middle ; or ->
  56. if line =~ '^\s*\([);]\|->\)'
  57. let ind = ind - shiftwidth()
  58. endif
  59. return ind
  60. endfunction