diff --git a/runtime/ftplugin/llvm.vim b/runtime/ftplugin/llvm.vim new file mode 100644 index 0000000000..148b12f102 --- /dev/null +++ b/runtime/ftplugin/llvm.vim @@ -0,0 +1,12 @@ +" Vim filetype plugin file +" Language: LLVM IR +" Last Change: 2024 Oct 22 +" Maintainer: Wu, Zhenyu + +if exists("b:did_ftplugin") | finish | endif +let b:did_ftplugin = 1 + +setl comments=:; +setl commentstring=;\ %s + +let b:undo_ftplugin = "setl commentstring< comments<" diff --git a/runtime/lua/vim/filetype.lua b/runtime/lua/vim/filetype.lua index f22d814647..3b3c4481f2 100644 --- a/runtime/lua/vim/filetype.lua +++ b/runtime/lua/vim/filetype.lua @@ -682,7 +682,6 @@ local extension = { l = 'lex', lhs = 'lhaskell', lidr = 'lidris2', - ll = 'lifelines', ly = 'lilypond', ily = 'lilypond', liquid = 'liquid', @@ -697,6 +696,7 @@ local extension = { lt = 'lite', lite = 'lite', livemd = 'livebook', + ll = detect.ll, log = detect.log, Log = detect.log, LOG = detect.log, diff --git a/runtime/lua/vim/filetype/detect.lua b/runtime/lua/vim/filetype/detect.lua index 1b9e28efad..98b001bd51 100644 --- a/runtime/lua/vim/filetype/detect.lua +++ b/runtime/lua/vim/filetype/detect.lua @@ -868,6 +868,16 @@ function M.log(path, _) end end +--- @type vim.filetype.mapfn +function M.ll(_, bufnr) + local first_line = getline(bufnr, 1) + if matchregex(first_line, [[;\|\\|\]]) then + return 'llvm' + else + return 'lifelines' + end +end + --- @type vim.filetype.mapfn function M.lpc(_, bufnr) if vim.g.lpc_syntax_for_c then diff --git a/test/old/testdir/test_filetype.vim b/test/old/testdir/test_filetype.vim index 62053f1c2c..f70144b379 100644 --- a/test/old/testdir/test_filetype.vim +++ b/test/old/testdir/test_filetype.vim @@ -2440,6 +2440,24 @@ func Test_inc_file() filetype off endfunc +func Test_ll_file() + filetype on + + " LLVM IR + call writefile(['target triple = "nvptx64-nvidia-cuda"'], 'Xfile.ll', 'D') + split Xfile.ll + call assert_equal('llvm', &filetype) + bwipe! + + " lifelines + call writefile(['proc main() {}'], 'Xfile.ll', 'D') + split Xfile.ll + call assert_equal('lifelines', &filetype) + bwipe! + + filetype off +endfunc + func Test_lsl_file() filetype on