# HG changeset patch # User Ludovic Chabant # Date 1323360867 28800 # Node ID 05fd225bd1a05cf815c071d4f86e8a96b12bb905 # Parent a6bc310e7015ab3589adbae087e1dfa1181475e3 Fixed detect autocmds. diff -r a6bc310e7015 -r 05fd225bd1a0 vim/bundle/lawrencium/plugin/lawrencium.vim --- 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(':p')) -" autocmd VimEnter * if expand('')==''|call s:DetectMercurialRepository(getcwd())|endif + autocmd BufNewFile,BufReadPost * call s:setup_buffer_commands() + autocmd VimEnter * if expand('')==''|call s:setup_buffer_commands()|endif augroup end " }}}