prolog.vim 1.8 KB

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