just.vim 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. " Vim indent file
  2. " Language: Justfile
  3. " Maintainer: Peter Benjamin <@pbnj>
  4. " Last Change: 2025 Jan 19
  5. " Credits: The original author, Noah Bogart <https://github.com/NoahTheDuke/vim-just/>
  6. " Only load this indent file when no other was loaded yet.
  7. if exists("b:did_indent")
  8. finish
  9. endif
  10. let b:did_indent = 1
  11. setlocal indentexpr=GetJustfileIndent()
  12. setlocal indentkeys=0},0),!^F,o,O,0=''',0=\"\"\"
  13. let b:undo_indent = "setlocal indentexpr< indentkeys<"
  14. if exists("*GetJustfileIndent")
  15. finish
  16. endif
  17. function GetJustfileIndent()
  18. if v:lnum < 2
  19. return 0
  20. endif
  21. let prev_line = getline(v:lnum - 1)
  22. let last_indent = indent(v:lnum - 1)
  23. if getline(v:lnum) =~ "\\v^\\s+%([})]|'''$|\"\"\"$)"
  24. return last_indent - shiftwidth()
  25. elseif prev_line =~ '\V#'
  26. return last_indent
  27. elseif prev_line =~ "\\v%([:{(]|^.*\\S.*%([^']'''|[^\"]\"\"\"))\\s*$"
  28. return last_indent + shiftwidth()
  29. elseif prev_line =~ '\\$'
  30. if v:lnum == 2 || getline(v:lnum - 2) !~ '\\$'
  31. if prev_line =~ '\v:\=@!'
  32. return last_indent + shiftwidth() + shiftwidth()
  33. else
  34. return last_indent + shiftwidth()
  35. endif
  36. endif
  37. elseif v:lnum > 2 && getline(v:lnum - 2) =~ '\\$'
  38. return last_indent - shiftwidth()
  39. elseif prev_line =~ '\v:\s*%(\h|\()' && prev_line !~ '\V:='
  40. return last_indent + shiftwidth()
  41. endif
  42. return last_indent
  43. endfunction