aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/filetype/detect.lua
diff options
context:
space:
mode:
authorJosh Rahm <joshuarahm@gmail.com>2025-02-05 23:09:29 +0000
committerJosh Rahm <joshuarahm@gmail.com>2025-02-05 23:09:29 +0000
commitd5f194ce780c95821a855aca3c19426576d28ae0 (patch)
treed45f461b19f9118ad2bb1f440a7a08973ad18832 /runtime/lua/vim/filetype/detect.lua
parentc5d770d311841ea5230426cc4c868e8db27300a8 (diff)
parent44740e561fc93afe3ebecfd3618bda2d2abeafb0 (diff)
downloadrneovim-rahm.tar.gz
rneovim-rahm.tar.bz2
rneovim-rahm.zip
Merge remote-tracking branch 'upstream/master' into mix_20240309HEADrahm
Diffstat (limited to 'runtime/lua/vim/filetype/detect.lua')
-rw-r--r--runtime/lua/vim/filetype/detect.lua61
1 files changed, 53 insertions, 8 deletions
diff --git a/runtime/lua/vim/filetype/detect.lua b/runtime/lua/vim/filetype/detect.lua
index 98b001bd51..fc0b45ecd8 100644
--- a/runtime/lua/vim/filetype/detect.lua
+++ b/runtime/lua/vim/filetype/detect.lua
@@ -34,6 +34,12 @@ local matchregex = vim.filetype._matchregex
-- can be detected from the first five lines of the file.
--- @type vim.filetype.mapfn
function M.asm(path, bufnr)
+ -- tiasm uses `* comment`
+ local lines = table.concat(getlines(bufnr, 1, 10), '\n')
+ if findany(lines, { '^%*', '\n%*', 'Texas Instruments Incorporated' }) then
+ return 'tiasm'
+ end
+
local syntax = vim.b[bufnr].asmsyntax
if not syntax or syntax == '' then
syntax = M.asm_syntax(path, bufnr)
@@ -181,6 +187,16 @@ function M.changelog(_, bufnr)
end
--- @type vim.filetype.mapfn
+function M.cl(_, bufnr)
+ local lines = table.concat(getlines(bufnr, 1, 4))
+ if lines:match('/%*') then
+ return 'opencl'
+ else
+ return 'lisp'
+ end
+end
+
+--- @type vim.filetype.mapfn
function M.class(_, bufnr)
-- Check if not a Java class (starts with '\xca\xfe\xba\xbe')
if not getline(bufnr, 1):find('^\202\254\186\190') then
@@ -209,6 +225,24 @@ function M.cls(_, bufnr)
return 'st'
end
+--- *.cmd is close to a Batch file, but on OS/2 Rexx files and TI linker command files also use *.cmd.
+--- lnk: `/* comment */`, `// comment`, and `--linker-option=value`
+--- rexx: `/* comment */`, `-- comment`
+--- @type vim.filetype.mapfn
+function M.cmd(_, bufnr)
+ local lines = table.concat(getlines(bufnr, 1, 20))
+ if matchregex(lines, [[MEMORY\|SECTIONS\|\%(^\|\n\)--\S\|\%(^\|\n\)//]]) then
+ return 'lnk'
+ else
+ local line1 = getline(bufnr, 1)
+ if line1:find('^/%*') then
+ return 'rexx'
+ else
+ return 'dosbatch'
+ end
+ end
+end
+
--- @type vim.filetype.mapfn
function M.conf(path, bufnr)
if fn.did_filetype() ~= 0 or path:find(vim.g.ft_ignore_pat) then
@@ -227,7 +261,8 @@ end
--- Debian Control
--- @type vim.filetype.mapfn
function M.control(_, bufnr)
- if getline(bufnr, 1):find('^Source:') then
+ local line1 = getline(bufnr, 1)
+ if line1 and findany(line1, { '^Source:', '^Package:' }) then
return 'debcontrol'
end
end
@@ -722,7 +757,7 @@ function M.html(_, bufnr)
if
matchregex(
line,
- [[@\(if\|for\|defer\|switch\)\|\*\(ngIf\|ngFor\|ngSwitch\|ngTemplateOutlet\)\|ng-template\|ng-content\|{{.*}}]]
+ [[@\(if\|for\|defer\|switch\)\|\*\(ngIf\|ngFor\|ngSwitch\|ngTemplateOutlet\)\|ng-template\|ng-content]]
)
then
return 'htmlangular'
@@ -846,7 +881,7 @@ end
--- (refactor of filetype.vim since the patterns are case-insensitive)
--- @type vim.filetype.mapfn
function M.log(path, _)
- path = path:lower()
+ path = path:lower() --- @type string LuaLS bug
if
findany(
path,
@@ -1132,7 +1167,7 @@ end
--- @type vim.filetype.mapfn
function M.perl(path, bufnr)
local dir_name = vim.fs.dirname(path)
- if fn.expand(path, '%:e') == 't' and (dir_name == 't' or dir_name == 'xt') then
+ if fn.fnamemodify(path, '%:e') == 't' and (dir_name == 't' or dir_name == 'xt') then
return 'perl'
end
local first_line = getline(bufnr, 1)
@@ -1340,7 +1375,7 @@ end
local udev_rules_pattern = '^%s*udev_rules%s*=%s*"([%^"]+)/*".*'
--- @type vim.filetype.mapfn
function M.rules(path)
- path = path:lower()
+ path = path:lower() --- @type string LuaLS bug
if
findany(path, {
'/etc/udev/.*%.rules$',
@@ -1363,7 +1398,7 @@ function M.rules(path)
if not ok then
return 'hog'
end
- local dir = fn.expand(path, ':h')
+ local dir = fn.fnamemodify(path, ':h')
for _, line in ipairs(config_lines) do
local match = line:match(udev_rules_pattern)
if match then
@@ -1395,6 +1430,15 @@ function M.sig(_, bufnr)
end
end
+--- @type vim.filetype.mapfn
+function M.sa(_, bufnr)
+ local lines = table.concat(getlines(bufnr, 1, 4), '\n')
+ if findany(lines, { '^;', '\n;' }) then
+ return 'tiasm'
+ end
+ return 'sather'
+end
+
-- This function checks the first 25 lines of file extension "sc" to resolve
-- detection between scala and SuperCollider
--- @type vim.filetype.mapfn
@@ -1719,7 +1763,7 @@ function M.v(_, bufnr)
return vim.g.filetype_v
end
local in_comment = 0
- for _, line in ipairs(getlines(bufnr, 1, 200)) do
+ for _, line in ipairs(getlines(bufnr, 1, 500)) do
if line:find('^%s*/%*') then
in_comment = 1
end
@@ -1733,7 +1777,7 @@ function M.v(_, bufnr)
or line:find('%(%*') and not line:find('/[/*].*%(%*')
then
return 'coq'
- elseif findany(line, { ';%s*$', ';%s*/[/*]' }) then
+ elseif findany(line, { ';%s*$', ';%s*/[/*]', '^%s*module%s+%w+%s*%(' }) then
return 'verilog'
end
end
@@ -1833,6 +1877,7 @@ local patterns_hashbang = {
ruby = 'ruby',
['node\\(js\\)\\=\\>\\|js\\>'] = { 'javascript', { vim_regex = true } },
['rhino\\>'] = { 'javascript', { vim_regex = true } },
+ just = 'just',
-- BC calculator
['^bc\\>'] = { 'bc', { vim_regex = true } },
['sed\\>'] = { 'sed', { vim_regex = true } },