vim9script
# Vim functions forfile type detection
#
# Maintainer: The Vim Project <https://github.com/vim/vim>
# Last Change: 2024 May 23
# Former Maintainer: Bram Moolenaar <Bram@vim.org>
# These functions are moved here from runtime/filetype.vimtomake 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("$")whilen<= nmax
if getline(n)=~? "^header surface data"setf trasys
breakendifn+=1endwhileendif
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 =""endififb:asmsyntax ==""
FTasmsyntax()endif
# ifb:asmsyntax still isn'tset, default to asmsyntax or GNU
ifb:asmsyntax ==""if exists("g:asmsyntax")b:asmsyntax =g:asmsyntax
elseb:asmsyntax ="asm"endifendif
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')ifmatch!=''b:asmsyntax =matchelseif((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
returnendif
# 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\+\|' ..
# compileroption'option\s\+\%(byval\|dynamic\|escape\|\%(no\)\=gosub\|nokeyword\|private\|static\)\>\|' ..
# metacommand
'\%(''\|rem\)\s*\$lang\>\|' ..
# default datatype
'def\%(byte\|longint\|short\|ubyte\|uint\|ulongint\|ushort\)\>