Patch 9.0.1478
Problem:    Filetypes for *.v files not detected properly.
Solution:   Use the file contents to detect the filetype. (Turiiya,
            closes #12281)
Files:      runtime/autoload/dist/ft.vim, runtime/filetype.vim,
            src/testdir/test_filetype.vim


*** ../vim-9.0.1477/runtime/autoload/dist/ft.vim        2023-04-02 
20:29:33.741597887 +0100
--- runtime/autoload/dist/ft.vim        2023-04-22 21:37:26.730204510 +0100
***************
*** 1106,1110 ****
--- 1106,1145 ----
    endif
  enddef
  
+ # Set the filetype of a *.v file to Verilog, V or Cog based on the first 200
+ # lines.
+ export def FTv()
+   if did_filetype()
+     # ":setf" will do nothing, bail out early
+     return
+   endif
+ 
+   for line in getline(1, 200)
+     if line[0] =~ '^\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
+       return
+     endif
+ 
+     # Coq: line ends with a '.' followed by an optional variable number of
+     # spaces and an optional start of a comment.
+     # Example: "Definition x := 10. (*".
+     if line =~ '\.\(\s*\)\?\((\*.*\)\?$'
+       setf coq
+       return
+     endif
+   endfor
+ 
+   # No line matched, fall back to "v".
+   setf v
+ enddef
+ 
  # Uncomment this line to check for compilation errors early
  # defcompile
*** ../vim-9.0.1477/runtime/filetype.vim        2023-04-22 12:41:05.122919187 
+0100
--- runtime/filetype.vim        2023-04-22 21:30:37.190106865 +0100
***************
*** 2303,2310 ****
  " Vagrant (uses Ruby syntax)
  au BufNewFile,BufRead Vagrantfile             setf ruby
  
! " Verilog HDL
! au BufNewFile,BufRead *.v                     setf verilog
  
  " Verilog-AMS HDL
  au BufNewFile,BufRead *.va,*.vams             setf verilogams
--- 2303,2310 ----
  " Vagrant (uses Ruby syntax)
  au BufNewFile,BufRead Vagrantfile             setf ruby
  
! " Verilog HDL, V or Coq
! au BufNewFile,BufRead *.v                     call dist#ft#FTv()
  
  " Verilog-AMS HDL
  au BufNewFile,BufRead *.va,*.vams             setf verilogams
*** ../vim-9.0.1477/src/testdir/test_filetype.vim       2023-04-22 
12:41:05.122919187 +0100
--- src/testdir/test_filetype.vim       2023-04-22 21:30:37.190106865 +0100
***************
*** 646,652 ****
      \ 'vdmrt': ['file.vdmrt'],
      \ 'vdmsl': ['file.vdm', 'file.vdmsl'],
      \ 'vera': ['file.vr', 'file.vri', 'file.vrh'],
-     \ 'verilog': ['file.v'],
      \ 'verilogams': ['file.va', 'file.vams'],
      \ 'vgrindefs': ['vgrindefs'],
      \ 'vhdl': ['file.hdl', 'file.vhd', 'file.vhdl', 'file.vbe', 'file.vst', 
'file.vhdl_123', 'file.vho', 'some.vhdl_1', 'some.vhdl_1-file'],
--- 646,651 ----
***************
*** 1769,1774 ****
--- 1768,1794 ----
    bwipe!
  
    filetype off
+ endfunc
+ 
+ func Test_v_file()
+   filetype on
+ 
+   call writefile(['module tb; // Looks like a Verilog'], 'Xfile.v', 'D')
+   split Xfile.v
+   call assert_equal('verilog', &filetype)
+   bwipe!
+ 
+   call writefile(['module main'], 'Xfile.v')
+   split Xfile.v
+   call assert_equal('v', &filetype)
+   bwipe!
+ 
+   call writefile(['Definition x := 10.  (*'], 'Xfile.v')
+   split Xfile.v
+   call assert_equal('coq', &filetype)
+   bwipe!
+ 
+   filetype off
  endfunc
  
  func Test_xpm_file()
*** ../vim-9.0.1477/src/version.c       2023-04-22 21:14:21.585140551 +0100
--- src/version.c       2023-04-22 21:37:51.990208458 +0100
***************
*** 697,698 ****
--- 697,700 ----
  {   /* Add new patch number below this line */
+ /**/
+     1478,
  /**/

-- 
JOHN CLEESE PLAYED: SECOND SOLDIER WITH A KEEN INTEREST IN BIRDS, LARGE MAN
                    WITH DEAD BODY, BLACK KNIGHT, MR NEWT (A VILLAGE
                    BLACKSMITH INTERESTED IN BURNING WITCHES), A QUITE
                    EXTRAORDINARILY RUDE FRENCHMAN, TIM THE WIZARD, SIR
                    LAUNCELOT
                 "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///                                                                      \\\
\\\        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
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/20230422203921.1B5981C074F%40moolenaar.net.

Raspunde prin e-mail lui