diff options
author | Chris Laplante via bitbake-devel <bitbake-devel@lists.openembedded.org> | 2019-10-17 12:36:53 -0400 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2019-10-23 22:57:25 +0100 |
commit | dd7b65360a43818bd583b11242079809d3b7a225 (patch) | |
tree | 52573c32022dc6bd756d4946aaf590e32b3269b7 | |
parent | 796fb26d87f93ef4b3e31684a3355181d536343c (diff) | |
download | bitbake-dd7b65360a43818bd583b11242079809d3b7a225.tar.gz |
bitbake: contrib/vim: indenting for assignments; tweak Python indenting
Signed-off-by: Chris Laplante <chris.laplante@agilent.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r-- | bitbake/contrib/vim/indent/bitbake.vim | 56 |
1 files changed, 53 insertions, 3 deletions
diff --git a/bitbake/contrib/vim/indent/bitbake.vim b/bitbake/contrib/vim/indent/bitbake.vim index 76f84e5c2..1d0a6e82d 100644 --- a/bitbake/contrib/vim/indent/bitbake.vim +++ b/bitbake/contrib/vim/indent/bitbake.vim @@ -110,7 +110,12 @@ function GetPythonIndent(lnum) \ . " =~ '\\(Comment\\|Todo\\|String\\)$'", \ searchpair_stopline, searchpair_timeout) if p > 0 - if s:is_python_func_def(p) + if s:is_bb_python_func_def(p) + " Handle first non-empty line inside a BB Python task + if p == plnum + return shiftwidth() + endif + " Handle the user actually trying to close a BitBake Python task let line = getline(a:lnum) if line =~ '^\s*}' @@ -242,6 +247,7 @@ unlet s:keepcpo let b:did_indent = 1 +setlocal indentkeys+=0\" function BitbakeIndent(lnum) @@ -249,13 +255,57 @@ function BitbakeIndent(lnum) return -1 endif - let stack = synstack(a:lnum, col(".")) + let stack = synstack(a:lnum, 1) if len(stack) == 0 return -1 endif let name = synIDattr(stack[0], "name") - "echo name + + " TODO: support different styles of indentation for assignments. For now, + " we only support like this: + " VAR = " \ + " value1 \ + " value2 \ + " " + " + " i.e. each value indented by shiftwidth(), with the final quote " completely unindented. + if name == "bbVarValue" + " Quote handling is tricky. kernel.bbclass has this line for instance: + " EXTRA_OEMAKE = " HOSTCC="${BUILD_CC} ${BUILD_CFLAGS} ${BUILD_LDFLAGS}" " HOSTCPP="${BUILD_CPP}"" + " Instead of trying to handle crazy cases like that, just assume that a + " double-quote on a line by itself (following an assignment) means the + " user is closing the assignment, and de-dent. + if getline(a:lnum) =~ '^\s*"$' + return 0 + endif + + let prevstack = synstack(a:lnum - 1, 1) + if len(prevstack) == 0 + return -1 + endif + + let prevname = synIDattr(prevstack[0], "name") + + " Only indent if there was actually a continuation character on + " the previous line, to avoid misleading indentation. + let prevlinelastchar = synIDattr(synID(a:lnum - 1, col([a:lnum - 1, "$"]) - 1, 1), "name") + let prev_continued = prevlinelastchar == "bbContinue" + + " Did the previous line introduce an assignment? + if index(["bbVarDef", "bbVarFlagDef"], prevname) != -1 + if prev_continued + return shiftwidth() + endif + endif + + if !prev_continued + return 0 + endif + + " Autoindent can take it from here + return -1 + endif if index(["bbPyDefRegion", "bbPyFuncRegion"], name) != -1 let ret = GetPythonIndent(a:lnum) |