diff runtime/autoload/dist/ft.vim @ 23584:397f95f103e8 v8.2.2334

patch 8.2.2334: Pascal-like filetypes not always detected Commit: https://github.com/vim/vim/commit/a0122dcd1cc9e9bb62c071a9b91426a8bce4f8d9 Author: Bram Moolenaar <Bram@vim.org> Date: Tue Jan 12 17:42:24 2021 +0100 patch 8.2.2334: Pascal-like filetypes not always detected Problem: Pascal-like filetypes not always detected. Solution: Improved Puppet, InstantFPC and Pascal detection. (Doug Kearns, closes #7662)
author Bram Moolenaar <Bram@vim.org>
date Tue, 12 Jan 2021 17:45:04 +0100
parents bbca88cd13d5
children fda44c0b4b7b
line wrap: on
line diff
--- a/runtime/autoload/dist/ft.vim
+++ b/runtime/autoload/dist/ft.vim
@@ -362,6 +362,10 @@ func dist#ft#FTinc()
       setf aspvbs
     elseif lines =~ "<?"
       setf php
+    " Pascal supports // comments but they're vary rarely used for file
+    " headers so assume POV-Ray
+    elseif lines =~ '^\s*\%({\|(\*\)' || lines =~? s:ft_pascal_keywords
+      setf pascal
     else
       call dist#ft#FTasmsyntax()
       if exists("b:asmsyntax")
@@ -408,6 +412,9 @@ func dist#ft#FTprogress_asm()
   setf progress
 endfunc
 
+let s:ft_pascal_comments = '^\s*\%({\|(\*\|//\)'
+let s:ft_pascal_keywords = '^\s*\%(program\|unit\|library\|uses\|begin\|procedure\|function\|const\|type\|var\)\>'
+
 func dist#ft#FTprogress_pascal()
   if exists("g:filetype_p")
     exe "setf " . g:filetype_p
@@ -419,8 +426,7 @@ func dist#ft#FTprogress_pascal()
   let lnum = 1
   while lnum <= 10 && lnum < line('$')
     let line = getline(lnum)
-    if line =~ '^\s*\(program\|unit\|procedure\|function\|const\|type\|var\)\>'
-	\ || line =~ '^\s*{' || line =~ '^\s*(\*'
+    if line =~ s:ft_pascal_comments || line =~? s:ft_pascal_keywords
       setf pascal
       return
     elseif line !~ '^\s*$' || line =~ '^/\*'
@@ -433,6 +439,19 @@ func dist#ft#FTprogress_pascal()
   setf progress
 endfunc
 
+func dist#ft#FTpp()
+  if exists("g:filetype_pp")
+    exe "setf " . g:filetype_pp
+  else
+    let line = getline(nextnonblank(1))
+    if line =~ s:ft_pascal_comments || line =~? s:ft_pascal_keywords
+      setf pascal
+    else
+      setf puppet
+    endif
+  endif
+endfunc
+
 func dist#ft#FTr()
   let max = line("$") > 50 ? 50 : line("$")