aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2024-06-20 17:45:41 +0800
committerGitHub <noreply@github.com>2024-06-20 17:45:41 +0800
commitaf0021f990bfd9681e8889ef217d26a89fadf5f0 (patch)
tree3d77149629ab08190c69eaa09317bde50733ffa3
parentac6f0c02cf31a5e6a426db0b4044c4a5d86f67a1 (diff)
downloadrneovim-af0021f990bfd9681e8889ef217d26a89fadf5f0.tar.gz
rneovim-af0021f990bfd9681e8889ef217d26a89fadf5f0.tar.bz2
rneovim-af0021f990bfd9681e8889ef217d26a89fadf5f0.zip
vim-patch:9.1.0505: filetype: Faust files are not recognized (#29426)
Problem: filetype: Faust files are not recognized Solution: Detect '*.lib' files as Faust filetype, add detection for '*.dsp' files (Faust or Make), remove '*.lib' from Cobol filetype (PowerUser64) closes: vim/vim#14894 https://github.com/vim/vim/commit/aa61b8a9087e9cd999ef07e0d87b60f43d68f2c6 Co-authored-by: PowerUser64 <blake@blakenorth.net>
-rw-r--r--runtime/doc/filetype.txt1
-rw-r--r--runtime/lua/vim/filetype.lua4
-rw-r--r--runtime/lua/vim/filetype/detect.lua35
-rw-r--r--test/old/testdir/test_filetype.vim31
4 files changed, 67 insertions, 4 deletions
diff --git a/runtime/doc/filetype.txt b/runtime/doc/filetype.txt
index eddf14014a..70bbd02790 100644
--- a/runtime/doc/filetype.txt
+++ b/runtime/doc/filetype.txt
@@ -147,6 +147,7 @@ variables can be used to overrule the filetype used for certain extensions:
`*.csh` g:filetype_csh |ft-csh-syntax|
`*.dat` g:filetype_dat
`*.def` g:filetype_def
+ `*.dsp` g:filetype_dsp
`*.f` g:filetype_f |ft-forth-syntax|
`*.frm` g:filetype_frm |ft-form-syntax|
`*.fs` g:filetype_fs |ft-forth-syntax|
diff --git a/runtime/lua/vim/filetype.lua b/runtime/lua/vim/filetype.lua
index 2bb50d8c0b..7373c403b5 100644
--- a/runtime/lua/vim/filetype.lua
+++ b/runtime/lua/vim/filetype.lua
@@ -281,7 +281,6 @@ local extension = {
cook = 'cook',
cmake = 'cmake',
cmod = 'cmod',
- lib = 'cobol',
cob = 'cobol',
cbl = 'cobol',
atg = 'coco',
@@ -366,6 +365,7 @@ local extension = {
gv = 'dot',
drac = 'dracula',
drc = 'dracula',
+ dsp = detect.dsp,
dtd = 'dtd',
d = detect.dtrace,
dts = 'dts',
@@ -417,6 +417,7 @@ local extension = {
fal = 'falcon',
fan = 'fan',
fwt = 'fan',
+ lib = 'faust',
fnl = 'fennel',
m4gl = 'fgl',
['4gl'] = 'fgl',
@@ -666,7 +667,6 @@ local extension = {
eml = 'mail',
mk = 'make',
mak = 'make',
- dsp = 'make',
page = 'mallard',
map = 'map',
mws = 'maple',
diff --git a/runtime/lua/vim/filetype/detect.lua b/runtime/lua/vim/filetype/detect.lua
index 997b53ba4b..b52dba7388 100644
--- a/runtime/lua/vim/filetype/detect.lua
+++ b/runtime/lua/vim/filetype/detect.lua
@@ -472,6 +472,41 @@ function M.def(_, bufnr)
end
--- @type vim.filetype.mapfn
+function M.dsp(path, bufnr)
+ if vim.g.filetype_dsp then
+ return vim.g.filetype_dsp
+ end
+
+ -- Test the filename
+ local file_name = fn.fnamemodify(path, ':t')
+ if file_name:find('^[mM]akefile.*$') then
+ return 'make'
+ end
+
+ -- Test the file contents
+ for _, line in ipairs(getlines(bufnr, 1, 200)) do
+ if
+ findany(line, {
+ -- Check for comment style
+ [[#.*]],
+ -- Check for common lines
+ [[^.*Microsoft Developer Studio Project File.*$]],
+ [[^!MESSAGE This is not a valid makefile\..+$]],
+ -- Check for keywords
+ [[^!(IF,ELSEIF,ENDIF).*$]],
+ -- Check for common assignments
+ [[^SOURCE=.*$]],
+ })
+ then
+ return 'make'
+ end
+ end
+
+ -- Otherwise, assume we have a Faust file
+ return 'faust'
+end
+
+--- @type vim.filetype.mapfn
function M.e(_, bufnr)
if vim.g.filetype_euphoria then
return vim.g.filetype_euphoria
diff --git a/test/old/testdir/test_filetype.vim b/test/old/testdir/test_filetype.vim
index ec9d88d3bf..5d9e5a8a27 100644
--- a/test/old/testdir/test_filetype.vim
+++ b/test/old/testdir/test_filetype.vim
@@ -161,7 +161,7 @@ func s:GetFilenameChecks() abort
\ 'cmakecache': ['CMakeCache.txt'],
\ 'cmod': ['file.cmod'],
\ 'cmusrc': ['any/.cmus/autosave', 'any/.cmus/rc', 'any/.cmus/command-history', 'any/.cmus/file.theme', 'any/cmus/rc', 'any/cmus/file.theme', '/.cmus/autosave', '/.cmus/command-history', '/.cmus/file.theme', '/.cmus/rc', '/cmus/file.theme', '/cmus/rc'],
- \ 'cobol': ['file.cbl', 'file.cob', 'file.lib'],
+ \ 'cobol': ['file.cbl', 'file.cob'],
\ 'coco': ['file.atg'],
\ 'conaryrecipe': ['file.recipe'],
\ 'conf': ['auto.master', 'file.conf', 'texdoc.cnf', '.x11vncrc', '.chktexrc', '.ripgreprc', 'ripgreprc', 'file.ctags', '.mbsyncrc'],
@@ -257,6 +257,7 @@ func s:GetFilenameChecks() abort
\ 'factor': ['file.factor'],
\ 'falcon': ['file.fal'],
\ 'fan': ['file.fan', 'file.fwt'],
+ \ 'faust': ['file.dsp', 'file.lib'],
\ 'fennel': ['file.fnl'],
\ 'fetchmail': ['.fetchmailrc'],
\ 'fgl': ['file.4gl', 'file.4gh', 'file.m4gl'],
@@ -421,7 +422,7 @@ func s:GetFilenameChecks() abort
\ 'mail': ['snd.123', '.letter', '.letter.123', '.followup', '.article', '.article.123', 'pico.123', 'mutt-xx-xxx', 'muttng-xx-xxx', 'ae123.txt', 'file.eml', 'reportbug-file'],
\ 'mailaliases': ['/etc/mail/aliases', '/etc/aliases', 'any/etc/aliases', 'any/etc/mail/aliases'],
\ 'mailcap': ['.mailcap', 'mailcap'],
- \ 'make': ['file.mk', 'file.mak', 'file.dsp', 'makefile', 'Makefile', 'makefile-file', 'Makefile-file', 'some-makefile', 'some-Makefile', 'Kbuild'],
+ \ 'make': ['file.mk', 'file.mak', 'makefile', 'Makefile', 'makefile-file', 'Makefile-file', 'some-makefile', 'some-Makefile', 'Kbuild'],
\ 'mallard': ['file.page'],
"\ 'man': ['file.man'],
\ 'manconf': ['/etc/man.conf', 'man.config', 'any/etc/man.conf'],
@@ -2399,6 +2400,32 @@ func Test_typ_file()
filetype off
endfunc
+func Test_dsp_file()
+ filetype on
+
+ " Microsoft Developer Studio Project file
+
+ call writefile(['# Microsoft Developer Studio Project File'], 'Xfile.dsp', 'D')
+ split Xfile.dsp
+ call assert_equal('make', &filetype)
+ bwipe!
+
+ let g:filetype_dsp = 'make'
+ split test.dsp
+ call assert_equal('make', &filetype)
+ bwipe!
+ unlet g:filetype_dsp
+
+ " Faust
+
+ call writefile(['this is a fallback'], 'Xfile.dsp')
+ split Xfile.dsp
+ call assert_equal('faust', &filetype)
+ bwipe!
+
+ filetype off
+endfunc
+
func Test_vba_file()
filetype on