patch 9.1.1732: filetype: .inc file detection can be improved

Commit: 
https://github.com/vim/vim/commit/9fd1a657d2efae5cff278eb5acaa380623a50cf6
Author: Martin Schwan <[email protected]>
Date:   Thu Sep 4 22:09:26 2025 +0200

    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 <[email protected]>
    Signed-off-by: Christian Brabandt <[email protected]>

diff --git a/runtime/autoload/dist/ft.vim b/runtime/autoload/dist/ft.vim
index bb2bc2c1c..4d39689cc 100644
--- a/runtime/autoload/dist/ft.vim
+++ b/runtime/autoload/dist/ft.vim
@@ -3,7 +3,7 @@ vim9script
 # Vim functions for file type detection
 #
 # Maintainer:          The Vim Project <https://github.com/vim/vim>
-# Last Change:         2025 Aug 26
+# Last Change:         2025 Sep 04
 # Former Maintainer:   Bram Moolenaar <[email protected]>
 
 # These functions are moved here from runtime/filetype.vim to make startup
@@ -828,26 +828,32 @@ export def FTinc()
   if exists("g:filetype_inc")
     exe "setf " .. g:filetype_inc
   else
-    var lines = getline(1) .. getline(2) .. getline(3)
-    if lines =~? "perlscript"
-      setf aspperl
-    elseif lines =~ "<%"
-      setf aspvbs
-    elseif lines =~ "<?"
-      setf php
-    # Pascal supports // comments but they're vary rarely used for file
-    # headers so assume POV-Ray
-    elseif lines =~ '^\s*\%({\|(\*\)' || lines =~? ft_pascal_keywords
-      setf pascal
-    elseif lines =~# '\<\%(require\|inherit\)\>' || lines =~# 
'[A-Z][A-Za-z0-9_:${}]*\s\+\%(??\|[?:+]\)\?= '
-      setf bitbake
-    else
-      FTasmsyntax()
-      if exists("b:asmsyntax")
-        exe "setf " .. fnameescape(b:asmsyntax)
-      else
-        setf pov
+    for lnum in range(1, min([line("$"), 20]))
+      var line = getline(lnum)
+      if line =~? "perlscript"
+        setf aspperl
+        return
+      elseif line =~ "<%"
+        setf aspvbs
+        return
+      elseif line =~ "<?"
+        setf php
+        return
+      # Pascal supports // comments but they're vary rarely used for file
+      # headers so assume POV-Ray
+      elseif line =~ '^\s*\%({\|(\*\)' || line =~? ft_pascal_keywords
+        setf pascal
+        return
+      elseif line =~# '\<\%(require\|inherit\)\>' || line =~# 
'[A-Z][A-Za-z0-9_:${}/]*\s\+\%(??\|[?:+.]\)\?=.\? '
+        setf bitbake
+        return
       endif
+    endfor
+    FTasmsyntax()
+    if exists("b:asmsyntax")
+      exe "setf " .. fnameescape(b:asmsyntax)
+    else
+      setf pov
     endif
   endif
 enddef
diff --git a/src/testdir/test_filetype.vim b/src/testdir/test_filetype.vim
index ee0eaa095..d91d1bafe 100644
--- a/src/testdir/test_filetype.vim
+++ b/src/testdir/test_filetype.vim
@@ -2694,6 +2694,21 @@ func Test_inc_file()
   call assert_equal('bitbake', &filetype)
   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
   call writefile(['asmsyntax=foo'], 'Xfile.inc')
   split Xfile.inc
diff --git a/src/version.c b/src/version.c
index c2381542b..b28f72e8b 100644
--- a/src/version.c
+++ b/src/version.c
@@ -724,6 +724,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1732,
 /**/
     1731,
 /**/

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/vim_dev/E1uuGMN-0049N2-Lu%40256bit.org.

Raspunde prin e-mail lui