Source

dotfiles / vim / .vim / ftplugin / hg.vim

Full commit
" Show diff while editing a Mercurial commit message
" Inspired by http://stackoverflow.com/questions/8009333/vim-show-diff-on-commit-in-mercurial
" and Michael Scherer' svn.vim

fun! HgCommitMQDiff()
    " open new diff window
    pclose
    new
    setlocal ft=diff previewwindow bufhidden=delete nobackup noswf nobuflisted nowrap buftype=nofile
    silent exec ':0r!hg export qtip'
    setlocal nomodifiable
    goto 1
    redraw!

    " no idea why I have to do this
    syn enable
endfun

fun! HgCommitDiff()
    let i = 0
    let modfiles = ''

    " skip message lines
    while i <= line('$') && getline(i) != 'HG: --'
        let i = i + 1
    endwhile

    " get files to read
    while i <= line('$')
        let line = getline(i)
        if line =~ '^HG: \(added\|changed\)'
            let fname = substitute(line, '^HG: \(added\|changed\) ', '', '')
            let fname = "'".substitute(fname, "'", "'\''", '')."'"
            let modfiles = modfiles . ' ' . fname
        endif
        let i = i + 1
    endwhile

    if modfiles == ""
        return
    endif

    " open new diff window
    pclose
    new
    setlocal ft=diff previewwindow bufhidden=delete nobackup noswf nobuflisted nowrap buftype=nofile
    silent exec ':0r!hg diff ' . modfiles
    setlocal nomodifiable
    goto 1
    redraw!

    " no idea why I have to do this
    syn enable
endfun

set colorcolumn=72
set textwidth=72