vim-patch:9.2.0539: filetype: too many Bitbake include files are recognized (#40014)

Problem:  filetype: too many Bitbake include files are recognized
          (Brahmajit Das, after v9.1.1732)
Solution: Tighten the pattern to detect BitBake include files, update
          tests (Martin Schwan).

Be more strict when detecting BitBake inc files. In particular, only
match include keywords and variable assignments at the beginning of a
line (excluding whitespace).

Use non-capturing groups to slightly improve performance.

Use regex or-operators to exactly match BitBake assignment operators.
The previous expression would falsely match

    FOO .=. "bar"

, which is not valid BitBake syntax. The new capturing group is more
specific and matches only valid assignments.

fixes:  vim/vim#20288
closes: vim/vim#20335

2df68c8e4b

Co-authored-by: Martin Schwan <m.schwan@phytec.de>
This commit is contained in:
zeertzjq
2026-05-27 07:12:53 +08:00
committed by GitHub
parent d214c24129
commit b3dfa86e02
2 changed files with 13 additions and 2 deletions

View File

@@ -936,10 +936,10 @@ function M.inc(path, bufnr)
elseif findany(line, { '^%s{', '^%s%(%*' }) or matchregex(line, pascal_keywords) then
return 'pascal'
elseif
matchregex(line, [[\<\%(require\|inherit\)\>]])
matchregex(line, [[^\s*\<\%(require\|inherit\)\>]])
or matchregex(
line,
[=[[A-Z][A-Za-z0-9_:${}/]*\(\[[A-Za-z0-9_:/]\+\]\)*\s\+\%(??\|[?:+.]\)\?=.\? ]=]
[=[^\s*[A-Z][A-Za-z0-9_:${}/]*\%(\[[A-Za-z0-9_:/]\+\]\)*\s\+\%(??=\|[?:+.]=\|=[+.]\?\)\s\+]=]
)
then
return 'bitbake'

View File

@@ -2817,11 +2817,17 @@ endfunc
func Test_inc_file()
filetype on
" pov
call writefile(['this is the fallback'], 'Xfile.inc', 'D')
split Xfile.inc
call assert_equal('pov', &filetype)
bwipe!
call writefile(['!Comment with formular a = b/c'], 'Xfile.inc')
split Xfile.inc
call assert_equal('pov', &filetype)
bwipe!
" ObjectScript routine
call writefile(['ROUTINE Sample [Type=INC]'], 'Xfile.inc', 'D')
split Xfile.inc
@@ -2874,6 +2880,11 @@ func Test_inc_file()
call assert_equal('bitbake', &filetype)
bwipe!
call writefile(['MACHINE ?= "qemu"'], 'Xfile.inc')
split Xfile.inc
call assert_equal('bitbake', &filetype)
bwipe!
call writefile(['MACHINE ??= "qemu"'], 'Xfile.inc')
split Xfile.inc
call assert_equal('bitbake', &filetype)