]> granicus.if.org Git - vim/commitdiff
patch 8.1.1593: filetype not detected for C++ header files without extension v8.1.1593
authorBram Moolenaar <Bram@vim.org>
Tue, 25 Jun 2019 19:34:26 +0000 (21:34 +0200)
committerBram Moolenaar <Bram@vim.org>
Tue, 25 Jun 2019 19:34:26 +0000 (21:34 +0200)
Problem:    Filetype not detected for C++ header files without extension.
Solution:   Recognize the file by the Emacs file mode. (Dmitry Ilyin,
            closes #4593)

runtime/scripts.vim
src/testdir/test_filetype.vim
src/version.c

index ab66c0c0a12b735a6637bd3053668f5d94f90686..8d460cd317a5cf7bc7569a7e720a09f8f8281411 100644 (file)
@@ -195,7 +195,7 @@ else
   if s:line1 =~# '^:$'
     call dist#ft#SetFileTypeSH(s:line1)        " defined in filetype.vim
 
-    " Z shell scripts
+  " Z shell scripts
   elseif s:line1 =~# '^#compdef\>' || s:line1 =~# '^#autoload\>' ||
         \ "\n".s:line1."\n".s:line2."\n".s:line3."\n".s:line4."\n".s:line5 =~# '\n\s*emulate\s\+\%(-[LR]\s\+\)\=[ckz]\=sh\>'
     set ft=zsh
@@ -204,15 +204,20 @@ else
   elseif s:line1 =~# '^From \([a-zA-Z][a-zA-Z_0-9\.=-]*\(@[^ ]*\)\=\|-\) .* \(19\|20\)\d\d$'
     set ft=mail
 
-    " Mason
+  " Mason
   elseif s:line1 =~# '^<[%&].*>'
     set ft=mason
 
-    " Vim scripts (must have '" vim' as the first line to trigger this)
+  " Vim scripts (must have '" vim' as the first line to trigger this)
   elseif s:line1 =~# '^" *[vV]im$'
     set ft=vim
 
-    " MOO
+  " libcxx and libstdc++ standard library headers like "iostream" do not have
+  " an extension, recognize the Emacs file mode.
+  elseif s:line1 =~? '-\*-.*C++.*-\*-'
+    set ft=cpp
+
+  " MOO
   elseif s:line1 =~# '^\*\* LambdaMOO Database, Format Version \%([1-3]\>\)\@!\d\+ \*\*$'
     set ft=moo
 
index 95fb62e71228868bc28e8d9cd2544a35625dc42c..37d8ceda9216830696e5a7e8b0e5e3f73c88d645 100644 (file)
@@ -586,6 +586,8 @@ let s:script_checks = {
       \ 'cfengine': [['#!/path/cfengine']],
       \ 'erlang': [['#!/path/escript']],
       \ 'haskell': [['#!/path/haskell']],
+      \ 'cpp': [['// Standard iostream objects -*- C++ -*-'],
+      \         ['// -*- C++ -*-']],
       \ }
 
 func Test_script_detection()
index 5514b4b9c96f62cc435a3450aaf224a289663add..c25c1ff10c5001ba323075467619b3d685ceefad 100644 (file)
@@ -777,6 +777,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1593,
 /**/
     1592,
 /**/