|
| 1 | +if polyglot#init#is_disabled(expand('<sfile>:p'), 'org', 'syntax/org.vim') |
| 2 | + finish |
| 3 | +endif |
| 4 | + |
| 5 | +" Vim syntax file for GNU Emacs' Org mode |
| 6 | +" |
| 7 | +" Maintainer: Alex Vear <[email protected]> |
| 8 | +" License: Vim (see `:help license`) |
| 9 | +" Location: syntax/org.vim |
| 10 | +" Website: https://github.com/axvr/org.vim |
| 11 | +" Last Change: 2020-01-05 |
| 12 | +" |
| 13 | +" Reference Specification: Org mode manual |
| 14 | +" GNU Info: `$ info Org` |
| 15 | +" Web: <https://orgmode.org/manual/index.html> |
| 16 | + |
| 17 | +if exists('b:current_syntax') && b:current_syntax !=# 'outline' |
| 18 | + finish |
| 19 | +endif |
| 20 | + |
| 21 | +" Enable spell check for non syntax highlighted text |
| 22 | +syntax spell toplevel |
| 23 | + |
| 24 | + |
| 25 | +" Bold, underine, italic, etc. |
| 26 | +syntax region orgItalic matchgroup=orgItalicDelimiter start="\(^\|[- '"({\]]\)\@<=\/\ze[^ ]" end="^\@!\/\([^\k\/]\|$\)\@=" keepend contains=@Spell |
| 27 | +syntax region orgBold matchgroup=orgBoldDelimiter start="\(^\|[- '"({\]]\)\@<=\*\ze[^ ]" end="^\@!\*\([^\k\*]\|$\)\@=" keepend contains=@Spell |
| 28 | +syntax region orgUnderline matchgroup=orgUnderlineDelimiter start="\(^\|[- '"({\]]\)\@<=_\ze[^ ]" end="^\@!_\([^\k_]\|$\)\@=" keepend contains=@Spell |
| 29 | +syntax region orgStrikethrough matchgroup=orgStrikethroughDelimiter start="\(^\|[ '"({\]]\)\@<=+\ze[^ ]" end="^\@!+\([^\k+]\|$\)\@=" keepend contains=@Spell |
| 30 | + |
| 31 | +if org#option('org_use_italics', 1) |
| 32 | + highlight def orgItalic term=italic cterm=italic gui=italic |
| 33 | +else |
| 34 | + highlight def orgItalic term=none cterm=none gui=none |
| 35 | +endif |
| 36 | + |
| 37 | +highlight def orgBold term=bold cterm=bold gui=bold |
| 38 | +highlight def orgUnderline term=underline cterm=underline gui=underline |
| 39 | +highlight def orgStrikethrough term=strikethrough cterm=strikethrough gui=strikethrough |
| 40 | +highlight def link orgBoldDelimiter orgBold |
| 41 | +highlight def link orgUnderlineDelimiter orgUnderline |
| 42 | +highlight def link orgStrikethroughDelimiter orgStrikethrough |
| 43 | + |
| 44 | + |
| 45 | +" Options |
| 46 | +syntax match orgOption /^\s*#+\w\+.*$/ keepend |
| 47 | +syntax region orgTitle matchgroup=orgOption start="\c^\s*#+TITLE:\s*" end="$" keepend oneline |
| 48 | +highlight def link orgBlockDelimiter SpecialComment |
| 49 | +highlight def link orgOption SpecialComment |
| 50 | +highlight def link orgTitle Title |
| 51 | + |
| 52 | + |
| 53 | +" Code and vervatim text |
| 54 | +syntax region orgCode matchgroup=orgCodeDelimiter start="\(^\|[- '"({\]]\)\@<=\~\ze[^ ]" end="^\@!\~\([^\k\~]\|$\)\@=" keepend |
| 55 | +syntax region orgVerbatim matchgroup=orgVerbatimDelimiter start="\(^\|[- '"({\]]\)\@<==\ze[^ ]" end="^\@!=\([^\k=]\|$\)\@=" keepend |
| 56 | +syntax match orgVerbatim /^\s*: .*$/ keepend |
| 57 | +syntax region orgVerbatim matchgroup=orgBlockDelimiter start="\c^\s*#+BEGIN_.*" end="\c^\s*#+END_.*" keepend |
| 58 | +syntax region orgCode matchgroup=orgBlockDelimiter start="\c^\s*#+BEGIN_SRC" end="\c^\s*#+END_SRC" keepend |
| 59 | +syntax region orgCode matchgroup=orgBlockDelimiter start="\c^\s*#+BEGIN_EXAMPLE" end="\c^\s*#+END_EXAMPLE" keepend |
| 60 | + |
| 61 | +highlight def link orgVerbatim Identifier |
| 62 | +highlight def link orgVerbatimDelimiter orgVerbatim |
| 63 | +highlight def link orgCode Statement |
| 64 | +highlight def link orgCodeDelimiter orgCode |
| 65 | + |
| 66 | + |
| 67 | +" Comments |
| 68 | +syntax match orgComment /^\s*#\s\+.*$/ keepend |
| 69 | +syntax region orgComment matchgroup=orgBlockDelimiter start="\c^\s*#+BEGIN_COMMENT" end="\c^\s*#+END_COMMENT" keepend |
| 70 | +highlight def link orgComment Comment |
| 71 | + |
| 72 | + |
| 73 | +" Headings |
| 74 | +syntax match orgHeading1 /^\s*\*\{1}\s\+.*$/ keepend contains=@Spell,orgTag,orgTodo,orgMath |
| 75 | +syntax match orgHeading2 /^\s*\*\{2}\s\+.*$/ keepend contains=@Spell,orgTag,orgTodo,orgMath |
| 76 | +syntax match orgHeading3 /^\s*\*\{3}\s\+.*$/ keepend contains=@Spell,orgTag,orgTodo,orgMath |
| 77 | +syntax match orgHeading4 /^\s*\*\{4}\s\+.*$/ keepend contains=@Spell,orgTag,orgTodo,orgMath |
| 78 | +syntax match orgHeading5 /^\s*\*\{5}\s\+.*$/ keepend contains=@Spell,orgTag,orgTodo,orgMath |
| 79 | +syntax match orgHeading6 /^\s*\*\{6,}\s\+.*$/ keepend contains=@Spell,orgTag,orgTodo,orgMath |
| 80 | + |
| 81 | +syntax cluster orgHeadingGroup contains=orgHeading1,orgHeading2,orgHeading3,orgHeading4,orgHeading5,orgHeading6 |
| 82 | + |
| 83 | +syntax match orgTag /:\w\{-}:/ contained contains=orgTag |
| 84 | +exec 'syntax keyword orgTodo contained ' . join(org#option('org_state_keywords', ['TODO', 'NEXT', 'DONE']), ' ') |
| 85 | + |
| 86 | +highlight def link orgHeading1 Title |
| 87 | +highlight def link orgHeading2 orgHeading1 |
| 88 | +highlight def link orgHeading3 orgHeading2 |
| 89 | +highlight def link orgHeading4 orgHeading3 |
| 90 | +highlight def link orgHeading5 orgHeading4 |
| 91 | +highlight def link orgHeading6 orgHeading5 |
| 92 | +highlight def link orgTodo Todo |
| 93 | +highlight def link orgTag Type |
| 94 | + |
| 95 | + |
| 96 | +" Lists |
| 97 | +syntax match orgUnorderedListMarker "^\s*[-+]\s\+" keepend contains=@Spell |
| 98 | +syntax match orgOrderedListMarker "^\s*\d\+[.)]\s\+" keepend contains=@Spell |
| 99 | +if org#option('org_list_alphabetical_bullets', 0) |
| 100 | + syntax match orgOrderedListMarker "^\s*\a[.)]\s\+" keepend contains=@Spell |
| 101 | +endif |
| 102 | +highlight def link orgUnorderedListMarker Statement |
| 103 | +highlight def link orgOrderedListMarker orgUnorderedListMarker |
| 104 | + |
| 105 | + |
| 106 | +" Timestamps |
| 107 | +syntax match orgTimestampActive /<\d\{4}-\d\{2}-\d\{2}.\{-}>/ keepend |
| 108 | +syntax match orgTimestampInactive /\[\d\{4}-\d\{2}-\d\{2}.\{-}\]/ keepend |
| 109 | +highlight def link orgTimestampActive Operator |
| 110 | +highlight def link orgTimestampInactive Comment |
| 111 | + |
| 112 | + |
| 113 | +" Hyperlinks |
| 114 | +syntax match orgHyperlink /\[\{2}\([^][]\{-1,}\]\[\)\?[^][]\{-1,}\]\{2}/ containedin=ALL contains=orgHyperLeft,orgHyperRight,orgHyperURL |
| 115 | +syntax match orgHyperLeft /\[\{2}/ contained conceal |
| 116 | +syntax match orgHyperRight /\]\{2}/ contained conceal |
| 117 | +syntax match orgHyperURL /[^][]\{-1,}\]\[/ contains=orgHyperCentre contained conceal |
| 118 | +syntax match orgHyperCentre /\]\[/ contained conceal |
| 119 | + |
| 120 | +syntax cluster orgHyperlinkBracketsGroup contains=orgHyperLeft,orgHyperRight,orgHyperCentre |
| 121 | +syntax cluster orgHyperlinkGroup contains=orgHyperlink,orgHyperURL,orgHyperlinkBracketsGroup |
| 122 | + |
| 123 | +highlight def link orgHyperlink Underlined |
| 124 | +highlight def link orgHyperURL String |
| 125 | +highlight def link orgHyperCentre Comment |
| 126 | +highlight def link orgHyperLeft Comment |
| 127 | +highlight def link orgHyperRight Comment |
| 128 | + |
| 129 | + |
| 130 | +" TeX |
| 131 | +" Ref: https://orgmode.org/manual/LaTeX-fragments.html |
| 132 | +if org#option('org_highlight_tex', 1) |
| 133 | + syntax include @LATEX syntax/tex.vim |
| 134 | + syntax region orgMath start="\\begin\[.*\]{.*}" end="\\end{.*}" keepend contains=@LATEX |
| 135 | + syntax region orgMath start="\\begin{.*}" end="\\end{.*}" keepend contains=@LATEX |
| 136 | + syntax region orgMath start="\\\[" end="\\\]" keepend contains=@LATEX |
| 137 | + syntax region orgMath start="\\(" end="\\)" keepend contains=@LATEX |
| 138 | + syntax region orgMath start="\S\@<=\$\|\$\S\@=" end="\S\@<=\$\|\$\S\@=" keepend oneline contains=@LATEX |
| 139 | + syntax region orgMath start=/\$\$/ end=/\$\$/ keepend contains=@LATEX |
| 140 | + syntax match orgMath /\\\$/ conceal cchar=$ |
| 141 | + highlight def link orgMath String |
| 142 | +endif |
| 143 | + |
| 144 | + |
| 145 | +let b:current_syntax = 'org' |
0 commit comments