neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

commit 0ef1147313caa47c87c7baa79043ddcff55ef5e1
parent f2c0755828d529af101b5d0e4a1fd204fd0a7039
Author: zeertzjq <zeertzjq@outlook.com>
Date:   Tue, 11 Mar 2025 06:48:17 +0800

Merge pull request #32828 from zeertzjq/vim-9.1.1186

vim-patch:9.1.{1186,1191,1194}: filetype: help files in git repos are not detected
Diffstat:
Mruntime/doc/insert.txt | 2+-
Mruntime/lua/vim/filetype.lua | 8+++++++-
Mtest/old/testdir/test_filetype.vim | 32++++++++++++++++++++++++++++++--
3 files changed, 38 insertions(+), 4 deletions(-)

diff --git a/runtime/doc/insert.txt b/runtime/doc/insert.txt @@ -643,7 +643,7 @@ Also see the 'infercase' option if you want to adjust the case of the match. When inserting a selected candidate word from the |popup-menu|, the part of the candidate word that does not match the query is highlighted using -|hl-ComplMatchIns|. If fuzzy is enabled in 'completeopt', highlighting will +|hl-ComplMatchIns|. If fuzzy is enabled in 'completeopt', highlighting will not be applied. *complete_CTRL-E* diff --git 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:') or line:find('%svim:') + 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'), diff --git a/test/old/testdir/test_filetype.vim b/test/old/testdir/test_filetype.vim @@ -916,8 +916,6 @@ func s:GetFilenameChecks() abort \ '.zcompdump', '.zlogin', '.zlogout', '.zshenv', '.zshrc', '.zsh_history', \ '.zcompdump-file', '.zlog', '.zlog-file', '.zsh', '.zsh-file', \ 'any/etc/zprofile', 'zlog', 'zlog-file', 'zsh', 'zsh-file'], - \ - \ 'help': [$VIMRUNTIME .. '/doc/help.txt'], \ } endfunc @@ -1620,6 +1618,36 @@ func Test_haredoc_file() filetype off endfunc +func Test_help_file() + set nomodeline + filetype on + call assert_true(mkdir('doc', 'pR')) + + call writefile(['some text', 'vim:ft=help:'], 'doc/help.txt', 'D') + split doc/help.txt + call assert_equal('help', &filetype) + bwipe! + + call writefile(['some text', 'Copyright: |manual-copyright| vim:ft=help:'], + \ 'doc/help1.txt', 'D') + split doc/help1.txt + call assert_equal('help', &filetype) + bwipe! + + call writefile(['some text'], 'doc/nothelp.txt', 'D') + split doc/nothelp.txt + call assert_notequal('help', &filetype) + bwipe! + + call writefile(['some text', '`vim:ft=help`'], 'doc/nothelp1.txt', 'D') + split doc/nothelp1.txt + call assert_notequal('help', &filetype) + bwipe! + + filetype off + set modeline& +endfunc + func Test_hook_file() filetype on