comparison plugin/lawrencium.vim @ 66:75e9d909758a

`Hglog` changes: - `Hglog` now list the history for the whole repository. - `Hglogthis` lists the history for the current file. Fixed a bug with displaying diff summaries. Updated documentation.
author Ludovic Chabant <ludovic@chabant.com>
date Sun, 25 Nov 2012 20:00:34 -0800
parents e8f252a7ed9e
children 1cf08e4a7947
comparison
equal deleted inserted replaced
65:e8f252a7ed9e 66:75e9d909758a
423 execute 'augroup end' 423 execute 'augroup end'
424 call s:trace("Built new buffer object for buffer: " . a:number) 424 call s:trace("Built new buffer object for buffer: " . a:number)
425 return l:newBuffer 425 return l:newBuffer
426 endfunction 426 endfunction
427 427
428 function! s:Buffer.GetName() dict abort
429 return bufname(self.nr)
430 endfunction
431
428 function! s:Buffer.GetVar(var) dict abort 432 function! s:Buffer.GetVar(var) dict abort
429 return getbufvar(self.nr, a:var) 433 return getbufvar(self.nr, a:var)
430 endfunction 434 endfunction
431 435
432 function! s:Buffer.SetVar(var, value) dict abort 436 function! s:Buffer.SetVar(var, value) dict abort
1039 " fancy filename modifiers. 1043 " fancy filename modifiers.
1040 let l:repo = s:hg_repo() 1044 let l:repo = s:hg_repo()
1041 let l:path = expand(a:filename) 1045 let l:path = expand(a:filename)
1042 call s:trace("Diff'ing revisions: '".l:revs."' on file: ".l:path) 1046 call s:trace("Diff'ing revisions: '".l:revs."' on file: ".l:path)
1043 let l:special = l:repo.GetLawrenciumPath(l:path, 'diff', l:revs) 1047 let l:special = l:repo.GetLawrenciumPath(l:path, 'diff', l:revs)
1048 let l:cmd = 'edit '
1044 if a:split == 1 1049 if a:split == 1
1045 split 1050 let l:cmd = 'rightbelow split '
1046 elseif a:split == 2 1051 elseif a:split == 2
1047 vsplit 1052 let l:cmd = 'rightbelow vsplit '
1048 endif 1053 endif
1049 execute 'edit ' . l:special 1054 execute l:cmd . l:special
1050 " Open all folds by default.
1051 " TODO: maybe set `nofoldenable` instead?
1052 %foldopen!
1053 endfunction 1055 endfunction
1054 1056
1055 call s:AddMainCommand("-nargs=* Hgdiffsum :call s:HgDiffSummary('%:p', 0, <f-args>)") 1057 call s:AddMainCommand("-nargs=* Hgdiffsum :call s:HgDiffSummary('%:p', 0, <f-args>)")
1056 call s:AddMainCommand("-nargs=* Hgdiffsumsplit :call s:HgDiffSummary('%:p', 1, <f-args>)") 1058 call s:AddMainCommand("-nargs=* Hgdiffsumsplit :call s:HgDiffSummary('%:p', 1, <f-args>)")
1057 call s:AddMainCommand("-nargs=* Hgvdiffsumsplit :call s:HgDiffSummary('%:p', 2, <f-args>)") 1059 call s:AddMainCommand("-nargs=* Hgvdiffsumsplit :call s:HgDiffSummary('%:p', 2, <f-args>)")
1191 1193
1192 call s:AddMainCommand("-bang -nargs=* -complete=customlist,s:ListRepoFiles Hgrevert :call s:HgRevert(<bang>0, <f-args>)") 1194 call s:AddMainCommand("-bang -nargs=* -complete=customlist,s:ListRepoFiles Hgrevert :call s:HgRevert(<bang>0, <f-args>)")
1193 1195
1194 " }}} 1196 " }}}
1195 1197
1196 " Hglog, Hgrepolog {{{ 1198 " Hglog, Hglogthis {{{
1197 1199
1198 function! s:HgLog(is_file, ...) abort 1200 function! s:HgLog(...) abort
1199 " Get the file or directory to get the log from, or figure out 1201 " Get the file or directory to get the log from.
1200 " some nice defaults (the current file, or the whole repository). 1202 " (empty string is for the whole repository)
1201 if a:is_file 1203 let l:repo = s:hg_repo()
1202 let l:path = expand('%:p') 1204 if a:0 > 0
1205 let l:path = l:repo.GetRelativePath(expand(a:1))
1203 else 1206 else
1204 let l:path = '' 1207 let l:path = ''
1205 endif 1208 endif
1206 1209
1207 " Remember the file that opened this log. 1210 " Get the Lawrencium path for this `hg log`,
1208 let l:original_path = expand('%:p') 1211 " open it in a preview window and jump to it.
1209
1210 " Get the Lawrencium path for this `hg log`.
1211 let l:repo = s:hg_repo()
1212 let l:log_path = l:repo.GetLawrenciumPath(l:path, 'log', '') 1212 let l:log_path = l:repo.GetLawrenciumPath(l:path, 'log', '')
1213
1214 " Open it in a preview window and jump to it.
1215 execute 'pedit ' . l:log_path 1213 execute 'pedit ' . l:log_path
1216 wincmd P 1214 wincmd P
1217 1215
1218 " Add some other nice commands and mappings. 1216 " Add some other nice commands and mappings.
1217 let l:is_file = (l:path != '' && filereadable(l:repo.GetFullPath(l:path)))
1219 command! -buffer -nargs=* Hglogdiff :call s:HgLog_Diff(<f-args>) 1218 command! -buffer -nargs=* Hglogdiff :call s:HgLog_Diff(<f-args>)
1220 if a:is_file 1219 if l:is_file
1221 let b:lawrencium_logged_path = l:repo.GetRelativePath(l:path) 1220 command! -buffer Hglogrevedit :call s:HgLog_FileRevEdit()
1222 command! -buffer -nargs=? Hglogrevedit :call s:HgLog_FileRevEdit(<f-args>)
1223 endif 1221 endif
1224 1222
1225 if g:lawrencium_define_mappings 1223 if g:lawrencium_define_mappings
1226 nnoremap <buffer> <silent> <cr> :Hglogdiff<cr> 1224 nnoremap <buffer> <silent> <cr> :Hglogdiff<cr>
1227 nnoremap <buffer> <silent> q :bdelete!<cr> 1225 nnoremap <buffer> <silent> q :bdelete!<cr>
1228 if a:is_file 1226 if l:is_file
1229 nnoremap <buffer> <silent> <C-E> :Hglogrevedit<cr> 1227 nnoremap <buffer> <silent> <C-E> :Hglogrevedit<cr>
1230 endif 1228 endif
1231 endif 1229 endif
1232 1230
1233 " Clean up when the log buffer is deleted. 1231 " Clean up when the log buffer is deleted.
1240 call s:delete_dependency_buffers('lawrencium_diff_for', a:bufnr) 1238 call s:delete_dependency_buffers('lawrencium_diff_for', a:bufnr)
1241 call s:delete_dependency_buffers('lawrencium_rev_for', a:bufnr) 1239 call s:delete_dependency_buffers('lawrencium_rev_for', a:bufnr)
1242 endif 1240 endif
1243 endfunction 1241 endfunction
1244 1242
1245 function! s:HgLog_FileRevEdit(...) 1243 function! s:HgLog_FileRevEdit()
1246 if a:0 > 0
1247 " Revision was given manually.
1248 let l:rev = a:1
1249 else
1250 " Revision should be parsed from the current line in the log.
1251 let l:rev = s:HgLog_GetSelectedRev()
1252 endif
1253 let l:repo = s:hg_repo() 1244 let l:repo = s:hg_repo()
1254 let l:bufobj = s:buffer_obj() 1245 let l:bufobj = s:buffer_obj()
1255 let l:path = l:repo.GetLawrenciumPath(b:lawrencium_logged_path, 'rev', l:rev) 1246 let l:rev = s:HgLog_GetSelectedRev()
1247 let l:log_path = s:parse_lawrencium_path(l:bufobj.GetName())
1248 let l:path = l:repo.GetLawrenciumPath(l:log_path['path'], 'rev', l:rev)
1256 1249
1257 " Go to the window we were in before going in the log window, 1250 " Go to the window we were in before going in the log window,
1258 " and open the revision there. 1251 " and open the revision there.
1259 wincmd p 1252 wincmd p
1260 call s:edit_deletable_buffer('lawrencium_rev_for', l:bufobj.nr, l:path) 1253 call s:edit_deletable_buffer('lawrencium_rev_for', l:bufobj.nr, l:path)
1268 else 1261 else
1269 let l:revs = s:HgLog_GetSelectedRev() 1262 let l:revs = s:HgLog_GetSelectedRev()
1270 endif 1263 endif
1271 let l:repo = s:hg_repo() 1264 let l:repo = s:hg_repo()
1272 let l:bufobj = s:buffer_obj() 1265 let l:bufobj = s:buffer_obj()
1273 let l:path = l:repo.GetLawrenciumPath(b:lawrencium_logged_path, 'diff', l:revs) 1266 let l:log_path = s:parse_lawrencium_path(l:bufobj.GetName())
1267 let l:path = l:repo.GetLawrenciumPath(l:log_path['path'], 'diff', l:revs)
1274 1268
1275 " Go to the window we were in before going in the log window, 1269 " Go to the window we were in before going in the log window,
1276 " and open the diff there. 1270 " and open the diff there.
1277 wincmd p 1271 wincmd p
1278 call s:edit_deletable_buffer('lawrencium_diff_for', l:bufobj.nr, l:path) 1272 call s:edit_deletable_buffer('lawrencium_diff_for', l:bufobj.nr, l:path)
1290 call s:throw("Can't parse revision number from line: " . l:line) 1284 call s:throw("Can't parse revision number from line: " . l:line)
1291 endif 1285 endif
1292 return l:rev 1286 return l:rev
1293 endfunction 1287 endfunction
1294 1288
1295 call s:AddMainCommand("-nargs=? -complete=customlist,s:ListRepoDirs Hgrepolog :call s:HgLog(0, <f-args>)") 1289 call s:AddMainCommand("Hglogthis :call s:HgLog('%:p')")
1296 call s:AddMainCommand("-nargs=? -complete=customlist,s:ListRepoFiles Hglog :call s:HgLog(1, <f-args>)") 1290 call s:AddMainCommand("-nargs=? -complete=customlist,s:ListRepoFiles Hglog :call s:HgLog(<f-args>)")
1297 1291
1298 " }}} 1292 " }}}
1299 1293
1300 " Hgannotate {{{ 1294 " Hgannotate {{{
1301 1295