Source

Vim Hg2O / plugin / hg2o.vim

Full commit
" hg2o.vim - Vim Hg2O is a wrapper for Mercurial version control system.
" Maintainer:  Ian Liu Rodrigues
" Version:     0.1

" Init {{{1
if exists('g:loaded_hg2o') || &cp
  finish
endif

let g:loaded_hg2o = 1
let s:HG = 'hg'
" }}}1
" Utils {{{1
fun! s:throw(msg)
  let v:errmsg = 'Hg2O: ' . a:msg
  throw v:errmsg
endf

" Returns the root dir of current buffer's HG repo
fun! s:root() abort
  if exists('b:hg_root') && b:hg_root !=# ''
    return b:hg_root
  endif
  let b:hg_root = system(s:HG . ' root')
  if v:shell_error == 0
    return b:hg_root
  endif
  call s:throw('not a mercurial repository: ' . expand('%:p'))
endf
" }}}1
" Hg {{{1
com! -nargs=? -complete=customlist,s:HgComplete Hg :execute s:Hg(<q-args>)

fun! s:Hg(cmd) abort
  exe '!' . s:HG . ' ' . a:cmd
endf

fun! s:HgComplete(A, L, P) abort
  let items = system(s:HG . ' debugcomplete '. a:A)
  if v:shell_error == 0
    return split(items, '\n')
  endif
endf
" }}}1
" Hgstatus {{{1
com! -nargs=0 Hgstatus :execute s:Hgstatus()

fun! s:Hgstatus()
  pedit hg2o://status
  wincmd P
  silent execute '0read !'.s:HG.' status'
  setlocal nomodifiable nomodified readonly ft=hgstatus
endf
" }}}1