[bitbake-devel] [PATCH 7/9] bitbake: contrib/vim: indenting for assignments; tweak Python indenting

Chris Laplante chris.laplante at agilent.com
Fri Oct 11 16:23:07 UTC 2019


Signed-off-by: Chris Laplante <chris.laplante at agilent.com>
---
 bitbake/contrib/vim/indent/bitbake.vim | 56 ++++++++++++++++++++++++++++++++--
 1 file changed, 53 insertions(+), 3 deletions(-)

diff --git a/bitbake/contrib/vim/indent/bitbake.vim b/bitbake/contrib/vim/indent/bitbake.vim
index 782137f..ed2bd32 100644
--- a/bitbake/contrib/vim/indent/bitbake.vim
+++ b/bitbake/contrib/vim/indent/bitbake.vim
@@ -109,7 +109,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*}'
@@ -241,6 +246,7 @@ unlet s:keepcpo
 
 
 let b:did_indent = 1
+setlocal indentkeys+=0\"
 
 
 function BitbakeIndent(lnum)
@@ -248,13 +254,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)
-- 
2.7.4



More information about the bitbake-devel mailing list