From 6dfcb2b78463949ba066851a949bae15e869b33c Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 25 Mar 2026 09:02:04 +0800 Subject: [PATCH] vim-patch:9.2.0237: filetype: ObjectScript routines are not recognized (#38479) Problem: filetype: ObjectScript routines are not recognized Solution: Add ObjectScript routines detection for .mac, .int, and .inc files (Hannah Kimura) Reference: https://docs.intersystems.com/latest/csp/docbook/DocBook.UI.Page.cls?KEY=GORIENT_ch_intro#GORIENT_intro_routines closes: vim/vim#19805 https://github.com/vim/vim/commit/25f6539645d805295b11253c7bd8632aa20604f4 Co-authored-by: Hannah Kimura --- runtime/doc/filetype.txt | 2 ++ runtime/lua/vim/filetype.lua | 4 +-- runtime/lua/vim/filetype/detect.lua | 33 ++++++++++++++++++ test/old/testdir/test_filetype.vim | 54 +++++++++++++++++++++++++++++ 4 files changed, 91 insertions(+), 2 deletions(-) diff --git a/runtime/doc/filetype.txt b/runtime/doc/filetype.txt index acdef58782..7f5fec5b16 100644 --- a/runtime/doc/filetype.txt +++ b/runtime/doc/filetype.txt @@ -155,8 +155,10 @@ variables can be used to overrule the filetype used for certain extensions: `*.h` g:c_syntax_for_h |ft-c-syntax| `*.i` g:filetype_i |ft-progress-syntax| `*.inc` g:filetype_inc + `*.int` g:filetype_int `*.lsl` g:filetype_lsl `*.m` g:filetype_m |ft-mathematica-syntax| + `*.mac` g:filetype_mac `*[mM]makefile,*.mk,*.mak,[mM]akefile*` g:make_flavor |ft-make-syntax| `*.markdown,*.mdown,*.mkd,*.mkdn,*.mdwn,*.md` diff --git a/runtime/lua/vim/filetype.lua b/runtime/lua/vim/filetype.lua index 0a112fa894..37cdb7aed8 100644 --- a/runtime/lua/vim/filetype.lua +++ b/runtime/lua/vim/filetype.lua @@ -233,7 +233,6 @@ local extension = { a = detect.asm, A = detect.asm, lst = detect.asm, - mac = detect.asm, asn1 = 'asn', asn = 'asn', asp = detect.asp, @@ -598,7 +597,6 @@ local extension = { ihex = 'hex', ihe = 'hex', ihx = 'hex', - int = 'hex', mcs = 'hex', hjson = 'hjson', m3u = 'hlsplaylist', @@ -633,6 +631,7 @@ local extension = { ii = 'initng', inko = 'inko', inp = detect.inp, + int = detect.int, ms = detect_seq(detect.nroff, 'xmath'), ipkg = 'ipkg', iss = 'iss', @@ -764,6 +763,7 @@ local extension = { mc = detect.mc, quake = 'm3quake', m4 = detect.m4, + mac = detect.mac, eml = 'mail', mk = detect.make, mak = detect.make, diff --git a/runtime/lua/vim/filetype/detect.lua b/runtime/lua/vim/filetype/detect.lua index 6f81e92150..e214dee07a 100644 --- a/runtime/lua/vim/filetype/detect.lua +++ b/runtime/lua/vim/filetype/detect.lua @@ -63,6 +63,14 @@ function M.app(path, bufnr) end end +--- @param bufnr integer +--- @return boolean +local function is_objectscript_routime(bufnr) + local line1 = getline(bufnr, 1) + line1 = fn.substitute(line1, [[^\ufeff]], '', '') + return matchregex(line1, [[\c^\s*routine\>\s\+[%A-Za-z][%A-Za-z0-9_.]*\%(\s*\[\|\s*;\|$\)]]) +end + -- This function checks for the kind of assembly that is wanted by the user, or -- can be detected from the beginning of the file. --- @type vim.filetype.mapfn @@ -85,6 +93,17 @@ function M.asm(path, bufnr) end end +--- @type vim.filetype.mapfn +function M.mac(path, bufnr) + if vim.g.filetype_mac then + return vim.g.filetype_mac + elseif is_objectscript_routime(bufnr) then + return 'objectscript_routine' + else + return 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 @@ -896,6 +915,9 @@ function M.inc(path, bufnr) if vim.g.filetype_inc then return vim.g.filetype_inc end + if is_objectscript_routime(bufnr) then + return 'objectscript_routine' + end for _, line in ipairs(getlines(bufnr, 1, 20)) do if line:lower():find('perlscript') then return 'aspperl' @@ -945,6 +967,17 @@ function M.install(path, bufnr) return M.bash(path, bufnr) end +--- @type vim.filetype.mapfn +function M.int(_, bufnr) + if vim.g.filetype_int then + return vim.g.filetype_int + elseif is_objectscript_routime(bufnr) then + return 'objectscript_routine' + else + return 'hex' + end +end + --- Innovation Data Processing --- (refactor of filetype.vim since the patterns are case-insensitive) --- @type vim.filetype.mapfn diff --git a/test/old/testdir/test_filetype.vim b/test/old/testdir/test_filetype.vim index 54178a9cfc..6dd32860fb 100644 --- a/test/old/testdir/test_filetype.vim +++ b/test/old/testdir/test_filetype.vim @@ -2765,6 +2765,12 @@ func Test_inc_file() call assert_equal('pov', &filetype) bwipe! + " ObjectScript routine + call writefile(['ROUTINE Sample [Type=INC]'], 'Xfile.inc', 'D') + split Xfile.inc + call assert_equal('objectscript_routine', &filetype) + bwipe! + let g:filetype_inc = 'foo' split Xfile.inc call assert_equal('foo', &filetype) @@ -2850,6 +2856,54 @@ func Test_inc_file() filetype off endfunc +func Test_int_file() + filetype on + + " Intel HEX + call writefile([':10010000214601360121470136007EFE09D2190140'], 'Xfile.int', 'D') + split Xfile.int + call assert_equal('hex', &filetype) + bwipe! + + " ObjectScript routine + call writefile(['ROUTINE Sample [Type=INT]'], 'Xfile.int', 'D') + split Xfile.int + call assert_equal('objectscript_routine', &filetype) + bwipe! + + let g:filetype_int = 'foo' + split Xfile.int + call assert_equal('foo', &filetype) + bwipe! + unlet g:filetype_int + + filetype off +endfunc + +func Test_mac_file() + filetype on + + " Assembly + call writefile(['looks like asm'], 'Xfile.mac', 'D') + split Xfile.mac + call assert_equal('asm', &filetype) + bwipe! + + " ObjectScript routine + call writefile(['ROUTINE Sample [Type=MAC]'], 'Xfile.mac', 'D') + split Xfile.mac + call assert_equal('objectscript_routine', &filetype) + bwipe! + + let g:filetype_mac = 'foo' + split Xfile.mac + call assert_equal('foo', &filetype) + bwipe! + unlet g:filetype_mac + + filetype off +endfunc + func Test_ll_file() filetype on