From 0406612877f2ea31c1e40d06d4e90749cab1705f Mon Sep 17 00:00:00 2001 From: Alex Vear Date: Sat, 8 Dec 2018 22:40:13 +0000 Subject: [PATCH] Initial commit --- LICENCE | 15 ++++++++ README.md | 5 +++ ftdetect/org.vim | 7 ++++ ftplugin/org.vim | 26 ++++++++++++++ syntax/org.vim | 90 ++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 143 insertions(+) create mode 100644 LICENCE create mode 100644 README.md create mode 100644 ftdetect/org.vim create mode 100644 ftplugin/org.vim create mode 100644 syntax/org.vim diff --git a/LICENCE b/LICENCE new file mode 100644 index 0000000..22c0844 --- /dev/null +++ b/LICENCE @@ -0,0 +1,15 @@ +ISC License + +Copyright (c) 2018, Alex Vear + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..a775e07 --- /dev/null +++ b/README.md @@ -0,0 +1,5 @@ +# Org-mode syntax highlighting for Vim + +TODO: test with other colorthemes +TODO: fix italics +TODO: fix hyperlinks diff --git a/ftdetect/org.vim b/ftdetect/org.vim new file mode 100644 index 0000000..0230209 --- /dev/null +++ b/ftdetect/org.vim @@ -0,0 +1,7 @@ +" ============================================================= +" Description: Detect Org-mode files +" Author: Alex Vear (axvr) +" Licence: ISC (2018) +" ============================================================= + +autocmd BufRead,BufNewFile *.org setfiletype org diff --git a/ftplugin/org.vim b/ftplugin/org.vim new file mode 100644 index 0000000..e7f7ef1 --- /dev/null +++ b/ftplugin/org.vim @@ -0,0 +1,26 @@ +" ============================================================= +" Description: Configure Org-mode folding +" Author: Alex Vear (axvr) +" Licence: ISC (2018) +" ============================================================= + +setlocal conceallevel=2 +setlocal commentstring=#%s + +function! OrgFold() + let l:depth = match(getline(v:lnum), '\(^\*\+\)\@<=\( .*$\)\@=') + if l:depth > 0 && synIDattr(synID(v:lnum, 1, 1), 'name') ~=# 'orgHeading' + return ">" . l:depth + endif + return "=" +endfunction + +setlocal foldexpr=OrgFold() +setlocal foldmethod=expr + +" Make folds more readable +setlocal foldtext=getline(v:foldstart) +setlocal fillchars-=fold:- +setlocal fillchars+=fold:\ + +" TODO add working links? diff --git a/syntax/org.vim b/syntax/org.vim new file mode 100644 index 0000000..198f6bd --- /dev/null +++ b/syntax/org.vim @@ -0,0 +1,90 @@ +" ============================================================= +" Description: Basic Org-mode syntax highlighting +" Author: Alex Vear (axvr) +" Licence: ISC (2018) +" ============================================================= + +if exists("b:current_syntax") + finish +endif + +" FIXME spell checking does not work on standard lines. + +syntax region orgItalic matchgroup=orgItalicDelimiter start="\S\@<=\/\|\/\S\@=" end="\S\@<=\/\|\/\S\@=" keepend contains=@Spell concealends oneline +syntax region orgBold matchgroup=orgBoldDelimiter start="\S\@<=\*\|\*\S\@=" end="\S\@<=\*\|\*\S\@=" keepend contains=@Spell concealends oneline +syntax region orgUnderline matchgroup=orgUnderlineDelimiter start="\S\@<=_\|_\S\@=" end="\S\@<=_\|_\S\@=" keepend contains=@Spell concealends oneline +syntax region orgStrikethrough start="\S\@<=+\|+\S\@=" end="\S\@<=+\|+\S\@=" keepend contains=@Spell concealends oneline + +syntax match orgOption /^\s*#+\w\+.*$/ keepend +syntax region orgTitle matchgroup=orgOption start="^\s*#+TITLE:\s*" end="$" keepend oneline + +syntax region orgCode matchgroup=orgCodeDelimiter start="\S\@<==\|=\S\@=" end="\S\@<==\|=\S\@=" keepend concealends oneline +syntax region orgVerbatim matchgroup=orgVerbatimDelimiter start="\S\@<=\~\|\~\S\@=" end="\S\@<=\~\|\~\S\@=" keepend concealends oneline +syntax match orgVerbatim /^\s*: .*$/ keepend +syntax region orgVerbatim matchgroup=orgBlockDelimiter start="^\s*#+BEGIN_.*" end="^\s*#+END_.*" keepend +syntax region orgCode matchgroup=orgBlockDelimiter start="^\s*#+BEGIN_SRC" end="^\s*#+END_SRC" keepend +syntax region orgCode matchgroup=orgBlockDelimiter start="^\s*#+BEGIN_EXAMPLE" end="^\s*#+END_EXAMPLE" keepend + + +" Comments +syntax match orgComment /^\s*#\s\+.*$/ keepend +syntax region orgComment matchgroup=orgBlockDelimiter start="^\s*#+BEGIN_COMMENT" end="^\s*#+END_COMMENT" keepend +highlight def link orgComment Comment + + +" Headings +syntax match orgHeading1 /^\s*\*\{1}\s\+.*$/ keepend contains=@Spell,orgTag,orgTodo +syntax match orgHeading2 /^\s*\*\{2}\s\+.*$/ keepend contains=@Spell,orgTag,orgTodo +syntax match orgHeading3 /^\s*\*\{3}\s\+.*$/ keepend contains=@Spell,orgTag,orgTodo +syntax match orgHeading4 /^\s*\*\{4}\s\+.*$/ keepend contains=@Spell,orgTag,orgTodo +syntax match orgHeading5 /^\s*\*\{5}\s\+.*$/ keepend contains=@Spell,orgTag,orgTodo +syntax match orgHeading6 /^\s*\*\{6}\s\+.*$/ keepend contains=@Spell,orgTag,orgTodo +syntax match orgTag /:\w\{-}:/ contained contains=orgTag +syntax keyword orgTodo contained TODO NEXT DONE + + +" Timestamp +syntax match orgTimestamp /<\d\{4}-\d\{2}-\d\{2}.\{-}>/ keepend +highlight def link orgTimestamp Operator + + +" FIXME Hyperlinks +" - Highlight a link without formatting +" - Fix issues with italics +syntax match orgHyperlink "\[\{2}[^][]*\(\]\[[^][]*\)\?\]\{2}" contains=orgHyperlinkBracketsLeft,orgHyperlinkURL,orgHyperlinkBracketsRight containedin=ALL +syntax match orgHyperlinkBracketsLeft contained "\[\{2}#\?" conceal +syntax match orgHyperlinkURL contained "[^][]*\]\[" conceal +syntax match orgHyperlinkBracketsRight contained "\]\{2}" conceal +highlight def link orgHyperlink Underlined + + +" TODO Tables + + +highlight def orgItalic term=italic cterm=italic gui=italic +highlight def orgBold term=bold cterm=bold gui=bold +highlight def orgUnderline term=underline cterm=underline gui=underline +highlight def link orgItalicDelimiter orgItalic +highlight def link orgBoldDelimiter orgBold +highlight def link orgUnderlineDelimiter orgUnderline + +highlight def link orgHeading1 htmlH1 +highlight def link orgHeading2 htmlH2 +highlight def link orgHeading3 htmlH3 +highlight def link orgHeading4 htmlH4 +highlight def link orgHeading5 htmlH5 +highlight def link orgHeading6 htmlH6 +highlight def link orgTodo Todo +highlight def link orgTag Constant + +highlight def link orgVerbatim Delimiter +highlight def link orgVerbatimDelimiter orgVerbatim +highlight def link orgCode Statement +highlight def link orgCodeDelimiter orgCode + +highlight def link orgBlockDelimiter SpecialComment +highlight def link orgOption Constant +highlight def link orgTitle Function + + +let b:current_syntax = 'org'