postscr.vim 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. " PostScript indent file
  2. " Language: PostScript
  3. " Maintainer: Mike Williams <mrw@eandem.co.uk>
  4. " Last Change: 2022 Apr 06
  5. " Only load this indent file when no other was loaded.
  6. if exists("b:did_indent")
  7. finish
  8. endif
  9. let b:did_indent = 1
  10. setlocal indentexpr=PostscrIndentGet(v:lnum)
  11. setlocal indentkeys+=0],0=>>,0=%%,0=end,0=restore,0=grestore indentkeys-=:,0#,e
  12. let b:undo_indent = "setl inde< indk<"
  13. " Catch multiple instantiations
  14. if exists("*PostscrIndentGet")
  15. finish
  16. endif
  17. function! PostscrIndentGet(lnum)
  18. " Find a non-empty non-comment line above the current line.
  19. " Note: ignores DSC comments as well!
  20. let lnum = a:lnum - 1
  21. while lnum != 0
  22. let lnum = prevnonblank(lnum)
  23. if getline(lnum) !~ '^\s*%.*$'
  24. break
  25. endif
  26. let lnum = lnum - 1
  27. endwhile
  28. " Hit the start of the file, use user indent.
  29. if lnum == 0
  30. return -1
  31. endif
  32. " Start with the indent of the previous line
  33. let ind = indent(lnum)
  34. let pline = getline(lnum)
  35. " Indent for dicts, arrays, and saves with possible trailing comment
  36. if pline =~ '\(begin\|<<\|g\=save\|{\|[\)\s*\(%.*\)\=$'
  37. let ind = ind + shiftwidth()
  38. endif
  39. " Remove indent for popped dicts, and restores.
  40. if pline =~ '\(end\|g\=restore\)\s*$'
  41. let ind = ind - shiftwidth()
  42. " Else handle immediate dedents of dicts, restores, and arrays.
  43. elseif getline(a:lnum) =~ '\(end\|>>\|g\=restore\|}\|]\)'
  44. let ind = ind - shiftwidth()
  45. " Else handle DSC comments - always start of line.
  46. elseif getline(a:lnum) =~ '^\s*%%'
  47. let ind = 0
  48. endif
  49. " For now catch excessive left indents if they occur.
  50. if ind < 0
  51. let ind = -1
  52. endif
  53. return ind
  54. endfunction
  55. " vim:sw=2