Skip to content

Commit 4899585

Browse files
committed
Add org mode, close #706
1 parent 4f997c5 commit 4899585

File tree

10 files changed

+286
-2
lines changed

10 files changed

+286
-2
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ A collection of language packs for Vim.
77
> One to rule them all, one to find them, one to bring them all and in the darkness bind them.
88
99
- It **won't affect your startup time**, as scripts are loaded only on demand\*.
10-
- It **installs and updates 120+ times faster** than the <!--Package Count-->606<!--/Package Count--> packages it consists of.
10+
- It **installs and updates 120+ times faster** than the <!--Package Count-->607<!--/Package Count--> packages it consists of.
1111
- It is also more secure (scripts loaded for every filetype are generated by vim-polyglot)
1212
- Best syntax and indentation support (no other features). Hand-selected language packs.
1313
- Automatically detects indentation (includes performance-optimized version of [vim-sleuth](https://github.com/tpope/vim-sleuth), can be disabled)
@@ -143,6 +143,7 @@ On top of all language packs from [vim repository](https://github.com/vim/vim/tr
143143
- [odin](https://github.com/Tetralux/odin.vim) (Odin syntax highlighting for odin files)
144144
- [opencl](https://github.com/petRUShka/vim-opencl) (OpenCL syntax highlighting for cl and opencl files)
145145
- [openscad](https://github.com/sirtaj/vim-openscad) (Syntax highlighting for scad files)
146+
- [org](https://github.com/axvr/org.vim) (Syntax highlighting for org files)
146147
- [perl](https://github.com/vim-perl/vim-perl) (Perl syntax highlighting for pl, al, cgi, fcgi, perl and 12 more files)
147148
- [pest](https://github.com/pest-parser/pest.vim) (Syntax highlighting for pest files)
148149
- [pgsql](https://github.com/lifepillar/pgsql.vim) (PLpgSQL syntax highlighting for pgsql files)

autoload/org.vim

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
if polyglot#init#is_disabled(expand('<sfile>:p'), 'org', 'autoload/org.vim')
2+
finish
3+
endif
4+
5+
" Helper functions for org.vim
6+
"
7+
" Maintainer: Alex Vear <[email protected]>
8+
" License: Vim (see `:help license`)
9+
" Location: autoload/org.vim
10+
" Website: https://github.com/axvr/org.vim
11+
" Last Change: 2020-01-04
12+
13+
" Fallback chain for options. Buffer local --> Global --> default.
14+
function org#option(name, default) abort
15+
return get(b:, a:name, get(g:, a:name, a:default))
16+
endfunction
17+
18+
" Emacs-like fold text.
19+
function org#fold_text() abort
20+
return getline(v:foldstart) . '...'
21+
endfunction
22+
23+
" Check fold depth of a line.
24+
function org#fold_expr()
25+
let l:depth = match(getline(v:lnum), '\(^\*\+\)\@<=\( .*$\)\@=')
26+
if l:depth > 0 && synIDattr(synID(v:lnum, 1, 1), 'name') =~# '\m^o\(rg\|utline\)Heading'
27+
return ">" . l:depth
28+
endif
29+
return "="
30+
endfunction

autoload/polyglot/init.vim

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,10 @@ let did_load_filetypes = 1
169169

170170
" DO NOT EDIT CODE BELOW, IT IS GENERATED WITH MAKEFILE
171171

172+
if !has_key(g:polyglot_is_disabled, 'org')
173+
au BufNewFile,BufRead *.org setf org
174+
endif
175+
172176
if !has_key(g:polyglot_is_disabled, 'mermaid')
173177
au BufNewFile,BufRead *.mermaid,*.mm,*.mmd setf mermaid
174178
endif

autoload/polyglot/sleuth.vim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,7 @@ let s:globs = {
388388
\ 'openscad': '*.scad',
389389
\ 'opl': '*.[Oo][Pp][Ll]',
390390
\ 'ora': '*.ora',
391+
\ 'org': '*.org',
391392
\ 'pamconf': '',
392393
\ 'pamenv': 'pam_env.conf,.pam_environment',
393394
\ 'papp': '*.papp,*.pxml,*.pxsl',

ftplugin/org.vim

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
if polyglot#init#is_disabled(expand('<sfile>:p'), 'org', 'ftplugin/org.vim')
2+
finish
3+
endif
4+
5+
" Vim filetype plugin for GNU Emacs' Org mode
6+
"
7+
" Maintainer: Alex Vear <[email protected]>
8+
" License: Vim (see `:help license`)
9+
" Location: ftplugin/org.vim
10+
" Website: https://github.com/axvr/org.vim
11+
" Last Change: 2020-01-04
12+
"
13+
" Reference Specification: Org mode manual
14+
" GNU Info: `$ info Org`
15+
" Web: <https://orgmode.org/manual/index.html>
16+
17+
setlocal commentstring=#%s
18+
setlocal comments=fb:*,fb:-,fb:+,b:#,b:\:
19+
setlocal formatoptions+=ncqlt
20+
let &l:formatlistpat = '^\s*\(\d\+[.)]\|[+-]\)\s\+'
21+
22+
setlocal foldexpr=org#fold_expr()
23+
setlocal foldmethod=expr
24+
25+
if org#option('org_clean_folds', 0)
26+
setlocal foldtext=org#fold_text()
27+
setlocal fillchars-=fold:-
28+
endif

ftplugin/outline.vim

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
if polyglot#init#is_disabled(expand('<sfile>:p'), 'org', 'ftplugin/outline.vim')
2+
finish
3+
endif
4+
5+
" Vim filetype plugin for GNU Emacs' Outline mode
6+
"
7+
" Maintainer: Alex Vear <[email protected]>
8+
" License: Vim (see `:help license`)
9+
" Location: ftplugin/outline.vim
10+
" Website: https://github.com/axvr/org.vim
11+
" Last Change: 2020-01-04
12+
"
13+
" Reference Specification: GNU Emacs Manual, section 'Outline Mode'
14+
" GNU Info: `$ info Emacs Outline Mode`
15+
" Web: <https://www.gnu.org/software/emacs/manual/html_node/emacs/Outline-Mode.html>
16+
17+
setlocal foldexpr=org#fold_expr()
18+
setlocal foldmethod=expr
19+
20+
if org#option('org_clean_folds', 0)
21+
setlocal foldtext=org#fold_text()
22+
setlocal fillchars-=fold:-
23+
endif

packages.yaml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5612,4 +5612,12 @@ filetypes:
56125612
- name: mermaid
56135613
patterns:
56145614
- pattern: '*.mermaid,*.mm,*.mmd'
5615-
description: Mermaid (https://mermaid-js.github.io/)
5615+
description: Mermaid (https://mermaid-js.github.io/)
5616+
---
5617+
name: org
5618+
remote: axvr/org.vim
5619+
filetypes:
5620+
- name: org
5621+
patterns:
5622+
- pattern: '*.org'
5623+
description: GNU Emacs' Org mode

syntax/org.vim

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
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'

syntax/outline.vim

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
if polyglot#init#is_disabled(expand('<sfile>:p'), 'org', 'syntax/outline.vim')
2+
finish
3+
endif
4+
5+
" Vim syntax file for GNU Emacs' Outline mode
6+
"
7+
" Maintainer: Alex Vear <[email protected]>
8+
" License: Vim (see `:help license`)
9+
" Location: syntax/outline.vim
10+
" Website: https://github.com/axvr/org.vim
11+
" Last Change: 2019-09-28
12+
"
13+
" Reference Specification: GNU Emacs Manual, section 'Outline Mode'
14+
" GNU Info: `$ info Emacs Outline Mode`
15+
" Web: <https://www.gnu.org/software/emacs/manual/html_node/emacs/Outline-Mode.html>
16+
17+
if exists('b:current_syntax')
18+
finish
19+
endif
20+
21+
" Enable spell check for non syntax highlighted text
22+
syntax spell toplevel
23+
24+
25+
" Headings
26+
syntax match outlineHeading1 /^\s*\*\{1}\s\+.*$/ keepend contains=@Spell
27+
syntax match outlineHeading2 /^\s*\*\{2}\s\+.*$/ keepend contains=@Spell
28+
syntax match outlineHeading3 /^\s*\*\{3}\s\+.*$/ keepend contains=@Spell
29+
syntax match outlineHeading4 /^\s*\*\{4}\s\+.*$/ keepend contains=@Spell
30+
syntax match outlineHeading5 /^\s*\*\{5}\s\+.*$/ keepend contains=@Spell
31+
syntax match outlineHeading6 /^\s*\*\{6,}\s\+.*$/ keepend contains=@Spell
32+
33+
syntax cluster outlineHeadingGroup contains=outlineHeading1,outlineHeading2,outlineHeading3,outlineHeading4,outlineHeading5,outlineHeading6
34+
35+
hi def link outlineHeading1 Title
36+
hi def link outlineHeading2 outlineHeading1
37+
hi def link outlineHeading3 outlineHeading2
38+
hi def link outlineHeading4 outlineHeading3
39+
hi def link outlineHeading5 outlineHeading4
40+
hi def link outlineHeading6 outlineHeading5
41+
42+
43+
let b:current_syntax = 'outline'

tests/filetypes.vim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,7 @@ call TestFiletype('just')
653653
call TestFiletype('nftables')
654654
call TestFiletype('openscad')
655655
call TestFiletype('mermaid')
656+
call TestFiletype('org')
656657

657658
" DO NOT EDIT CODE ABOVE, IT IS GENERATED WITH MAKEFILE
658659

0 commit comments

Comments
 (0)