summaryrefslogtreecommitdiffstats
path: root/runtime/autoload
diff options
context:
space:
mode:
authorChristian Brabandt <cb@256bit.org>2024-01-01 19:19:20 +0100
committerChristian Brabandt <cb@256bit.org>2024-01-01 19:19:20 +0100
commit10b4f75d4c03c1cd4f579be5fdc812ba41b72fef (patch)
treea6e3523cf8c906d4465094c559b457535ea796ea /runtime/autoload
parentb16fc9805535dc6eb084142da0c87210fc102494 (diff)
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>
Diffstat (limited to 'runtime/autoload')
-rw-r--r--runtime/autoload/dist/ft.vim42
1 files changed, 31 insertions, 11 deletions
diff --git a/runtime/autoload/dist/ft.vim b/runtime/autoload/dist/ft.vim
index 53c56f6b52..2423fd4469 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