diff options
| -rw-r--r-- | bitbake/bitbake/contrib/vim/bitbake.vim | 238 |
1 files changed, 238 insertions, 0 deletions
diff --git a/bitbake/bitbake/contrib/vim/bitbake.vim b/bitbake/bitbake/contrib/vim/bitbake.vim new file mode 100644 index 0000000000..a210cf5111 --- /dev/null +++ b/bitbake/bitbake/contrib/vim/bitbake.vim | |||
| @@ -0,0 +1,238 @@ | |||
| 1 | if exists("b:did_indent") | ||
| 2 | finish | ||
| 3 | endif | ||
| 4 | |||
| 5 | runtime! indent/sh.vim | ||
| 6 | unlet b:did_indent | ||
| 7 | |||
| 8 | setlocal indentexpr=BitbakeIndent(v:lnum) | ||
| 9 | setlocal autoindent nolisp | ||
| 10 | |||
| 11 | function s:is_python_func_def(lnum) | ||
| 12 | let stack = synstack(a:lnum, 1) | ||
| 13 | if len(stack) == 0 | ||
| 14 | return 0 | ||
| 15 | endif | ||
| 16 | |||
| 17 | let top = synIDattr(stack[0], "name") | ||
| 18 | echo top | ||
| 19 | |||
| 20 | return synIDattr(stack[0], "name") == "bbPyFuncDef" | ||
| 21 | endfunction | ||
| 22 | |||
| 23 | """" begin modified from indent/python.vim, upstream commit 7a9bd7c1e0ce1baf5a02daf36eeae3638aa315c7 | ||
| 24 | """" This copied code is licensed the same as Vim itself. | ||
| 25 | setlocal indentkeys+=<:>,=elif,=except | ||
| 26 | |||
| 27 | let s:keepcpo= &cpo | ||
| 28 | set cpo&vim | ||
| 29 | |||
| 30 | let s:maxoff = 50 " maximum number of lines to look backwards for () | ||
| 31 | |||
| 32 | function GetPythonIndent(lnum) | ||
| 33 | |||
| 34 | " If this line is explicitly joined: If the previous line was also joined, | ||
| 35 | " line it up with that one, otherwise add two 'shiftwidth' | ||
| 36 | if getline(a:lnum - 1) =~ '\\$' | ||
| 37 | if a:lnum > 1 && getline(a:lnum - 2) =~ '\\$' | ||
| 38 | return indent(a:lnum - 1) | ||
| 39 | endif | ||
| 40 | return indent(a:lnum - 1) + (exists("g:pyindent_continue") ? eval(g:pyindent_continue) : (shiftwidth() * 2)) | ||
| 41 | endif | ||
| 42 | |||
| 43 | " If the start of the line is in a string don't change the indent. | ||
| 44 | if has('syntax_items') | ||
| 45 | \ && synIDattr(synID(a:lnum, 1, 1), "name") =~ "String$" | ||
| 46 | return -1 | ||
| 47 | endif | ||
| 48 | |||
| 49 | " Search backwards for the previous non-empty line. | ||
| 50 | let plnum = prevnonblank(v:lnum - 1) | ||
| 51 | |||
| 52 | if plnum == 0 | ||
| 53 | " This is the first non-empty line, use zero indent. | ||
| 54 | return 0 | ||
| 55 | endif | ||
| 56 | |||
| 57 | call cursor(plnum, 1) | ||
| 58 | |||
| 59 | " Identing inside parentheses can be very slow, regardless of the searchpair() | ||
| 60 | " timeout, so let the user disable this feature if he doesn't need it | ||
| 61 | let disable_parentheses_indenting = get(g:, "pyindent_disable_parentheses_indenting", 0) | ||
| 62 | |||
| 63 | if disable_parentheses_indenting == 1 | ||
| 64 | let plindent = indent(plnum) | ||
| 65 | let plnumstart = plnum | ||
| 66 | else | ||
| 67 | " searchpair() can be slow sometimes, limit the time to 150 msec or what is | ||
| 68 | " put in g:pyindent_searchpair_timeout | ||
| 69 | let searchpair_stopline = 0 | ||
| 70 | let searchpair_timeout = get(g:, 'pyindent_searchpair_timeout', 150) | ||
| 71 | |||
| 72 | " If the previous line is inside parenthesis, use the indent of the starting | ||
| 73 | " line. | ||
| 74 | " Trick: use the non-existing "dummy" variable to break out of the loop when | ||
| 75 | " going too far back. | ||
| 76 | let parlnum = searchpair('(\|{\|\[', '', ')\|}\|\]', 'nbW', | ||
| 77 | \ "line('.') < " . (plnum - s:maxoff) . " ? dummy :" | ||
| 78 | \ . " synIDattr(synID(line('.'), col('.'), 1), 'name')" | ||
| 79 | \ . " =~ '\\(Comment\\|Todo\\|String\\)$'", | ||
| 80 | \ searchpair_stopline, searchpair_timeout) | ||
| 81 | if parlnum > 0 | ||
| 82 | let plindent = indent(parlnum) | ||
| 83 | let plnumstart = parlnum | ||
| 84 | else | ||
| 85 | let plindent = indent(plnum) | ||
| 86 | let plnumstart = plnum | ||
| 87 | endif | ||
| 88 | |||
| 89 | " When inside parenthesis: If at the first line below the parenthesis add | ||
| 90 | " two 'shiftwidth', otherwise same as previous line. | ||
| 91 | " i = (a | ||
| 92 | " + b | ||
| 93 | " + c) | ||
| 94 | call cursor(a:lnum, 1) | ||
| 95 | let p = searchpair('(\|{\|\[', '', ')\|}\|\]', 'bW', | ||
| 96 | \ "line('.') < " . (a:lnum - s:maxoff) . " ? dummy :" | ||
| 97 | \ . " synIDattr(synID(line('.'), col('.'), 1), 'name')" | ||
| 98 | \ . " =~ '\\(Comment\\|Todo\\|String\\)$'", | ||
| 99 | \ searchpair_stopline, searchpair_timeout) | ||
| 100 | if p > 0 | ||
| 101 | if p == plnum | ||
| 102 | " When the start is inside parenthesis, only indent one 'shiftwidth'. | ||
| 103 | let pp = searchpair('(\|{\|\[', '', ')\|}\|\]', 'bW', | ||
| 104 | \ "line('.') < " . (a:lnum - s:maxoff) . " ? dummy :" | ||
| 105 | \ . " synIDattr(synID(line('.'), col('.'), 1), 'name')" | ||
| 106 | \ . " =~ '\\(Comment\\|Todo\\|String\\)$'", | ||
| 107 | \ searchpair_stopline, searchpair_timeout) | ||
| 108 | if pp > 0 | ||
| 109 | return indent(plnum) + (exists("g:pyindent_nested_paren") ? eval(g:pyindent_nested_paren) : shiftwidth()) | ||
| 110 | endif | ||
| 111 | return indent(plnum) + (exists("g:pyindent_open_paren") ? eval(g:pyindent_open_paren) : (shiftwidth() * 2)) | ||
| 112 | endif | ||
| 113 | if plnumstart == p | ||
| 114 | return indent(plnum) | ||
| 115 | endif | ||
| 116 | return plindent | ||
| 117 | endif | ||
| 118 | |||
| 119 | endif | ||
| 120 | |||
| 121 | |||
| 122 | " Get the line and remove a trailing comment. | ||
| 123 | " Use syntax highlighting attributes when possible. | ||
| 124 | let pline = getline(plnum) | ||
| 125 | let pline_len = strlen(pline) | ||
| 126 | if has('syntax_items') | ||
| 127 | " If the last character in the line is a comment, do a binary search for | ||
| 128 | " the start of the comment. synID() is slow, a linear search would take | ||
| 129 | " too long on a long line. | ||
| 130 | if synIDattr(synID(plnum, pline_len, 1), "name") =~ "\\(Comment\\|Todo\\)$" | ||
| 131 | let min = 1 | ||
| 132 | let max = pline_len | ||
| 133 | while min < max | ||
| 134 | let col = (min + max) / 2 | ||
| 135 | if synIDattr(synID(plnum, col, 1), "name") =~ "\\(Comment\\|Todo\\)$" | ||
| 136 | let max = col | ||
| 137 | else | ||
| 138 | let min = col + 1 | ||
| 139 | endif | ||
| 140 | endwhile | ||
| 141 | let pline = strpart(pline, 0, min - 1) | ||
| 142 | endif | ||
| 143 | else | ||
| 144 | let col = 0 | ||
| 145 | while col < pline_len | ||
| 146 | if pline[col] == '#' | ||
| 147 | let pline = strpart(pline, 0, col) | ||
| 148 | break | ||
| 149 | endif | ||
| 150 | let col = col + 1 | ||
| 151 | endwhile | ||
| 152 | endif | ||
| 153 | |||
| 154 | " If the previous line ended with a colon, indent this line | ||
| 155 | if pline =~ ':\s*$' | ||
| 156 | return plindent + shiftwidth() | ||
| 157 | endif | ||
| 158 | |||
| 159 | " If the previous line was a stop-execution statement... | ||
| 160 | if getline(plnum) =~ '^\s*\(break\|continue\|raise\|return\|pass\)\>' | ||
| 161 | " See if the user has already dedented | ||
| 162 | if indent(a:lnum) > indent(plnum) - shiftwidth() | ||
| 163 | " If not, recommend one dedent | ||
| 164 | return indent(plnum) - shiftwidth() | ||
| 165 | endif | ||
| 166 | " Otherwise, trust the user | ||
| 167 | return -1 | ||
| 168 | endif | ||
| 169 | |||
| 170 | " If the current line begins with a keyword that lines up with "try" | ||
| 171 | if getline(a:lnum) =~ '^\s*\(except\|finally\)\>' | ||
| 172 | let lnum = a:lnum - 1 | ||
| 173 | while lnum >= 1 | ||
| 174 | if getline(lnum) =~ '^\s*\(try\|except\)\>' | ||
| 175 | let ind = indent(lnum) | ||
| 176 | if ind >= indent(a:lnum) | ||
| 177 | return -1 " indent is already less than this | ||
| 178 | endif | ||
| 179 | return ind " line up with previous try or except | ||
| 180 | endif | ||
| 181 | let lnum = lnum - 1 | ||
| 182 | endwhile | ||
| 183 | return -1 " no matching "try"! | ||
| 184 | endif | ||
| 185 | |||
| 186 | " If the current line begins with a header keyword, dedent | ||
| 187 | if getline(a:lnum) =~ '^\s*\(elif\|else\)\>' | ||
| 188 | |||
| 189 | " Unless the previous line was a one-liner | ||
| 190 | if getline(plnumstart) =~ '^\s*\(for\|if\|try\)\>' | ||
| 191 | return plindent | ||
| 192 | endif | ||
| 193 | |||
| 194 | " Or the user has already dedented | ||
| 195 | if indent(a:lnum) <= plindent - shiftwidth() | ||
| 196 | return -1 | ||
| 197 | endif | ||
| 198 | |||
| 199 | return plindent - shiftwidth() | ||
| 200 | endif | ||
| 201 | |||
| 202 | " When after a () construct we probably want to go back to the start line. | ||
| 203 | " a = (b | ||
| 204 | " + c) | ||
| 205 | " here | ||
| 206 | if parlnum > 0 | ||
| 207 | return plindent | ||
| 208 | endif | ||
| 209 | |||
| 210 | return -1 | ||
| 211 | |||
| 212 | endfunction | ||
| 213 | |||
| 214 | let &cpo = s:keepcpo | ||
| 215 | unlet s:keepcpo | ||
| 216 | |||
| 217 | """ end of stuff from indent/python.vim | ||
| 218 | |||
| 219 | |||
| 220 | let b:did_indent = 1 | ||
| 221 | |||
| 222 | |||
| 223 | function BitbakeIndent(lnum) | ||
| 224 | let stack = synstack(a:lnum, col(".")) | ||
| 225 | if len(stack) == 0 | ||
| 226 | return -1 | ||
| 227 | endif | ||
| 228 | |||
| 229 | let name = synIDattr(stack[0], "name") | ||
| 230 | |||
| 231 | if index(["bbPyDefRegion", "bbPyFuncRegion"], name) != -1 | ||
| 232 | let ret = GetPythonIndent(a:lnum) | ||
| 233 | return ret | ||
| 234 | endif | ||
| 235 | |||
| 236 | return -1 | ||
| 237 | "return s:pythonIndentExpr() | ||
| 238 | endfunction | ||
