logtalk.vim 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. " Maintainer: Paulo Moura <pmoura@logtalk.org>
  2. " Revised on: 2018.08.04
  3. " Language: Logtalk
  4. " This Logtalk indent file is a modified version of the Prolog
  5. " indent file written by Gergely Kontra
  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 indentexpr=GetLogtalkIndent()
  12. setlocal indentkeys-=:,0#
  13. setlocal indentkeys+=0%,-,0;,>,0)
  14. " Only define the function once.
  15. if exists("*GetLogtalkIndent")
  16. finish
  17. endif
  18. function! GetLogtalkIndent()
  19. " Find a non-blank line above the current line.
  20. let pnum = prevnonblank(v:lnum - 1)
  21. " Hit the start of the file, use zero indent.
  22. if pnum == 0
  23. return 0
  24. endif
  25. let line = getline(v:lnum)
  26. let pline = getline(pnum)
  27. let ind = indent(pnum)
  28. " Previous line was comment -> use previous line's indent
  29. if pline =~ '^\s*%'
  30. retu ind
  31. endif
  32. " Check for entity opening directive on previous line
  33. if pline =~ '^\s*:-\s\(object\|protocol\|category\)\ze(.*,$'
  34. let ind = ind + shiftwidth()
  35. " Check for clause head on previous line
  36. elseif pline =~ ':-\s*\(%.*\)\?$'
  37. let ind = ind + shiftwidth()
  38. " Check for grammar rule head on previous line
  39. elseif pline =~ '-->\s*\(%.*\)\?$'
  40. let ind = ind + shiftwidth()
  41. " Check for entity closing directive on previous line
  42. elseif pline =~ '^\s*:-\send_\(object\|protocol\|category\)\.\(%.*\)\?$'
  43. let ind = ind - shiftwidth()
  44. " Check for end of clause on previous line
  45. elseif pline =~ '\.\s*\(%.*\)\?$'
  46. let ind = ind - shiftwidth()
  47. endif
  48. " Check for opening conditional on previous line
  49. if pline =~ '^\s*\([(;]\|->\)' && pline !~ '\.\s*\(%.*\)\?$' && pline !~ '^.*\([)][,]\s*\(%.*\)\?$\)'
  50. let ind = ind + shiftwidth()
  51. endif
  52. " Check for closing an unclosed paren, or middle ; or ->
  53. if line =~ '^\s*\([);]\|->\)'
  54. let ind = ind - shiftwidth()
  55. endif
  56. return ind
  57. endfunction