runtime(dist/ft): improve filetype detection for *.v (V/Verilog/Coq)
Patch provided by Dan Alt closes: #13793 Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
42
runtime/autoload/dist/ft.vim
vendored
42
runtime/autoload/dist/ft.vim
vendored
@ -1186,28 +1186,48 @@ export def FTv()
|
|||||||
# ":setf" will do nothing, bail out early
|
# ":setf" will do nothing, bail out early
|
||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
|
if exists("g:filetype_v")
|
||||||
|
exe "setf " .. g:filetype_v
|
||||||
|
return
|
||||||
|
endif
|
||||||
|
|
||||||
for line in getline(1, 200)
|
var in_comment = 0
|
||||||
if line[0] =~ '^\s*/'
|
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
|
# skip comment line
|
||||||
continue
|
continue
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
# 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
|
||||||
|
|
||||||
# Verilog: line ends with ';' 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.
|
# spaces and an optional start of a comment.
|
||||||
# Example: " b <= a + 1; // Add 1".
|
# Example: " b <= a + 1; // Add 1".
|
||||||
if line =~ ';\(\s*\)\?\(/.*\)\?$'
|
if line =~ ';\s*\(/[/*].*\)\?$'
|
||||||
setf verilog
|
setf verilog
|
||||||
return
|
return
|
||||||
endif
|
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
|
endfor
|
||||||
|
|
||||||
# No line matched, fall back to "v".
|
# No line matched, fall back to "v".
|
||||||
|
|||||||
@ -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
|
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|
|
*.sh g:bash_is_sh |ft-sh-syntax|
|
||||||
*.tex g:tex_flavor |ft-tex-plugin|
|
*.tex g:tex_flavor |ft-tex-plugin|
|
||||||
*.typ g:filetype_typ
|
*.typ g:filetype_typ
|
||||||
|
*.v g:filetype_v
|
||||||
*.w g:filetype_w |ft-cweb-syntax|
|
*.w g:filetype_w |ft-cweb-syntax|
|
||||||
|
|
||||||
For a few filetypes the global variable is used only when the filetype could
|
For a few filetypes the global variable is used only when the filetype could
|
||||||
|
|||||||
Reference in New Issue
Block a user