Skip to content

Commit 9fd1a65

Browse files
mschwan-phytecchrisbra
authored andcommitted
patch 9.1.1732: filetype: .inc file detection can be improved
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: #18202 Signed-off-by: Martin Schwan <m.schwan@phytec.de> Signed-off-by: Christian Brabandt <cb@256bit.org>
1 parent 63a02ca commit 9fd1a65

3 files changed

Lines changed: 43 additions & 20 deletions

File tree

runtime/autoload/dist/ft.vim

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ vim9script
33
# Vim functions for file type detection
44
#
55
# Maintainer: The Vim Project <https://github.com/vim/vim>
6-
# Last Change: 2025 Aug 26
6+
# Last Change: 2025 Sep 04
77
# Former Maintainer: Bram Moolenaar <Bram@vim.org>
88

99
# These functions are moved here from runtime/filetype.vim to make startup
@@ -828,26 +828,32 @@ export def FTinc()
828828
if exists("g:filetype_inc")
829829
exe "setf " .. g:filetype_inc
830830
else
831-
var lines = getline(1) .. getline(2) .. getline(3)
832-
if lines =~? "perlscript"
833-
setf aspperl
834-
elseif lines =~ "<%"
835-
setf aspvbs
836-
elseif lines =~ "<?"
837-
setf php
838-
# Pascal supports // comments but they're vary rarely used for file
839-
# headers so assume POV-Ray
840-
elseif lines =~ '^\s*\%({\|(\*\)' || lines =~? ft_pascal_keywords
841-
setf pascal
842-
elseif lines =~# '\<\%(require\|inherit\)\>' || lines =~# '[A-Z][A-Za-z0-9_:${}]*\s\+\%(??\|[?:+]\)\?= '
843-
setf bitbake
844-
else
845-
FTasmsyntax()
846-
if exists("b:asmsyntax")
847-
exe "setf " .. fnameescape(b:asmsyntax)
848-
else
849-
setf pov
831+
for lnum in range(1, min([line("$"), 20]))
832+
var line = getline(lnum)
833+
if line =~? "perlscript"
834+
setf aspperl
835+
return
836+
elseif line =~ "<%"
837+
setf aspvbs
838+
return
839+
elseif line =~ "<?"
840+
setf php
841+
return
842+
# Pascal supports // comments but they're vary rarely used for file
843+
# headers so assume POV-Ray
844+
elseif line =~ '^\s*\%({\|(\*\)' || line =~? ft_pascal_keywords
845+
setf pascal
846+
return
847+
elseif line =~# '\<\%(require\|inherit\)\>' || line =~# '[A-Z][A-Za-z0-9_:${}/]*\s\+\%(??\|[?:+.]\)\?=.\? '
848+
setf bitbake
849+
return
850850
endif
851+
endfor
852+
FTasmsyntax()
853+
if exists("b:asmsyntax")
854+
exe "setf " .. fnameescape(b:asmsyntax)
855+
else
856+
setf pov
851857
endif
852858
endif
853859
enddef

src/testdir/test_filetype.vim

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2694,6 +2694,21 @@ func Test_inc_file()
26942694
call assert_equal('bitbake', &filetype)
26952695
bwipe!
26962696

2697+
call writefile(['PREFERRED_PROVIDER_virtual/kernel = "linux-yocto"'], 'Xfile.inc')
2698+
split Xfile.inc
2699+
call assert_equal('bitbake', &filetype)
2700+
bwipe!
2701+
2702+
call writefile(['MACHINEOVERRIDES =. "qemuall:"'], 'Xfile.inc')
2703+
split Xfile.inc
2704+
call assert_equal('bitbake', &filetype)
2705+
bwipe!
2706+
2707+
call writefile(['BBPATH .= ":${LAYERDIR}"'], 'Xfile.inc')
2708+
split Xfile.inc
2709+
call assert_equal('bitbake', &filetype)
2710+
bwipe!
2711+
26972712
" asm
26982713
call writefile(['asmsyntax=foo'], 'Xfile.inc')
26992714
split Xfile.inc

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,8 @@ static char *(features[]) =
724724

725725
static int included_patches[] =
726726
{ /* Add new patch number below this line */
727+
/**/
728+
1732,
727729
/**/
728730
1731,
729731
/**/

0 commit comments

Comments
 (0)