summaryrefslogtreecommitdiffstats
path: root/runtime
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2021-01-12 17:42:24 +0100
committerBram Moolenaar <Bram@vim.org>2021-01-12 17:42:24 +0100
commita0122dcd1cc9e9bb62c071a9b91426a8bce4f8d9 (patch)
treeef586f6cb1068f0dd84b7d08f7492348d1f91a90 /runtime
parentcb6cbf29e97b7abdeb1e6cbdc5e735f5b55e97a1 (diff)
patch 8.2.2334: Pascal-like filetypes not always detectedv8.2.2334
Problem: Pascal-like filetypes not always detected. Solution: Improved Puppet, InstantFPC and Pascal detection. (Doug Kearns, closes #7662)
Diffstat (limited to 'runtime')
-rw-r--r--runtime/autoload/dist/ft.vim23
-rw-r--r--runtime/filetype.vim4
-rw-r--r--runtime/scripts.vim4
3 files changed, 28 insertions, 3 deletions
diff --git a/runtime/autoload/dist/ft.vim b/runtime/autoload/dist/ft.vim
index 2c3179e314..1ac74b5785 100644
--- 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("$")
diff --git a/runtime/filetype.vim b/runtime/filetype.vim
index dddb6d11cc..7a33f8fa2b 100644
--- a/runtime/filetype.vim
+++ b/runtime/filetype.vim
@@ -1174,7 +1174,9 @@ au BufNewFile,BufRead *.papp,*.pxml,*.pxsl setf papp
au BufNewFile,BufRead */etc/passwd,*/etc/passwd-,*/etc/passwd.edit,*/etc/shadow,*/etc/shadow-,*/etc/shadow.edit,*/var/backups/passwd.bak,*/var/backups/shadow.bak setf passwd
" Pascal (also *.p)
-au BufNewFile,BufRead *.pas,*.pp setf pascal
+au BufNewFile,BufRead *.pas setf pascal
+
+au BufNewFile,BufRead *.pp call dist#ft#FTpp()
" Delphi or Lazarus program file
au BufNewFile,BufRead *.dpr,*.lpr setf pascal
diff --git a/runtime/scripts.vim b/runtime/scripts.vim
index 9c2787ace6..9217b4416a 100644
--- a/runtime/scripts.vim
+++ b/runtime/scripts.vim
@@ -182,6 +182,10 @@ if s:line1 =~# "^#!"
elseif s:name =~# 'clojure'
set ft=clojure
+ " Free Pascal
+ elseif s:name =~# 'instantfpc\>'
+ set ft=pascal
+
endif
unlet s:name