Skip to content

Commit 8571fe7

Browse files
gpanderssmjonas
authored andcommitted
vim-patch:9.0.0055 (neovim#19392)
vim-patch:9.0.0055: bitbake files are not detected Problem: Bitbake files are not detected. Solution: Add bitbake filetype detection by file name and contents. (Gregory Anders, closes vim/vim#10697) vim/vim@fa49eb4
1 parent 41131c6 commit 8571fe7

File tree

5 files changed

+70
-3
lines changed

5 files changed

+70
-3
lines changed

runtime/autoload/dist/ft.vim

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -519,12 +519,14 @@ func dist#ft#FTinc()
519519
" headers so assume POV-Ray
520520
elseif lines =~ '^\s*\%({\|(\*\)' || lines =~? s:ft_pascal_keywords
521521
setf pascal
522+
elseif lines =~# '\<\%(require\|inherit\)\>' || lines =~# '\w\+ = '
523+
setf bitbake
522524
else
523525
call dist#ft#FTasmsyntax()
524526
if exists("b:asmsyntax")
525-
exe "setf " . fnameescape(b:asmsyntax)
527+
exe "setf " . fnameescape(b:asmsyntax)
526528
else
527-
setf pov
529+
setf pov
528530
endif
529531
endif
530532
endif

runtime/filetype.vim

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,9 @@ au BufNewFile,BufRead *.db call dist#ft#BindzoneCheck('')
253253
" Blank
254254
au BufNewFile,BufRead *.bl setf blank
255255

256+
" Bitbake
257+
au BufNewFile,BufRead *.bb,*.bbappend,*.bbclass,*/build/conf/*.conf,*/meta{-*,}/conf/*.conf setf bitbake
258+
256259
" Blkid cache file
257260
au BufNewFile,BufRead */etc/blkid.tab,*/etc/blkid.tab.old setf xml
258261

runtime/lua/vim/filetype.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,9 @@ local extension = {
172172
return require('vim.filetype.detect').bindzone(bufnr, '')
173173
end,
174174
bicep = 'bicep',
175+
bb = 'bitbake',
176+
bbappend = 'bitbake',
177+
bbclass = 'bitbake',
175178
bl = 'blank',
176179
bsdl = 'bsdl',
177180
bst = 'bst',
@@ -1662,6 +1665,9 @@ local pattern = {
16621665
['[mM]akefile%.am'] = 'automake',
16631666
['.*/bind/db%..*'] = starsetf('bindzone'),
16641667
['.*/named/db%..*'] = starsetf('bindzone'),
1668+
['.*/build/conf/.*%.conf'] = 'bitbake',
1669+
['.*/meta/conf/.*%.conf'] = 'bitbake',
1670+
['.*/meta%-.*/conf/.*%.conf'] = 'bitbake',
16651671
['.*bsd'] = 'bsdl',
16661672
['bzr_log%..*'] = 'bzr',
16671673
['.*enlightenment/.*%.cfg'] = 'c',

runtime/lua/vim/filetype/detect.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ end
6262
-- Checks the first 5 lines for a asmsyntax=foo override.
6363
-- Only whitespace characters can be present immediately before or after this statement.
6464
function M.asm_syntax(bufnr)
65-
local lines = table.concat(getlines(bufnr, 1, 5), ' '):lower()
65+
local lines = ' ' .. table.concat(getlines(bufnr, 1, 5), ' '):lower() .. ' '
6666
local match = lines:match('%sasmsyntax=([a-zA-Z0-9]+)%s')
6767
if match then
6868
return match
@@ -554,6 +554,8 @@ function M.inc(bufnr)
554554
-- headers so assume POV-Ray
555555
elseif findany(lines, { '^%s{', '^%s%(%*' }) or matchregex(lines, pascal_keywords) then
556556
return 'pascal'
557+
elseif findany(lines, { '^%s*inherit ', '^%s*require ', '^%s*%w+%s+= ' }) then
558+
return 'bitbake'
557559
else
558560
local syntax = M.asm_syntax(bufnr)
559561
if not syntax or syntax == '' then

src/nvim/testdir/test_filetype.vim

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ let s:filename_checks = {
8383
\ 'bib': ['file.bib'],
8484
\ 'bicep': ['file.bicep'],
8585
\ 'bindzone': ['named.root', '/bind/db.file', '/named/db.file', 'any/bind/db.file', 'any/named/db.file'],
86+
\ 'bitbake': ['file.bb', 'file.bbappend', 'file.bbclass', 'build/conf/local.conf', 'meta/conf/layer.conf', 'build/conf/bbappend.conf', 'meta-layer/conf/distro/foo.conf'],
8687
\ 'blank': ['file.bl'],
8788
\ 'bsdl': ['file.bsd', 'file.bsdl', 'bsd', 'some-bsd'],
8889
\ 'bst': ['file.bst'],
@@ -1813,5 +1814,58 @@ func Test_sig_file()
18131814
filetype off
18141815
endfunc
18151816

1817+
func Test_inc_file()
1818+
filetype on
1819+
1820+
call writefile(['this is the fallback'], 'Xfile.inc')
1821+
split Xfile.inc
1822+
call assert_equal('pov', &filetype)
1823+
bwipe!
1824+
1825+
let g:filetype_inc = 'foo'
1826+
split Xfile.inc
1827+
call assert_equal('foo', &filetype)
1828+
bwipe!
1829+
unlet g:filetype_inc
1830+
1831+
" aspperl
1832+
call writefile(['perlscript'], 'Xfile.inc')
1833+
split Xfile.inc
1834+
call assert_equal('aspperl', &filetype)
1835+
bwipe!
1836+
1837+
" aspvbs
1838+
call writefile(['<% something'], 'Xfile.inc')
1839+
split Xfile.inc
1840+
call assert_equal('aspvbs', &filetype)
1841+
bwipe!
1842+
1843+
" php
1844+
call writefile(['<?php'], 'Xfile.inc')
1845+
split Xfile.inc
1846+
call assert_equal('php', &filetype)
1847+
bwipe!
1848+
1849+
" pascal
1850+
call writefile(['program'], 'Xfile.inc')
1851+
split Xfile.inc
1852+
call assert_equal('pascal', &filetype)
1853+
bwipe!
1854+
1855+
" bitbake
1856+
call writefile(['require foo'], 'Xfile.inc')
1857+
split Xfile.inc
1858+
call assert_equal('bitbake', &filetype)
1859+
bwipe!
1860+
1861+
" asm
1862+
call writefile(['asmsyntax=bar'], 'Xfile.inc')
1863+
split Xfile.inc
1864+
call assert_equal('bar', &filetype)
1865+
bwipe!
1866+
1867+
call delete('Xfile.inc')
1868+
filetype off
1869+
endfunc
18161870

18171871
" vim: shiftwidth=2 sts=2 expandtab

0 commit comments

Comments
 (0)