aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--runtime/lua/vim/filetype.lua8
-rw-r--r--test/old/testdir/test_filetype.vim19
2 files changed, 24 insertions, 3 deletions
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'),
diff --git a/test/old/testdir/test_filetype.vim b/test/old/testdir/test_filetype.vim
index 296062f92c..0355956447 100644
--- 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,23 @@ func Test_haredoc_file()
filetype off
endfunc
+func Test_help_file()
+ 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'], 'doc/nothelp.txt', 'D')
+ split doc/nothelp.txt
+ call assert_notequal('help', &filetype)
+ bwipe!
+
+ filetype off
+endfunc
+
func Test_hook_file()
filetype on