aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/filetype
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/lua/vim/filetype')
-rw-r--r--runtime/lua/vim/filetype/detect.lua127
1 files changed, 110 insertions, 17 deletions
diff --git a/runtime/lua/vim/filetype/detect.lua b/runtime/lua/vim/filetype/detect.lua
index ba86d8de5a..1cc81b177f 100644
--- a/runtime/lua/vim/filetype/detect.lua
+++ b/runtime/lua/vim/filetype/detect.lua
@@ -450,7 +450,7 @@ local function modula2(bufnr)
return 'modula2',
function(b)
- vim.api.nvim_buf_call(b, function()
+ vim._with({ buf = b }, function()
fn['modula2#SetDialect'](dialect, extension)
end)
end
@@ -472,6 +472,41 @@ function M.def(_, bufnr)
end
--- @type vim.filetype.mapfn
+function M.dsp(path, bufnr)
+ if vim.g.filetype_dsp then
+ return vim.g.filetype_dsp
+ end
+
+ -- Test the filename
+ local file_name = fn.fnamemodify(path, ':t')
+ if file_name:find('^[mM]akefile.*$') then
+ return 'make'
+ end
+
+ -- Test the file contents
+ for _, line in ipairs(getlines(bufnr, 1, 200)) do
+ if
+ findany(line, {
+ -- Check for comment style
+ [[#.*]],
+ -- Check for common lines
+ [[^.*Microsoft Developer Studio Project File.*$]],
+ [[^!MESSAGE This is not a valid makefile\..+$]],
+ -- Check for keywords
+ [[^!(IF,ELSEIF,ENDIF).*$]],
+ -- Check for common assignments
+ [[^SOURCE=.*$]],
+ })
+ then
+ return 'make'
+ end
+ end
+
+ -- Otherwise, assume we have a Faust file
+ return 'faust'
+end
+
+--- @type vim.filetype.mapfn
function M.e(_, bufnr)
if vim.g.filetype_euphoria then
return vim.g.filetype_euphoria
@@ -594,7 +629,7 @@ function M.frm(_, bufnr)
end
--- @type vim.filetype.mapfn
-function M.fvwm_1(_, _)
+function M.fvwm_v1(_, _)
return 'fvwm', function(bufnr)
vim.b[bufnr].fvwm_version = 1
end
@@ -650,13 +685,58 @@ function M.header(_, bufnr)
end
end
+--- Recursively search for Hare source files in a directory and any
+--- subdirectories, up to a given depth.
+--- @param dir string
+--- @param depth number
+--- @return boolean
+local function is_hare_module(dir, depth)
+ depth = math.max(depth, 0)
+ for name, _ in vim.fs.dir(dir, { depth = depth + 1 }) do
+ if name:find('%.ha$') then
+ return true
+ end
+ end
+ return false
+end
+
+--- @type vim.filetype.mapfn
+function M.haredoc(path, _)
+ if vim.g.filetype_haredoc then
+ if is_hare_module(vim.fs.dirname(path), vim.g.haredoc_search_depth or 1) then
+ return 'haredoc'
+ end
+ end
+end
+
--- @type vim.filetype.mapfn
function M.html(_, bufnr)
- for _, line in ipairs(getlines(bufnr, 1, 10)) do
- if matchregex(line, [[\<DTD\s\+XHTML\s]]) then
+ -- Disabled for the reasons mentioned here:
+ -- https://github.com/vim/vim/pull/13594#issuecomment-1834465890
+ -- local filename = fn.fnamemodify(path, ':t')
+ -- if filename:find('%.component%.html$') then
+ -- return 'htmlangular'
+ -- end
+
+ for _, line in ipairs(getlines(bufnr, 1, 40)) do
+ if
+ matchregex(
+ line,
+ [[@\(if\|for\|defer\|switch\)\|\*\(ngIf\|ngFor\|ngSwitch\|ngTemplateOutlet\)\|ng-template\|ng-content\|{{.*}}]]
+ )
+ then
+ return 'htmlangular'
+ elseif matchregex(line, [[\<DTD\s\+XHTML\s]]) then
return 'xhtml'
- elseif matchregex(line, [[\c{%\s*\(extends\|block\|load\)\>\|{#\s\+]]) then
+ elseif
+ matchregex(
+ line,
+ [[\c{%\s*\(autoescape\|block\|comment\|csrf_token\|cycle\|debug\|extends\|filter\|firstof\|for\|if\|ifchanged\|include\|load\|lorem\|now\|query_string\|regroup\|resetcycle\|spaceless\|templatetag\|url\|verbatim\|widthratio\|with\)\>\|{#\s\+]]
+ )
+ then
return 'htmldjango'
+ elseif findany(line, { '<extend', '<super>' }) then
+ return 'superhtml'
end
end
return 'html'
@@ -894,6 +974,24 @@ local function m4(contents)
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
function M.markdown(_, _)
return vim.g.filetype_md or 'markdown'
@@ -1038,6 +1136,8 @@ function M.perl(path, bufnr)
end
end
+local prolog_patterns = { '^%s*:%-', '^%s*%%+%s', '^%s*%%+$', '^%s*/%*', '%.%s*$' }
+
--- @type vim.filetype.mapfn
function M.pl(_, bufnr)
if vim.g.filetype_pl then
@@ -1046,11 +1146,7 @@ function M.pl(_, bufnr)
-- Recognize Prolog by specific text in the first non-empty line;
-- require a blank after the '%' because Perl uses "%list" and "%translate"
local line = nextnonblank(bufnr, 1)
- if
- line and line:find(':%-')
- or matchregex(line, [[\c\<prolog\>]])
- or findany(line, { '^%s*%%+%s', '^%s*%%+$', '^%s*/%*' })
- then
+ if line and matchregex(line, [[\c\<prolog\>]]) or findany(line, prolog_patterns) then
return 'prolog'
else
return 'perl'
@@ -1154,11 +1250,7 @@ function M.proto(_, bufnr)
-- Recognize Prolog by specific text in the first non-empty line;
-- require a blank after the '%' because Perl uses "%list" and "%translate"
local line = nextnonblank(bufnr, 1)
- if
- line and line:find(':%-')
- or matchregex(line, [[\c\<prolog\>]])
- or findany(line, { '^%s*%%+%s', '^%s*%%+$', '^%s*/%*' })
- then
+ if line and matchregex(line, [[\c\<prolog\>]]) or findany(line, prolog_patterns) then
return 'prolog'
end
end
@@ -1331,7 +1423,7 @@ end
function M.sgml(_, bufnr)
local lines = table.concat(getlines(bufnr, 1, 5))
if lines:find('linuxdoc') then
- return 'smgllnx'
+ return 'sgmllnx'
elseif lines:find('<!DOCTYPE.*DocBook') then
return 'docbk',
function(b)
@@ -1533,7 +1625,7 @@ function M.tex(path, bufnr)
end
end
--- Determine if a *.tf file is TF mud client or terraform
+-- Determine if a *.tf file is TF (TinyFugue) mud client or terraform
--- @type vim.filetype.mapfn
function M.tf(_, bufnr)
for _, line in ipairs(getlines(bufnr)) do
@@ -1759,6 +1851,7 @@ local patterns_hashbang = {
['^janet\\>'] = { 'janet', { vim_regex = true } },
['^dart\\>'] = { 'dart', { vim_regex = true } },
['^execlineb\\>'] = { 'execline', { vim_regex = true } },
+ ['^vim\\>'] = { 'vim', { vim_regex = true } },
}
---@private