mirror of
https://github.com/vim/vim
synced 2025-07-15 16:51:57 +00:00
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:
committed by
Christian Brabandt
parent
93c2d5bf7f
commit
32a1b26ef3
30
runtime/autoload/dist/ft.vim
vendored
30
runtime/autoload/dist/ft.vim
vendored
@ -3,7 +3,7 @@ vim9script
|
|||||||
# Vim functions for file type detection
|
# Vim functions for file type detection
|
||||||
#
|
#
|
||||||
# Maintainer: The Vim Project <https://github.com/vim/vim>
|
# 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>
|
# Former Maintainer: Bram Moolenaar <Bram@vim.org>
|
||||||
|
|
||||||
# These functions are moved here from runtime/filetype.vim to make startup
|
# These functions are moved here from runtime/filetype.vim to make startup
|
||||||
@ -30,12 +30,8 @@ export def Check_inp()
|
|||||||
enddef
|
enddef
|
||||||
|
|
||||||
# This function checks for the kind of assembly that is wanted by the user, or
|
# 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()
|
export def FTasm()
|
||||||
# tiasm uses `* commment`
|
|
||||||
if join(getline(1, 10), "\n") =~ '\%(\%(^\|\n\)\*\|Texas Instruments Incorporated\)'
|
|
||||||
setf tiasm
|
|
||||||
endif
|
|
||||||
# make sure b:asmsyntax exists
|
# make sure b:asmsyntax exists
|
||||||
if !exists("b:asmsyntax")
|
if !exists("b:asmsyntax")
|
||||||
b:asmsyntax = ""
|
b:asmsyntax = ""
|
||||||
@ -65,8 +61,26 @@ export def FTasmsyntax()
|
|||||||
var match = matchstr(head, '\sasmsyntax=\zs[a-zA-Z0-9]\+\ze\s')
|
var match = matchstr(head, '\sasmsyntax=\zs[a-zA-Z0-9]\+\ze\s')
|
||||||
if match != ''
|
if match != ''
|
||||||
b:asmsyntax = match
|
b:asmsyntax = match
|
||||||
elseif ((head =~? '\.title') || (head =~? '\.ident') || (head =~? '\.macro') || (head =~? '\.subtitle') || (head =~? '\.library'))
|
else
|
||||||
b:asmsyntax = "vmasm"
|
# 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
|
endif
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user