changeset 26296:9f32ccdadd22 v8.2.3679

patch 8.2.3679: objc file detected as Octave Commit: https://github.com/vim/vim/commit/7329cfab36356c48edab7ed68f6244eb9e20a5b1 Author: Doug Kearns <dougkearns@gmail.com> Date: Fri Nov 26 13:01:41 2021 +0000 patch 8.2.3679: objc file detected as Octave Problem: objc file detected as Octave. (Antony Lee) Solution: Detect objc by preprocessor lines. (Doug Kearns, closes https://github.com/vim/vim/issues/9223, closes #9220)
author Bram Moolenaar <Bram@vim.org>
date Fri, 26 Nov 2021 14:15:05 +0100
parents 84d52b86a6b3
children e69362eb5521
files runtime/autoload/dist/ft.vim src/testdir/test_filetype.vim src/version.c
diffstat 3 files changed, 15 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/runtime/autoload/dist/ft.vim
+++ b/runtime/autoload/dist/ft.vim
@@ -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
--- a/src/testdir/test_filetype.vim
+++ b/src/testdir/test_filetype.vim
@@ -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')
--- a/src/version.c
+++ b/src/version.c
@@ -758,6 +758,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    3679,
+/**/
     3678,
 /**/
     3677,