Skip to content

Commit 60c451b

Browse files
n-osborneshym
andcommitted
Add documentation highlighting in OCaml files
Co-authored-by: Samuel Hym <[email protected]>
1 parent 382b0c4 commit 60c451b

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

syntax/ocaml.vim

+18-5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
" Issac Trotts <[email protected]>
77
" URL: https://github.com/ocaml/vim-ocaml
88
" Last Change:
9+
" 2024 Jan 25 - Add OCamldoc/Odoc highlighting (Samuel Hym, Nicolas Osborne)
910
" 2019 Nov 05 - Accurate type highlighting (Maëlan)
1011
" 2018 Nov 08 - Improved highlighting of operators (Maëlan)
1112
" 2018 Apr 22 - Improved support for PPX (Andrey Popp)
@@ -86,11 +87,19 @@ syn region ocamlNone transparent matchgroup=ocamlEncl start="{" matchgroup=oca
8687
syn region ocamlNone transparent matchgroup=ocamlEncl start="\[" matchgroup=ocamlEncl end="\]" contains=ALLBUT,@ocamlContained,ocamlBrackErr
8788
syn region ocamlNone transparent matchgroup=ocamlEncl start="\[|" matchgroup=ocamlEncl end="|\]" contains=ALLBUT,@ocamlContained,ocamlArrErr
8889

89-
90-
" Comments
91-
syn region ocamlComment start="(\*" end="\*)" contains=@Spell,ocamlComment,ocamlTodo
90+
" Comments and documentation
9291
syn keyword ocamlTodo contained TODO FIXME XXX NOTE
9392

93+
if !exists('odoc_syntax_loading')
94+
" Load odoc syntax only when we are not in a *.mld file
95+
syn region ocamlComment start="(\*" end="\*)" contains=@Spell,ocamlComment,ocamlTodo
96+
syn include @ocamlOdoc syntax/odoc.vim
97+
syn region ocamlDocumentation matchgroup=ocamlComment start="(\*\*" end="\*)" contains=@ocamlOdoc
98+
else
99+
" Nested in odoc syntax: for some reason, allowing ocamlComment inside
100+
" ocamlComment in odocCodeBlock in ocamlDocumentation breaks
101+
syn region ocamlComment start="(\*" end="\*)" contains=@Spell,ocamlTodo
102+
endif
94103

95104
" Objects
96105
syn region ocamlEnd matchgroup=ocamlObject start="\<object\>" matchgroup=ocamlObject end="\<end\>" contains=ALLBUT,@ocamlContained,ocamlEndErr
@@ -662,7 +671,11 @@ hi def link ocamlPpxEncl ocamlEncl
662671

663672
let b:current_syntax = "ocaml"
664673

665-
let &cpo = s:keepcpo
666-
unlet s:keepcpo
674+
" Because of the nesting (ocaml in odoc in ocaml), s:keepcpo might have been
675+
" unlet already
676+
if exists('s:keepcpo')
677+
let &cpo = s:keepcpo
678+
unlet s:keepcpo
679+
endif
667680

668681
" vim: ts=8

0 commit comments

Comments
 (0)