mirror of
https://github.com/neovim/neovim.git
synced 2026-07-12 12:29:44 +00:00
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
25f6539645
Co-authored-by: Hannah Kimura <hannah.kimura@intersystems.com>
This commit is contained in:
@@ -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|
|
`*.h` g:c_syntax_for_h |ft-c-syntax|
|
||||||
`*.i` g:filetype_i |ft-progress-syntax|
|
`*.i` g:filetype_i |ft-progress-syntax|
|
||||||
`*.inc` g:filetype_inc
|
`*.inc` g:filetype_inc
|
||||||
|
`*.int` g:filetype_int
|
||||||
`*.lsl` g:filetype_lsl
|
`*.lsl` g:filetype_lsl
|
||||||
`*.m` g:filetype_m |ft-mathematica-syntax|
|
`*.m` g:filetype_m |ft-mathematica-syntax|
|
||||||
|
`*.mac` g:filetype_mac
|
||||||
`*[mM]makefile,*.mk,*.mak,[mM]akefile*`
|
`*[mM]makefile,*.mk,*.mak,[mM]akefile*`
|
||||||
g:make_flavor |ft-make-syntax|
|
g:make_flavor |ft-make-syntax|
|
||||||
`*.markdown,*.mdown,*.mkd,*.mkdn,*.mdwn,*.md`
|
`*.markdown,*.mdown,*.mkd,*.mkdn,*.mdwn,*.md`
|
||||||
|
|||||||
@@ -233,7 +233,6 @@ local extension = {
|
|||||||
a = detect.asm,
|
a = detect.asm,
|
||||||
A = detect.asm,
|
A = detect.asm,
|
||||||
lst = detect.asm,
|
lst = detect.asm,
|
||||||
mac = detect.asm,
|
|
||||||
asn1 = 'asn',
|
asn1 = 'asn',
|
||||||
asn = 'asn',
|
asn = 'asn',
|
||||||
asp = detect.asp,
|
asp = detect.asp,
|
||||||
@@ -598,7 +597,6 @@ local extension = {
|
|||||||
ihex = 'hex',
|
ihex = 'hex',
|
||||||
ihe = 'hex',
|
ihe = 'hex',
|
||||||
ihx = 'hex',
|
ihx = 'hex',
|
||||||
int = 'hex',
|
|
||||||
mcs = 'hex',
|
mcs = 'hex',
|
||||||
hjson = 'hjson',
|
hjson = 'hjson',
|
||||||
m3u = 'hlsplaylist',
|
m3u = 'hlsplaylist',
|
||||||
@@ -633,6 +631,7 @@ local extension = {
|
|||||||
ii = 'initng',
|
ii = 'initng',
|
||||||
inko = 'inko',
|
inko = 'inko',
|
||||||
inp = detect.inp,
|
inp = detect.inp,
|
||||||
|
int = detect.int,
|
||||||
ms = detect_seq(detect.nroff, 'xmath'),
|
ms = detect_seq(detect.nroff, 'xmath'),
|
||||||
ipkg = 'ipkg',
|
ipkg = 'ipkg',
|
||||||
iss = 'iss',
|
iss = 'iss',
|
||||||
@@ -764,6 +763,7 @@ local extension = {
|
|||||||
mc = detect.mc,
|
mc = detect.mc,
|
||||||
quake = 'm3quake',
|
quake = 'm3quake',
|
||||||
m4 = detect.m4,
|
m4 = detect.m4,
|
||||||
|
mac = detect.mac,
|
||||||
eml = 'mail',
|
eml = 'mail',
|
||||||
mk = detect.make,
|
mk = detect.make,
|
||||||
mak = detect.make,
|
mak = detect.make,
|
||||||
|
|||||||
@@ -63,6 +63,14 @@ function M.app(path, bufnr)
|
|||||||
end
|
end
|
||||||
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
|
-- This function checks for the kind of assembly that is wanted by the user, or
|
||||||
-- can be detected from the beginning of the file.
|
-- can be detected from the beginning of the file.
|
||||||
--- @type vim.filetype.mapfn
|
--- @type vim.filetype.mapfn
|
||||||
@@ -85,6 +93,17 @@ function M.asm(path, bufnr)
|
|||||||
end
|
end
|
||||||
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.
|
-- Checks the first lines for a asmsyntax=foo override.
|
||||||
-- Only whitespace characters can be present immediately before or after this statement.
|
-- Only whitespace characters can be present immediately before or after this statement.
|
||||||
--- @type vim.filetype.mapfn
|
--- @type vim.filetype.mapfn
|
||||||
@@ -896,6 +915,9 @@ function M.inc(path, bufnr)
|
|||||||
if vim.g.filetype_inc then
|
if vim.g.filetype_inc then
|
||||||
return vim.g.filetype_inc
|
return vim.g.filetype_inc
|
||||||
end
|
end
|
||||||
|
if is_objectscript_routime(bufnr) then
|
||||||
|
return 'objectscript_routine'
|
||||||
|
end
|
||||||
for _, line in ipairs(getlines(bufnr, 1, 20)) do
|
for _, line in ipairs(getlines(bufnr, 1, 20)) do
|
||||||
if line:lower():find('perlscript') then
|
if line:lower():find('perlscript') then
|
||||||
return 'aspperl'
|
return 'aspperl'
|
||||||
@@ -945,6 +967,17 @@ function M.install(path, bufnr)
|
|||||||
return M.bash(path, bufnr)
|
return M.bash(path, bufnr)
|
||||||
end
|
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
|
--- Innovation Data Processing
|
||||||
--- (refactor of filetype.vim since the patterns are case-insensitive)
|
--- (refactor of filetype.vim since the patterns are case-insensitive)
|
||||||
--- @type vim.filetype.mapfn
|
--- @type vim.filetype.mapfn
|
||||||
|
|||||||
@@ -2765,6 +2765,12 @@ func Test_inc_file()
|
|||||||
call assert_equal('pov', &filetype)
|
call assert_equal('pov', &filetype)
|
||||||
bwipe!
|
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'
|
let g:filetype_inc = 'foo'
|
||||||
split Xfile.inc
|
split Xfile.inc
|
||||||
call assert_equal('foo', &filetype)
|
call assert_equal('foo', &filetype)
|
||||||
@@ -2850,6 +2856,54 @@ func Test_inc_file()
|
|||||||
filetype off
|
filetype off
|
||||||
endfunc
|
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()
|
func Test_ll_file()
|
||||||
filetype on
|
filetype on
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user