Skip to content

Commit 37853b7

Browse files
igna_martinoliclasonzeertzjq
authored andcommitted
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 <[email protected]> Co-authored-by: zeertzjq <[email protected]> Signed-off-by: igna_martinoli <[email protected]> Signed-off-by: Christian Brabandt <[email protected]>
1 parent eb6d733 commit 37853b7

4 files changed

Lines changed: 45 additions & 3 deletions

File tree

runtime/autoload/dist/ft.vim

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ vim9script
99
# These functions are moved here from runtime/filetype.vim to make startup
1010
# faster.
1111

12+
var prolog_pattern = '^\s*\(:-\|%\+\(\s\|$\)\|\/\*\)\|\.\s*$'
13+
1214
export def Check_inp()
1315
if getline(1) =~ '%%'
1416
setf tex
@@ -465,7 +467,7 @@ export def ProtoCheck(default: string)
465467
# recognize Prolog by specific text in the first non-empty line
466468
# require a blank after the '%' because Perl uses "%list" and "%translate"
467469
var lnum = getline(nextnonblank(1))
468-
if lnum =~ '\<prolog\>' || lnum =~ '^\(:-\|%\|\/\*\)\|\.$'
470+
if lnum =~ '\<prolog\>' || lnum =~ prolog_pattern
469471
setf prolog
470472
else
471473
exe 'setf ' .. default
@@ -644,7 +646,7 @@ export def FTpl()
644646
# recognize Prolog by specific text in the first non-empty line
645647
# require a blank after the '%' because Perl uses "%list" and "%translate"
646648
var line = getline(nextnonblank(1))
647-
if line =~ '\<prolog\>' || line =~ '^\s*\(%\+\(\s\|$\)\|/\*\)' || line =~ ':-'
649+
if line =~ '\<prolog\>' || line =~ prolog_pattern
648650
setf prolog
649651
else
650652
setf perl

runtime/filetype.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1719,7 +1719,7 @@ au BufNewFile,BufRead *.pcmk setf pcmk
17191719
" PEM (Privacy-Enhanced Mail)
17201720
au BufNewFile,BufRead *.pem,*.cer,*.crt,*.csr setf pem
17211721

1722-
" Perl
1722+
" Perl or Prolog
17231723
if has("fname_case")
17241724
au BufNewFile,BufRead *.pl,*.PL call dist#ft#FTpl()
17251725
else

src/testdir/test_filetype.vim

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2603,6 +2603,44 @@ func Test_pro_file()
26032603
call assert_equal('prolog', &filetype)
26042604
bwipe!
26052605

2606+
" IDL
2607+
call writefile(['x = findgen(100)/10'], 'Xfile.pro', 'D')
2608+
split Xfile.pro
2609+
call assert_equal('idlang', &filetype)
2610+
2611+
filetype off
2612+
endfunc
2613+
2614+
2615+
func Test_pl_file()
2616+
filetype on
2617+
2618+
"Prolog
2619+
call writefile([':-module(test/1,'], 'Xfile.pl', 'D')
2620+
split Xfile.pl
2621+
call assert_equal('prolog', &filetype)
2622+
bwipe!
2623+
2624+
call writefile(['% comment'], 'Xfile.pl', 'D')
2625+
split Xfile.pl
2626+
call assert_equal('prolog', &filetype)
2627+
bwipe!
2628+
2629+
call writefile(['/* multiline comment'], 'Xfile.pl', 'D')
2630+
split Xfile.pl
2631+
call assert_equal('prolog', &filetype)
2632+
bwipe!
2633+
2634+
call writefile(['rule(test, 1.7).'], 'Xfile.pl', 'D')
2635+
split Xfile.pl
2636+
call assert_equal('prolog', &filetype)
2637+
bwipe!
2638+
2639+
" Perl
2640+
call writefile(['%data = (1, 2, 3);'], 'Xfile.pl', 'D')
2641+
split Xfile.pl
2642+
call assert_equal('perl', &filetype)
2643+
26062644
filetype off
26072645
endfunc
26082646

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,8 @@ static char *(features[]) =
704704

705705
static int included_patches[] =
706706
{ /* Add new patch number below this line */
707+
/**/
708+
602,
707709
/**/
708710
601,
709711
/**/

0 commit comments

Comments
 (0)