bitbake.vim 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. " Support for bitbake indenting, see runtime/indent/bitbake.vim
  2. function s:is_bb_python_func_def(lnum)
  3. let stack = synstack(a:lnum, 1)
  4. if len(stack) == 0
  5. return 0
  6. endif
  7. return synIDattr(stack[0], "name") == "bbPyFuncDef"
  8. endfunction
  9. function bitbake#Indent(lnum)
  10. if !has('syntax_items')
  11. return -1
  12. endif
  13. let stack = synstack(a:lnum, 1)
  14. if len(stack) == 0
  15. return -1
  16. endif
  17. let name = synIDattr(stack[0], "name")
  18. " TODO: support different styles of indentation for assignments. For now,
  19. " we only support like this:
  20. " VAR = " \
  21. " value1 \
  22. " value2 \
  23. " "
  24. "
  25. " i.e. each value indented by shiftwidth(), with the final quote " completely unindented.
  26. if name == "bbVarValue"
  27. " Quote handling is tricky. kernel.bbclass has this line for instance:
  28. " EXTRA_OEMAKE = " HOSTCC="${BUILD_CC} ${BUILD_CFLAGS} ${BUILD_LDFLAGS}" " HOSTCPP="${BUILD_CPP}""
  29. " Instead of trying to handle crazy cases like that, just assume that a
  30. " double-quote on a line by itself (following an assignment) means the
  31. " user is closing the assignment, and de-dent.
  32. if getline(a:lnum) =~ '^\s*"$'
  33. return 0
  34. endif
  35. let prevstack = synstack(a:lnum - 1, 1)
  36. if len(prevstack) == 0
  37. return -1
  38. endif
  39. let prevname = synIDattr(prevstack[0], "name")
  40. " Only indent if there was actually a continuation character on
  41. " the previous line, to avoid misleading indentation.
  42. let prevlinelastchar = synIDattr(synID(a:lnum - 1, col([a:lnum - 1, "$"]) - 1, 1), "name")
  43. let prev_continued = prevlinelastchar == "bbContinue"
  44. " Did the previous line introduce an assignment?
  45. if index(["bbVarDef", "bbVarFlagDef"], prevname) != -1
  46. if prev_continued
  47. return shiftwidth()
  48. endif
  49. endif
  50. if !prev_continued
  51. return 0
  52. endif
  53. " Autoindent can take it from here
  54. return -1
  55. endif
  56. if index(["bbPyDefRegion", "bbPyFuncRegion"], name) != -1
  57. let ret = python#GetIndent(a:lnum, function('s:is_bb_python_func_def'))
  58. " Should normally always be indented by at least one shiftwidth; but allow
  59. " return of -1 (defer to autoindent) or -2 (force indent to 0)
  60. if ret == 0
  61. return shiftwidth()
  62. elseif ret == -2
  63. return 0
  64. endif
  65. return ret
  66. endif
  67. " TODO: GetShIndent doesn't detect tasks prepended with 'fakeroot'
  68. " Need to submit a patch upstream to Vim to provide an extension point.
  69. " Unlike the Python indenter, the Sh indenter is way too large to copy and
  70. " modify here.
  71. if name == "bbShFuncRegion"
  72. return GetShIndent()
  73. endif
  74. " TODO:
  75. " + heuristics for de-denting out of a bbPyDefRegion? e.g. when the user
  76. " types an obvious BB keyword like addhandler or addtask, or starts
  77. " writing a shell task. Maybe too hard to implement...
  78. return -1
  79. endfunction