]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.0505: filetype: Faust files are not recognized v9.1.0505
authorPowerUser64 <blake@blakenorth.net>
Wed, 19 Jun 2024 18:32:11 +0000 (20:32 +0200)
committerChristian Brabandt <cb@256bit.org>
Wed, 19 Jun 2024 18:32:11 +0000 (20:32 +0200)
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: #14894

Signed-off-by: PowerUser64 <blake@blakenorth.net>
Signed-off-by: Christian Brabandt <cb@256bit.org>
runtime/autoload/dist/ft.vim
runtime/doc/filetype.txt
runtime/filetype.vim
src/testdir/test_filetype.vim
src/version.c

index 50b4c3ef2102af17f58e7c9c6a904bcd33753081..2e93dd0d579992e8292f87332259e5922c62cf2f 100644 (file)
@@ -1265,6 +1265,56 @@ export def FTtyp()
   setf typst
 enddef
 
+# Detect Microsoft Developer Studio Project files (Makefile) or Faust DSP
+# files.
+export def FTdsp()
+  if exists("g:filetype_dsp")
+    exe "setf " .. g:filetype_dsp
+    return
+  endif
+
+  # Test the filename
+  if expand('%:t') =~ '^[mM]akefile.*$'
+    setf make
+    return
+  endif
+
+  # Test the file contents
+  for line in getline(1, 200)
+    # Chech for comment style
+    if line =~ '^#.*'
+      setf make
+      return
+    endif
+
+    # Check for common lines
+    if line =~ '^.*Microsoft Developer Studio Project File.*$'
+      setf make
+      return
+    endif
+
+    if line =~ '^!MESSAGE This is not a valid makefile\..+$'
+      setf make
+      return
+    endif
+
+    # Check for keywords
+    if line =~ '^!(IF,ELSEIF,ENDIF).*$'
+      setf make
+      return
+    endif
+
+    # Check for common assignments
+    if line =~ '^SOURCE=.*$'
+      setf make
+      return
+    endif
+  endfor
+
+  # Otherwise, assume we have a Faust file
+  setf faust
+enddef
+
 # Set the filetype of a *.v file to Verilog, V or Cog based on the first 200
 # lines.
 export def FTv()
index 927b75c3a814270408b5173f2c3d2ceb7d8d409d..910731aff3ff4756bf3c96c459d983e642573e84 100644 (file)
@@ -149,6 +149,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|
index a2daf144c71ba788accc1296e35d8e682d081dc9..54bce30e2068af15f702d1c3be99575962e80a98 100644 (file)
@@ -457,7 +457,7 @@ au BufNewFile,BufRead */.cmus/{autosave,rc,command-history,*.theme} setf cmusrc
 au BufNewFile,BufRead */cmus/{rc,*.theme}                      setf cmusrc
 
 " Cobol
-au BufNewFile,BufRead *.cbl,*.cob,*.lib        setf cobol
+au BufNewFile,BufRead *.cbl,*.cob      setf cobol
 "   cobol or zope form controller python script? (heuristic)
 au BufNewFile,BufRead *.cpy
        \ if getline(1) =~ '^##' |
@@ -532,6 +532,10 @@ au BufNewFile,BufRead s6-*                              setf execline
 " Fontconfig config files
 au BufNewFile,BufRead fonts.conf                       setf xml
 
+" Faust
+au BufNewFile,BufRead *.lib                            setf faust
+au BufNewFile,BufRead *.dsp                            call dist#ft#FTdsp()
+
 " Libreoffice config files
 au BufNewFile,BufRead *.xcu,*.xlb,*.xlc,*.xba          setf xml
 au BufNewFile,BufRead psprint.conf,sofficerc           setf dosini
@@ -1365,8 +1369,8 @@ au BufNewFile,BufRead */etc/mail/aliases,*/etc/aliases    setf mailaliases
 au BufNewFile,BufRead .mailcap,mailcap         setf mailcap
 
 " Makefile
-au BufNewFile,BufRead *[mM]akefile,*.mk,*.mak,*.dsp setf make
-au BufNewFile,BufRead Kbuild setf make
+au BufNewFile,BufRead *[mM]akefile,*.mk,*.mak  setf make
+au BufNewFile,BufRead Kbuild                   setf make
 
 " MakeIndex
 au BufNewFile,BufRead *.ist,*.mst              setf ist
index d0a078f73253e0ca4e9cb5fc6f0d9459a9f77816..5aec6fba2612870347fd1645348561a5699d95c2 100644 (file)
@@ -160,7 +160,7 @@ def s:GetFilenameChecks(): dict<list<string>>
     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'],
@@ -256,6 +256,7 @@ def s:GetFilenameChecks(): dict<list<string>>
     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'],
@@ -420,7 +421,7 @@ def s:GetFilenameChecks(): dict<list<string>>
     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'],
@@ -2401,6 +2402,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
 
index 0d8b57d7f13e93e1f1811e372bdf6be6d6e5d098..44d0214750df4197df777545be77fd6c828ee32f 100644 (file)
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    505,
 /**/
     504,
 /**/