]> granicus.if.org Git - vim/commitdiff
patch 8.2.3679: objc file detected as Octave v8.2.3679
authorDoug Kearns <dougkearns@gmail.com>
Fri, 26 Nov 2021 13:01:41 +0000 (13:01 +0000)
committerBram Moolenaar <Bram@vim.org>
Fri, 26 Nov 2021 13:01:41 +0000 (13:01 +0000)
Problem:    objc file detected as Octave. (Antony Lee)
Solution:   Detect objc by preprocessor lines. (Doug Kearns, closes #9223,
            closes #9220)

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

index 7484149a26d418d66af469ae3fd4e4f98c0a554b..344889249bdb11e7c82fff766728ba876e6af268 100644 (file)
@@ -272,6 +272,8 @@ func dist#ft#FTm()
   " excluding end(for|function|if|switch|while) common to Murphi
   let octave_block_terminators = '\<end\%(_try_catch\|classdef\|enumeration\|events\|methods\|parfor\|properties\)\>'
 
+  let objc_preprocessor = '^\s*#\s*\%(import\|include\|define\|if\|ifn\=def\|undef\|line\|error\|pragma\)\>'
+
   let n = 1
   let saw_comment = 0 " Whether we've seen a multiline comment leader.
   while n < 100
@@ -282,7 +284,7 @@ func dist#ft#FTm()
       " anything more definitive.
       let saw_comment = 1
     endif
-    if line =~ '^\s*\(#\s*\(include\|import\)\>\|@import\>\|//\)'
+    if line =~ '^\s*//' || line =~ '^\s*@import\>' || line =~ objc_preprocessor
       setf objc
       return
     endif
index 6134b328d974819360afe017f3da3732db0ffabd..81ddbe9ea8db121ac0f0c11e7458eb0e0c8e6b39 100644 (file)
@@ -891,6 +891,16 @@ func Test_m_file()
   call assert_equal('objc', &filetype)
   bwipe!
 
+  call writefile(['#include <header.h>'], 'Xfile.m')
+  split Xfile.m
+  call assert_equal('objc', &filetype)
+  bwipe!
+
+  call writefile(['#define FORTY_TWO'], 'Xfile.m')
+  split Xfile.m
+  call assert_equal('objc', &filetype)
+  bwipe!
+
   " Octave
 
   call writefile(['# Octave line comment'], 'Xfile.m')
index b7a93edbb2b388e2236dc9e2eee1986116bbbb5c..ca0f16fcd0d4bcba0c597d0a179c2de4dc20d762 100644 (file)
@@ -757,6 +757,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    3679,
 /**/
     3678,
 /**/