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

2 views
Skip to first unread message

Christian Brabandt

unread,
Jul 8, 2025, 4:01:03 PM7/8/25
to vim...@googlegroups.com
runtime(filetype): improve asm heuristics and move into FTasmsyntax()

Commit: https://github.com/vim/vim/commit/32a1b26ef3e821de9b5c518829b08002e933fa5a
Author: Wu Yongwei <wuyo...@gmail.com>
Date: Tue Jul 8 21:42:37 2025 +0200

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

fixes: https://github.com/vim/vim/issues/17474
closes: https://github.com/vim/vim/issues/17683

Signed-off-by: Wu Yongwei <wuyo...@gmail.com>
Signed-off-by: Christian Brabandt <c...@256bit.org>

diff --git a/runtime/autoload/dist/ft.vim b/runtime/autoload/dist/ft.vim
index 5014e7544..ff1dc037d 100644
--- a/runtime/autoload/dist/ft.vim
+++ b/runtime/autoload/dist/ft.vim
@@ -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 <Br...@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), "
") =~ '\%(\%(^\|
\)\*\|Texas Instruments Incorporated\)'
- setf tiasm
- endif
# make sure b:asmsyntax exists
if !exists("b:asmsyntax")
b:asmsyntax = ""
@@ -65,8 +61,26 @@ 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'))
- b:asmsyntax = "vmasm"
+ 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 =~ '\%(^\|
\)/\*'
+ is_slash_star_encountered = true
+ endif
+ if line =~# '^; Listing generated by Microsoft' || line =~? '\%(^\|
\)\%(\%(CONST\|_BSS\|_DATA\|_TEXT\)\s\+SEGMENT\>\)\|\s*\.[2-6]86P\?\>\|\s*\.XMM\>'
+ b:asmsyntax = "masm"
+ elseif line =~ 'Texas Instruments Incorporated' || (line =~ '\%(^\|
\)\*' && !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

Reply all
Reply to author
Forward
0 new messages