commit dc00b379658ff7d545bd49161a7e81d83474b194
parent 0ee5a4d481557e858983396e7ec93a03f3c357d9
Author: zeertzjq <zeertzjq@outlook.com>
Date: Thu, 10 Apr 2025 16:20:22 +0800
vim-patch:9.1.1212: filetype: logrotate'd pacmanlogs are not recognized (#33412)
Problem: filetype: logrotate'd pacmanlogs are not recognized
Solution: also detect pacman.log* files as pacmanlog filetype,
remove BufNewFile autocmd (Eisuke Kawashima)
closes: vim/vim#16873
https://github.com/vim/vim/commit/20d23ce93b84ea199d5ea56d7ec86f5e6846d6cc
Co-authored-by: Eisuke Kawashima <e-kwsm@users.noreply.github.com>
Diffstat:
2 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/runtime/lua/vim/filetype.lua b/runtime/lua/vim/filetype.lua
@@ -1730,7 +1730,6 @@ local filename = {
['.ondirrc'] = 'ondir',
opam = 'opam',
['opam.locked'] = 'opam',
- ['pacman.log'] = 'pacmanlog',
['/etc/pam.conf'] = 'pamconf',
['pam_env.conf'] = 'pamenv',
['.pam_environment'] = 'pamenv',
@@ -2480,6 +2479,9 @@ local pattern = {
['/octave/history$'] = 'octave',
['%.opam%.locked$'] = 'opam',
['%.opam%.template$'] = 'opam',
+ ['^pacman%.log'] = starsetf(function(path, bufnr)
+ return vim.uv.fs_stat(path) and 'pacmanlog' or nil
+ end),
['printcap'] = starsetf(function(path, bufnr)
return require('vim.filetype.detect').printcap('print')
end),
diff --git a/test/old/testdir/test_filetype.vim b/test/old/testdir/test_filetype.vim
@@ -572,7 +572,6 @@ func s:GetFilenameChecks() abort
\ 'opl': ['file.OPL', 'file.OPl', 'file.OpL', 'file.Opl', 'file.oPL', 'file.oPl', 'file.opL', 'file.opl'],
\ 'ora': ['file.ora'],
\ 'org': ['file.org', 'file.org_archive'],
- \ 'pacmanlog': ['pacman.log'],
\ 'pamconf': ['/etc/pam.conf', '/etc/pam.d/file', 'any/etc/pam.conf', 'any/etc/pam.d/file'],
\ 'pamenv': ['/etc/security/pam_env.conf', '/home/user/.pam_environment', '.pam_environment', 'pam_env.conf'],
\ 'pandoc': ['file.pandoc', 'file.pdk', 'file.pd', 'file.pdc'],
@@ -2892,4 +2891,16 @@ func Test_org_file()
filetype off
endfunc
+" Filetypes detected from names of existing files
+func Test_pacmanlog()
+ filetype on
+ for fname in ['pacman.log', 'pacman.log.1', 'pacman.log-20250123']
+ call writefile(["[2025-01-23T01:23:45+0000] [PACMAN] Running 'pacman -S -y --config /etc/pacman.conf --'"], fname, 'D')
+ exe 'split ' .. fname
+ call assert_equal('pacmanlog', &filetype, 'for text: ' .. string(fname))
+ bwipe!
+ endfor
+ filetype off
+endfunc
+
" vim: shiftwidth=2 sts=2 expandtab