summaryrefslogtreecommitdiff
path: root/runtime
diff options
context:
space:
mode:
authorTuriiya <34311583+tobealive@users.noreply.github.com>2023-04-22 21:38:47 +0100
committerBram Moolenaar <Bram@vim.org>2023-04-22 21:38:47 +0100
commit80406c26188219f3773b2e9c49160caeeb386ee2 (patch)
treea9444688887fecf0d257649055337e2a3a940829 /runtime
parentb67ba03d3ef2e6c5f207d508e85fc6906f938028 (diff)
downloadvim-git-80406c26188219f3773b2e9c49160caeeb386ee2.tar.gz
patch 9.0.1478: filetypes for *.v files not detected properlyv9.0.1478
Problem: Filetypes for *.v files not detected properly. Solution: Use the file contents to detect the filetype. (Turiiya, closes #12281)
Diffstat (limited to 'runtime')
-rw-r--r--runtime/autoload/dist/ft.vim35
-rw-r--r--runtime/filetype.vim4
2 files changed, 37 insertions, 2 deletions
diff --git a/runtime/autoload/dist/ft.vim b/runtime/autoload/dist/ft.vim
index 5d2053d70..4e0906d8b 100644
--- a/runtime/autoload/dist/ft.vim
+++ b/runtime/autoload/dist/ft.vim
@@ -1106,5 +1106,40 @@ export def FTlsl()
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
diff --git a/runtime/filetype.vim b/runtime/filetype.vim
index 50187f6db..538ddd8d6 100644
--- a/runtime/filetype.vim
+++ b/runtime/filetype.vim
@@ -2303,8 +2303,8 @@ au BufNewFile,BufRead *.vr,*.vri,*.vrh setf vera
" Vagrant (uses Ruby syntax)
au BufNewFile,BufRead Vagrantfile setf ruby
-" Verilog HDL
-au BufNewFile,BufRead *.v setf verilog
+" Verilog HDL, V or Coq
+au BufNewFile,BufRead *.v call dist#ft#FTv()
" Verilog-AMS HDL
au BufNewFile,BufRead *.va,*.vams setf verilogams