]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.1304: filetype: some man files are not recognized v9.1.1304
authorEisuke Kawashima <e-kwsm@users.noreply.github.com>
Tue, 15 Apr 2025 16:30:05 +0000 (18:30 +0200)
committerChristian Brabandt <cb@256bit.org>
Tue, 15 Apr 2025 16:30:05 +0000 (18:30 +0200)
Problem:  filetype: some man files are not recognized
          (e.g. 1p (POSIX commands))
Solution: update the filetype detection pattern and detect more man
          files as nroff (Eisuke Kawashima)

- sections are revised referring to
    - debian-12:/etc/manpath.config
    - fedora-41:/etc/man_db.conf
- detection logic is improved
- detection test is implemented

closes: #17117

Signed-off-by: Eisuke Kawashima <e-kwsm@users.noreply.github.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
runtime/autoload/dist/ft.vim
runtime/filetype.vim
src/testdir/test_filetype.vim
src/version.c

index 4053e51f0061cd90e13f88ecb3a5f17a08621f61..25c7f571ab3473bf4f60eb4e476ac860e919660b 100644 (file)
@@ -3,7 +3,7 @@ vim9script
 # 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
@@ -595,11 +595,15 @@ enddef
 # 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
 
index 35726a78880907366753631e354cb2a2ff0a302f..573d2f3139171d45b1edcc85f586f4ed39fd4571 100644 (file)
@@ -1,7 +1,7 @@
 " 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
@@ -1726,7 +1726,7 @@ au BufNewFile,BufRead *.me
        \   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()
index a56e1ac027e2ca6ace3e478ba12b67a2a59e51cb..98dba23ebcd1e6d1edc9509a404a095209fc237d 100644 (file)
@@ -2889,6 +2889,20 @@ func Test_map_file()
   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
 
index e2314ca12fb9b4961c1548db763405a0ed72249e..30904d7c06000d8a57e9859faa4170c66ed73146 100644 (file)
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1304,
 /**/
     1303,
 /**/