comparison plugin/lawrencium.vim @ 6:1da613c13d81

Better hg-status window. Better debug/tracing.
author Ludovic Chabant <ludovic@chabant.com>
date Fri, 09 Dec 2011 17:12:13 -0800
parents 3a4f9f41a7e2
children adc267e2f0f4
comparison
equal deleted inserted replaced
5:3a4f9f41a7e2 6:1da613c13d81
9 endif 9 endif
10 10
11 if (exists('g:loaded_lawrencium') || &cp) && !g:lawrencium_debug 11 if (exists('g:loaded_lawrencium') || &cp) && !g:lawrencium_debug
12 finish 12 finish
13 endif 13 endif
14 if (exists('g:loaded_lawrencium') && g:lawrencium_debug)
15 echom "Reloaded Lawrencium."
16 endif
14 let g:loaded_lawrencium = 1 17 let g:loaded_lawrencium = 1
15 18
16 if !exists('g:lawrencium_hg_executable') 19 if !exists('g:lawrencium_hg_executable')
17 let g:lawrencium_hg_executable = 'hg' 20 let g:lawrencium_hg_executable = 'hg'
18 endif 21 endif
19 22
20 if !exists('g:lawrencium_trace') 23 if !exists('g:lawrencium_trace')
21 let g:lawrencium_trace = 0 24 let g:lawrencium_trace = 0
22 endif
23
24 if g:lawrencium_debug
25 echom "Loaded Lawrencium."
26 endif 25 endif
27 26
28 " }}} 27 " }}}
29 28
30 " Utility {{{ 29 " Utility {{{
44 return a:path 43 return a:path
45 endif 44 endif
46 endfunction 45 endfunction
47 46
48 " Prints a message if debug tracing is enabled. 47 " Prints a message if debug tracing is enabled.
49 function! s:trace(message) 48 function! s:trace(message, ...)
50 if g:lawrencium_trace 49 if g:lawrencium_trace || (a:0 && a:1)
51 let l:message = "lawrencium: " . a:message 50 let l:message = "lawrencium: " . a:message
52 echom l:message 51 echom l:message
53 endif 52 endif
54 endfunction 53 endfunction
55 54
230 \'?': 'not tracked', 229 \'?': 'not tracked',
231 \'I': 'ignored', 230 \'I': 'ignored',
232 \} 231 \}
233 232
234 function! s:HgStatus() abort 233 function! s:HgStatus() abort
234 " Get the repo and the `hg status` output.
235 let l:repo = s:hg_repo() 235 let l:repo = s:hg_repo()
236 let l:status_text = l:repo.RunCommand('status') 236 let l:status_text = l:repo.RunCommand('status')
237 let l:status_lines = split(l:status_text, '\n') 237 let l:status_lines = split(l:status_text, '\n')
238 let l:entries = [] 238
239 for l:line in l:status_lines 239 " Open a new temp buffer in the preview window, jump to it,
240 if l:line =~# '^\s*$' 240 " and paste the `hg status` output in there.
241 continue 241 " Also, make it a nice size, but restore the `previewheight` setting after
242 endif 242 " we're done.
243 echom "STATUS: " . l:line 243 let l:temp_file = tempname()
244 let l:tokens = split(l:line, '\s\+') 244 let l:preview_height = &previewheight
245 let l:entry = { 245 execute "setlocal previewheight=" . (len(l:status_lines) + 1)
246 \'type': l:tokens[0], 246 execute "pedit " . l:temp_file
247 \'filename': (l:repo.root_dir . l:tokens[1]), 247 wincmd p
248 \'text': s:hg_status_messages[l:tokens[0]], 248 call append(0, l:status_lines)
249 \} 249 execute "setlocal previewheight=" . l:preview_height
250 call add(l:entries, l:entry) 250
251 endfor 251 " Setup the buffer correctly.
252 call setloclist(0, l:entries) 252 let b:mercurial_dir = l:repo.root_dir
253 lopen 253 setlocal buftype=nofile
254 setlocal nomodified
255 setlocal nomodifiable
256 setlocal readonly
257
258 " Add some handy mappings.
259 nnoremap <buffer> <silent> <C-N> :call search('^[MARC\!\?I ]\s.', 'We')<cr>
260 nnoremap <buffer> <silent> <C-P> :call search('^[MARC\!\?I ]\s.','Wbe')<cr>
261 nnoremap <buffer> <silent> <cr> :execute <SID>HgStatus_FileEdit()<cr>
262 nnoremap <buffer> <silent> q :bdelete<cr>
263 endfunction
264
265 function! s:HgStatus_FileEdit() abort
266 let l:repo = s:hg_repo()
267 let l:line = getline('.')
268 " Yay, awesome, Vim's regex syntax is fucked up like shit, especially for
269 " look-aheads and look-behinds. See for yourself:
270 let l:filename = matchstr(l:line, '\([MARC\!\?I ]\s\)\@<=.*')
271 let l:filename = l:repo.GetFullPath(l:filename)
272 " Go back to the previous window and open the file there, or open an
273 " existing buffer.
274 wincmd p
275 if bufexists(l:filename)
276 execute 'buffer ' . l:filename
277 else
278 execute 'edit ' . l:filename
279 endif
254 endfunction 280 endfunction
255 281
256 call s:AddMainCommand("Hgstatus :execute s:HgStatus()") 282 call s:AddMainCommand("Hgstatus :execute s:HgStatus()")
257 283
258 " }}} 284 " }}}