logtalk.vim 1.9 KB

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