Skip to content

Commit 6763b0e

Browse files
zeertzjqchrisbra
authored andcommitted
patch 9.1.1194: filetype: false positive help filetype detection
Problem: filetype: false positive help filetype detection Solution: Only detect a file as help if modeline appears either at start of line or is preceded by whitespace (zeertzjq). closes: #16845 Signed-off-by: zeertzjq <zeertzjq@outlook.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
1 parent c262382 commit 6763b0e

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

runtime/filetype.vim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
" Vim support file to detect file types
22
"
33
" Maintainer: The Vim Project <https://github.com/vim/vim>
4-
" Last Change: 2025 Mar 08
4+
" Last Change: 2025 Mar 10
55
" Former Maintainer: Bram Moolenaar <Bram@vim.org>
66

77
" Listen very carefully, I will say this only once
@@ -53,7 +53,7 @@ endfunc
5353

5454
" Vim help file, set ft explicitly, because 'modeline' might be off
5555
au BufNewFile,BufRead */doc/*.txt
56-
\ if getline('$') =~ 'vim:.*\<\(ft\|filetype\)=help\>'
56+
\ if getline('$') =~ '\(^\|\s\)vim:.*\<\(ft\|filetype\)=help\>'
5757
\| setf help
5858
\| endif
5959

src/testdir/test_filetype.vim

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1634,11 +1634,22 @@ func Test_help_file()
16341634
call assert_equal('help', &filetype)
16351635
bwipe!
16361636

1637+
call writefile(['some text', 'Copyright: |manual-copyright| vim:ft=help:'],
1638+
\ 'doc/help1.txt', 'D')
1639+
split doc/help1.txt
1640+
call assert_equal('help', &filetype)
1641+
bwipe!
1642+
16371643
call writefile(['some text'], 'doc/nothelp.txt', 'D')
16381644
split doc/nothelp.txt
16391645
call assert_notequal('help', &filetype)
16401646
bwipe!
16411647

1648+
call writefile(['some text', '`vim:ft=help`'], 'doc/nothelp1.txt', 'D')
1649+
split doc/nothelp1.txt
1650+
call assert_notequal('help', &filetype)
1651+
bwipe!
1652+
16421653
filetype off
16431654
set modeline&
16441655
endfunc

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,8 @@ static char *(features[]) =
704704

705705
static int included_patches[] =
706706
{ /* Add new patch number below this line */
707+
/**/
708+
1194,
707709
/**/
708710
1193,
709711
/**/

0 commit comments

Comments
 (0)