Tim Chase wrote:
> For a more complex version, you could use
>
> fde=(getline(v:lnum)=~'^Index')?0:(getline(v:lnum)=~'^=\\{3,}')?1:((getline(v:lnum)=~'^@@')?'>2':'=')
>
> (all in one line, in case mailers mung it) which should handle
> both multiple hunks and multiple files-to-be-patched in the same
> .diff/.patch file.
>
> That breaks down as
>
> - If it begins with 'Index', don't indent it
>
> - If it begins with 3+ "=" signs, start indenting 1 level
>
> - If it starts with "@@", consider it the beginning of a hunk and
> start indent-level-2
>
> - Finally, for everything else, treat it as the indentation that
> comes from the previous line.
Thank you for your input. I used it as inspiration for the attached 'diff'
ftplugin, which handles the fold level of various diff formats (normal, context,
unified, subversion, git, rcs, ed).
--
Andreas.
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---
setlocal fdm=expr
setlocal fde=DiffFoldLevel()
setlocal fdc=1
" Get fold level for diff mode
" Works with normal, context, unified, rcs, ed, subversion and git diffs.
" For rcs diffs, folds only files (rcs has no hunks in the common sense)
" fdl=1 ==> file
" fld=2 ==> hunk
" context diffs need special treatment, as hunks are defined
" via context (after '***************'); checking for '*** '
" or ('--- ') only does not work, as the file lines have the
" same marker.
" Inspired by Tim Chase.
function! DiffFoldLevel()
let l:line=getline(v:lnum)
if l:line =~# '^\(diff\|Index\)' " file
return '>1'
elseif l:line =~# '^\(@@\|\d\)' " hunk
return '>2'
elseif l:line =~# '^\*\*\* \d\+,\d\+ \*\*\*\*$' " context: file1
return '>2'
elseif l:line =~# '^--- \d\+,\d\+ ----$' " context: file2
return '>2'
else
return '='
endif
endfunction