aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/lua/vim')
-rw-r--r--runtime/lua/vim/filetype.lua2
-rw-r--r--runtime/lua/vim/filetype/detect.lua24
2 files changed, 25 insertions, 1 deletions
diff --git a/runtime/lua/vim/filetype.lua b/runtime/lua/vim/filetype.lua
index d1fdd0aa16..2ab6cc6059 100644
--- a/runtime/lua/vim/filetype.lua
+++ b/runtime/lua/vim/filetype.lua
@@ -1637,7 +1637,7 @@ local filename = {
['.xsdbcmdhistory'] = 'tcl',
['texmf.cnf'] = 'texmf',
COPYING = 'text',
- README = 'text',
+ README = detect_seq(detect.haredoc, 'text'),
LICENSE = 'text',
AUTHORS = 'text',
tfrc = 'tf',
diff --git a/runtime/lua/vim/filetype/detect.lua b/runtime/lua/vim/filetype/detect.lua
index ba86d8de5a..58d2666564 100644
--- a/runtime/lua/vim/filetype/detect.lua
+++ b/runtime/lua/vim/filetype/detect.lua
@@ -650,6 +650,30 @@ 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