runtime(dist/ft): improve filetype detection for *.v (V/Verilog/Coq)

Commit: 
https://github.com/vim/vim/commit/10b4f75d4c03c1cd4f579be5fdc812ba41b72fef
Author: Christian Brabandt <[email protected]>
Date:   Mon Jan 1 19:19:20 2024 +0100

    runtime(dist/ft): improve filetype detection for *.v (V/Verilog/Coq)
    
    Patch provided by Dan Alt
    
    closes: #13793
    
    Signed-off-by: Christian Brabandt <[email protected]>

diff --git a/runtime/autoload/dist/ft.vim b/runtime/autoload/dist/ft.vim
index 53c56f6b5..2423fd446 100644
--- a/runtime/autoload/dist/ft.vim
+++ b/runtime/autoload/dist/ft.vim
@@ -1186,26 +1186,46 @@ export def FTv()
     # ":setf" will do nothing, bail out early
     return
   endif
+  if exists("g:filetype_v")
+    exe "setf " .. g:filetype_v
+    return
+  endif
 
-  for line in getline(1, 200)
-    if line[0] =~ '^\s*/'
+  var in_comment = 0
+  for lnum in range(1, min([line("$"), 200]))
+    var line = getline(lnum)
+    # Skip Verilog and V comments (lines and blocks).
+    if line =~ '^\s*/\*'
+      # start comment block
+      in_comment = 1
+    endif
+    if in_comment == 1
+      if line =~ '\*/'
+        # end comment block
+        in_comment = 0
+      endif
+      # skip comment-block line
+      continue
+    endif
+    if line =~ '^\s*//'
       # skip comment line
       continue
     endif
 
-    # Verilog: line ends with ';' followed by an optional variable number of
-    # spaces and an optional start of a comment.
-    # Example: " b <= a + 1; // Add 1".
-    if line =~ ';\(\s*\)\?\(/.*\)\?$'
-      setf verilog
+    # Coq: line ends with a '.' followed by an optional variable number of
+    # spaces or contains the start of a comment, but not inside a Verilog or V
+    # comment.
+    # Example: "Definition x := 10. (*".
+    if (line =~ '\.\s*$' && line !~ '/[/*]') || (line =~ '(\*' && line !~ 
'/[/*].*(\*')
+      setf coq
       return
     endif
 
-    # Coq: line ends with a '.' followed by an optional variable number of
+    # Verilog: line ends with ';' followed by an optional variable number of
     # spaces and an optional start of a comment.
-    # Example: "Definition x := 10. (*".
-    if line =~ '\.\(\s*\)\?\((\*.*\)\?$'
-      setf coq
+    # Example: " b <= a + 1; // Add 1".
+    if line =~ ';\s*\(/[/*].*\)\?$'
+      setf verilog
       return
     endif
   endfor
diff --git a/runtime/doc/filetype.txt b/runtime/doc/filetype.txt
index deb947cf1..597141d49 100644
--- a/runtime/doc/filetype.txt
+++ b/runtime/doc/filetype.txt
@@ -1,4 +1,4 @@
-*filetype.txt*  For Vim version 9.0.  Last change: 2023 Dec 23
+*filetype.txt*  For Vim version 9.0.  Last change: 2024 Jan 01
 
 
                  VIM REFERENCE MANUAL    by Bram Moolenaar
@@ -169,6 +169,7 @@ variables can be used to overrule the filetype used for 
certain extensions:
        *.sh            g:bash_is_sh            |ft-sh-syntax|
        *.tex           g:tex_flavor            |ft-tex-plugin|
        *.typ           g:filetype_typ
+       *.v             g:filetype_v
        *.w             g:filetype_w            |ft-cweb-syntax|
 
 For a few filetypes the global variable is used only when the filetype could

-- 
-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/E1rKN34-007kLf-Cz%40256bit.org.

Raspunde prin e-mail lui