vim-patch:32a1b26: runtime(filetype): improve asm heuristics and move into FTasmsyntax() (#34863)

fixes: vim/vim#17474
closes: vim/vim#17683

32a1b26ef3

vim-patch:41ee98c: runtime(filetype): fix incorrect pattern and break early

- Using `\n` is incorrect, as result of getline() does not contain line
  breaks and only uses `\n` for NUL bytes.
- Return when b:asmsyntax is set, like many other filetypes.

closes: vim/vim#17706

41ee98c3c5

Co-authored-by: Wu Yongwei <wuyongwei@gmail.com>
This commit is contained in:
zeertzjq
2025-07-10 20:30:39 +08:00
committed by GitHub
parent fccd016a0f
commit 7f18811668

View File

@ -31,15 +31,9 @@ local matchregex = vim.filetype._matchregex
-- luacheck: push ignore 122
-- This function checks for the kind of assembly that is wanted by the user, or
-- can be detected from the first five lines of the file.
-- can be detected from the beginning 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)
@ -58,6 +52,40 @@ function M.asm(path, bufnr)
end
end
-- Checks the first lines for a asmsyntax=foo override.
-- Only whitespace characters can be present immediately before or after this statement.
--- @type vim.filetype.mapfn
function M.asm_syntax(_, bufnr)
local lines = ' ' .. table.concat(getlines(bufnr, 1, 5), ' '):lower() .. ' '
local match = lines:match('%sasmsyntax=([a-zA-Z0-9]+)%s')
if match then
return match
end
local is_slash_star_encountered = false
for _, line in ipairs(getlines(bufnr, 1, 50)) do
if line:find('^/%*') then
is_slash_star_encountered = true
end
if
line:find('^; Listing generated by Microsoft')
or matchregex(
line,
[[\c^\%(\%(CONST\|_BSS\|_DATA\|_TEXT\)\s\+SEGMENT\>\)\|\s*\.[2-6]86P\?\>\|\s*\.XMM\>]]
)
then
return 'masm'
elseif
line:find('Texas Instruments Incorporated')
-- tiasm uses `* commment`, but detection is unreliable if '/*' is seen
or (line:find('^%*') and not is_slash_star_encountered)
then
return 'tiasm'
elseif matchregex(line, [[\c\.title\>\|\.ident\>\|\.macro\>\|\.subtitle\>\|\.library\>]]) then
return 'vmasm'
end
end
end
--- Active Server Pages (with Perl or Visual Basic Script)
--- @type vim.filetype.mapfn
function M.asp(_, bufnr)
@ -69,19 +97,6 @@ function M.asp(_, bufnr)
return 'aspvbs'
end
-- Checks the first 5 lines for a asmsyntax=foo override.
-- Only whitespace characters can be present immediately before or after this statement.
--- @type vim.filetype.mapfn
function M.asm_syntax(_, bufnr)
local lines = ' ' .. table.concat(getlines(bufnr, 1, 5), ' '):lower() .. ' '
local match = lines:match('%sasmsyntax=([a-zA-Z0-9]+)%s')
if match then
return match
elseif findany(lines, { '%.title', '%.ident', '%.macro', '%.subtitle', '%.library' }) then
return 'vmasm'
end
end
local visual_basic_content =
[[\c^\s*\%(Attribute\s\+VB_Name\|Begin\s\+\%(VB\.\|{\%(\x\+-\)\+\x\+}\)\)]]