vim-patch:8.2.4464: Dtrace files are recognized as filetype D (#17518)

Problem:    Dtrace files are recognized as filetype D.
Solution:   Add a pattern for Dtrace files. (Teubel György, closes vim/vim#9841)
            Add some more testing.
4d56b971cb
This commit is contained in:
Christian Clason 2022-02-26 14:01:37 +01:00 committed by GitHub
parent 2703cf95dd
commit d0f8f76224
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 44 additions and 0 deletions

View File

@ -211,6 +211,10 @@ func dist#ft#EuphoriaCheck()
endfunc endfunc
func dist#ft#DtraceCheck() func dist#ft#DtraceCheck()
if did_filetype()
" Filetype was already detected
return
endif
let lines = getline(1, min([line("$"), 100])) let lines = getline(1, min([line("$"), 100]))
if match(lines, '^module\>\|^import\>') > -1 if match(lines, '^module\>\|^import\>') > -1
" D files often start with a module and/or import statement. " D files often start with a module and/or import statement.

View File

@ -480,6 +480,7 @@ au BufNewFile,BufRead */etc/dnsmasq.conf setf dnsmasq
au BufNewFile,BufRead *.desc setf desc au BufNewFile,BufRead *.desc setf desc
" the D language or dtrace " the D language or dtrace
au BufNewFile,BufRead */dtrace/*.d setf dtrace
au BufNewFile,BufRead *.d call dist#ft#DtraceCheck() au BufNewFile,BufRead *.d call dist#ft#DtraceCheck()
" Desktop files " Desktop files

View File

@ -1178,6 +1178,7 @@ local pattern = {
[".*/etc/yum%.conf"] = "dosini", [".*/etc/yum%.conf"] = "dosini",
[".*lvs"] = "dracula", [".*lvs"] = "dracula",
[".*lpe"] = "dracula", [".*lpe"] = "dracula",
[".*/dtrace/.*%.d"] = "dtrace",
[".*esmtprc"] = "esmtprc", [".*esmtprc"] = "esmtprc",
[".*Eterm/.*%.cfg"] = "eterm", [".*Eterm/.*%.cfg"] = "eterm",
[".*%.git/modules/.*/config"] = "gitconfig", [".*%.git/modules/.*/config"] = "gitconfig",

View File

@ -132,6 +132,7 @@ let s:filename_checks = {
\ 'cvs': ['cvs123'], \ 'cvs': ['cvs123'],
\ 'cvsrc': ['.cvsrc'], \ 'cvsrc': ['.cvsrc'],
\ 'cynpp': ['file.cyn'], \ 'cynpp': ['file.cyn'],
\ 'd': ['file.d'],
\ 'dart': ['file.dart', 'file.drt'], \ 'dart': ['file.dart', 'file.drt'],
\ 'datascript': ['file.ds'], \ 'datascript': ['file.ds'],
\ 'dcd': ['file.dcd'], \ 'dcd': ['file.dcd'],
@ -154,6 +155,7 @@ let s:filename_checks = {
\ 'dot': ['file.dot', 'file.gv'], \ 'dot': ['file.dot', 'file.gv'],
\ 'dracula': ['file.drac', 'file.drc', 'filelvs', 'filelpe', 'drac.file', 'lpe', 'lvs', 'some-lpe', 'some-lvs'], \ 'dracula': ['file.drac', 'file.drc', 'filelvs', 'filelpe', 'drac.file', 'lpe', 'lvs', 'some-lpe', 'some-lvs'],
\ 'dtd': ['file.dtd'], \ 'dtd': ['file.dtd'],
\ 'dtrace': ['/usr/lib/dtrace/io.d'],
\ 'dts': ['file.dts', 'file.dtsi'], \ 'dts': ['file.dts', 'file.dtsi'],
\ 'dune': ['jbuild', 'dune', 'dune-project', 'dune-workspace'], \ 'dune': ['jbuild', 'dune', 'dune-project', 'dune-workspace'],
\ 'dylan': ['file.dylan'], \ 'dylan': ['file.dylan'],
@ -802,6 +804,42 @@ func Test_bas_file()
filetype off filetype off
endfunc endfunc
func Test_d_file()
filetype on
call writefile(['looks like D'], 'Xfile.d')
split Xfile.d
call assert_equal('d', &filetype)
bwipe!
call writefile(['#!/some/bin/dtrace'], 'Xfile.d')
split Xfile.d
call assert_equal('dtrace', &filetype)
bwipe!
call writefile(['#pragma D option'], 'Xfile.d')
split Xfile.d
call assert_equal('dtrace', &filetype)
bwipe!
call writefile([':some:thing:'], 'Xfile.d')
split Xfile.d
call assert_equal('dtrace', &filetype)
bwipe!
call writefile(['module this', '#pragma D option'], 'Xfile.d')
split Xfile.d
call assert_equal('d', &filetype)
bwipe!
call writefile(['import that', '#pragma D option'], 'Xfile.d')
split Xfile.d
call assert_equal('d', &filetype)
bwipe!
filetype off
endfunc
func Test_dep3patch_file() func Test_dep3patch_file()
filetype on filetype on