]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.1466: filetype: not all lex files are recognized v9.1.1466
authorEisuke Kawashima <e-kwsm@users.noreply.github.com>
Tue, 17 Jun 2025 18:30:52 +0000 (20:30 +0200)
committerChristian Brabandt <cb@256bit.org>
Tue, 17 Jun 2025 18:30:52 +0000 (20:30 +0200)
Problem:  filetype: not all lex files are recognized
Solution: detect *.ll as lex, llvm or lifelines filetype, depending on
          the content (Eisuke Kawashima)

closes: #17560

Signed-off-by: Eisuke Kawashima <e-kwsm@users.noreply.github.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
runtime/autoload/dist/ft.vim
runtime/filetype.vim
src/testdir/test_filetype.vim
src/version.c

index 95135c8b8f75c4e4af5a209fd145f15ae549bd0f..5014e7544212782e8d8587b064226baba4a6152d 100644 (file)
@@ -3,7 +3,7 @@ vim9script
 # Vim functions for file type detection
 #
 # Maintainer:          The Vim Project <https://github.com/vim/vim>
-# Last Change:         2025 Apr 21
+# Last Change:         2025 Jun 17
 # Former Maintainer:   Bram Moolenaar <Bram@vim.org>
 
 # These functions are moved here from runtime/filetype.vim to make startup
@@ -184,9 +184,18 @@ enddef
 export def FTll()
   if getline(1) =~ ';\|\<source_filename\>\|\<target\>'
     setf llvm
-  else
-    setf lifelines
+    return
   endif
+  var n = 1
+  while n < 100 && n <= line("$")
+    var line = getline(n)
+    if line =~ '^\s*%'
+      setf lex
+      return
+    endif
+    n += 1
+  endwhile
+  setf lifelines
 enddef
 
 export def FTlpc()
index 76229eddebc6d736b1e5316780e32251160186b2..f90c6f87bb792fbd63247d7b7a272b19ed2aecc2 100644 (file)
@@ -1420,7 +1420,7 @@ au BufNewFile,BufRead */etc/sensors.conf,*/etc/sensors3.conf      setf sensors
 " LFTP
 au BufNewFile,BufRead lftp.conf,.lftprc,*lftp/rc       setf lftp
 
-" Lifelines (or Lex for C++!)
+" Lifelines, LLVM, or Lex for C++
 au BufNewFile,BufRead *.ll                     call dist#ft#FTll()
 
 " Lilo: Linux loader
index c2ea8f1eef6604dcbb8847dbd57e5caec2d792a3..3ae16e418bbf4ec06199a83933c97653fb497a64 100644 (file)
@@ -2634,6 +2634,12 @@ func Test_ll_file()
   call assert_equal('llvm', &filetype)
   bwipe!
 
+  " lex (C++)
+  call writefile(['%{', '#include <iostream>', '%}'], 'Xfile.ll', 'D')
+  split Xfile.ll
+  call assert_equal('lex', &filetype)
+  bwipe!
+
   " lifelines
   call writefile(['proc main() {}'], 'Xfile.ll', 'D')
   split Xfile.ll
index fc2abd85e6f5df6bf5267fd3f3aeaac0dd58346a..0b6a3b028e4df74d18aa108c1d17d62d416079b9 100644 (file)
@@ -709,6 +709,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1466,
 /**/
     1465,
 /**/