]> granicus.if.org Git - vim/commitdiff
patch 8.2.4305: tex filetype detection fails v8.2.4305
authorBram Moolenaar <Bram@vim.org>
Sat, 5 Feb 2022 19:50:34 +0000 (19:50 +0000)
committerBram Moolenaar <Bram@vim.org>
Sat, 5 Feb 2022 19:50:34 +0000 (19:50 +0000)
Problem:    Tex filetype detection fails.
Solution:   Check value to be positive. (closes #9704)

runtime/autoload/dist/ft.vim
src/testdir/test_filetype.vim
src/version.c

index d4e7be44b08e58224b4633d5d20dd66675036abf..a8ca90080eef9d6c6c710930e21ec16d5b2325fe 100644 (file)
@@ -3,7 +3,7 @@ vim9script
 # Vim functions for file type detection
 #
 # Maintainer:  Bram Moolenaar <Bram@vim.org>
-# Last Change: 2022 Feb 04
+# Last Change: 2022 Feb 05
 
 # These functions are moved here from runtime/filetype.vim to make startup
 # faster.
@@ -722,7 +722,7 @@ export def FTperl(): number
   endif
   var save_cursor = getpos('.')
   call cursor(1, 1)
-  var has_use = search('^use\s\s*\k', 'c', 30)
+  var has_use = search('^use\s\s*\k', 'c', 30) > 0
   call setpos('.', save_cursor)
   if has_use
     setf perl
@@ -755,7 +755,8 @@ export def FTtex()
     var save_cursor = getpos('.')
     call cursor(1, 1)
     var firstNC = search('^\s*[^[:space:]%]', 'c', 1000)
-    if firstNC # Check the next thousand lines for a LaTeX or ConTeXt keyword.
+    if firstNC > 0
+      # Check the next thousand lines for a LaTeX or ConTeXt keyword.
       var lpat = 'documentclass\>\|usepackage\>\|begin{\|newcommand\>\|renewcommand\>'
       var cpat = 'start\a\+\|setup\a\+\|usemodule\|enablemode\|enableregime\|setvariables\|useencoding\|usesymbols\|stelle\a\+\|verwende\a\+\|stel\a\+\|gebruik\a\+\|usa\a\+\|imposta\a\+\|regle\a\+\|utilisemodule\>'
       var kwline = search('^\s*\\\%(' .. lpat .. '\)\|^\s*\\\(' .. cpat .. '\)',
index 6f4a42581460f1e7f73d800ea784adc44424e75d..b9909c6484a84348112f10cc7e608e5dc6f34853 100644 (file)
@@ -1306,4 +1306,23 @@ func Test_frm_file()
   filetype off
 endfunc
 
+func Test_tex_file()
+  filetype on
+
+  " only tests one case, should do more
+  let lines =<< trim END
+      % This is a sentence.
+
+      This is a sentence.
+  END
+  call writefile(lines, "Xfile.tex")
+  split Xfile.tex
+  call assert_equal('plaintex', &filetype)
+  bwipe
+
+  call delete('Xfile.tex')
+  filetype off
+endfunc
+
+
 " vim: shiftwidth=2 sts=2 expandtab
index 3df4cfca9498f4ff7c208914e1716b59a46ac54f..3d72ecafc60f0313e2136cc3ee3d58884c14153d 100644 (file)
@@ -746,6 +746,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    4305,
 /**/
     4304,
 /**/