patch 9.1.0602: filetype: Prolog detection can be improved
Problem: filetype: Prolog detection can be improved
Solution: update the prolog detection regex
(igna_martinoli)
related: #10835
related: #15206
closes: #15253
Co-authored-by: clason <c.clason@uni-graz.at>
Co-authored-by: zeertzjq <zeertzjq@outlook.com>
Signed-off-by: igna_martinoli <ignamartinoli@protonmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
committed by
Christian Brabandt
parent
eb6d733bef
commit
37853b7de3
6
runtime/autoload/dist/ft.vim
vendored
6
runtime/autoload/dist/ft.vim
vendored
@ -9,6 +9,8 @@ vim9script
|
|||||||
# These functions are moved here from runtime/filetype.vim to make startup
|
# These functions are moved here from runtime/filetype.vim to make startup
|
||||||
# faster.
|
# faster.
|
||||||
|
|
||||||
|
var prolog_pattern = '^\s*\(:-\|%\+\(\s\|$\)\|\/\*\)\|\.\s*$'
|
||||||
|
|
||||||
export def Check_inp()
|
export def Check_inp()
|
||||||
if getline(1) =~ '%%'
|
if getline(1) =~ '%%'
|
||||||
setf tex
|
setf tex
|
||||||
@ -465,7 +467,7 @@ export def ProtoCheck(default: string)
|
|||||||
# recognize Prolog by specific text in the first non-empty line
|
# recognize Prolog by specific text in the first non-empty line
|
||||||
# require a blank after the '%' because Perl uses "%list" and "%translate"
|
# require a blank after the '%' because Perl uses "%list" and "%translate"
|
||||||
var lnum = getline(nextnonblank(1))
|
var lnum = getline(nextnonblank(1))
|
||||||
if lnum =~ '\<prolog\>' || lnum =~ '^\(:-\|%\|\/\*\)\|\.$'
|
if lnum =~ '\<prolog\>' || lnum =~ prolog_pattern
|
||||||
setf prolog
|
setf prolog
|
||||||
else
|
else
|
||||||
exe 'setf ' .. default
|
exe 'setf ' .. default
|
||||||
@ -644,7 +646,7 @@ export def FTpl()
|
|||||||
# recognize Prolog by specific text in the first non-empty line
|
# recognize Prolog by specific text in the first non-empty line
|
||||||
# require a blank after the '%' because Perl uses "%list" and "%translate"
|
# require a blank after the '%' because Perl uses "%list" and "%translate"
|
||||||
var line = getline(nextnonblank(1))
|
var line = getline(nextnonblank(1))
|
||||||
if line =~ '\<prolog\>' || line =~ '^\s*\(%\+\(\s\|$\)\|/\*\)' || line =~ ':-'
|
if line =~ '\<prolog\>' || line =~ prolog_pattern
|
||||||
setf prolog
|
setf prolog
|
||||||
else
|
else
|
||||||
setf perl
|
setf perl
|
||||||
|
|||||||
@ -1719,7 +1719,7 @@ au BufNewFile,BufRead *.pcmk setf pcmk
|
|||||||
" PEM (Privacy-Enhanced Mail)
|
" PEM (Privacy-Enhanced Mail)
|
||||||
au BufNewFile,BufRead *.pem,*.cer,*.crt,*.csr setf pem
|
au BufNewFile,BufRead *.pem,*.cer,*.crt,*.csr setf pem
|
||||||
|
|
||||||
" Perl
|
" Perl or Prolog
|
||||||
if has("fname_case")
|
if has("fname_case")
|
||||||
au BufNewFile,BufRead *.pl,*.PL call dist#ft#FTpl()
|
au BufNewFile,BufRead *.pl,*.PL call dist#ft#FTpl()
|
||||||
else
|
else
|
||||||
|
|||||||
@ -2603,6 +2603,44 @@ func Test_pro_file()
|
|||||||
call assert_equal('prolog', &filetype)
|
call assert_equal('prolog', &filetype)
|
||||||
bwipe!
|
bwipe!
|
||||||
|
|
||||||
|
" IDL
|
||||||
|
call writefile(['x = findgen(100)/10'], 'Xfile.pro', 'D')
|
||||||
|
split Xfile.pro
|
||||||
|
call assert_equal('idlang', &filetype)
|
||||||
|
|
||||||
|
filetype off
|
||||||
|
endfunc
|
||||||
|
|
||||||
|
|
||||||
|
func Test_pl_file()
|
||||||
|
filetype on
|
||||||
|
|
||||||
|
"Prolog
|
||||||
|
call writefile([':-module(test/1,'], 'Xfile.pl', 'D')
|
||||||
|
split Xfile.pl
|
||||||
|
call assert_equal('prolog', &filetype)
|
||||||
|
bwipe!
|
||||||
|
|
||||||
|
call writefile(['% comment'], 'Xfile.pl', 'D')
|
||||||
|
split Xfile.pl
|
||||||
|
call assert_equal('prolog', &filetype)
|
||||||
|
bwipe!
|
||||||
|
|
||||||
|
call writefile(['/* multiline comment'], 'Xfile.pl', 'D')
|
||||||
|
split Xfile.pl
|
||||||
|
call assert_equal('prolog', &filetype)
|
||||||
|
bwipe!
|
||||||
|
|
||||||
|
call writefile(['rule(test, 1.7).'], 'Xfile.pl', 'D')
|
||||||
|
split Xfile.pl
|
||||||
|
call assert_equal('prolog', &filetype)
|
||||||
|
bwipe!
|
||||||
|
|
||||||
|
" Perl
|
||||||
|
call writefile(['%data = (1, 2, 3);'], 'Xfile.pl', 'D')
|
||||||
|
split Xfile.pl
|
||||||
|
call assert_equal('perl', &filetype)
|
||||||
|
|
||||||
filetype off
|
filetype off
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
|||||||
@ -704,6 +704,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
602,
|
||||||
/**/
|
/**/
|
||||||
601,
|
601,
|
||||||
/**/
|
/**/
|
||||||
|
|||||||
Reference in New Issue
Block a user