changeset 27557:ce72087b601f v8.2.4305

patch 8.2.4305: tex filetype detection fails Commit: https://github.com/vim/vim/commit/e5b7897585eccec84431d8b23df5cde2e283828c Author: Bram Moolenaar <Bram@vim.org> Date: Sat Feb 5 19:50:34 2022 +0000 patch 8.2.4305: tex filetype detection fails Problem: Tex filetype detection fails. Solution: Check value to be positive. (closes https://github.com/vim/vim/issues/9704)
author Bram Moolenaar <Bram@vim.org>
date Sat, 05 Feb 2022 21:00:03 +0100
parents b940866eac65
children fe527f3590ed
files runtime/autoload/dist/ft.vim src/testdir/test_filetype.vim src/version.c
diffstat 3 files changed, 25 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/runtime/autoload/dist/ft.vim
+++ b/runtime/autoload/dist/ft.vim
@@ -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 .. '\)',
--- a/src/testdir/test_filetype.vim
+++ b/src/testdir/test_filetype.vim
@@ -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
--- a/src/version.c
+++ b/src/version.c
@@ -747,6 +747,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    4305,
+/**/
     4304,
 /**/
     4303,