runtime(filetype): improve asm heuristics and move into FTasmsyntax()
Commit:
https://github.com/vim/vim/commit/32a1b26ef3e821de9b5c518829b08002e933fa5a
Author: Wu Yongwei <[email protected]>
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 <[email protected]>
Signed-off-by: Christian Brabandt <[email protected]>
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 <[email protected]>
# 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
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/vim_dev/E1uZEU0-00BHSH-4X%40256bit.org.