From 638b3c0717219ce152cbd255cbc878aa1b34ab95 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 11 Mar 2025 06:13:31 +0800 Subject: vim-patch:9.1.1186: filetype: help files in git repos are not detected Problem: filetype: help files in git repos are not detected Solution: detect */doc/*.txt files as help if they end with a help modeline, even if 'modeline' is off Here's how I checked that this would still detect vim's own help files correctly: $ find . -type f -path '*/doc/*.txt' \ > -exec awk '{ } ENDFILE { print FILENAME ":" $0; }' '{}' + | > grep -v 'vim:.*\<\(ft\|filetype\)=help\>' ./src/libvterm/doc/seqs.txt: 23 DECSM 42 = DECNRCM, national/multinational character closes: vim/vim#16817 https://github.com/vim/vim/commit/16d6fff98ed3a9dfd34a41696b005b0c4c7800f8 Split the pattern into a Lua pattern for the first part and a Vim regex pattern for the second part, so that if the first part doesn't match there is no need to use the Vim regex. Co-authored-by: David Mandelberg --- runtime/lua/vim/filetype.lua | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'runtime') diff --git a/runtime/lua/vim/filetype.lua b/runtime/lua/vim/filetype.lua index 2c058bc6bf..4c6b3b108f 100644 --- a/runtime/lua/vim/filetype.lua +++ b/runtime/lua/vim/filetype.lua @@ -2415,7 +2415,13 @@ local pattern = { ['/boot/grub/menu%.lst$'] = 'grub', -- gtkrc* and .gtkrc* ['^%.?gtkrc'] = starsetf('gtkrc'), - ['^${VIMRUNTIME}/doc/.*%.txt$'] = 'help', + ['/doc/.*%.txt$'] = function(_, bufnr) + local line = M._getline(bufnr, -1) + local ml = line:find('vim:') + if ml and M._matchregex(line:sub(ml), [[\<\(ft\|filetype\)=help\>]]) then + return 'help' + end + end, ['^hg%-editor%-.*%.txt$'] = 'hgcommit', ['%.html%.m4$'] = 'htmlm4', ['^JAM.*%.'] = starsetf('jam'), -- cgit