patch 9.0.0349: filetype of *.sil files not well detected
Problem: Filetype of *.sil files not well detected.
Solution: Inspect the file contents to guess the filetype.
diff --git a/runtime/autoload/dist/ft.vim b/runtime/autoload/dist/ft.vim
index 5db68d3..48eaf3f 100644
--- a/runtime/autoload/dist/ft.vim
+++ b/runtime/autoload/dist/ft.vim
@@ -878,6 +878,23 @@
endif
enddef
+# This function checks the first 100 lines of files matching "*.sil" to
+# resolve detection between Swift Intermediate Language and SILE.
+export def FTsil()
+ for lnum in range(1, [line('$'), 100]->min())
+ var line: string = getline(lnum)
+ if line =~ '^\s*[\\%]'
+ setf sile
+ return
+ elseif line =~ '^\s*\S'
+ setf sil
+ return
+ endif
+ endfor
+ # no clue, default to "sil"
+ setf sil
+enddef
+
export def FTsys()
if exists("g:filetype_sys")
exe "setf " .. g:filetype_sys
diff --git a/runtime/filetype.vim b/runtime/filetype.vim
index c2b89a5..c7670d0 100644
--- a/runtime/filetype.vim
+++ b/runtime/filetype.vim
@@ -1822,7 +1822,7 @@
au BufNewFile,BufRead *.st setf st
" Smalltalk (and Rexx, TeX, and Visual Basic)
-au BufNewFile,BufRead *.cls call dist#ft#FTcls()
+au BufNewFile,BufRead *.cls call dist#ft#FTcls()
" Smarty templates
au BufNewFile,BufRead *.tpl setf smarty
@@ -1929,8 +1929,8 @@
au BufNewFile,BufRead *.swift setf swift
au BufNewFile,BufRead *.swift.gyb setf swiftgyb
-" Swift Intermediate Language
-au BufNewFile,BufRead *.sil setf sil
+" Swift Intermediate Language or SILE
+au BufNewFile,BufRead *.sil call dist#ft#FTsil()
" Sysctl
au BufNewFile,BufRead */etc/sysctl.conf,*/etc/sysctl.d/*.conf setf sysctl