From b3dfa86e02b0ce0f3ef9bc7b90dbbd790e7da31e Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 27 May 2026 07:12:53 +0800 Subject: [PATCH] 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 https://github.com/vim/vim/commit/2df68c8e4bc03a5222218e22e74897861b8c1896 Co-authored-by: Martin Schwan --- runtime/lua/vim/filetype/detect.lua | 4 ++-- test/old/testdir/test_filetype.vim | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/runtime/lua/vim/filetype/detect.lua b/runtime/lua/vim/filetype/detect.lua index 79cc6651c4..49739dba4f 100644 --- a/runtime/lua/vim/filetype/detect.lua +++ b/runtime/lua/vim/filetype/detect.lua @@ -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' diff --git a/test/old/testdir/test_filetype.vim b/test/old/testdir/test_filetype.vim index c84c9c4b88..fa4d96247a 100644 --- a/test/old/testdir/test_filetype.vim +++ b/test/old/testdir/test_filetype.vim @@ -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)