patch 9.1.1327: filetype: nroff detection can be improved

Commit: 
https://github.com/vim/vim/commit/2cb42efc18e46402ac84fd51afe54bb48be8aea7
Author: Eisuke Kawashima <e-k...@users.noreply.github.com>
Date:   Mon Apr 21 10:51:05 2025 +0200

    patch 9.1.1327: filetype: nroff detection can be improved
    
    Problem:  filetype: nroff detection can be improved
    Solution: improve nroff detection (Eisuke Kawashima)
    
    - explicitly check roff comments and macros typically found in manpages
    - do not try to detect alphabetically-sectioned files, except for n, as
      nroff
        - l: > 'l' happens to be a section for historical reasons
             <https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=391977>
        - n: e.g. /usr/share/man/mann/Tcl.n.gz
        - o: unsure (perhaps fedora-specific)
        - p: unsure (perhaps fedora-specific)
    
    closes: #17160
    
    Signed-off-by: Eisuke Kawashima <e-k...@users.noreply.github.com>
    Signed-off-by: Christian Brabandt <c...@256bit.org>

diff --git a/runtime/autoload/dist/ft.vim b/runtime/autoload/dist/ft.vim
index 0c0b872f6..95135c8b8 100644
--- a/runtime/autoload/dist/ft.vim
+++ b/runtime/autoload/dist/ft.vim
@@ -3,7 +3,7 @@ vim9script
 # Vim functions for file type detection
 #
 # Maintainer:          The Vim Project <https://github.com/vim/vim>
-# Last Change:         2025 Apr 19
+# Last Change:         2025 Apr 21
 # Former Maintainer:   Bram Moolenaar <b...@vim.org>
 
 # These functions are moved here from runtime/filetype.vim to make startup
@@ -639,13 +639,14 @@ export def FTmms()
   setf mmix
 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.
+# This function checks if one of the first five lines start with a typical
+# nroff pattern in man files.  In that case it is probably an nroff file:
+# 'filetype' is set and 1 is returned.
 export def FTnroff(): number
   var n = 1
-  while n < 5
+  while n <= 5
     var line = getline(n)
-    if line =~ '^\.\S\S\?'
+    if line =~ 
'^\%([.'']\s*\%(TH\|D[dt]\|S[Hh]\|d[es]1\?\|so\)\s\+\S\|[.'']\s*ig\>\|\%([.'']\s*\)\?\"\)'
       setf nroff
       return 1
     endif
diff --git a/runtime/filetype.vim b/runtime/filetype.vim
index da74e25c0..98e64a9f3 100644
--- a/runtime/filetype.vim
+++ b/runtime/filetype.vim
@@ -1,7 +1,7 @@
 " Vim support file to detect file types
 "
 " Maintainer:  The Vim Project <https://github.com/vim/vim>
-" Last Change: 2025 Apr 19
+" Last Change: 2025 Apr 21
 " Former Maintainer:   Bram Moolenaar <b...@vim.org>
 
 " Listen very carefully, I will say this only once
@@ -1728,7 +1728,7 @@ au BufNewFile,BufRead *.me
        \   setf nroff |
        \ endif
 au BufNewFile,BufRead *.tr,*.nr,*.roff,*.tmac,*.mom    setf nroff
-au BufNewFile,BufRead 
*.[0-9],*.[013]p,*.[1-8]x,*.3{am,perl,pm,posix,type},*.[nlop]    call 
dist#ft#FTnroff()
+au BufNewFile,BufRead *.[0-9],*.[013]p,*.[1-8]x,*.3{am,perl,pm,posix,type},*.n 
call dist#ft#FTnroff()
 
 " Nroff or Objective C++
 au BufNewFile,BufRead *.mm                     call dist#ft#FTmm()
diff --git a/src/testdir/test_filetype.vim b/src/testdir/test_filetype.vim
index d241276f6..a7bb8bf7d 100644
--- a/src/testdir/test_filetype.vim
+++ b/src/testdir/test_filetype.vim
@@ -2955,11 +2955,21 @@ endfunc
 func Test_nroff_file()
   filetype on
 
-  call writefile(['.TH vim 1 "YYYY Mth DD"'], 'Xfile.1', 'D')
+  call writefile(['.TH VIM 1 "YYYY Mth DD"'], 'Xfile.1', 'D')
   split Xfile.1
   call assert_equal('nroff', &filetype)
   bwipe!
 
+  call writefile(['.Dd $Mdocdate$', '.Dt "DETECTION TEST" "7"', '.Os'], 
'Xfile.7', 'D')
+  split Xfile.7
+  call assert_equal('nroff', &filetype)
+  bwipe!
+
+  call writefile(['''\" t'], 'Xfile.3p', 'D')
+  split Xfile.3p
+  call assert_equal('nroff', &filetype)
+  bwipe!
+
   call writefile(['. /etc/profile'], 'Xfile.1', 'D')
   split Xfile.1
   call assert_notequal('nroff', &filetype)
diff --git a/src/version.c b/src/version.c
index 3b90185c5..36e94bc28 100644
--- a/src/version.c
+++ b/src/version.c
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1327,
 /**/
     1326,
 /**/

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
To view this discussion visit 
https://groups.google.com/d/msgid/vim_dev/E1u6n0V-00GDhD-MS%40256bit.org.

Raspunde prin e-mail lui