# Vim functions for file type detection
#
# Maintainer: The Vim Project <https://github.com/vim/vim>
-# Last Change: 2025 Apr 10
+# Last Change: 2025 Apr 15
# Former Maintainer: Bram Moolenaar <Bram@vim.org>
# These functions are moved here from runtime/filetype.vim to make startup
# This function checks if one of the first five lines start with a dot. In
# that case it is probably an nroff file: 'filetype' is set and 1 is returned.
export def FTnroff(): number
- if getline(1)[0] .. getline(2)[0] .. getline(3)[0]
- .. getline(4)[0] .. getline(5)[0] =~ '\.'
- setf nroff
- return 1
- endif
+ var n = 1
+ while n < 5
+ var line = getline(n)
+ if line =~ '^\.\S\S\?'
+ setf nroff
+ return 1
+ endif
+ n += 1
+ endwhile
return 0
enddef
" Vim support file to detect file types
"
" Maintainer: The Vim Project <https://github.com/vim/vim>
-" Last Change: 2025 Apr 13
+" Last Change: 2025 Apr 15
" Former Maintainer: Bram Moolenaar <Bram@vim.org>
" Listen very carefully, I will say this only once
\ setf nroff |
\ endif
au BufNewFile,BufRead *.tr,*.nr,*.roff,*.tmac,*.mom setf nroff
-au BufNewFile,BufRead *.[1-9] call dist#ft#FTnroff()
+au BufNewFile,BufRead *.[0-9],*.[013]p,*.[1-8]x,*.3{am,perl,pm,posix,type},*.[nlop] call dist#ft#FTnroff()
" Nroff or Objective C++
au BufNewFile,BufRead *.mm call dist#ft#FTmm()
filetype off
endfunc
+func Test_nroff_file()
+ filetype on
+
+ call writefile(['.TH vim 1 "YYYY Mth DD"'], 'Xfile.1', 'D')
+ split Xfile.1
+ call assert_equal('nroff', &filetype)
+ bwipe!
+
+ call writefile(['. /etc/profile'], 'Xfile.1', 'D')
+ split Xfile.1
+ call assert_notequal('nroff', &filetype)
+ bwipe!
+endfunc
+
func Test_org_file()
filetype on
static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 1304,
/**/
1303,
/**/