patch 9.1.0616: filetype: Make syntax highlighting off for MS Makefiles

Commit: 
https://github.com/vim/vim/commit/eb4b903c9b238ebcc1d14cfcb207129b4931a33d
Author: Ken Takata <ken...@csc.jp>
Date:   Thu Jul 25 21:07:13 2024 +0200

    patch 9.1.0616: filetype: Make syntax highlighting off for MS Makefiles
    
    Problem:  filetype: Make syntax highlighting off for MS Makefiles
    Solution: Try to detect MS Makefiles and adjust syntax rules to it.
              (Ken Takata)
    
    Highlighting of variable expansion in Microsoft Makefile can be broken.
    E.g.:
    
https://github.com/vim/vim/blob/2979cfc2627d76a9c09cad46a1647dcd4aa73f5f/src/Make_mvc.mak#L1331
    
    Don't use backslash as escape characters if `make_microsoft` is set.
    Also fix that `make_no_comments` was not considered if `make_microsoft`
    was set.
    
    Also add description for `make_microsoft` and `make_no_comments` to the
    documentation and include a very simple filetype test
    
    closes: #15341
    
    Signed-off-by: Christian Brabandt <c...@256bit.org>
    Signed-off-by: Ken Takata <ken...@csc.jp>

diff --git a/runtime/autoload/dist/ft.vim b/runtime/autoload/dist/ft.vim
index be299ef50..e53cdacbe 100644
--- a/runtime/autoload/dist/ft.vim
+++ b/runtime/autoload/dist/ft.vim
@@ -532,6 +532,25 @@ export def FTm()
   endif
 enddef
 
+export def FTmake()
+  # Check if it is a Microsoft Makefile
+  unlet! b:make_microsoft
+  var n = 1
+  while n < 1000 && n <= line('$')
+    var line = getline(n)
+    if line =~? '^\s*!\s*\(ifn\=\(def\)\=\|include\|message\|error\)\>'
+      b:make_microsoft = 1
+      break
+    elseif line =~ '^ *ifn\=\(eq\|def\)\>' || line =~ '^ *[-s]\=include\s'
+      break
+    elseif line =~ '^ *\w\+\s*[!?:+]='
+      break
+    endif
+    n += 1
+  endwhile
+  setf make
+enddef
+
 export def FTmms()
   var n = 1
   while n < 20
diff --git a/runtime/doc/syntax.txt b/runtime/doc/syntax.txt
index f84308218..2f8d9505c 100644
--- a/runtime/doc/syntax.txt
+++ b/runtime/doc/syntax.txt
@@ -1,4 +1,4 @@
-*syntax.txt*   For Vim version 9.1.  Last change: 2024 Jul 23
+*syntax.txt*   For Vim version 9.1.  Last change: 2024 Jul 25
 
 
                  VIM REFERENCE MANUAL    by Bram Moolenaar
@@ -2278,7 +2278,7 @@ By default mail.vim synchronises syntax to 100 lines 
before the first
 displayed line.  If you have a slow machine, and generally deal with emails
 with short headers, you can change this to a smaller value: >
 
-    :let mail_minlines = 30
+       :let mail_minlines = 30
 
 
 MAKE                                           *make.vim* *ft-make-syntax*
@@ -2289,6 +2289,16 @@ feature off by using: >
 
        :let make_no_commands = 1
 
+Comments are also highlighted by default.  You can turn this off by using: >
+
+       :let make_no_comments = 1
+
+Microsoft Makefile handles variable expansion and comments differently
+(backslashes are not used for escape).  If you see any wrong highlights
+because of this, you can try this: >
+
+       :let make_microsoft = 1
+
 
 MAPLE                                          *maple.vim* *ft-maple-syntax*
 
diff --git a/runtime/filetype.vim b/runtime/filetype.vim
index b589a0b78..d02826578 100644
--- a/runtime/filetype.vim
+++ b/runtime/filetype.vim
@@ -1387,7 +1387,7 @@ au BufNewFile,BufRead */etc/mail/aliases,*/etc/aliases    
setf mailaliases
 au BufNewFile,BufRead .mailcap,mailcap         setf mailcap
 
 " Makefile
-au BufNewFile,BufRead *[mM]akefile,*.mk,*.mak  setf make
+au BufNewFile,BufRead *[mM]akefile,*.mk,*.mak  call dist#ft#FTmake()
 au BufNewFile,BufRead Kbuild                   setf make
 
 " MakeIndex
diff --git a/runtime/syntax/make.vim b/runtime/syntax/make.vim
index b4573044c..d3ddf7829 100644
--- a/runtime/syntax/make.vim
+++ b/runtime/syntax/make.vim
@@ -28,8 +28,13 @@ syn match makePreCondit 
"^!\s*\(cmdswitches\|error\|message\|include\|if\|ifdef\
 syn case match
 
 " identifiers
-syn region makeIdent   start="\$(" skip="\)\|\\" end=")" 
contains=makeStatement,makeIdent
-syn region makeIdent   start="\${" skip="\}\|\\" end="}" 
contains=makeStatement,makeIdent
+if exists("b:make_microsoft") || exists("make_microsoft")
+  syn region makeIdent start="\$(" end=")" contains=makeStatement,makeIdent
+  syn region makeIdent start="\${" end="}" contains=makeStatement,makeIdent
+else
+  syn region makeIdent start="\$(" skip="\)\|\\" end=")" 
contains=makeStatement,makeIdent
+  syn region makeIdent start="\${" skip="\}\|\\" end="}" 
contains=makeStatement,makeIdent
+endif
 syn match makeIdent    "\$\$\w*"
 syn match makeIdent    "\$[^({]"
 syn match makeIdent    "^ *[^:#=       ]*\s*[:+?!*]="me=e-2
@@ -78,11 +83,13 @@ syn match makeOverride      "^ *override\>"
 syn match makeStatement contained 
"(\(abspath\|addprefix\|addsuffix\|and\|basename\|call\|dir\|error\|eval\|file\|filter-out\|filter\|findstring\|firstword\|flavor\|foreach\|guile\|if\|info\|join\|lastword\|notdir\|or\|origin\|patsubst\|realpath\|shell\|sort\|strip\|subst\|suffix\|value\|warning\|wildcard\|word\|wordlist\|words\)\>"ms=s+1
 
 " Comment
-if exists("make_microsoft")
-   syn match  makeComment "#.*" contains=@Spell,makeTodo
-elseif !exists("make_no_comments")
-   syn region  makeComment     start="#" end="^$" end="[^\]$" keepend 
contains=@Spell,makeTodo
-   syn match   makeComment     "#$" contains=@Spell
+if !exists("make_no_comments")
+  if exists("b:make_microsoft") || exists("make_microsoft")
+    syn match   makeComment    "#.*" contains=@Spell,makeTodo
+  else
+    syn region  makeComment    start="#" end="^$" end="[^\]$" keepend 
contains=@Spell,makeTodo
+    syn match   makeComment    "#$" contains=@Spell
+  endif
 endif
 syn keyword makeTodo TODO FIXME XXX contained
 
diff --git a/src/testdir/test_filetype.vim b/src/testdir/test_filetype.vim
index cee7c21f3..f8b3ea872 100644
--- a/src/testdir/test_filetype.vim
+++ b/src/testdir/test_filetype.vim
@@ -2646,4 +2646,21 @@ func Test_pl_file()
   filetype off
 endfunc
 
+func Test_make_file()
+  filetype on
+
+  " Microsoft Makefile
+  call writefile(['# Makefile for Windows', '!if "$(VIMDLL)" == "yes"'], 
'XMakefile.mak', 'D')
+  split XMakefile.mak
+  call assert_equal(1, get(b:, 'make_microsoft', 0))
+  bwipe!
+
+  call writefile(['# get the list of tests', 'include testdir/Make_all.mak'], 
'XMakefile.mak', 'D')
+  split XMakefile.mak
+  call assert_equal(0, get(b:, 'make_microsoft', 0))
+  bwipe!
+
+  filetype off
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
diff --git a/src/version.c b/src/version.c
index f434a136b..9ee1592cf 100644
--- a/src/version.c
+++ b/src/version.c
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    616,
 /**/
     615,
 /**/

-- 
-- 
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 vim_dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/E1sX4A8-00AaTy-5N%40256bit.org.

Raspunde prin e-mail lui