vim9script
# Vim functions for file type detection
#
# Maintainer: The Vim Project <https://github.com/vim/vim>
# Last Change: 2024 Feb 18
# Former Maintainer: Bram Moolenaar <Bram@vim.org>
# These functions are moved here from runtime/filetype.vim to make startup
# faster.
export def Check_inp()
if getline(1) =~ '%%'
setf tex
elseif getline(1) =~ '^\*'
setf abaqus
else
var n = 1
var nmax = line("$") > 500 ? 500 : line("$")
while n <= nmax
if getline(n) =~? "^header surface data"
setf trasys
break
endif
n += 1
endwhile
endif
enddef
# This function checks for the kind of assembly that is wanted by the user, or
# can be detected from the first five lines of the file.
export def FTasm()
# make sure b:asmsyntax exists
if !exists("b:asmsyntax")
b:asmsyntax = ""
endif
if b:asmsyntax == ""
FTasmsyntax()
endif
# if b:asmsyntax still isn't set, default to asmsyntax or GNU
if b:asmsyntax == ""
if exists("g:asmsyntax")
b:asmsyntax = g:asmsyntax
else
b:asmsyntax = "asm"
endif
endif
exe "setf " .. fnameescape(b:asmsyntax)
enddef
export def FTasmsyntax()
# see if the file contains any asmsyntax=foo overrides. If so, change
# b:asmsyntax appropriately
var head = " " .. getline(1) .. " " .. getline(2) .. " "
.. getline(3) .. " " .. getline(4) .. " " .. getline(5) .. " "
var match = matchstr(head, '\sasmsyntax=\zs[a-zA-Z0-9]\+\ze\s')
if match != ''
b:asmsyntax = match
elseif ((head =~? '\.title') || (head =~? '\.ident') || (head =~? '\.macro') || (head =~? '\.subtitle') || (head =~? '\.library'))
b:asmsyntax = "vmasm"
endif
enddef
var ft_visual_basic_content = '\c^\s*\%(Attribute\s\+VB_Name\|Begin\s\+\%(VB\.\|{\%(\x\+-\)\+\x\+}\)\)'
# See FTfrm() for Visual Basic form file detection
export def FTbas()
if exists("g:filetype_bas")
exe "setf " .. g:filetype_bas
return
endif
# most frequent FreeBASIC-specific keywords in distro files
var fb_keywords = '\c^\s*\%(extern\|var\|enum\|private\|scope\|union\|byref\|operator\|constructor\|delete\|namespace\|public\|property\|with\|destructor\|using\)\>\%(\s*[:=(]\)\@!'
var fb_preproc = '\c^\s*\%(' ..
# preprocessor
'#\s*\a\+\|' ..
# compiler option
'option\s\+\%(byval\|dynamic\|escape\|\%(no\)\=gosub\|nokeyword\|private\|static\)\>\|' ..
# metacommand
'\%(''\|rem\)\s*\$lang\>\|' ..
# default datatype
'def\%(byte\|longint\|short\|ubyte\|uint\|ulongint\|ushort\)\>' ..
'\)'
var fb_comment = "^\\s*/'"
# OPTION EXPLICIT, without the leading underscore, is common to many dialects
var qb64_preproc = '\c^\s*\%($\a\+\|option\s\+\%(_explicit\|_\=explicitarray\)\>\)'
for lnum in range(1, min([line("$"), 100]))
var line = getline(lnum)
if line =~ ft_visual_basic_content
setf vb
return
elseif line =~ fb_preproc || line =~ fb_comment || line =~ fb_keywords
setf freebasic
return
elseif line =~ qb64_preproc
setf qb64
return
endif
endfor
setf basic
enddef
export def FTbtm()
if exists("g:dosbatch_syntax_for_btm") && g:dosbatch_syntax_for_btm
setf dosbatch
else
setf btm
endif
enddef
export def BindzoneCheck(default = '')
if getline(1) .. getline(2) .. getline(3) .. getline(4)
=~ '^; <<>> DiG [0-9.]\+.* <<>>\|$ORIGIN\|$TTL\|IN\s\+SOA'
setf bindzone
elseif default