]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.1606: filetype: a few more files are not recognized v9.1.1606
authorlacygoill <lacygoill@lacygoill.me>
Fri, 8 Aug 2025 11:17:57 +0000 (13:17 +0200)
committerChristian Brabandt <cb@256bit.org>
Fri, 8 Aug 2025 11:17:57 +0000 (13:17 +0200)
Problem:  filetype: a few more files are not recognized
Solution: guess Mail, Info and Terminfo files by its content
          (lacygoill)

closes: #17880

Signed-off-by: lacygoill <lacygoill@lacygoill.me>
Signed-off-by: Christian Brabandt <cb@256bit.org>
runtime/autoload/dist/script.vim
src/testdir/test_filetype.vim
src/version.c

index c184bd032d3ccafb3d78de23af0297b3bf5d7d85..8781391a5297add515cb0b34a2a0a65bcf639cce 100644 (file)
@@ -264,6 +264,7 @@ def DetectFromText(line1: string)
 
   # ELM Mail files
   elseif line1 =~ '^From \([a-zA-Z][a-zA-Z_0-9\.=-]*\(@[^ ]*\)\=\|-\) .* \(19\|20\)\d\d$'
+      || line1 =~ '^\creturn-path:\s<.*@.*>$'
     setl ft=mail
 
   # Mason
@@ -453,6 +454,12 @@ def DetectFromText(line1: string)
   elseif line1 =~ '^#n\%($\|\s\)'
     setl ft=sed
 
+  elseif line1 =~ '^#\s\+Reconstructed via infocmp from file:'
+    setl ft=terminfo
+
+  elseif line1 =~ '^File: .*\.info,  Node: .*,  \%(Next\|Prev\): .*,  Up: \|This is the top of the INFO tree.'
+    setl ft=info
+
   else
     var lnum = 1
     while getline(lnum) =~ "^? " && lnum < line("$")
index d9e342b65f96ef4341feb01c99923ddbbf1af29c..d7acd331e48cefe526a0ad528c0d61b0cb6359bb 100644 (file)
@@ -3024,6 +3024,39 @@ func Test_org_file()
   filetype off
 endfunc
 
+func Test_info_file()
+  filetype on
+
+  call writefile(['File: coreutils.info,  Node: Top,  Next: Introduction,  Up: (dir)', 'D'], 'Xfile', 'D')
+  split Xfile
+  call assert_equal('info', &filetype)
+  bwipe!
+
+  filetype off
+endfunc
+
+func Test_mail_file()
+  filetype on
+
+  call writefile(['Return-path: <lgc@debian.home.arpa>', 'D'], 'Xfile', 'D')
+  split Xfile
+  call assert_equal('mail', &filetype)
+  bwipe!
+
+  filetype off
+endfunc
+
+func Test_terminfo_file()
+  filetype on
+
+  call writefile(['#   Reconstructed via infocmp from file: /etc/terminfo/x/xterm', 'D'], 'Xfile', 'D')
+  split Xfile
+  call assert_equal('terminfo', &filetype)
+  bwipe!
+
+  filetype off
+endfunc
+
 " Filetypes detected from names of existing files
 func Test_pacmanlog()
   filetype on
index e4acba9a5d8df04faec88357300c3b34cffce897..d07747c958b1cabf61e3013187ae3c14b3f7e17f 100644 (file)
@@ -719,6 +719,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1606,
 /**/
     1605,
 /**/