mirror of
https://github.com/neovim/neovim.git
synced 2025-12-15 19:05:40 +00:00
vim-patch:9.1.0013: Modula2 filetype support lacking (#27020)
Problem: Modula2 filetype support lacking
Solution: Improve the Modula-2 runtime support, add additional modula2
dialects, add compiler plugin, update syntax highlighting,
include syntax tests, update Makefiles (Doug Kearns)
closes: vim/vim#6796
closes: vim/vim#8115
68a8947069
- Luaify the detection script:
- Split the `(*!m2foo*)` and `(*!m2foo+bar*)` detection into two Lua patterns,
as Lua capture groups cannot be used with `?` and friends (as they only work
on character classes).
- Use `vim.api.nvim_buf_call()` (ew) to call `modula2#SetDialect()` to ensure
`b:modula2` is set for the given bufnr.
- Skip the syntax screendump tests. (A shame as they test some of the detection
from `(*!m2foo+bar*)` tags, but I tested this locally and it seems to work)
- Port the synmenu.vim changes from Vim9 script. (Also tested this locally)
- (And also add the missing comma for `b:browsefilter` from earlier.)
Co-authored-by: Doug Kearns <dougkearns@gmail.com>
This commit is contained in:
@@ -341,7 +341,7 @@ local extension = {
|
||||
decl = detect.decl,
|
||||
dec = detect.decl,
|
||||
dcl = detect_seq(detect.decl, 'clean'),
|
||||
def = 'def',
|
||||
def = detect.def,
|
||||
desc = 'desc',
|
||||
directory = 'desktop',
|
||||
desktop = 'desktop',
|
||||
@@ -674,8 +674,6 @@ local extension = {
|
||||
mmp = 'mmp',
|
||||
mms = detect.mms,
|
||||
DEF = 'modula2',
|
||||
m2 = 'modula2',
|
||||
mi = 'modula2',
|
||||
lm3 = 'modula3',
|
||||
mojo = 'mojo',
|
||||
['🔥'] = 'mojo', -- 🙄
|
||||
|
||||
@@ -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*(\*]])
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user