patch 9.2.0489: filetype: some Objective-C files are not recognized
Commit:
https://github.com/vim/vim/commit/bc7f736a393123c1349fe3fbe4fb48bfc56754b1
Author: Keith Smiley <[email protected]>
Date: Sat May 16 07:46:25 2026 +0000
patch 9.2.0489: filetype: some Objective-C files are not recognized
Problem: filetype: some Objective-C files are not recognized
Solution: Add g:filetype_mm override variable, improve the objective c
pattern detection (Keith Smiley).
closes: #20221
Signed-off-by: Keith Smiley <[email protected]>
Signed-off-by: Christian Brabandt <[email protected]>
diff --git a/runtime/autoload/dist/ft.vim b/runtime/autoload/dist/ft.vim
index 17b261823..3085f3575 100644
--- a/runtime/autoload/dist/ft.vim
+++ b/runtime/autoload/dist/ft.vim
@@ -3,7 +3,7 @@ vim9script
# Vim functions for file type detection
#
# Maintainer: The Vim Project <https://github.com/vim/vim>
-# Last Change: 2026 Apr 23
+# Last Change: 2026 May 16
# Former Maintainer: Bram Moolenaar <[email protected]>
# These functions are moved here from runtime/filetype.vim to make startup
@@ -798,9 +798,14 @@ export def FTnroff(): number
enddef
export def FTmm()
+ if exists("g:filetype_mm")
+ exe "setf " .. g:filetype_mm
+ return
+ endif
+
var n = 1
while n < 20
- if getline(n) =~ '^\s*\(#\s*\(include\|import\)\>\|@import\>\|/\*\)'
+ if getline(n) =~ '^\s*\(//\|#\s*\(include\|import\)\>\|@import\>\|/\*\)'
setf objcpp
return
endif
diff --git a/runtime/doc/filetype.txt b/runtime/doc/filetype.txt
index 2c978ebc9..5078913e6 100644
--- a/runtime/doc/filetype.txt
+++ b/runtime/doc/filetype.txt
@@ -1,4 +1,4 @@
-*filetype.txt* For Vim version 9.2. Last change: 2026 Apr 13
+*filetype.txt* For Vim version 9.2. Last change: 2026 May 16
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -164,6 +164,7 @@ variables can be used to overrule the filetype used for
certain extensions:
*.int g:filetype_int
*.lsl g:filetype_lsl
*.m g:filetype_m |ft-mathematica-syntax|
+ *.mm g:filetype_mm
*.mac g:filetype_mac
*[mM]makefile,*.mk,*.mak,[mM]akefile*
g:make_flavor |ft-make-syntax|
diff --git a/src/testdir/test_filetype.vim b/src/testdir/test_filetype.vim
index 5040ac0e6..9aa99a97d 100644
--- a/src/testdir/test_filetype.vim
+++ b/src/testdir/test_filetype.vim
@@ -2068,6 +2068,37 @@ func Test_m4_file()
endtry
endfunc
+func Test_mm_file()
+ filetype on
+
+ call writefile(['#import "test.h"'], 'Xfile.mm', 'D')
+ split Xfile.mm
+ call assert_equal('objcpp', &filetype)
+ bwipe!
+
+ call writefile(['// Objective-C++ line comment'], 'Xfile.mm', 'D')
+ split Xfile.mm
+ call assert_equal('objcpp', &filetype)
+ bwipe!
+
+ call writefile(['.TH VIM 1 "YYYY Mth DD"'], 'Xfile.mm', 'D')
+ split Xfile.mm
+ call assert_equal('nroff', &filetype)
+ bwipe!
+
+ try
+ let g:filetype_mm = 'objcpp'
+ call writefile(['.TH VIM 1 "YYYY Mth DD"'], 'Xfile_override.mm', 'D')
+ split Xfile_override.mm
+ call assert_equal('objcpp', &filetype)
+ bwipe!
+ finally
+ unlet! g:filetype_mm
+ endtry
+
+ filetype off
+endfunc
+
func Test_mod_file()
filetype on
diff --git a/src/version.c b/src/version.c
index 982065514..fb89edd04 100644
--- a/src/version.c
+++ b/src/version.c
@@ -729,6 +729,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 489,
/**/
488,
/**/
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/vim_dev/E1wO9wM-007ZZJ-7j%40256bit.org.