annotate runtime/autoload/bitbake.vim @ 29664:6569c71c5ca5 v9.0.0172

patch 9.0.0172: trying to allocate zero bytes Commit: https://github.com/vim/vim/commit/1024690c015921b0a458172bc368133f63af1b89 Author: Bram Moolenaar <Bram@vim.org> Date: Mon Aug 8 17:08:05 2022 +0100 patch 9.0.0172: trying to allocate zero bytes Problem: Trying to allocate zero bytes. Solution: Do not allocate the proptype array when there are none. (closes #10867)
author Bram Moolenaar <Bram@vim.org>
date Mon, 08 Aug 2022 18:15:03 +0200
parents 67f31c24291b
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
29450
67f31c24291b Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1 " Support for bitbake indenting, see runtime/indent/bitbake.vim
67f31c24291b Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2
67f31c24291b Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3 function s:is_bb_python_func_def(lnum)
67f31c24291b Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4 let stack = synstack(a:lnum, 1)
67f31c24291b Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5 if len(stack) == 0
67f31c24291b Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6 return 0
67f31c24291b Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7 endif
67f31c24291b Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8
67f31c24291b Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9 return synIDattr(stack[0], "name") == "bbPyFuncDef"
67f31c24291b Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
10 endfunction
67f31c24291b Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
11
67f31c24291b Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
12 function bitbake#Indent(lnum)
67f31c24291b Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
13 if !has('syntax_items')
67f31c24291b Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
14 return -1
67f31c24291b Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
15 endif
67f31c24291b Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
16
67f31c24291b Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
17 let stack = synstack(a:lnum, 1)
67f31c24291b Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
18 if len(stack) == 0
67f31c24291b Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
19 return -1
67f31c24291b Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
20 endif
67f31c24291b Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
21
67f31c24291b Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
22 let name = synIDattr(stack[0], "name")
67f31c24291b Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
23
67f31c24291b Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
24 " TODO: support different styles of indentation for assignments. For now,
67f31c24291b Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
25 " we only support like this:
67f31c24291b Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
26 " VAR = " \
67f31c24291b Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
27 " value1 \
67f31c24291b Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
28 " value2 \
67f31c24291b Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
29 " "
67f31c24291b Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
30 "
67f31c24291b Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
31 " i.e. each value indented by shiftwidth(), with the final quote " completely unindented.
67f31c24291b Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
32 if name == "bbVarValue"
67f31c24291b Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
33 " Quote handling is tricky. kernel.bbclass has this line for instance:
67f31c24291b Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
34 " EXTRA_OEMAKE = " HOSTCC="${BUILD_CC} ${BUILD_CFLAGS} ${BUILD_LDFLAGS}" " HOSTCPP="${BUILD_CPP}""
67f31c24291b Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
35 " Instead of trying to handle crazy cases like that, just assume that a
67f31c24291b Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
36 " double-quote on a line by itself (following an assignment) means the
67f31c24291b Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
37 " user is closing the assignment, and de-dent.
67f31c24291b Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
38 if getline(a:lnum) =~ '^\s*"$'
67f31c24291b Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
39 return 0
67f31c24291b Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
40 endif
67f31c24291b Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
41
67f31c24291b Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
42 let prevstack = synstack(a:lnum - 1, 1)
67f31c24291b Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
43 if len(prevstack) == 0
67f31c24291b Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
44 return -1
67f31c24291b Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
45 endif
67f31c24291b Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
46
67f31c24291b Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
47 let prevname = synIDattr(prevstack[0], "name")
67f31c24291b Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
48
67f31c24291b Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
49 " Only indent if there was actually a continuation character on
67f31c24291b Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
50 " the previous line, to avoid misleading indentation.
67f31c24291b Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
51 let prevlinelastchar = synIDattr(synID(a:lnum - 1, col([a:lnum - 1, "$"]) - 1, 1), "name")
67f31c24291b Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
52 let prev_continued = prevlinelastchar == "bbContinue"
67f31c24291b Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
53
67f31c24291b Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
54 " Did the previous line introduce an assignment?
67f31c24291b Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
55 if index(["bbVarDef", "bbVarFlagDef"], prevname) != -1
67f31c24291b Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
56 if prev_continued
67f31c24291b Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
57 return shiftwidth()
67f31c24291b Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
58 endif
67f31c24291b Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
59 endif
67f31c24291b Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
60
67f31c24291b Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
61 if !prev_continued
67f31c24291b Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
62 return 0
67f31c24291b Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
63 endif
67f31c24291b Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
64
67f31c24291b Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
65 " Autoindent can take it from here
67f31c24291b Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
66 return -1
67f31c24291b Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
67 endif
67f31c24291b Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
68
67f31c24291b Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
69 if index(["bbPyDefRegion", "bbPyFuncRegion"], name) != -1
67f31c24291b Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
70 let ret = python#GetIndent(a:lnum, function('s:is_bb_python_func_def'))
67f31c24291b Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
71 " Should normally always be indented by at least one shiftwidth; but allow
67f31c24291b Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
72 " return of -1 (defer to autoindent) or -2 (force indent to 0)
67f31c24291b Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
73 if ret == 0
67f31c24291b Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
74 return shiftwidth()
67f31c24291b Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
75 elseif ret == -2
67f31c24291b Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
76 return 0
67f31c24291b Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
77 endif
67f31c24291b Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
78 return ret
67f31c24291b Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
79 endif
67f31c24291b Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
80
67f31c24291b Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
81 " TODO: GetShIndent doesn't detect tasks prepended with 'fakeroot'
67f31c24291b Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
82 " Need to submit a patch upstream to Vim to provide an extension point.
67f31c24291b Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
83 " Unlike the Python indenter, the Sh indenter is way too large to copy and
67f31c24291b Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
84 " modify here.
67f31c24291b Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
85 if name == "bbShFuncRegion"
67f31c24291b Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
86 return GetShIndent()
67f31c24291b Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
87 endif
67f31c24291b Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
88
67f31c24291b Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
89 " TODO:
67f31c24291b Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
90 " + heuristics for de-denting out of a bbPyDefRegion? e.g. when the user
67f31c24291b Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
91 " types an obvious BB keyword like addhandler or addtask, or starts
67f31c24291b Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
92 " writing a shell task. Maybe too hard to implement...
67f31c24291b Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
93
67f31c24291b Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
94 return -1
67f31c24291b Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
95 endfunction