mirror of
https://github.com/neovim/neovim.git
synced 2024-12-19 10:45:16 -07:00
vim-patch:9.1.0616: filetype: Make syntax highlighting off for MS Makefiles (#29874)
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.:2979cfc262/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: vim/vim#15341eb4b903c9b
Co-authored-by: Ken Takata <kentkt@csc.jp>
This commit is contained in:
parent
aa853f362a
commit
60967cd9aa
@ -1806,7 +1806,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
|
displayed line. If you have a slow machine, and generally deal with emails
|
||||||
with short headers, you can change this to a smaller value: >
|
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*
|
MAKE *make.vim* *ft-make-syntax*
|
||||||
@ -1817,6 +1817,16 @@ feature off by using: >
|
|||||||
|
|
||||||
:let make_no_commands = 1
|
: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*
|
MAPLE *maple.vim* *ft-maple-syntax*
|
||||||
|
|
||||||
|
@ -693,8 +693,8 @@ local extension = {
|
|||||||
return not (path:find('html%.m4$') or path:find('fvwm2rc')) and 'm4' or nil
|
return not (path:find('html%.m4$') or path:find('fvwm2rc')) and 'm4' or nil
|
||||||
end,
|
end,
|
||||||
eml = 'mail',
|
eml = 'mail',
|
||||||
mk = 'make',
|
mk = detect.make,
|
||||||
mak = 'make',
|
mak = detect.make,
|
||||||
page = 'mallard',
|
page = 'mallard',
|
||||||
map = 'map',
|
map = 'map',
|
||||||
mws = 'maple',
|
mws = 'maple',
|
||||||
@ -2122,7 +2122,7 @@ local pattern = {
|
|||||||
['^Containerfile%.'] = starsetf('dockerfile'),
|
['^Containerfile%.'] = starsetf('dockerfile'),
|
||||||
['^Dockerfile%.'] = starsetf('dockerfile'),
|
['^Dockerfile%.'] = starsetf('dockerfile'),
|
||||||
['^[jJ]ustfile$'] = 'just',
|
['^[jJ]ustfile$'] = 'just',
|
||||||
['[mM]akefile$'] = 'make',
|
['[mM]akefile$'] = detect.make,
|
||||||
['^[mM]akefile'] = starsetf('make'),
|
['^[mM]akefile'] = starsetf('make'),
|
||||||
['^[rR]akefile$'] = 'ruby',
|
['^[rR]akefile$'] = 'ruby',
|
||||||
['^[rR]akefile'] = starsetf('ruby'),
|
['^[rR]akefile'] = starsetf('ruby'),
|
||||||
|
@ -972,6 +972,24 @@ local function m4(contents)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Check if it is a Microsoft Makefile
|
||||||
|
--- @type vim.filetype.mapfn
|
||||||
|
function M.make(_, bufnr)
|
||||||
|
vim.b.make_microsoft = nil
|
||||||
|
for _, line in ipairs(getlines(bufnr, 1, 1000)) do
|
||||||
|
if matchregex(line, [[\c^\s*!\s*\(ifn\=\(def\)\=\|include\|message\|error\)\>]]) then
|
||||||
|
vim.b.make_microsoft = 1
|
||||||
|
break
|
||||||
|
elseif
|
||||||
|
matchregex(line, [[^ *ifn\=\(eq\|def\)\>]])
|
||||||
|
or findany(line, { '^ *[-s]?%s', '^ *%w+%s*[!?:+]=' })
|
||||||
|
then
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return 'make'
|
||||||
|
end
|
||||||
|
|
||||||
--- @type vim.filetype.mapfn
|
--- @type vim.filetype.mapfn
|
||||||
function M.markdown(_, _)
|
function M.markdown(_, _)
|
||||||
return vim.g.filetype_md or 'markdown'
|
return vim.g.filetype_md or 'markdown'
|
||||||
|
@ -28,8 +28,13 @@ syn match makePreCondit "^!\s*\(cmdswitches\|error\|message\|include\|if\|ifdef\
|
|||||||
syn case match
|
syn case match
|
||||||
|
|
||||||
" identifiers
|
" identifiers
|
||||||
syn region makeIdent start="\$(" skip="\\)\|\\\\" end=")" contains=makeStatement,makeIdent
|
if exists("b:make_microsoft") || exists("make_microsoft")
|
||||||
syn region makeIdent start="\${" skip="\\}\|\\\\" end="}" contains=makeStatement,makeIdent
|
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 "\$\$\w*"
|
||||||
syn match makeIdent "\$[^({]"
|
syn match makeIdent "\$[^({]"
|
||||||
syn match makeIdent "^ *[^:#= \t]*\s*[:+?!*]="me=e-2
|
syn match makeIdent "^ *[^:#= \t]*\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
|
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
|
" Comment
|
||||||
if exists("make_microsoft")
|
if !exists("make_no_comments")
|
||||||
syn match makeComment "#.*" contains=@Spell,makeTodo
|
if exists("b:make_microsoft") || exists("make_microsoft")
|
||||||
elseif !exists("make_no_comments")
|
syn match makeComment "#.*" contains=@Spell,makeTodo
|
||||||
syn region makeComment start="#" end="^$" end="[^\\]$" keepend contains=@Spell,makeTodo
|
else
|
||||||
syn match makeComment "#$" contains=@Spell
|
syn region makeComment start="#" end="^$" end="[^\\]$" keepend contains=@Spell,makeTodo
|
||||||
|
syn match makeComment "#$" contains=@Spell
|
||||||
|
endif
|
||||||
endif
|
endif
|
||||||
syn keyword makeTodo TODO FIXME XXX contained
|
syn keyword makeTodo TODO FIXME XXX contained
|
||||||
|
|
||||||
|
@ -2641,4 +2641,21 @@ func Test_pl_file()
|
|||||||
filetype off
|
filetype off
|
||||||
endfunc
|
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
|
" vim: shiftwidth=2 sts=2 expandtab
|
||||||
|
Loading…
Reference in New Issue
Block a user