diff options
Diffstat (limited to 'runtime/autoload/dist/ft.vim')
-rw-r--r-- | runtime/autoload/dist/ft.vim | 101 |
1 files changed, 96 insertions, 5 deletions
diff --git a/runtime/autoload/dist/ft.vim b/runtime/autoload/dist/ft.vim index bf9e32e..c8942eb 100644 --- a/runtime/autoload/dist/ft.vim +++ b/runtime/autoload/dist/ft.vim @@ -9,6 +9,8 @@ vim9script # These functions are moved here from runtime/filetype.vim to make startup # faster. +var prolog_pattern = '^\s*\(:-\|%\+\(\s\|$\)\|\/\*\)\|\.\s*$' + export def Check_inp() if getline(1) =~ '%%' setf tex @@ -402,18 +404,38 @@ export def FTharedoc() endif enddef -# Distinguish between HTML, XHTML and Django +# Distinguish between HTML, XHTML, Django and Angular export def FThtml() var n = 1 - while n < 10 && n <= line("$") + + # Test if the filename follows the Angular component template convention + # Disabled for the reasons mentioned here: #13594 + # if expand('%:t') =~ '^.*\.component\.html$' + # setf htmlangular + # return + # endif + + while n < 40 && n <= line("$") + # Check for Angular + if getline(n) =~ '@\(if\|for\|defer\|switch\)\|\*\(ngIf\|ngFor\|ngSwitch\|ngTemplateOutlet\)\|ng-template\|ng-content\|{{.*}}' + setf htmlangular + return + endif + # Check for XHTML if getline(n) =~ '\<DTD\s\+XHTML\s' setf xhtml return endif - if getline(n) =~ '{%\s*\(extends\|block\|load\)\>\|{#\s\+' + # Check for Django + if getline(n) =~ '{%\s*\(autoescape\|block\|comment\|csrf_token\|cycle\|debug\|extends\|filter\|firstof\|for\|if\|ifchanged\|include\|load\|lorem\|now\|query_string\|regroup\|resetcycle\|spaceless\|templatetag\|url\|verbatim\|widthratio\|with\)\>\|{#\s\+' setf htmldjango return endif + # Check for SuperHTML + if getline(n) =~ '<extend\|<super>' + setf superhtml + return + endif n += 1 endwhile setf FALLBACK html @@ -449,7 +471,7 @@ export def ProtoCheck(default: string) # recognize Prolog by specific text in the first non-empty line # require a blank after the '%' because Perl uses "%list" and "%translate" var lnum = getline(nextnonblank(1)) - if lnum =~ '\<prolog\>' || lnum =~ '^\s*\(%\+\(\s\|$\)\|/\*\)' || lnum =~ ':-' + if lnum =~ '\<prolog\>' || lnum =~ prolog_pattern setf prolog else exe 'setf ' .. default @@ -514,6 +536,25 @@ export def FTm() endif enddef +export def FTmake() + # Check if it is a Microsoft Makefile + unlet! b:make_microsoft + var n = 1 + while n < 1000 && n <= line('$') + var line = getline(n) + if line =~? '^\s*!\s*\(ifn\=\(def\)\=\|include\|message\|error\)\>' + b:make_microsoft = 1 + break + elseif line =~ '^ *ifn\=\(eq\|def\)\>' || line =~ '^ *[-s]\=include\s' + break + elseif line =~ '^ *\w\+\s*[!?:+]=' + break + endif + n += 1 + endwhile + setf make +enddef + export def FTmms() var n = 1 while n < 20 @@ -628,7 +669,7 @@ export def FTpl() # recognize Prolog by specific text in the first non-empty line # require a blank after the '%' because Perl uses "%list" and "%translate" var line = getline(nextnonblank(1)) - if line =~ '\<prolog\>' || line =~ '^\s*\(%\+\(\s\|$\)\|/\*\)' || line =~ ':-' + if line =~ '\<prolog\>' || line =~ prolog_pattern setf prolog else setf perl @@ -1265,6 +1306,56 @@ export def FTtyp() setf typst enddef +# Detect Microsoft Developer Studio Project files (Makefile) or Faust DSP +# files. +export def FTdsp() + if exists("g:filetype_dsp") + exe "setf " .. g:filetype_dsp + return + endif + + # Test the filename + if expand('%:t') =~ '^[mM]akefile.*$' + setf make + return + endif + + # Test the file contents + for line in getline(1, 200) + # Chech for comment style + if line =~ '^#.*' + setf make + return + endif + + # Check for common lines + if line =~ '^.*Microsoft Developer Studio Project File.*$' + setf make + return + endif + + if line =~ '^!MESSAGE This is not a valid makefile\..+$' + setf make + return + endif + + # Check for keywords + if line =~ '^!(IF,ELSEIF,ENDIF).*$' + setf make + return + endif + + # Check for common assignments + if line =~ '^SOURCE=.*$' + setf make + return + endif + endfor + + # Otherwise, assume we have a Faust file + setf faust +enddef + # Set the filetype of a *.v file to Verilog, V or Cog based on the first 200 # lines. export def FTv() |