Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions vim/ftplugin/prr.vim
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
setlocal foldmethod=syntax
setlocal foldmethod=expr
setlocal foldexpr=s:DiffFoldLevel()
setlocal foldcolumn=3

let b:undo_ftplugin = 'setl fdm&'
" Adapted from https://github.com/sgeb/vim-diff-fold
function! s:DiffFoldLevel()
let l:line=getline(v:lnum)

if l:line =~# '^> \(diff\|Index\)' " file
return '>1'
elseif l:line =~# '^> \(@@\|\d\)' " hunk
return '>2'
else
return '='
endif
endfunction

let b:undo_ftplugin = 'setl fdm< | setl fde< | setl fdc<'
24 changes: 11 additions & 13 deletions vim/syntax/prr.vim
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,24 @@ if exists("b:current_syntax")
finish
endif

syn region prrFile start=/^> diff/ end=/^> diff/ms=s-1,me=s-1 transparent fold keepend contains=prrHeader,prrIndex,prrChunk
" match + but not +++
syn match prrAdded "^> +\(++\)\@!.*"
" match - but not ---
syn match prrRemoved "^> -\(--\)\@!.*"

syn region prrChunk start=/^> @@/ start=/^\n> /rs=e-2 end=/^> @@/ms=s-1,me=s-1 end=/^> diff/ms=s-1,me=s-1 end=/^$/ transparent fold keepend contains=CONTAINED,prrTag

syn match prrAdded contained "^> +.*"
syn match prrRemoved contained "^> -.*"

syn match prrHeader contained "^> diff.*"
syn match prrIndex contained "^> index.*"
syn match prrChunkH contained "^> @@.*"
syn match prrHeader "^> diff --git .*"
syn match prrIndex "^> index \w*\.\.\w*\( \w*\)\?"
syn match prrChunkH "^> @@ .* @@"

syn match prrTag "^@.*" contains=prrTagName,prrResult transparent

syn match prrTagName contained "@prr" nextgroup=prrResult
syn keyword prrResult contained approve reject comment
syn match prrTagName "@prr" nextgroup=prrResult
syn keyword prrResult approve reject comment

" Define the default highlighting.
" Only used when an item doesn't have highlighting yet
hi def link prrAdded Identifier
hi def link prrRemoved Special
hi def link prrAdded Added
hi def link prrRemoved Removed

hi def link prrTagName Keyword
hi def link prrResult String
Expand Down