Mercurial > dotfiles
changeset 52:05fd225bd1a0
Fixed detect autocmds.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Thu, 08 Dec 2011 08:14:27 -0800 |
parents | a6bc310e7015 |
children | 966df1f863be |
files | vim/bundle/lawrencium/plugin/lawrencium.vim |
diffstat | 1 files changed, 25 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/vim/bundle/lawrencium/plugin/lawrencium.vim Wed Dec 07 23:32:39 2011 -0800 +++ b/vim/bundle/lawrencium/plugin/lawrencium.vim Thu Dec 08 08:14:27 2011 -0800 @@ -61,20 +61,6 @@ return l:newRepo endfunction -" Sets up the current buffer with local variables -function! s:HgRepo.SetupBuffer() abort - if exists('b:mercurial_dir') && (b:mercurial_dir =~# '/^\s*$/') - unlet b:mercurial_dir - endif - if !exists('b:mercurial_dir') - let b:mercurial_dir = self.root_dir - endif - if exists('b:mercurial_dir') - call s:trace("Setting Mercurial directory to : " . expand(b:mercurial_dir)) - silent doautocmd User Lawrencium - endif -endfunction - " Gets a full path given a repo-relative path function! s:HgRepo.GetFullPath(path) abort let l:path = self.root_dir @@ -103,7 +89,6 @@ let l:path = b:mercurial_dir else let l:path = s:find_repo_root(expand('%:p')) - let b:mercurial_dir = l:path endif else let l:path = a:1 @@ -118,10 +103,33 @@ endif endfunction +" Sets up the current buffer with Lawrencium commands if it contains a file from a Mercurial repo. +" If the file is not in a Mercurial repo, just exit silently. +function! s:setup_buffer_commands() abort + let l:do_setup = 1 + if exists('b:mercurial_dir') + if b:mercurial_dir =~# '/^\s*$/' + unlet b:mercurial_dir + else + let l:do_setup = 0 + endif + endif + try + let l:repo = s:hg_repo() + catch /^lawrencium\:/ + return + endtry + let b:mercurial_dir = l:repo.root_dir + if exists('b:mercurial_dir') && l:do_setup + call s:trace("Setting Mercurial commands for buffer '" . bufname('%') . "' with repo : " . expand(b:mercurial_dir)) + silent doautocmd User Lawrencium + endif +endfunction + augroup lawrencium_detect autocmd! -" autocmd BufNewFile,BufReadPost * call s:DetectMercurialRepository(expand('<amatch>:p')) -" autocmd VimEnter * if expand('<amatch>')==''|call s:DetectMercurialRepository(getcwd())|endif + autocmd BufNewFile,BufReadPost * call s:setup_buffer_commands() + autocmd VimEnter * if expand('<amatch>')==''|call s:setup_buffer_commands()|endif augroup end " }}}