aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsmjonas <jonas.strittmatter@gmx.de>2022-07-06 16:25:23 +0200
committersmjonas <jonas.strittmatter@gmx.de>2022-07-06 16:25:23 +0200
commitf3c78a4465942db62cf231b9eedc5107ad46e655 (patch)
tree79a20d17e11e25f4c753a13ac88b6a9685804b27
parentc68f1d7263cd5296e723d8cfee914c72f58138c3 (diff)
downloadrneovim-f3c78a4465942db62cf231b9eedc5107ad46e655.tar.gz
rneovim-f3c78a4465942db62cf231b9eedc5107ad46e655.tar.bz2
rneovim-f3c78a4465942db62cf231b9eedc5107ad46e655.zip
fix(filetype): fix filetype patterns
-rw-r--r--runtime/filetype.lua8
-rw-r--r--runtime/lua/vim/filetype.lua136
-rw-r--r--runtime/lua/vim/filetype/detect.lua22
3 files changed, 135 insertions, 31 deletions
diff --git a/runtime/filetype.lua b/runtime/filetype.lua
index 35bb31edce..7728892c78 100644
--- a/runtime/filetype.lua
+++ b/runtime/filetype.lua
@@ -13,7 +13,13 @@ vim.api.nvim_create_autocmd({ 'BufRead', 'BufNewFile' }, {
group = 'filetypedetect',
callback = function(args)
local ft, on_detect = vim.filetype.match({ buf = args.buf })
- if ft then
+ if not ft then
+ -- Generic configuration file used as fallback
+ ft = require('vim.filetype.detect').conf(args.file, args.buf)
+ if ft then
+ vim.api.nvim_cmd({ cmd = 'setf', args = { 'FALLBACK', ft } }, {})
+ end
+ else
vim.api.nvim_buf_set_option(args.buf, 'filetype', ft)
if on_detect then
on_detect(args.buf)
diff --git a/runtime/lua/vim/filetype.lua b/runtime/lua/vim/filetype.lua
index 377e416f12..de79d65f48 100644
--- a/runtime/lua/vim/filetype.lua
+++ b/runtime/lua/vim/filetype.lua
@@ -17,7 +17,7 @@ local function starsetf(ft, opts)
end
end,
{
- -- Starset matches should always have lowest priority
+ -- Starset matches should have lowest priority by default
priority = (opts and opts.priority) or -math.huge,
},
}
@@ -310,7 +310,7 @@ local extension = {
end,
ecd = 'ecd',
edf = 'edif',
- edfi = 'edif',
+ edif = 'edif',
edo = 'edif',
edn = function(path, bufnr)
return require('vim.filetype.detect').edn(bufnr)
@@ -425,7 +425,6 @@ local extension = {
gleam = 'gleam',
glsl = 'glsl',
gpi = 'gnuplot',
- gnuplot = 'gnuplot',
go = 'go',
gp = 'gp',
gs = 'grads',
@@ -1175,9 +1174,8 @@ local extension = {
return require('vim.filetype.detect').sgml(bufnr)
end,
t = function(path, bufnr)
- if not require('vim.filetype.detect').nroff(bufnr) and not require('vim.filetype.detect').perl(path, bufnr) then
- return 'tads'
- end
+ local nroff = require('vim.filetype.detect').nroff(bufnr)
+ return nroff or require('vim.filetype.detect').perl(path, bufnr) or 'tads'
end,
-- Ignored extensions
bak = function(path, bufnr)
@@ -1253,13 +1251,6 @@ local filename = {
['.arch-inventory'] = 'arch',
['GNUmakefile.am'] = 'automake',
['named.root'] = 'bindzone',
- ['.*/bind/db%..*'] = starsetf('bindzone'),
- ['.*/named/db%..*'] = starsetf('bindzone'),
- ['cabal%.project%..*'] = starsetf('cabalproject'),
- ['sgml%.catalog.*'] = starsetf('catalog'),
- ['.*/etc/hostname%..*'] = starsetf('config'),
- ['.*/etc/cron%.d/.*'] = starsetf('crontab'),
- ['crontab%..*'] = starsetf('crontab'),
WORKSPACE = 'bzl',
BUILD = 'bzl',
['cabal.project'] = 'cabalproject',
@@ -1305,9 +1296,6 @@ local filename = {
['/debian/copyright'] = 'debcopyright',
['/etc/apt/sources.list'] = 'debsources',
['denyhosts.conf'] = 'denyhosts',
- ['.*/debian/patches/.*'] = function(path, bufnr)
- return require('vim.filetype.detect').dep3patch(path, bufnr)
- end,
['dict.conf'] = 'dictconf',
['.dictrc'] = 'dictconf',
['/etc/DIR_COLORS'] = 'dircolors',
@@ -1366,6 +1354,7 @@ local filename = {
['.gnashpluginrc'] = 'gnash',
gnashpluginrc = 'gnash',
gnashrc = 'gnash',
+ ['.gnuplot'] = 'gnuplot',
['go.work'] = 'gowork',
['.gprc'] = 'gp',
['/.gnupg/gpg.conf'] = 'gpg',
@@ -1514,7 +1503,6 @@ local filename = {
['.screenrc'] = 'screen',
['/etc/sensors3.conf'] = 'sensors',
['/etc/sensors.conf'] = 'sensors',
- ['.*/etc/sensors%.d/[^.].*'] = starsetf('sensors'),
['/etc/services'] = 'services',
['/etc/serial.conf'] = 'setserial',
['/etc/udev/cdsymlinks.conf'] = 'sh',
@@ -1560,13 +1548,15 @@ local filename = {
['.slrnrc'] = 'slrnrc',
['sendmail.cf'] = 'sm',
['squid.conf'] = 'squid',
- ['/.ssh/config'] = 'sshconfig',
['ssh_config'] = 'sshconfig',
['sshd_config'] = 'sshdconfig',
['/etc/sudoers'] = 'sudoers',
['sudoers.tmp'] = 'sudoers',
['/etc/sysctl.conf'] = 'sysctl',
tags = 'tags',
+ ['pending.data'] = 'taskdata',
+ ['completed.data'] = 'taskdata',
+ ['undo.data'] = 'taskdata',
['.tclshrc'] = 'tcl',
['.wishrc'] = 'tcl',
['tclsh.rc'] = 'tcl',
@@ -1667,12 +1657,16 @@ local pattern = {
return require('vim.filetype.detect').asm(bufnr)
end,
['[mM]akefile%.am'] = 'automake',
+ ['.*/bind/db%..*'] = starsetf('bindzone'),
+ ['.*/named/db%..*'] = starsetf('bindzone'),
['.*bsd'] = 'bsdl',
['bzr_log%..*'] = 'bzr',
['.*enlightenment/.*%.cfg'] = 'c',
+ ['cabal%.project%..*'] = starsetf('cabalproject'),
['.*/%.calendar/.*'] = starsetf('calendar'),
['.*/share/calendar/.*/calendar%..*'] = starsetf('calendar'),
['.*/share/calendar/calendar%..*'] = starsetf('calendar'),
+ ['sgml%.catalog.*'] = starsetf('catalog'),
['.*/etc/defaults/cdrdao'] = 'cdrdaoconf',
['.*/etc/cdrdao%.conf'] = 'cdrdaoconf',
['.*/etc/default/cdrdao'] = 'cdrdaoconf',
@@ -1681,10 +1675,13 @@ local pattern = {
function(path, bufnr)
return require('vim.filetype.detect').cfg(bufnr)
end,
- -- Decrease the priority to avoid conflicts with more specific patterns
+ -- Decrease priority to avoid conflicts with more specific patterns
-- such as '.*/etc/a2ps/.*%.cfg', '.*enlightenment/.*%.cfg', etc.
{ priority = -1 },
},
+ ['[cC]hange[lL]og.*'] = starsetf(function(path, bufnr)
+ require('vim.filetype.detect').changelog(bufnr)
+ end),
['.*%.%.ch'] = 'chill',
['.*%.cmake%.in'] = 'cmake',
-- */cmus/rc and */.cmus/rc
@@ -1693,6 +1690,9 @@ local pattern = {
['.*/%.?cmus/.*%.theme'] = 'cmusrc',
['.*/%.cmus/autosave'] = 'cmusrc',
['.*/%.cmus/command%-history'] = 'cmusrc',
+ ['.*/etc/hostname%..*'] = starsetf('config'),
+ ['crontab%..*'] = starsetf('crontab'),
+ ['.*/etc/cron%.d/.*'] = starsetf('crontab'),
['%.cshrc.*'] = function(path, bufnr)
return require('vim.filetype.detect').csh(path, bufnr)
end,
@@ -1703,9 +1703,9 @@ local pattern = {
['.*%.[Dd][Aa][Tt]'] = function(path, bufnr)
return require('vim.filetype.detect').dat(path, bufnr)
end,
- ['[cC]hange[lL]og.*'] = starsetf(function(path, bufnr)
- require('vim.filetype.detect').changelog(bufnr)
- end),
+ ['.*/debian/patches/.*'] = function(path, bufnr)
+ return require('vim.filetype.detect').dep3patch(path, bufnr)
+ end,
['.*/etc/dnsmasq%.d/.*'] = starsetf('dnsmasq'),
['Containerfile%..*'] = starsetf('dockerfile'),
['Dockerfile%..*'] = starsetf('dockerfile'),
@@ -1716,6 +1716,8 @@ local pattern = {
['.*/debian/copyright'] = 'debcopyright',
['.*/etc/apt/sources%.list%.d/.*%.list'] = 'debsources',
['.*/etc/apt/sources%.list'] = 'debsources',
+ ['.*%.directory'] = 'desktop',
+ ['.*%.desktop'] = 'desktop',
['dictd.*%.conf'] = 'dictdconf',
['.*/etc/DIR_COLORS'] = 'dircolors',
['.*/etc/dnsmasq%.conf'] = 'dnsmasq',
@@ -1770,10 +1772,15 @@ local pattern = {
['.*/gitolite%-admin/conf/.*'] = starsetf('gitolite'),
['tmac%..*'] = starsetf('nroff'),
['.*/%.gitconfig%.d/.*'] = starsetf('gitconfig'),
- ['.*%.git/.*'] = function(path, bufnr)
- require('vim.filetype.detect').git(bufnr)
- end,
+ ['.*%.git/.*'] = {
+ function(path, bufnr)
+ return require('vim.filetype.detect').git(bufnr)
+ end,
+ -- Decrease priority to run after simple pattern checks
+ { priority = -1 },
+ },
['.*%.git/modules/.*/config'] = 'gitconfig',
+ ['.*%.git/modules/config'] = 'gitconfig',
['.*%.git/config'] = 'gitconfig',
['.*/etc/gitconfig'] = 'gitconfig',
['.*/%.config/git/config'] = 'gitconfig',
@@ -1859,6 +1866,83 @@ local pattern = {
['.*[mM]akefile'] = 'make',
['[mM]akefile.*'] = starsetf('make'),
['.*/etc/man%.conf'] = 'manconf',
+ ['.*/log/auth'] = 'messages',
+ ['.*/log/cron'] = 'messages',
+ ['.*/log/daemon'] = 'messages',
+ ['.*/log/debug'] = 'messages',
+ ['.*/log/kern'] = 'messages',
+ ['.*/log/lpr'] = 'messages',
+ ['.*/log/mail'] = 'messages',
+ ['.*/log/messages'] = 'messages',
+ ['.*/log/news/news'] = 'messages',
+ ['.*/log/syslog'] = 'messages',
+ ['.*/log/user'] = 'messages',
+ ['.*/log/auth%.log'] = 'messages',
+ ['.*/log/cron%.log'] = 'messages',
+ ['.*/log/daemon%.log'] = 'messages',
+ ['.*/log/debug%.log'] = 'messages',
+ ['.*/log/kern%.log'] = 'messages',
+ ['.*/log/lpr%.log'] = 'messages',
+ ['.*/log/mail%.log'] = 'messages',
+ ['.*/log/messages%.log'] = 'messages',
+ ['.*/log/news/news%.log'] = 'messages',
+ ['.*/log/syslog%.log'] = 'messages',
+ ['.*/log/user%.log'] = 'messages',
+ ['.*/log/auth%.err'] = 'messages',
+ ['.*/log/cron%.err'] = 'messages',
+ ['.*/log/daemon%.err'] = 'messages',
+ ['.*/log/debug%.err'] = 'messages',
+ ['.*/log/kern%.err'] = 'messages',
+ ['.*/log/lpr%.err'] = 'messages',
+ ['.*/log/mail%.err'] = 'messages',
+ ['.*/log/messages%.err'] = 'messages',
+ ['.*/log/news/news%.err'] = 'messages',
+ ['.*/log/syslog%.err'] = 'messages',
+ ['.*/log/user%.err'] = 'messages',
+ ['.*/log/auth%.info'] = 'messages',
+ ['.*/log/cron%.info'] = 'messages',
+ ['.*/log/daemon%.info'] = 'messages',
+ ['.*/log/debug%.info'] = 'messages',
+ ['.*/log/kern%.info'] = 'messages',
+ ['.*/log/lpr%.info'] = 'messages',
+ ['.*/log/mail%.info'] = 'messages',
+ ['.*/log/messages%.info'] = 'messages',
+ ['.*/log/news/news%.info'] = 'messages',
+ ['.*/log/syslog%.info'] = 'messages',
+ ['.*/log/user%.info'] = 'messages',
+ ['.*/log/auth%.warn'] = 'messages',
+ ['.*/log/cron%.warn'] = 'messages',
+ ['.*/log/daemon%.warn'] = 'messages',
+ ['.*/log/debug%.warn'] = 'messages',
+ ['.*/log/kern%.warn'] = 'messages',
+ ['.*/log/lpr%.warn'] = 'messages',
+ ['.*/log/mail%.warn'] = 'messages',
+ ['.*/log/messages%.warn'] = 'messages',
+ ['.*/log/news/news%.warn'] = 'messages',
+ ['.*/log/syslog%.warn'] = 'messages',
+ ['.*/log/user%.warn'] = 'messages',
+ ['.*/log/auth%.crit'] = 'messages',
+ ['.*/log/cron%.crit'] = 'messages',
+ ['.*/log/daemon%.crit'] = 'messages',
+ ['.*/log/debug%.crit'] = 'messages',
+ ['.*/log/kern%.crit'] = 'messages',
+ ['.*/log/lpr%.crit'] = 'messages',
+ ['.*/log/mail%.crit'] = 'messages',
+ ['.*/log/messages%.crit'] = 'messages',
+ ['.*/log/news/news%.crit'] = 'messages',
+ ['.*/log/syslog%.crit'] = 'messages',
+ ['.*/log/user%.crit'] = 'messages',
+ ['.*/log/auth%.notice'] = 'messages',
+ ['.*/log/cron%.notice'] = 'messages',
+ ['.*/log/daemon%.notice'] = 'messages',
+ ['.*/log/debug%.notice'] = 'messages',
+ ['.*/log/kern%.notice'] = 'messages',
+ ['.*/log/lpr%.notice'] = 'messages',
+ ['.*/log/mail%.notice'] = 'messages',
+ ['.*/log/messages%.notice'] = 'messages',
+ ['.*/log/news/news%.notice'] = 'messages',
+ ['.*/log/syslog%.notice'] = 'messages',
+ ['.*/log/user%.notice'] = 'messages',
['.*%.[Mm][Oo][Dd]'] = function(path, bufnr)
return require('vim.filetype.detect').mod(path, bufnr)
end,
@@ -1937,6 +2021,7 @@ local pattern = {
['[rR]akefile.*'] = starsetf('ruby'),
['[rR]antfile'] = 'ruby',
['[rR]akefile'] = 'ruby',
+ ['.*/etc/sensors%.d/[^.].*'] = starsetf('sensors'),
['.*/etc/sensors%.conf'] = 'sensors',
['.*/etc/sensors3%.conf'] = 'sensors',
['.*/etc/services'] = 'services',
@@ -1975,6 +2060,7 @@ local pattern = {
['.*/etc/slp%.spi'] = 'slpspi',
['.*/etc/ssh/ssh_config%.d/.*%.conf'] = 'sshconfig',
['.*/%.ssh/config'] = 'sshconfig',
+ ['.*/%.ssh/.*%.conf'] = 'sshconfig',
['.*/etc/ssh/sshd_config%.d/.*%.conf'] = 'sshdconfig',
['.*%.[Ss][Rr][Cc]'] = function(path, bufnr)
return require('vim.filetype.detect').src(bufnr)
diff --git a/runtime/lua/vim/filetype/detect.lua b/runtime/lua/vim/filetype/detect.lua
index c6d77dac51..fb36a502b0 100644
--- a/runtime/lua/vim/filetype/detect.lua
+++ b/runtime/lua/vim/filetype/detect.lua
@@ -187,6 +187,17 @@ function M.cls(bufnr)
end
end
+function M.conf(path, bufnr)
+ if vim.fn.did_filetype() ~= 0 or path:find(vim.g.ft_ignore_pat) then
+ return
+ end
+ for _, line in ipairs(getlines(bufnr, 1, 5)) do
+ if line:find('^#') then
+ return 'conf'
+ end
+ end
+end
+
-- Debian Control
function M.control(bufnr)
if getlines(bufnr, 1):find('^Source:') then
@@ -256,8 +267,9 @@ local function cvs_diff(path, contents)
end
function M.dat(path, bufnr)
+ local file_name = vim.fn.fnamemodify(path, ':t'):lower()
-- Innovation data processing
- if findany(path:lower(), { '^upstream%.dat$', '^upstream%..*%.dat$', '^.*%.upstream%.dat$' }) then
+ if findany(file_name, { '^upstream%.dat$', '^upstream%..*%.dat$', '^.*%.upstream%.dat$' }) then
return 'upstreamdat'
end
if vim.g.filetype_dat then
@@ -458,7 +470,7 @@ end
function M.git(bufnr)
local line = getlines(bufnr, 1)
- if line:find('^' .. string.rep('%x', 40) .. '+ ') or line:sub(1, 5) == 'ref: ' then
+ if matchregex(line, [[^\x\{40,\}\>\|^ref: ]]) then
return 'git'
end
end
@@ -568,7 +580,7 @@ function M.log(path)
return 'upstreaminstalllog'
elseif findany(path, { 'usserver%.log', 'usserver%..*%.log', '.*%.usserver%.log' }) then
return 'usserverlog'
- elseif findany(path, { 'usw2kagt%.log', 'usws2kagt%..*%.log', '.*%.usws2kagt%.log' }) then
+ elseif findany(path, { 'usw2kagt%.log', 'usw2kagt%..*%.log', '.*%.usw2kagt%.log' }) then
return 'usw2kagtlog'
end
end
@@ -759,8 +771,8 @@ end
-- If the first line starts with '#' and contains 'perl' it's probably a Perl file.
-- (Slow test) If a file contains a 'use' statement then it is almost certainly a Perl file.
function M.perl(path, bufnr)
- local dirname = vim.fn.expand(path, '%:p:h:t')
- if vim.fn.expand(dirname, '%:e') == 't' and (dirname == 't' or dirname == 'xt') then
+ local dir_name = vim.fs.dirname(path)
+ if vim.fn.expand(path, '%:e') == 't' and (dir_name == 't' or dir_name == 'xt') then
return 'perl'
end
local first_line = getlines(bufnr, 1)