]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.0876: filetype: openCL files are not recognized v9.1.0876
authorWu, Zhenyu <wuzhenyu@ustc.edu>
Tue, 19 Nov 2024 19:55:25 +0000 (20:55 +0100)
committerChristian Brabandt <cb@256bit.org>
Tue, 19 Nov 2024 20:03:09 +0000 (21:03 +0100)
Problem:  filetype: openCL files are not recognized
Solution: detect '*.cl' files as opencl or lisp filetype,
          include a opencl syntax and filetype plugin (Wu, Zhenyu)

closes: #15825

Signed-off-by: Wu, Zhenyu <wuzhenyu@ustc.edu>
Signed-off-by: Christian Brabandt <cb@256bit.org>
.github/MAINTAINERS
runtime/autoload/dist/ft.vim
runtime/filetype.vim
runtime/ftplugin/opencl.vim [new file with mode: 0644]
runtime/syntax/opencl.vim [new file with mode: 0644]
src/testdir/test_filetype.vim
src/version.c

index bae6c600c068c917ccde1eac14160d30246686e0..b899db3bd388046420571613b0659d051666efc7 100644 (file)
@@ -225,6 +225,7 @@ runtime/ftplugin/nsis.vim           @k-takata
 runtime/ftplugin/nu.vim                @mrcjkb
 runtime/ftplugin/octave.vim            @dkearns
 runtime/ftplugin/ondir.vim             @jparise
+runtime/ftplugin/opencl.vim            @Freed-Wu
 runtime/ftplugin/openvpn.vim           @ObserverOfTime
 runtime/ftplugin/pascal.vim            @dkearns
 runtime/ftplugin/pbtxt.vim             @lakshayg
@@ -526,6 +527,7 @@ runtime/syntax/nix.vim                      @equill
 runtime/syntax/nroff.vim               @jmarshall
 runtime/syntax/nsis.vim                        @k-takata
 runtime/syntax/ondir.vim               @jparise
+runtime/syntax/opencl.vim              @Freed-Wu
 runtime/syntax/openvpn.vim             @ObserverOfTime
 runtime/syntax/pacmanlog.vim           @rpigott
 runtime/syntax/pascal.vim              @dkearns
index 214cf6e3ec47e97a015badb7d65a20243732b57b..0936a85ede9adfd4320ded0254ff9815fa193569 100644 (file)
@@ -144,6 +144,14 @@ export def FTcfg()
   endif
 enddef
 
+export def FTcl()
+  if join(getline(1, 4), '') =~ '/\*'
+    setf opencl
+  else
+    setf lisp
+  endif
+enddef
+
 export def FTcls()
   if exists("g:filetype_cls")
     exe "setf " .. g:filetype_cls
index f53e449964c6d7abcd4b491be3dd374720c25111..3f93bebb75a42a3fced7776b02154270ba88acd7 100644 (file)
@@ -1365,14 +1365,17 @@ au BufNewFile,BufRead lilo.conf                 setf lilo
 " Lilypond
 au BufNewFile,BufRead *.ly,*.ily               setf lilypond
 
-" Lisp (*.el = ELisp, *.cl = Common Lisp)
+" Lisp (*.el = ELisp)
 " *.jl was removed, it's also used for Julia, better skip than guess wrong.
 if has("fname_case")
-  au BufNewFile,BufRead *.lsp,*.lisp,*.asd,*.el,*.cl,*.L,.emacs,.sawfishrc,*.stsg,*/supertux2/config setf lisp
+  au BufNewFile,BufRead *.lsp,*.lisp,*.asd,*.el,*.L,.emacs,.sawfishrc,*.stsg,*/supertux2/config setf lisp
 else
-  au BufNewFile,BufRead *.lsp,*.lisp,*.asd,*.el,*.cl,.emacs,.sawfishrc,*.stsg,*/supertux2/config setf lisp
+  au BufNewFile,BufRead *.lsp,*.lisp,*.asd,*.el,.emacs,.sawfishrc,*.stsg,*/supertux2/config setf lisp
 endif
 
+" *.cl = Common Lisp or OpenCL
+au BufNewFile,BufRead *.cl call dist#ft#FTcl()
+
 " SBCL implementation of Common Lisp
 au BufNewFile,BufRead sbclrc,.sbclrc           setf lisp
 
diff --git a/runtime/ftplugin/opencl.vim b/runtime/ftplugin/opencl.vim
new file mode 100644 (file)
index 0000000..e8570fb
--- /dev/null
@@ -0,0 +1,12 @@
+" Vim filetype plugin file
+" Language:    OpenCL
+" Maintainer:  Wu, Zhenyu <wuzhenyu@ustc.edu>
+" Last Change: 2024 Nov 19
+
+if exists("b:did_ftplugin") | finish | endif
+let b:did_ftplugin = 1
+
+setlocal comments=sO:*\ -,mO:*\ \ ,exO:*/,s1:/*,mb:*,ex:*/,:///,://
+setlocal commentstring=/*\ %s\ */ define& include&
+
+let b:undo_ftplugin = "setl commentstring< comments<"
diff --git a/runtime/syntax/opencl.vim b/runtime/syntax/opencl.vim
new file mode 100644 (file)
index 0000000..c237aa3
--- /dev/null
@@ -0,0 +1,13 @@
+" Vim syntax file
+" Language:    OpenCL
+" Last Change: 2024 Nov 19
+" Maintainer:  Wu, Zhenyu <wuzhenyu@ustc.edu>
+
+if exists("b:current_syntax")
+  finish
+endif
+
+" TODO: support openCL specific keywords
+runtime! syntax/c.vim
+
+let current_syntax = "opencl"
index eab9d1e28d9123100135aa155baa2ef4435a3447..17d6a44d7c1d9256691222418e8e5609471867a2 100644 (file)
@@ -425,7 +425,7 @@ def s:GetFilenameChecks(): dict<list<string>>
     limits: ['/etc/limits', '/etc/anylimits.conf', '/etc/anylimits.d/file.conf', '/etc/limits.conf', '/etc/limits.d/file.conf', '/etc/some-limits.conf', '/etc/some-limits.d/file.conf', 'any/etc/limits', 'any/etc/limits.conf', 'any/etc/limits.d/file.conf', 'any/etc/some-limits.conf', 'any/etc/some-limits.d/file.conf'],
     liquidsoap: ['file.liq'],
     liquid: ['file.liquid'],
-    lisp: ['file.lsp', 'file.lisp', 'file.asd', 'file.el', 'file.cl', '.emacs', '.sawfishrc', 'sbclrc', '.sbclrc', 'file.stsg', 'any/local/share/supertux2/config'],
+    lisp: ['file.lsp', 'file.lisp', 'file.asd', 'file.el', '.emacs', '.sawfishrc', 'sbclrc', '.sbclrc', 'file.stsg', 'any/local/share/supertux2/config'],
     lite: ['file.lite', 'file.lt'],
     litestep: ['/LiteStep/any/file.rc', 'any/LiteStep/any/file.rc'],
     logcheck: ['/etc/logcheck/file.d-some/file', '/etc/logcheck/file.d/file', 'any/etc/logcheck/file.d-some/file', 'any/etc/logcheck/file.d/file'],
@@ -1198,6 +1198,22 @@ func Test_cfg_file()
   filetype off
 endfunc
 
+func Test_cl_file()
+  filetype on
+
+  call writefile(['/*', ' * Xfile.cl', ' */', 'int f() {}'], 'Xfile.cl')
+  split Xfile.cl
+  call assert_equal('opencl', &filetype)
+  bwipe!
+
+  call writefile(['()'], 'Xfile.cl')
+  split Xfile.cl
+  call assert_equal('lisp', &filetype)
+  bwipe!
+
+  filetype off
+endfunc
+
 func Test_d_file()
   filetype on
 
index ed841229f8561315c2c7c7c2808bd3cbf19702b1..99fbbe8345d3d3ba7d36df5bd843da4744f8ecee 100644 (file)
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    876,
 /**/
     875,
 /**/