mirror of
https://github.com/neovim/neovim.git
synced 2025-09-05 19:08:15 +00:00
vim-patch:9.1.1732: filetype: .inc file detection can be improved (#35635)
Problem: filetype: .inc file detection can be improved
Solution: Update filetype detection for Pascal and BitBake code
(Martin Schwan).
Fix the detection of .inc files containing Pascal and BitBake code:
- the concatenated string, merged from three lines, only contains one
beginning and the pattern "^" would not match as expected. Use a range()
loop to iterate each line string individually. This way, the pattern "^"
works for beginning of lines.
- improve BitBake include file detection by also matching forward-slashes
"/" in variable names and assignment operators with a dot ".=" and "=.".
Valid examples, which should match, are:
PREFERRED_PROVIDER_virtual/kernel = "linux-yocto"
MACHINEOVERRIDES =. "qemuall:"
BBPATH .= ":${LAYERDIR}"
- parse twenty instead of just three lines, to accommodate for potential
comments at the beginning of files
closes: vim/vim#18202
9fd1a657d2
Co-authored-by: Martin Schwan <m.schwan@phytec.de>
This commit is contained in:
@@ -844,28 +844,30 @@ function M.inc(path, bufnr)
|
|||||||
if vim.g.filetype_inc then
|
if vim.g.filetype_inc then
|
||||||
return vim.g.filetype_inc
|
return vim.g.filetype_inc
|
||||||
end
|
end
|
||||||
local lines = table.concat(getlines(bufnr, 1, 3))
|
for _, line in ipairs(getlines(bufnr, 1, 20)) do
|
||||||
if lines:lower():find('perlscript') then
|
if line:lower():find('perlscript') then
|
||||||
return 'aspperl'
|
return 'aspperl'
|
||||||
elseif lines:find('<%%') then
|
elseif line:find('<%%') then
|
||||||
return 'aspvbs'
|
return 'aspvbs'
|
||||||
elseif lines:find('<%?') then
|
elseif line:find('<%?') then
|
||||||
return 'php'
|
return 'php'
|
||||||
-- Pascal supports // comments but they're vary rarely used for file
|
-- Pascal supports // comments but they're vary rarely used for file
|
||||||
-- headers so assume POV-Ray
|
-- headers so assume POV-Ray
|
||||||
elseif findany(lines, { '^%s{', '^%s%(%*' }) or matchregex(lines, pascal_keywords) then
|
elseif findany(line, { '^%s{', '^%s%(%*' }) or matchregex(line, pascal_keywords) then
|
||||||
return 'pascal'
|
return 'pascal'
|
||||||
elseif findany(lines, { '^%s*inherit ', '^%s*require ', '^%s*%u[%w_:${}]*%s+%??[?:+]?= ' }) then
|
elseif
|
||||||
return 'bitbake'
|
findany(line, { '^%s*inherit ', '^%s*require ', '^%s*%u[%w_:${}/]*%s+%??[?:+.]?=.? ' })
|
||||||
else
|
then
|
||||||
local syntax = M.asm_syntax(path, bufnr)
|
return 'bitbake'
|
||||||
if not syntax or syntax == '' then
|
|
||||||
return 'pov'
|
|
||||||
end
|
|
||||||
return syntax, function(b)
|
|
||||||
vim.b[b].asmsyntax = syntax
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
local syntax = M.asm_syntax(path, bufnr)
|
||||||
|
if not syntax or syntax == '' then
|
||||||
|
return 'pov'
|
||||||
|
end
|
||||||
|
return syntax, function(b)
|
||||||
|
vim.b[b].asmsyntax = syntax
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--- @type vim.filetype.mapfn
|
--- @type vim.filetype.mapfn
|
||||||
|
@@ -2660,6 +2660,21 @@ func Test_inc_file()
|
|||||||
call assert_equal('bitbake', &filetype)
|
call assert_equal('bitbake', &filetype)
|
||||||
bwipe!
|
bwipe!
|
||||||
|
|
||||||
|
call writefile(['PREFERRED_PROVIDER_virtual/kernel = "linux-yocto"'], 'Xfile.inc')
|
||||||
|
split Xfile.inc
|
||||||
|
call assert_equal('bitbake', &filetype)
|
||||||
|
bwipe!
|
||||||
|
|
||||||
|
call writefile(['MACHINEOVERRIDES =. "qemuall:"'], 'Xfile.inc')
|
||||||
|
split Xfile.inc
|
||||||
|
call assert_equal('bitbake', &filetype)
|
||||||
|
bwipe!
|
||||||
|
|
||||||
|
call writefile(['BBPATH .= ":${LAYERDIR}"'], 'Xfile.inc')
|
||||||
|
split Xfile.inc
|
||||||
|
call assert_equal('bitbake', &filetype)
|
||||||
|
bwipe!
|
||||||
|
|
||||||
" asm
|
" asm
|
||||||
call writefile(['asmsyntax=foo'], 'Xfile.inc')
|
call writefile(['asmsyntax=foo'], 'Xfile.inc')
|
||||||
split Xfile.inc
|
split Xfile.inc
|
||||||
|
Reference in New Issue
Block a user