aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/filetype
diff options
context:
space:
mode:
authorJosh Rahm <joshuarahm@gmail.com>2024-03-09 15:00:41 -0700
committerJosh Rahm <joshuarahm@gmail.com>2024-03-09 15:00:41 -0700
commit7a7f497b483cd65e340064f23ed1c73425ecba0a (patch)
treed5c99ea22a1e10300d06165f8ac96df6b0dc59e1 /runtime/lua/vim/filetype
parent1b7b916b7631ddf73c38e3a0070d64e4636cb2f3 (diff)
parentade1b12f49c3b3914c74847d791eb90ea90b56b7 (diff)
downloadrneovim-7a7f497b483cd65e340064f23ed1c73425ecba0a.tar.gz
rneovim-7a7f497b483cd65e340064f23ed1c73425ecba0a.tar.bz2
rneovim-7a7f497b483cd65e340064f23ed1c73425ecba0a.zip
Merge remote-tracking branch 'upstream/master' into aucmd_textputpost
Diffstat (limited to 'runtime/lua/vim/filetype')
-rw-r--r--runtime/lua/vim/filetype/detect.lua78
1 files changed, 72 insertions, 6 deletions
diff --git a/runtime/lua/vim/filetype/detect.lua b/runtime/lua/vim/filetype/detect.lua
index 9d0f1bd3ab..3db4f2bcdc 100644
--- a/runtime/lua/vim/filetype/detect.lua
+++ b/runtime/lua/vim/filetype/detect.lua
@@ -419,6 +419,55 @@ function M.dtrace(_, bufnr)
return 'd'
end
+--- @param bufnr integer
+--- @return boolean
+local function is_modula2(bufnr)
+ return matchregex(nextnonblank(bufnr, 1), [[\<MODULE\s\+\w\+\s*\%(\[.*]\s*\)\=;\|^\s*(\*]])
+end
+
+--- @param bufnr integer
+--- @return string, fun(b: integer)
+local function modula2(bufnr)
+ local dialect = vim.g.modula2_default_dialect or 'pim'
+ local extension = vim.g.modula2_default_extension or ''
+
+ -- ignore unknown dialects or badly formatted tags
+ for _, line in ipairs(getlines(bufnr, 1, 200)) do
+ local matched_dialect, matched_extension = line:match('%(%*!m2(%w+)%+(%w+)%*%)')
+ if not matched_dialect then
+ matched_dialect = line:match('%(%*!m2(%w+)%*%)')
+ end
+ if matched_dialect then
+ if vim.tbl_contains({ 'iso', 'pim', 'r10' }, matched_dialect) then
+ dialect = matched_dialect
+ end
+ if vim.tbl_contains({ 'gm2' }, matched_extension) then
+ extension = matched_extension
+ end
+ break
+ end
+ end
+
+ return 'modula2',
+ function(b)
+ vim.api.nvim_buf_call(b, function()
+ fn['modula2#SetDialect'](dialect, extension)
+ end)
+ end
+end
+
+--- @type vim.filetype.mapfn
+function M.def(_, bufnr)
+ if vim.g.filetype_def == 'modula2' or is_modula2(bufnr) then
+ return modula2(bufnr)
+ end
+
+ if vim.g.filetype_def then
+ return vim.g.filetype_def
+ end
+ return 'def'
+end
+
--- @type vim.filetype.mapfn
function M.e(_, bufnr)
if vim.g.filetype_euphoria then
@@ -906,14 +955,16 @@ end
--- Determine if *.mod is ABB RAPID, LambdaProlog, Modula-2, Modsim III or go.mod
--- @type vim.filetype.mapfn
function M.mod(path, bufnr)
+ if vim.g.filetype_mod == 'modula2' or is_modula2(bufnr) then
+ return modula2(bufnr)
+ end
+
if vim.g.filetype_mod then
return vim.g.filetype_mod
elseif matchregex(path, [[\c\<go\.mod$]]) then
return 'gomod'
elseif is_lprolog(bufnr) then
return 'lprolog'
- elseif matchregex(nextnonblank(bufnr, 1), [[\%(\<MODULE\s\+\w\+\s*;\|^\s*(\*\)]]) then
- return 'modula2'
elseif is_rapid(bufnr) then
return 'rapid'
end
@@ -1530,12 +1581,26 @@ function M.v(_, bufnr)
-- Filetype was already detected
return
end
+ if vim.g.filetype_v then
+ return vim.g.filetype_v
+ end
+ local in_comment = 0
for _, line in ipairs(getlines(bufnr, 1, 200)) do
- if not line:find('^%s*/') then
- if findany(line, { ';%s*$', ';%s*/' }) then
- return 'verilog'
- elseif findany(line, { '%.%s*$', '%.%s*%(%*' }) then
+ if line:find('^%s*/%*') then
+ in_comment = 1
+ end
+ if in_comment == 1 then
+ if line:find('%*/') then
+ in_comment = 0
+ end
+ elseif not line:find('^%s*//') then
+ if
+ line:find('%.%s*$') and not line:find('/[/*]')
+ or line:find('%(%*') and not line:find('/[/*].*%(%*')
+ then
return 'coq'
+ elseif findany(line, { ';%s*$', ';%s*/[/*]' }) then
+ return 'verilog'
end
end
end
@@ -1661,6 +1726,7 @@ local patterns_hashbang = {
['^\\%(rexx\\|regina\\)\\>'] = { 'rexx', { vim_regex = true } },
['^janet\\>'] = { 'janet', { vim_regex = true } },
['^dart\\>'] = { 'dart', { vim_regex = true } },
+ ['^execlineb\\>'] = { 'execline', { vim_regex = true } },
}
---@private