Patch 9.0.0349

2 views
Skip to first unread message

Bram Moolenaar

unread,
Sep 1, 2022, 10:02:10 AM9/1/22
to vim...@googlegroups.com

Patch 9.0.0349
Problem: Filetype of *.sil files not well detected.
Solution: Inspect the file contents to guess the filetype.
Files: runtime/autoload/dist/ft.vim, runtime/filetype.vim,
src/testdir/test_filetype.vim


*** ../vim-9.0.0348/runtime/autoload/dist/ft.vim 2022-07-26 21:41:28.711069937 +0100
--- runtime/autoload/dist/ft.vim 2022-09-01 14:56:43.829371045 +0100
***************
*** 348,354 ****
setf idl
enddef

! # Distinguish between "default" and Cproto prototype file. */
export def ProtoCheck(default: string)
# Cproto files have a comment in the first line and a function prototype in
# the second line, it always ends in ";". Indent files may also have
--- 348,354 ----
setf idl
enddef

! # Distinguish between "default", Prolog and Cproto prototype file.
export def ProtoCheck(default: string)
# Cproto files have a comment in the first line and a function prototype in
# the second line, it always ends in ";". Indent files may also have
***************
*** 358,364 ****
if getline(2) =~ '.;$'
setf cpp
else
! exe 'setf ' .. default
endif
enddef

--- 358,371 ----
if getline(2) =~ '.;$'
setf cpp
else
! # recognize Prolog by specific text in the first non-empty line
! # require a blank after the '%' because Perl uses "%list" and "%translate"
! var l = getline(nextnonblank(1))
! if l =~ '\<prolog\>' || l =~ '^\s*\(%\+\(\s\|$\)\|/\*\)' || l =~ ':-'
! setf prolog
! else
! exe 'setf ' .. default
! endif
endif
enddef

***************
*** 871,876 ****
--- 878,900 ----
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
*** ../vim-9.0.0348/runtime/filetype.vim 2022-08-29 15:28:49.802415298 +0100
--- runtime/filetype.vim 2022-09-01 14:57:19.057302449 +0100
***************
*** 1822,1828 ****
au BufNewFile,BufRead *.st setf st

" Smalltalk (and Rexx, TeX, and Visual Basic)
! au BufNewFile,BufRead *.cls call dist#ft#FTcls()

" Smarty templates
au BufNewFile,BufRead *.tpl setf smarty
--- 1822,1828 ----
au BufNewFile,BufRead *.st setf st

" Smalltalk (and Rexx, TeX, and Visual Basic)
! au BufNewFile,BufRead *.cls call dist#ft#FTcls()

" Smarty templates
au BufNewFile,BufRead *.tpl setf smarty
***************
*** 1929,1936 ****
au BufNewFile,BufRead *.swift setf swift
au BufNewFile,BufRead *.swift.gyb setf swiftgyb

! " Swift Intermediate Language
! au BufNewFile,BufRead *.sil setf sil

" Sysctl
au BufNewFile,BufRead */etc/sysctl.conf,*/etc/sysctl.d/*.conf setf sysctl
--- 1929,1936 ----
au BufNewFile,BufRead *.swift setf swift
au BufNewFile,BufRead *.swift.gyb setf swiftgyb

! " 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
*** ../vim-9.0.0348/src/testdir/test_filetype.vim 2022-08-29 15:28:49.802415298 +0100
--- src/testdir/test_filetype.vim 2022-09-01 14:58:03.189219753 +0100
***************
*** 1827,1832 ****
--- 1827,1870 ----
filetype off
endfunc

+ " Test dist#ft#FTsil()
+ func Test_sil_file()
+ filetype on
+
+ split Xfile.sil
+ call assert_equal('sil', &filetype)
+ bwipe!
+
+ let lines =<< trim END
+ // valid
+ let protoErasedPathA = \ABCProtocol.a
+
+ // also valid
+ let protoErasedPathA =
+ \ABCProtocol.a
+ END
+ call writefile(lines, 'Xfile.sil')
+
+ split Xfile.sil
+ call assert_equal('sil', &filetype)
+ bwipe!
+
+ " SILE
+
+ call writefile(['% some comment'], 'Xfile.sil')
+ split Xfile.sil
+ call assert_equal('sile', &filetype)
+ bwipe!
+
+ call writefile(['\begin[papersize=a6]{document}foo\end{document}'], 'Xfile.sil')
+ split Xfile.sil
+ call assert_equal('sile', &filetype)
+ bwipe!
+
+ call delete('Xfile.sil')
+ filetype off
+ endfunc
+
func Test_inc_file()
filetype on

*** ../vim-9.0.0348/src/version.c 2022-09-01 14:37:57.862658253 +0100
--- src/version.c 2022-09-01 14:58:25.953178393 +0100
***************
*** 709,710 ****
--- 709,712 ----
{ /* Add new patch number below this line */
+ /**/
+ 349,
/**/

--
Westheimer's Discovery:
A couple of months in the laboratory can
frequently save a couple of hours in the library.

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
Reply all
Reply to author
Forward
0 new messages