@@ -1186,26 +1186,46 @@ export def FTv()
1186
1186
# " :setf" will do nothing, bail out early
1187
1187
return
1188
1188
endif
1189
+ if exists (" g:filetype_v" )
1190
+ exe " setf " .. g: filetype_v
1191
+ return
1192
+ endif
1189
1193
1190
- for line in getline (1 , 200 )
1191
- if line [0 ] = ~ ' ^\s*/'
1194
+ var in_comment = 0
1195
+ for lnum in range (1 , min ([line (" $" ), 200 ]))
1196
+ var line = getline (lnum)
1197
+ # Skip Verilog and V comments (lines and blocks).
1198
+ if line = ~ ' ^\s*/\*'
1199
+ # start comment block
1200
+ in_comment = 1
1201
+ endif
1202
+ if in_comment == 1
1203
+ if line = ~ ' \*/'
1204
+ # end comment block
1205
+ in_comment = 0
1206
+ endif
1207
+ # skip comment - block line
1208
+ continue
1209
+ endif
1210
+ if line = ~ ' ^\s*//'
1192
1211
# skip comment line
1193
1212
continue
1194
1213
endif
1195
1214
1196
- # Verilog: line ends with ' ;' followed by an optional variable number of
1197
- # spaces and an optional start of a comment .
1198
- # Example: " b <= a + 1; // Add 1" .
1199
- if line = ~ ' ;\(\s*\)\?\(/.*\)\?$'
1200
- setf verilog
1215
+ # Coq: line ends with a ' .' followed by an optional variable number of
1216
+ # spaces or contains the start of a comment , but not inside a Verilog or V
1217
+ # comment .
1218
+ # Example: " Definition x := 10. (*" .
1219
+ if (line = ~ ' \.\s*$' && line !~ ' /[/*]' ) || (line = ~ ' (\*' && line !~ ' /[/*].*(\*' )
1220
+ setf coq
1201
1221
return
1202
1222
endif
1203
1223
1204
- # Coq : line ends with a ' . ' followed by an optional variable number of
1224
+ # Verilo g : line ends with ' ; ' followed by an optional variable number of
1205
1225
# spaces and an optional start of a comment .
1206
- # Example: " Definition x := 10. (* " .
1207
- if line = ~ ' \.\(\ s*\)\?\((\* .*\)\?$'
1208
- setf coq
1226
+ # Example: " b <= a + 1; // Add 1 " .
1227
+ if line = ~ ' ;\ s*\(/[/*] .*\)\?$'
1228
+ setf verilog
1209
1229
return
1210
1230
endif
1211
1231
endfor
0 commit comments