Mercurial > vim-lawrencium
comparison plugin/lawrencium.vim @ 63:02a1be804fe8
Using Lawrencium buffers for `Hgstatus`.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Fri, 23 Nov 2012 14:18:59 -0800 |
parents | 136be8fa8710 |
children | e75ecde434d7 |
comparison
equal
deleted
inserted
replaced
62:136be8fa8710 | 63:02a1be804fe8 |
---|---|
121 call s:throw("No Mercurial repository found above: " . a:path) | 121 call s:throw("No Mercurial repository found above: " . a:path) |
122 endfunction | 122 endfunction |
123 | 123 |
124 " Given a Lawrencium path (e.g: 'lawrencium:///repo/root_dir//foo/bar/file.py//rev=34'), extract | 124 " Given a Lawrencium path (e.g: 'lawrencium:///repo/root_dir//foo/bar/file.py//rev=34'), extract |
125 " the repository root, relative file path and revision number/changeset ID. | 125 " the repository root, relative file path and revision number/changeset ID. |
126 " | |
127 " If a second argument exists, it must be: | |
128 " - `relative`: to make the file path relative to the repository root. | |
129 " - `absolute`: to make the file path absolute. | |
130 " | |
126 function! s:parse_lawrencium_path(lawrencium_path, ...) | 131 function! s:parse_lawrencium_path(lawrencium_path, ...) |
127 let l:repo_path = s:shellslash(a:lawrencium_path) | 132 let l:repo_path = s:shellslash(a:lawrencium_path) |
128 if l:repo_path =~? '\v^lawrencium://' | 133 if l:repo_path =~? '\v^lawrencium://' |
129 let l:repo_path = strpart(l:repo_path, strlen('lawrencium://')) | 134 let l:repo_path = strpart(l:repo_path, strlen('lawrencium://')) |
130 endif | 135 endif |
632 " }}} | 637 " }}} |
633 | 638 |
634 " Hgstatus {{{ | 639 " Hgstatus {{{ |
635 | 640 |
636 function! s:HgStatus() abort | 641 function! s:HgStatus() abort |
637 " Get the repo and the `hg status` output. | 642 " Get the repo and the Lawrencium path for `hg status`. |
638 let l:repo = s:hg_repo() | 643 let l:repo = s:hg_repo() |
639 let l:status_text = l:repo.RunCommand('status') | 644 let l:status_path = l:repo.GetLawrenciumPath('', 'status', '') |
640 if l:status_text ==# '\v%^\s*%$' | 645 |
641 echo "Nothing modified." | 646 " Open the Lawrencium buffer in a new split window of the right size. |
642 endif | 647 execute "rightbelow split " . l:status_path |
643 | 648 if line('$') == 1 |
644 " Open a new temp buffer in a new window, jump to it, | 649 " Buffer is empty, which means there are not changes... |
645 " and paste the `hg status` output in there. | 650 " Quit and display a message. |
646 let l:temp_file = s:tempname('hg-status-', '.txt') | 651 q |
647 let l:status_lines = split(l:status_text, '\n') | 652 echom "Nothing was modified." |
648 split | 653 endif |
654 | |
655 execute "setlocal noreadonly" | |
649 execute "setlocal winfixheight" | 656 execute "setlocal winfixheight" |
650 execute "setlocal winheight=" . (len(l:status_lines) + 1) | 657 execute "setlocal winheight=" . (line('$') + 1) |
651 execute "resize " . (len(l:status_lines) + 1) | 658 execute "resize " . (line('$') + 1) |
652 execute "edit " . l:temp_file | |
653 call append(0, l:status_lines) | |
654 call cursor(1, 1) | |
655 " Make sure it's deleted when we exit the window. | |
656 setlocal bufhidden=delete | |
657 | |
658 " Setup the buffer correctly: readonly, and with the correct repo linked | |
659 " to it. | |
660 let b:mercurial_dir = l:repo.root_dir | |
661 setlocal buftype=nofile | |
662 setlocal filetype=hgstatus | |
663 | |
664 " Make commands available. | |
665 call s:DefineMainCommands() | |
666 | 659 |
667 " Add some nice commands. | 660 " Add some nice commands. |
668 command! -buffer Hgstatusedit :call s:HgStatus_FileEdit() | 661 command! -buffer Hgstatusedit :call s:HgStatus_FileEdit() |
669 command! -buffer Hgstatusdiff :call s:HgStatus_Diff(0) | 662 command! -buffer Hgstatusdiff :call s:HgStatus_Diff(0) |
670 command! -buffer Hgstatusvdiff :call s:HgStatus_Diff(1) | 663 command! -buffer Hgstatusvdiff :call s:HgStatus_Diff(1) |
671 command! -buffer Hgstatusdiffsum :call s:HgStatus_DiffSummary(0) | 664 command! -buffer Hgstatusdiffsum :call s:HgStatus_DiffSummary(0) |
672 command! -buffer Hgstatusvdiffsum :call s:HgStatus_DiffSummary(1) | 665 command! -buffer Hgstatusvdiffsum :call s:HgStatus_DiffSummary(1) |
673 command! -buffer Hgstatusrefresh :call s:HgStatus_Refresh() | 666 command! -buffer Hgstatusrefresh :call s:HgStatus_Refresh() |
674 command! -buffer -range Hgstatusaddremove :call s:HgStatus_AddRemove(<line1>, <line2>) | 667 command! -buffer -range Hgstatusaddremove :call s:HgStatus_AddRemove(<line1>, <line2>) |
675 command! -buffer -range=% -bang Hgstatuscommit :call s:HgStatus_Commit(<line1>, <line2>, <bang>0, 0) | 668 command! -buffer -range=% -bang Hgstatuscommit :call s:HgStatus_Commit(<line1>, <line2>, <bang>0, 0) |
676 command! -buffer -range=% -bang Hgstatusvcommit :call s:HgStatus_Commit(<line1>, <line2>, <bang>0, 1) | 669 command! -buffer -range=% -bang Hgstatusvcommit :call s:HgStatus_Commit(<line1>, <line2>, <bang>0, 1) |
677 command! -buffer -range=% -nargs=+ Hgstatusqnew :call s:HgStatus_QNew(<line1>, <line2>, <f-args>) | 670 command! -buffer -range=% -nargs=+ Hgstatusqnew :call s:HgStatus_QNew(<line1>, <line2>, <f-args>) |
678 command! -buffer -range=% Hgstatusqrefresh :call s:HgStatus_QRefresh(<line1>, <line2>) | 671 command! -buffer -range=% Hgstatusqrefresh :call s:HgStatus_QRefresh(<line1>, <line2>) |
679 | 672 |
692 nnoremap <buffer> <silent> q :bdelete!<cr> | 685 nnoremap <buffer> <silent> q :bdelete!<cr> |
693 | 686 |
694 vnoremap <buffer> <silent> <C-A> :Hgstatusaddremove<cr> | 687 vnoremap <buffer> <silent> <C-A> :Hgstatusaddremove<cr> |
695 vnoremap <buffer> <silent> <C-S> :Hgstatuscommit<cr> | 688 vnoremap <buffer> <silent> <C-S> :Hgstatuscommit<cr> |
696 endif | 689 endif |
697 | |
698 " Make sure the file is deleted with the buffer. | |
699 autocmd BufDelete <buffer> call s:clean_tempfile(expand('<afile>:p')) | |
700 endfunction | 690 endfunction |
701 | 691 |
702 function! s:HgStatus_Refresh() abort | 692 function! s:HgStatus_Refresh() abort |
703 " Get the repo and the `hg status` output. | 693 " Just re-edit the buffer, it will reload the contents by calling |
704 let l:repo = s:hg_repo() | 694 " the matching Mercurial command. |
705 let l:status_text = l:repo.RunCommand('status') | |
706 | |
707 " Replace the contents of the current buffer with it, and refresh. | |
708 let l:path = expand('%:p') | |
709 let l:status_lines = split(l:status_text, '\n') | |
710 call writefile(l:status_lines, l:path) | |
711 edit | 695 edit |
712 endfunction | 696 endfunction |
713 | 697 |
714 function! s:HgStatus_FileEdit() abort | 698 function! s:HgStatus_FileEdit() abort |
715 " Get the path of the file the cursor is on. | 699 " Get the path of the file the cursor is on. |
1434 if l:comps['value'] == '' | 1418 if l:comps['value'] == '' |
1435 call l:repo.ReadCommandOutput('cat', l:full_path) | 1419 call l:repo.ReadCommandOutput('cat', l:full_path) |
1436 else | 1420 else |
1437 call l:repo.ReadCommandOutput('cat', '-r', l:comps['value'], l:full_path) | 1421 call l:repo.ReadCommandOutput('cat', '-r', l:comps['value'], l:full_path) |
1438 endif | 1422 endif |
1423 elseif l:comps['action'] == 'status' | |
1424 " Status (`hg status`) | |
1425 if l:comps['path'] == '' | |
1426 call l:repo.ReadCommandOutput('status') | |
1427 else | |
1428 call l:repo.ReadCommandOutput('status', l:full_path) | |
1429 endif | |
1430 setlocal filetype=hgstatus | |
1439 elseif l:comps['action'] == 'diff' | 1431 elseif l:comps['action'] == 'diff' |
1440 " Diff revisions (`hg diff`) | 1432 " Diff revisions (`hg diff`) |
1441 let l:diffargs = [] | 1433 let l:diffargs = [] |
1442 let l:commaidx = stridx(l:comps['value'], ',') | 1434 let l:commaidx = stridx(l:comps['value'], ',') |
1443 if l:commaidx > 0 | 1435 if l:commaidx > 0 |