mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
vim-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 vim/vim#7662)
a0122dcd1c
This commit is contained in:
parent
bd02e29443
commit
d953614e72
23
runtime/autoload/dist/ft.vim
vendored
23
runtime/autoload/dist/ft.vim
vendored
@ -362,6 +362,10 @@ func dist#ft#FTinc()
|
|||||||
setf aspvbs
|
setf aspvbs
|
||||||
elseif lines =~ "<?"
|
elseif lines =~ "<?"
|
||||||
setf php
|
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
|
else
|
||||||
call dist#ft#FTasmsyntax()
|
call dist#ft#FTasmsyntax()
|
||||||
if exists("b:asmsyntax")
|
if exists("b:asmsyntax")
|
||||||
@ -408,6 +412,9 @@ func dist#ft#FTprogress_asm()
|
|||||||
setf progress
|
setf progress
|
||||||
endfunc
|
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()
|
func dist#ft#FTprogress_pascal()
|
||||||
if exists("g:filetype_p")
|
if exists("g:filetype_p")
|
||||||
exe "setf " . g:filetype_p
|
exe "setf " . g:filetype_p
|
||||||
@ -419,8 +426,7 @@ func dist#ft#FTprogress_pascal()
|
|||||||
let lnum = 1
|
let lnum = 1
|
||||||
while lnum <= 10 && lnum < line('$')
|
while lnum <= 10 && lnum < line('$')
|
||||||
let line = getline(lnum)
|
let line = getline(lnum)
|
||||||
if line =~ '^\s*\(program\|unit\|procedure\|function\|const\|type\|var\)\>'
|
if line =~ s:ft_pascal_comments || line =~? s:ft_pascal_keywords
|
||||||
\ || line =~ '^\s*{' || line =~ '^\s*(\*'
|
|
||||||
setf pascal
|
setf pascal
|
||||||
return
|
return
|
||||||
elseif line !~ '^\s*$' || line =~ '^/\*'
|
elseif line !~ '^\s*$' || line =~ '^/\*'
|
||||||
@ -433,6 +439,19 @@ func dist#ft#FTprogress_pascal()
|
|||||||
setf progress
|
setf progress
|
||||||
endfunc
|
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()
|
func dist#ft#FTr()
|
||||||
let max = line("$") > 50 ? 50 : line("$")
|
let max = line("$") > 50 ? 50 : line("$")
|
||||||
|
|
||||||
|
@ -1170,7 +1170,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
|
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)
|
" 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
|
" Delphi or Lazarus program file
|
||||||
au BufNewFile,BufRead *.dpr,*.lpr setf pascal
|
au BufNewFile,BufRead *.dpr,*.lpr setf pascal
|
||||||
|
@ -182,6 +182,10 @@ if s:line1 =~# "^#!"
|
|||||||
elseif s:name =~# 'clojure'
|
elseif s:name =~# 'clojure'
|
||||||
set ft=clojure
|
set ft=clojure
|
||||||
|
|
||||||
|
" Free Pascal
|
||||||
|
elseif s:name =~# 'instantfpc\>'
|
||||||
|
set ft=pascal
|
||||||
|
|
||||||
endif
|
endif
|
||||||
unlet s:name
|
unlet s:name
|
||||||
|
|
||||||
|
@ -332,7 +332,7 @@ let s:filename_checks = {
|
|||||||
\ 'pamconf': ['/etc/pam.conf'],
|
\ 'pamconf': ['/etc/pam.conf'],
|
||||||
\ 'pamenv': ['/etc/security/pam_env.conf', '/home/user/.pam_environment'],
|
\ 'pamenv': ['/etc/security/pam_env.conf', '/home/user/.pam_environment'],
|
||||||
\ 'papp': ['file.papp', 'file.pxml', 'file.pxsl'],
|
\ 'papp': ['file.papp', 'file.pxml', 'file.pxsl'],
|
||||||
\ 'pascal': ['file.pas', 'file.pp', 'file.dpr', 'file.lpr'],
|
\ 'pascal': ['file.pas', 'file.dpr', 'file.lpr'],
|
||||||
\ 'passwd': ['any/etc/passwd', 'any/etc/passwd-', 'any/etc/passwd.edit', 'any/etc/shadow', 'any/etc/shadow-', 'any/etc/shadow.edit', 'any/var/backups/passwd.bak', 'any/var/backups/shadow.bak'],
|
\ 'passwd': ['any/etc/passwd', 'any/etc/passwd-', 'any/etc/passwd.edit', 'any/etc/shadow', 'any/etc/shadow-', 'any/etc/shadow.edit', 'any/var/backups/passwd.bak', 'any/var/backups/shadow.bak'],
|
||||||
\ 'pbtxt': ['file.pbtxt'],
|
\ 'pbtxt': ['file.pbtxt'],
|
||||||
\ 'pccts': ['file.g'],
|
\ 'pccts': ['file.g'],
|
||||||
@ -368,6 +368,7 @@ let s:filename_checks = {
|
|||||||
\ 'proto': ['file.proto'],
|
\ 'proto': ['file.proto'],
|
||||||
\ 'protocols': ['/etc/protocols'],
|
\ 'protocols': ['/etc/protocols'],
|
||||||
\ 'psf': ['file.psf'],
|
\ 'psf': ['file.psf'],
|
||||||
|
\ 'puppet': ['file.pp'],
|
||||||
\ 'pyrex': ['file.pyx', 'file.pxd'],
|
\ 'pyrex': ['file.pyx', 'file.pxd'],
|
||||||
\ 'python': ['file.py', 'file.pyw', '.pythonstartup', '.pythonrc', 'file.ptl', 'file.pyi', 'SConstruct'],
|
\ 'python': ['file.py', 'file.pyw', '.pythonstartup', '.pythonrc', 'file.ptl', 'file.pyi', 'SConstruct'],
|
||||||
\ 'quake': ['anybaseq2/file.cfg', 'anyid1/file.cfg', 'quake3/file.cfg'],
|
\ 'quake': ['anybaseq2/file.cfg', 'anyid1/file.cfg', 'quake3/file.cfg'],
|
||||||
@ -619,6 +620,7 @@ let s:script_checks = {
|
|||||||
\ 'cpp': [['// Standard iostream objects -*- C++ -*-'],
|
\ 'cpp': [['// Standard iostream objects -*- C++ -*-'],
|
||||||
\ ['// -*- C++ -*-']],
|
\ ['// -*- C++ -*-']],
|
||||||
\ 'yaml': [['%YAML 1.2']],
|
\ 'yaml': [['%YAML 1.2']],
|
||||||
|
\ 'pascal': [['#!/path/instantfpc']],
|
||||||
\ }
|
\ }
|
||||||
|
|
||||||
" Various forms of "env" optional arguments.
|
" Various forms of "env" optional arguments.
|
||||||
@ -689,5 +691,33 @@ func Test_ts_file()
|
|||||||
filetype off
|
filetype off
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
func Test_pp_file()
|
||||||
|
filetype on
|
||||||
|
|
||||||
|
call writefile(['looks like puppet'], 'Xfile.pp')
|
||||||
|
split Xfile.pp
|
||||||
|
call assert_equal('puppet', &filetype)
|
||||||
|
bwipe!
|
||||||
|
|
||||||
|
let g:filetype_pp = 'pascal'
|
||||||
|
split Xfile.pp
|
||||||
|
call assert_equal('pascal', &filetype)
|
||||||
|
bwipe!
|
||||||
|
|
||||||
|
" Test dist#ft#FTpp()
|
||||||
|
call writefile(['{ pascal comment'], 'Xfile.pp')
|
||||||
|
split Xfile.pp
|
||||||
|
call assert_equal('pascal', &filetype)
|
||||||
|
bwipe!
|
||||||
|
|
||||||
|
call writefile(['procedure pascal'], 'Xfile.pp')
|
||||||
|
split Xfile.pp
|
||||||
|
call assert_equal('pascal', &filetype)
|
||||||
|
bwipe!
|
||||||
|
|
||||||
|
call delete('Xfile.ts')
|
||||||
|
filetype off
|
||||||
|
endfunc
|
||||||
|
|
||||||
|
|
||||||
" vim: shiftwidth=2 sts=2 expandtab
|
" vim: shiftwidth=2 sts=2 expandtab
|
||||||
|
Loading…
Reference in New Issue
Block a user