diff options
-rw-r--r-- | runtime/lua/vim/filetype/detect.lua | 12 | ||||
-rw-r--r-- | test/old/testdir/test_filetype.vim | 19 |
2 files changed, 27 insertions, 4 deletions
diff --git a/runtime/lua/vim/filetype/detect.lua b/runtime/lua/vim/filetype/detect.lua index 0609ac5513..934b02dcdd 100644 --- a/runtime/lua/vim/filetype/detect.lua +++ b/runtime/lua/vim/filetype/detect.lua @@ -194,13 +194,18 @@ function M.cls(_, bufnr) return vim.g.filetype_cls end local line1 = getline(bufnr, 1) - if line1:find('^[%%\\]') then - return 'tex' - elseif line1:find('^#') and line1:lower():find('rexx') then + if matchregex(line1, [[^#!.*\<\%(rexx\|regina\)\>]]) then return 'rexx' elseif line1 == 'VERSION 1.0 CLASS' then return 'vb' end + + local nonblank1 = nextnonblank(bufnr, 1) + if nonblank1 and nonblank1:find('^[%%\\]') then + return 'tex' + elseif nonblank1 and findany(nonblank1, { '^%s*/%*', '^%s*::%w' }) then + return 'rexx' + end return 'st' end @@ -1648,6 +1653,7 @@ local patterns_hashbang = { guile = 'scheme', ['nix%-shell'] = 'nix', ['crystal\\>'] = { 'crystal', { vim_regex = true } }, + ['^\\%(rexx\\|regina\\)\\>'] = { 'rexx', { vim_regex = true } }, } ---@private diff --git a/test/old/testdir/test_filetype.vim b/test/old/testdir/test_filetype.vim index 5d6b306d09..1dd255ccf9 100644 --- a/test/old/testdir/test_filetype.vim +++ b/test/old/testdir/test_filetype.vim @@ -856,6 +856,8 @@ let s:script_checks = { \ 'forth': [['#!/path/gforth']], \ 'icon': [['#!/path/icon']], \ 'crystal': [['#!/path/crystal']], + \ 'rexx': [['#!/path/rexx'], + \ ['#!/path/regina']], \ } " Various forms of "env" optional arguments. @@ -1953,7 +1955,22 @@ func Test_cls_file() " Rexx - call writefile(['# rexx'], 'Xfile.cls') + call writefile(['#!/usr/bin/rexx'], 'Xfile.cls') + split Xfile.cls + call assert_equal('rexx', &filetype) + bwipe! + + call writefile(['#!/usr/bin/regina'], 'Xfile.cls') + split Xfile.cls + call assert_equal('rexx', &filetype) + bwipe! + + call writefile(['/* Comment */'], 'Xfile.cls') + split Xfile.cls + call assert_equal('rexx', &filetype) + bwipe! + + call writefile(['::class Foo subclass Bar public'], 'Xfile.cls') split Xfile.cls call assert_equal('rexx', &filetype) bwipe! |