vim-patch:9.1.1606: filetype: a few more files are not recognized (#35268)

Problem:  filetype: a few more files are not recognized
Solution: guess Mail, Info and Terminfo files by its content
          (lacygoill)

closes: vim/vim#17880

eb2aebeb79

Co-authored-by: lacygoill <lacygoill@lacygoill.me>
This commit is contained in:
zeertzjq
2025-08-09 21:38:20 +08:00
committed by GitHub
parent f7e8efd2e9
commit e3913c0fc2
2 changed files with 38 additions and 0 deletions

View File

@@ -2048,6 +2048,7 @@ local patterns_text = {
['^From [a-zA-Z][a-zA-Z_0-9%.=%-]*(@[^ ]*)? .* 20%d%d$'] = 'mail',
['^From %- .* 19%d%d$'] = 'mail',
['^From %- .* 20%d%d$'] = 'mail',
['^[Rr][Ee][Tt][Uu][Rr][Nn]%-[Pp][Aa][Tt][Hh]:%s<.*@.*>$'] = 'mail',
-- Mason
['^<[%%&].*>'] = 'mason',
-- Vim scripts (must have '" vim' as the first line to trigger this)
@@ -2164,6 +2165,10 @@ local patterns_text = {
-- #ncomment is allowed but most likely a false positive so require a space before any trailing comment text
['^#n%s'] = 'sed',
['^#n$'] = 'sed',
['^#%s+Reconstructed via infocmp from file:'] = 'terminfo',
['^File: .*%.info, Node: .*, Next: .*, Up: '] = 'info',
['^File: .*%.info, Node: .*, Prev: .*, Up: '] = 'info',
['This is the top of the INFO tree.'] = 'info',
}
--- File does not start with "#!".

View File

@@ -2990,6 +2990,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