-
Notifications
You must be signed in to change notification settings - Fork 40
Add OCamldoc/Odoc highlighting #106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
n-osborne
wants to merge
10
commits into
ocaml:master
Choose a base branch
from
n-osborne:odoc-syntax
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
87e4832
Add syntax highlighting for *.mld
n-osborne 5d2b639
Add documentation highlighting in OCaml files
n-osborne bed49ad
Fix highlighting of module parameter
n-osborne 2749fb5
syntax/odoc: improve following review of #106
Maelan 3650b4e
syntax/odoc: add missing @tags
Maelan cb78554
syntax/odoc: add missing crossref keywords
Maelan 14b1875
syntax/odoc: disable spell-checking inside LaTeX snippets
Maelan 67dcf37
syntax/odoc: make relevant regions transparent
Maelan ae494cb
syntax/odoc: shuffle lines around
Maelan cc050b3
Allow for line feed in odocCodeBlock marker
n-osborne File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
au BufNewFile,BufRead *.mld setf odoc |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
" Vim syntax file | ||
" Language: Odoc/OCamldoc | ||
" Filenames: *.mld | ||
" Maintainers: Samuel Hym | ||
" Nicolas Osborne | ||
" URL: https://github.com/ocaml/vim-ocaml | ||
n-osborne marked this conversation as resolved.
Show resolved
Hide resolved
|
||
" Last Change: | ||
" 2024 Jan 26 - initial version | ||
|
||
" Quit when a syntax file was already loaded | ||
if !exists("odoc_syntax_loading") | ||
if exists("b:current_syntax") | ||
finish | ||
endif | ||
let odoc_syntax_loading = 1 | ||
endif | ||
|
||
let s:keepcpo = &cpo | ||
set cpo&vim | ||
|
||
syn spell toplevel | ||
|
||
syn case match | ||
|
||
syn include @odocSyntaxOCaml syntax/ocaml.vim | ||
unlet b:current_syntax | ||
|
||
n-osborne marked this conversation as resolved.
Show resolved
Hide resolved
|
||
syn cluster odocInline contains=odocBold,odocItalic,odocEmphasis,odocMiscInline,odocList,odocLinkText,odocUrl,odocCrossref,odocCode,odocCodeBlock,odocVerbatim,odocTargetSpecific,odocTag,odocEscaped,odocEscapedError,odocBraceError,odocTagError | ||
|
||
syn match odocBraceError "[{}]" | ||
|
||
syn region odocLinkText transparent matchgroup=odocMarker start="{\%({[!:]\)\@=" end="}" contains=odocUrl,odocCrossref,@Spell,@odocInline | ||
syn region odocUrl matchgroup=odocUrlMarker start="{:\_s*" end="\_s*}" | ||
" a bit leniant with ":" | ||
syn match odocCrossrefKw contained "\<\%(!modules\|module\%(-type\)\?\|class\%(-type\)\?\|val\|type\|exception\|method\|constructor\|extension\|extension-decl\|field\|instance-variable\|section\|page\)[-:]" | ||
syn match odocCrossrefKwDeprecated contained "\<\%(modtype\|classtype\|value\|exn\|const\|label\)[-:]" | ||
syn region odocCrossref matchgroup=odocCrossrefMarker start="{!" end="}" contains=odocCrossrefKw,odocCrossrefKwDeprecated | ||
|
||
syn region odocBold matchgroup=odocMarker start="{b\>" end="}" contains=@Spell,@odocInline | ||
syn region odocEmphasis matchgroup=odocMarker start="{e\>" end="}" contains=@Spell,@odocInline | ||
syn region odocItalic matchgroup=odocMarker start="{i\>" end="}" contains=@Spell,@odocInline | ||
syn region odocMiscInline matchgroup=odocMarker start="{[CLR^_]" end="}" contains=@Spell,@odocInline | ||
syn region odocVerbatim matchgroup=odocMarker start="{v\>" end="\<v}" | ||
|
||
n-osborne marked this conversation as resolved.
Show resolved
Hide resolved
|
||
syn region odocTargetSpecific matchgroup=odocUnknownTarget start="{%.\{-}:\|{%" end="%}" | ||
|
||
if get(g:,'odoc_html_support',0) | ||
syn include @odocHtml syntax/html.vim | ||
unlet b:current_syntax | ||
syn region odocTargetSpecific matchgroup=odocMarker start="{%html:" end="%}" contains=@odocHtml | ||
else | ||
syn region odocTargetSpecific matchgroup=odocMarker start="{%html:" end="%}" contains=@Spell | ||
endif | ||
|
||
syn region odocDyckWord contained transparent start="{" end="}" contains=odocDyckWord | ||
syn region odocTargetSpecific matchgroup=odocMarker start="{m\%(ath\)\?\>" end="}" contains=odocDyckWord | ||
syn region odocTargetSpecific matchgroup=odocMarker start="{%\%(latex\|texi\|man\):" end="%}" | ||
syn region odocHeading start="{[0-5]\%(\s\|$\|:\)\@=" end="}" contains=@Spell,odocHeadingLabel | ||
syn match odocHeadingLabel contained "\%({[0-5]\)\@<=:[^ \t:]*" | ||
syn region odocTable transparent matchgroup=odocMarker start="{t\>" end="}" contains=@Spell,@odocInline | ||
syn region odocTable transparent matchgroup=odocMarker start="{table\>" end="}" contains=odocTableRow | ||
syn region odocTableRow transparent matchgroup=odocMarker start="{tr\>" end="}" contains=odocTableEntry contained | ||
syn region odocTableEntry transparent matchgroup=odocMarker start="{t[dh]\>" end="}" contains=@Spell,@odocInline contained | ||
syn match odocEscapedBracket contained "\\[][]" | ||
syn region odocBalancedBracket contained transparent start="\[" end="]" | ||
syn region odocCode matchgroup=odocMarker start="\[" end="\]" contains=odocBalancedBracket,odocEscapedBracket | ||
syn region odocCodeBlock matchgroup=odocMarker start="{@[^\[]\+\[" end="\]}" | ||
syn region odocCodeBlock matchgroup=odocMarker start="{\%(@ocaml\%(\_s[^\[]*\)\?\)\?\[" end="\]}" contains=@odocSyntaxOCaml | ||
syn match odocListMarker "^\s*[-+]\s" | ||
syn region odocListItem contained transparent matchgroup=odocListMarker start="{\%(-\|li\>\)" end="}" contains=@Spell,@odocInline | ||
syn region odocList transparent matchgroup=odocListMarker start="{[ou]l\>" end="}" contains=odocListItem | ||
syn match odocTagError "@[a-zA-Z]*" | ||
syn match odocTag "@\%(author\|deprecated\|param\|raises\?\|returns\?\|see\|since\|before\|version\|open\|closed\|inline\|canonical\)\>" | ||
|
||
syn match odocEscapedError "\\." | ||
syn match odocEscaped "\\[][{}@\\]" | ||
|
||
n-osborne marked this conversation as resolved.
Show resolved
Hide resolved
|
||
" Shamelessly borrowed from HTML syntax | ||
hi def odocBold term=bold cterm=bold gui=bold | ||
hi def odocEmphasis term=underline cterm=underline gui=underline | ||
hi def odocItalic term=italic cterm=italic gui=italic | ||
|
||
hi def link odocUrlMarker odocMarker | ||
hi def link odocUrl Underlined | ||
hi def link odocCrossrefMarker odocCrossref " or odocMarker | ||
hi def link odocCrossref Label | ||
hi def link odocCrossrefKw Keyword | ||
hi def link odocCrossrefKwDeprecated Keyword " we may highlight it differently | ||
hi def link odocHeading Title | ||
hi def link odocHeadingLabel Label | ||
hi def link odocListMarker Operator | ||
hi def link odocMarker Delimiter | ||
hi def link odocTag Keyword | ||
|
||
hi def link odocBraceError Error | ||
hi def link odocUnknownTarget Error | ||
hi def link odocTagError Error | ||
hi def link odocEscapedError Error | ||
hi def link odocEscaped SpecialChar | ||
hi def link odocEscapedBracket odocEscaped | ||
|
||
let b:current_syntax = "odoc" | ||
|
||
unlet odoc_syntax_loading | ||
|
||
let &cpo = s:keepcpo | ||
unlet s:keepcpo | ||
|
||
" vim: ts=8 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.