mirror of
				https://github.com/neovim/neovim.git
				synced 2025-11-04 01:34:25 +00:00 
			
		
		
		
	vim-patch:9.0.0349: filetype of *.sil files not well detected (#20050)
Problem:    Filetype of *.sil files not well detected.
Solution:   Inspect the file contents to guess the filetype.
be807d5824
			
			
This commit is contained in:
		
				
					committed by
					
						
						GitHub
					
				
			
			
				
	
			
			
			
						parent
						
							12fe197cff
						
					
				
				
					commit
					ce80b8f50d
				
			
							
								
								
									
										17
									
								
								runtime/autoload/dist/ft.vim
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										17
									
								
								runtime/autoload/dist/ft.vim
									
									
									
									
										vendored
									
									
								
							@@ -877,6 +877,23 @@ func dist#ft#FTsig()
 | 
			
		||||
  endif
 | 
			
		||||
endfunc
 | 
			
		||||
 | 
			
		||||
" This function checks the first 100 lines of files matching "*.sil" to
 | 
			
		||||
" resolve detection between Swift Intermediate Language and SILE.
 | 
			
		||||
func dist#ft#FTsil()
 | 
			
		||||
  for lnum in range(1, [line('$'), 100]->min())
 | 
			
		||||
    let line = getline(lnum)
 | 
			
		||||
    if line =~ '^\s*[\\%]'
 | 
			
		||||
      setf sile
 | 
			
		||||
      return
 | 
			
		||||
    elseif line =~ '^\s*\S'
 | 
			
		||||
      setf sil
 | 
			
		||||
      return
 | 
			
		||||
    endif
 | 
			
		||||
  endfor
 | 
			
		||||
  " no clue, default to "sil"
 | 
			
		||||
  setf sil
 | 
			
		||||
endfunc
 | 
			
		||||
 | 
			
		||||
func dist#ft#FTsys()
 | 
			
		||||
  if exists("g:filetype_sys")
 | 
			
		||||
    exe "setf " .. g:filetype_sys
 | 
			
		||||
 
 | 
			
		||||
@@ -1930,8 +1930,8 @@ au BufNewFile,BufRead *.cm			setf voscm
 | 
			
		||||
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
 | 
			
		||||
 
 | 
			
		||||
@@ -902,7 +902,9 @@ local extension = {
 | 
			
		||||
  sig = function(path, bufnr)
 | 
			
		||||
    return require('vim.filetype.detect').sig(bufnr)
 | 
			
		||||
  end,
 | 
			
		||||
  sil = 'sil',
 | 
			
		||||
  sil = function(path, bufnr)
 | 
			
		||||
    return require('vim.filetype.detect').sil(bufnr)
 | 
			
		||||
  end,
 | 
			
		||||
  sim = 'simula',
 | 
			
		||||
  ['s85'] = 'sinda',
 | 
			
		||||
  sin = 'sinda',
 | 
			
		||||
 
 | 
			
		||||
@@ -1194,6 +1194,19 @@ function M.shell(path, contents, name)
 | 
			
		||||
  return name
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
-- Swift Intermediate Language or SILE
 | 
			
		||||
function M.sil(bufnr)
 | 
			
		||||
  for _, line in ipairs(getlines(bufnr, 1, 100)) do
 | 
			
		||||
    if line:find('^%s*[\\%%]') then
 | 
			
		||||
      return 'sile'
 | 
			
		||||
    elseif line:find('^%s*%S') then
 | 
			
		||||
      return 'sil'
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
  -- No clue, default to "sil"
 | 
			
		||||
  return 'sil'
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
-- SMIL or SNMP MIB file
 | 
			
		||||
function M.smi(bufnr)
 | 
			
		||||
  local line = getlines(bufnr, 1)
 | 
			
		||||
 
 | 
			
		||||
@@ -1824,6 +1824,44 @@ func Test_sig_file()
 | 
			
		||||
  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
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user