Mercurial > dotfiles
comparison vim/bundle/lawrencium/plugin/lawrencium.vim @ 52:05fd225bd1a0
Fixed detect autocmds.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Thu, 08 Dec 2011 08:14:27 -0800 |
parents | a6bc310e7015 |
children | 0dbb1fd60f71 |
comparison
equal
deleted
inserted
replaced
51:a6bc310e7015 | 52:05fd225bd1a0 |
---|---|
59 let l:newRepo.root_dir = s:find_repo_root(a:path) | 59 let l:newRepo.root_dir = s:find_repo_root(a:path) |
60 call s:trace("Built new Mercurial repository object at : " . l:newRepo.root_dir) | 60 call s:trace("Built new Mercurial repository object at : " . l:newRepo.root_dir) |
61 return l:newRepo | 61 return l:newRepo |
62 endfunction | 62 endfunction |
63 | 63 |
64 " Sets up the current buffer with local variables | |
65 function! s:HgRepo.SetupBuffer() abort | |
66 if exists('b:mercurial_dir') && (b:mercurial_dir =~# '/^\s*$/') | |
67 unlet b:mercurial_dir | |
68 endif | |
69 if !exists('b:mercurial_dir') | |
70 let b:mercurial_dir = self.root_dir | |
71 endif | |
72 if exists('b:mercurial_dir') | |
73 call s:trace("Setting Mercurial directory to : " . expand(b:mercurial_dir)) | |
74 silent doautocmd User Lawrencium | |
75 endif | |
76 endfunction | |
77 | |
78 " Gets a full path given a repo-relative path | 64 " Gets a full path given a repo-relative path |
79 function! s:HgRepo.GetFullPath(path) abort | 65 function! s:HgRepo.GetFullPath(path) abort |
80 let l:path = self.root_dir | 66 let l:path = self.root_dir |
81 if a:path =~# '^/' | 67 if a:path =~# '^/' |
82 let l:path = s:stripslash(self.root_dir) | 68 let l:path = s:stripslash(self.root_dir) |
101 if a:0 == 0 | 87 if a:0 == 0 |
102 if exists('b:mercurial_dir') | 88 if exists('b:mercurial_dir') |
103 let l:path = b:mercurial_dir | 89 let l:path = b:mercurial_dir |
104 else | 90 else |
105 let l:path = s:find_repo_root(expand('%:p')) | 91 let l:path = s:find_repo_root(expand('%:p')) |
106 let b:mercurial_dir = l:path | |
107 endif | 92 endif |
108 else | 93 else |
109 let l:path = a:1 | 94 let l:path = a:1 |
110 endif | 95 endif |
111 " Find a cache repo instance, or make a new one. | 96 " Find a cache repo instance, or make a new one. |
116 let s:buffer_repos[l:path] = l:repo | 101 let s:buffer_repos[l:path] = l:repo |
117 return l:repo | 102 return l:repo |
118 endif | 103 endif |
119 endfunction | 104 endfunction |
120 | 105 |
106 " Sets up the current buffer with Lawrencium commands if it contains a file from a Mercurial repo. | |
107 " If the file is not in a Mercurial repo, just exit silently. | |
108 function! s:setup_buffer_commands() abort | |
109 let l:do_setup = 1 | |
110 if exists('b:mercurial_dir') | |
111 if b:mercurial_dir =~# '/^\s*$/' | |
112 unlet b:mercurial_dir | |
113 else | |
114 let l:do_setup = 0 | |
115 endif | |
116 endif | |
117 try | |
118 let l:repo = s:hg_repo() | |
119 catch /^lawrencium\:/ | |
120 return | |
121 endtry | |
122 let b:mercurial_dir = l:repo.root_dir | |
123 if exists('b:mercurial_dir') && l:do_setup | |
124 call s:trace("Setting Mercurial commands for buffer '" . bufname('%') . "' with repo : " . expand(b:mercurial_dir)) | |
125 silent doautocmd User Lawrencium | |
126 endif | |
127 endfunction | |
128 | |
121 augroup lawrencium_detect | 129 augroup lawrencium_detect |
122 autocmd! | 130 autocmd! |
123 " autocmd BufNewFile,BufReadPost * call s:DetectMercurialRepository(expand('<amatch>:p')) | 131 autocmd BufNewFile,BufReadPost * call s:setup_buffer_commands() |
124 " autocmd VimEnter * if expand('<amatch>')==''|call s:DetectMercurialRepository(getcwd())|endif | 132 autocmd VimEnter * if expand('<amatch>')==''|call s:setup_buffer_commands()|endif |
125 augroup end | 133 augroup end |
126 | 134 |
127 " }}} | 135 " }}} |
128 | 136 |
129 " Commands {{{ | 137 " Commands {{{ |