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-11-07 19:43:14 +0000 |
commit | c426ba9afe2aef0f01baff10353ca3ed946bafb6 (patch) | |
tree | 01279fed23c1611595b15de4e187ac83a722f771 | |
parent | f45aa165f2dac3d1bf5a043c2351c9db61af3988 (diff) | |
download | poky-c426ba9afe2aef0f01baff10353ca3ed946bafb6.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/bitbake/contrib/vim/indent/bitbake.vim | 56 |
1 files changed, 53 insertions, 3 deletions
diff --git a/bitbake/bitbake/contrib/vim/indent/bitbake.vim b/bitbake/bitbake/contrib/vim/indent/bitbake.vim index 76f84e5c23..1d0a6e82d3 100644 --- a/bitbake/bitbake/contrib/vim/indent/bitbake.vim +++ b/bitbake/bitbake/contrib/vim/indent/bitbake.vim | |||
@@ -110,7 +110,12 @@ function GetPythonIndent(lnum) | |||
110 | \ . " =~ '\\(Comment\\|Todo\\|String\\)$'", | 110 | \ . " =~ '\\(Comment\\|Todo\\|String\\)$'", |
111 | \ searchpair_stopline, searchpair_timeout) | 111 | \ searchpair_stopline, searchpair_timeout) |
112 | if p > 0 | 112 | if p > 0 |
113 | if s:is_python_func_def(p) | 113 | if s:is_bb_python_func_def(p) |
114 | " Handle first non-empty line inside a BB Python task | ||
115 | if p == plnum | ||
116 | return shiftwidth() | ||
117 | endif | ||
118 | |||
114 | " Handle the user actually trying to close a BitBake Python task | 119 | " Handle the user actually trying to close a BitBake Python task |
115 | let line = getline(a:lnum) | 120 | let line = getline(a:lnum) |
116 | if line =~ '^\s*}' | 121 | if line =~ '^\s*}' |
@@ -242,6 +247,7 @@ unlet s:keepcpo | |||
242 | 247 | ||
243 | 248 | ||
244 | let b:did_indent = 1 | 249 | let b:did_indent = 1 |
250 | setlocal indentkeys+=0\" | ||
245 | 251 | ||
246 | 252 | ||
247 | function BitbakeIndent(lnum) | 253 | function BitbakeIndent(lnum) |
@@ -249,13 +255,57 @@ function BitbakeIndent(lnum) | |||
249 | return -1 | 255 | return -1 |
250 | endif | 256 | endif |
251 | 257 | ||
252 | let stack = synstack(a:lnum, col(".")) | 258 | let stack = synstack(a:lnum, 1) |
253 | if len(stack) == 0 | 259 | if len(stack) == 0 |
254 | return -1 | 260 | return -1 |
255 | endif | 261 | endif |
256 | 262 | ||
257 | let name = synIDattr(stack[0], "name") | 263 | let name = synIDattr(stack[0], "name") |
258 | "echo name | 264 | |
265 | " TODO: support different styles of indentation for assignments. For now, | ||
266 | " we only support like this: | ||
267 | " VAR = " \ | ||
268 | " value1 \ | ||
269 | " value2 \ | ||
270 | " " | ||
271 | " | ||
272 | " i.e. each value indented by shiftwidth(), with the final quote " completely unindented. | ||
273 | if name == "bbVarValue" | ||
274 | " Quote handling is tricky. kernel.bbclass has this line for instance: | ||
275 | " EXTRA_OEMAKE = " HOSTCC="${BUILD_CC} ${BUILD_CFLAGS} ${BUILD_LDFLAGS}" " HOSTCPP="${BUILD_CPP}"" | ||
276 | " Instead of trying to handle crazy cases like that, just assume that a | ||
277 | " double-quote on a line by itself (following an assignment) means the | ||
278 | " user is closing the assignment, and de-dent. | ||
279 | if getline(a:lnum) =~ '^\s*"$' | ||
280 | return 0 | ||
281 | endif | ||
282 | |||
283 | let prevstack = synstack(a:lnum - 1, 1) | ||
284 | if len(prevstack) == 0 | ||
285 | return -1 | ||
286 | endif | ||
287 | |||
288 | let prevname = synIDattr(prevstack[0], "name") | ||
289 | |||
290 | " Only indent if there was actually a continuation character on | ||
291 | " the previous line, to avoid misleading indentation. | ||
292 | let prevlinelastchar = synIDattr(synID(a:lnum - 1, col([a:lnum - 1, "$"]) - 1, 1), "name") | ||
293 | let prev_continued = prevlinelastchar == "bbContinue" | ||
294 | |||
295 | " Did the previous line introduce an assignment? | ||
296 | if index(["bbVarDef", "bbVarFlagDef"], prevname) != -1 | ||
297 | if prev_continued | ||
298 | return shiftwidth() | ||
299 | endif | ||
300 | endif | ||
301 | |||
302 | if !prev_continued | ||
303 | return 0 | ||
304 | endif | ||
305 | |||
306 | " Autoindent can take it from here | ||
307 | return -1 | ||
308 | endif | ||
259 | 309 | ||
260 | if index(["bbPyDefRegion", "bbPyFuncRegion"], name) != -1 | 310 | if index(["bbPyDefRegion", "bbPyFuncRegion"], name) != -1 |
261 | let ret = GetPythonIndent(a:lnum) | 311 | let ret = GetPythonIndent(a:lnum) |