]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.0558: filetype: prolog detection can be improved v9.1.0558
authorigna_martinoli <ignamartinoli@protonmail.com>
Wed, 10 Jul 2024 19:25:04 +0000 (21:25 +0200)
committerChristian Brabandt <cb@256bit.org>
Wed, 10 Jul 2024 19:25:04 +0000 (21:25 +0200)
Problem:  filetype: prolog detection can be improved
Solution: Improved the Prolog file detection regex and added tests for
          all cases. (igna_martinoli)

fixes: #10835
closes: #15206

Signed-off-by: igna_martinoli <ignamartinoli@protonmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
runtime/autoload/dist/ft.vim
src/testdir/test_filetype.vim
src/version.c

index 3c7d85cec652f05ec60516e2f9c67ada2d5d2a52..6aea180c5475a8172855f7ba707d7fad3dbd1fee 100644 (file)
@@ -465,7 +465,7 @@ export def ProtoCheck(default: string)
     # recognize Prolog by specific text in the first non-empty line
     # require a blank after the '%' because Perl uses "%list" and "%translate"
     var lnum = getline(nextnonblank(1))
-    if lnum =~ '\<prolog\>' || lnum =~ '^\s*\(%\+\(\s\|$\)\|/\*\)' || lnum =~ ':-'
+    if lnum =~ '\<prolog\>' || lnum =~ '(^\s*(:-\|%\|\/\*))\|.\s*$'
       setf prolog
     else
       exe 'setf ' .. default
index 3b0b2e99a5ff48151d5cd6faa49aef24d1eb586f..a4107856082ded466c7635013c159bd2d3ecdee6 100644 (file)
@@ -2576,4 +2576,31 @@ func Test_uci_file()
   filetype off
 endfunc
 
+func Test_pro_file()
+  filetype on
+
+  "Prolog
+  call writefile([':-module(test/1,'], 'Xfile.pro', 'D')
+  split Xfile.pro
+  call assert_equal('prolog', &filetype)
+  bwipe!
+
+  call writefile(['% comment'], 'Xfile.pro', 'D')
+  split Xfile.pro
+  call assert_equal('prolog', &filetype)
+  bwipe!
+
+  call writefile(['/* multiline comment'], 'Xfile.pro', 'D')
+  split Xfile.pro
+  call assert_equal('prolog', &filetype)
+  bwipe!
+
+  call writefile(['rule(test, 1.7).'], 'Xfile.pro', 'D')
+  split Xfile.pro
+  call assert_equal('prolog', &filetype)
+  bwipe!
+
+  filetype off
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
index 9c076f86b069fb184b7c5325312778b6a2783ca6..aaef85fee60911d2fb71e82371cb2c12260d0c71 100644 (file)
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    558,
 /**/
     557,
 /**/