Skip to content

Commit 7964f55

Browse files
committed
Initial commit
0 parents  commit 7964f55

File tree

3 files changed

+129
-0
lines changed

3 files changed

+129
-0
lines changed

README.mkd

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# vim-criticmarkup
2+
3+
Adds [criticmarkup][] support to vim. Attaches to `pandoc`, `markdown`, `mkd`
4+
and `txt` filetypes.
5+
6+
[criticmarkup]: http://criticmarkup.com/
7+
8+
![screenshot](http://i.imgur.com/cdlK1ek.png)
9+
10+
## Basic syntax
11+
12+
criticmarkup can be used to annotate additions, deletions, substitutions,
13+
highlights and comments in a text document.
14+
15+
### Additions
16+
17+
That was a {++very ++}hasty comment.
18+
19+
### Deletions
20+
21+
It is {--not --} uncommon for people to tell the truth.
22+
23+
### Substitutions
24+
25+
The {~~bird~>condor~~} flew majestic through the skies.
26+
27+
### Comments
28+
29+
I believe this is not enough.{>> @editor on what grounds? <<}
30+
31+
### Highlights
32+
33+
{==Some sources==}{>> Which? <<} mention ὰταραξία as the ancient skeptics goal.
34+
35+
## Handling annotations
36+
37+
vim-criticmarkup creates a command, `:Critic`, that can accept, reject and
38+
delete annotations. To accept an edit, simply place the cursor inside the
39+
annotation and then execute
40+
41+
:Critic accept
42+
43+
If you want to reject it, use
44+
45+
:Critic reject
46+
47+
Currently, neither accept or reject work on highlights or comments.
48+
49+
## TODO
50+
51+
* Expand `accept`s and `reject`s to handle highlights and comments.
52+
* Implement operators and keyboard mappings to create annotations.

autoload/criticmarkup.vim

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
function! criticmarkup#Init()
2+
command! -buffer -nargs=1 -complete=custom,criticmarkup#CriticCompleteFunc
3+
\Critic call criticmarkup#Critic("<args>")
4+
endfunction
5+
6+
function! criticmarkup#InjectHighlighting()
7+
syn region criticAddition start=/{++/ end=/++}/
8+
syn region criticDeletion start=/{--/ end=/--}/
9+
syn region criticSubstitutionDeletion start=/{\~\~/ end=/.\(\~>\)\@=/
10+
syn region criticSubstitutionAddition start=/\~>/ end=/\~\~}/
11+
syn region criticComment start=/{>>/ end=/<<}/
12+
syn region criticHighlight start=/{==/ end=/==}/
13+
14+
hi criticAddition guibg=#00ff00 guifg=#101010
15+
hi criticDeletion guibg=#ff0000 guifg=#ffffff
16+
hi link criticSubstitutionAddition criticAddition
17+
hi link criticSubstitutionDeletion criticDeletion
18+
hi criticComment guibg=#0099FF guifg=#101010
19+
hi criticHighlight guibg=#ffff00 guifg=#101010
20+
endfunction
21+
22+
function! criticmarkup#Accept()
23+
let kind = synIDattr(synID(line("."), col("."), 1), "name")
24+
if kind == "criticAddition"
25+
call search("{++", "cb")
26+
normal d3l
27+
call search("++}", "c")
28+
normal d3l
29+
elseif kind == "criticDeletion"
30+
call search("{--", "cb")
31+
"fails at end of line
32+
exe "normal d/\\(--}\\)\\@<=\\_.\<cr>"
33+
elseif kind =~ "criticSubstitution"
34+
call search('{\~\~', "cb")
35+
exe "normal d/\\(\\~>\\)\\@<=\\_.\<cr>"
36+
call search('\~\~}', "c")
37+
exe "normal d/\\(\\~\\~}\\)\\@<=\\_.\<cr>"
38+
endif
39+
endfunction
40+
41+
function! criticmarkup#Reject()
42+
let kind = synIDattr(synID(line("."), col("."), 1), "name")
43+
if kind == "criticDeletion"
44+
call search("{--", "cb")
45+
normal df}
46+
call search("--}", "c")
47+
normal d3l
48+
elseif kind == "criticAddition"
49+
call search("{++", "cb")
50+
normal df}
51+
elseif kind =~ "criticSubstitution"
52+
call search('{\~\~', "cb")
53+
normal df>
54+
call search('\~\~}', "c")
55+
normal df}
56+
endif
57+
endfunction
58+
59+
function! criticmarkup#Critic(args)
60+
if a:args =~ "accept"
61+
call criticmarkup#Accept()
62+
elseif a:args =~ "\(reject\|delete\)"
63+
call criticmarkup#Reject()
64+
endif
65+
endfunction
66+
67+
function! criticmarkup#CriticCompleteFunc(a, c, p)
68+
if len(split(a:c, " ", 1)) < 3
69+
return "accept\nreject\ndelete"
70+
else
71+
return ""
72+
endif
73+
endfunction

plugin/criticmarkup.vim

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
augroup criticmarkup
2+
au! Filetype pandoc,markdown,mkd,txt call criticmarkup#Init()
3+
au! Syntax pandoc,markdown,mkd,txt call criticmarkup#InjectHighlighting()
4+
augroup END

0 commit comments

Comments
 (0)