runtime(filetype): improve asm heuristics and move into FTasmsyntax()

fixes: #17474
closes: #17683

Signed-off-by: Wu Yongwei <wuyongwei@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
Wu Yongwei
2025-07-08 21:42:37 +02:00
committed by Christian Brabandt
parent 93c2d5bf7f
commit 32a1b26ef3

View File

@ -3,7 +3,7 @@ vim9script
# Vim functions for file type detection
#
# Maintainer: The Vim Project <https://github.com/vim/vim>
# Last Change: 2025 Jun 17
# Last Change: 2025 Jul 08
# Former Maintainer: Bram Moolenaar <Bram@vim.org>
# These functions are moved here from runtime/filetype.vim to make startup
@ -30,12 +30,8 @@ export def Check_inp()
enddef
# 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.
export def FTasm()
# tiasm uses `* commment`
if join(getline(1, 10), "\n") =~ '\%(\%(^\|\n\)\*\|Texas Instruments Incorporated\)'
setf tiasm
endif
# make sure b:asmsyntax exists
if !exists("b:asmsyntax")
b:asmsyntax = ""
@ -65,9 +61,27 @@ export def FTasmsyntax()
var match = matchstr(head, '\sasmsyntax=\zs[a-zA-Z0-9]\+\ze\s')
if match != ''
b:asmsyntax = match
elseif ((head =~? '\.title') || (head =~? '\.ident') || (head =~? '\.macro') || (head =~? '\.subtitle') || (head =~? '\.library'))
else
# Use heuristics
var is_slash_star_encountered = false
var i = 1
const n = min([50, line("$")])
while i <= n
const line = getline(i)
if line =~ '\%(^\|\n\)/\*'
is_slash_star_encountered = true
endif
if line =~# '^; Listing generated by Microsoft' || line =~? '\%(^\|\n\)\%(\%(CONST\|_BSS\|_DATA\|_TEXT\)\s\+SEGMENT\>\)\|\s*\.[2-6]86P\?\>\|\s*\.XMM\>'
b:asmsyntax = "masm"
elseif line =~ 'Texas Instruments Incorporated' || (line =~ '\%(^\|\n\)\*' && !is_slash_star_encountered)
# tiasm uses `* commment`, but detection is unreliable if '/*' is seen
b:asmsyntax = "tiasm"
elseif ((line =~? '\.title\>\|\.ident\>\|\.macro\>\|\.subtitle\>\|\.library\>'))
b:asmsyntax = "vmasm"
endif
i += 1
endwhile
endif
enddef
var ft_visual_basic_content = '\c^\s*\%(Attribute\s\+VB_Name\|Begin\s\+\%(VB\.\|{\%(\x\+-\)\+\x\+}\)\)'