Mercurial > vim-lawrencium
comparison plugin/lawrencium.vim @ 33:a5b2f8e4fb6c
Changes to the `Hgstatus` window:
- the buffer is editable, and actions like `addremove` or `commit` will only
act on the remaining filenames.
- added ability to run `addremove` on a selection range.
- added ability to run a commit action.
- added visual mode mappings.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Tue, 27 Dec 2011 23:48:50 -0800 |
parents | 799c7b57e19a |
children | 9361f6b9e5a4 |
comparison
equal
deleted
inserted
replaced
32:799c7b57e19a | 33:a5b2f8e4fb6c |
---|---|
354 setlocal bufhidden=delete | 354 setlocal bufhidden=delete |
355 | 355 |
356 " Setup the buffer correctly: readonly, and with the correct repo linked | 356 " Setup the buffer correctly: readonly, and with the correct repo linked |
357 " to it. | 357 " to it. |
358 let b:mercurial_dir = l:repo.root_dir | 358 let b:mercurial_dir = l:repo.root_dir |
359 setlocal nomodified | |
360 setlocal nomodifiable | |
361 setlocal readonly | |
362 setlocal buftype=nofile | 359 setlocal buftype=nofile |
363 setlocal syntax=hgstatus | 360 setlocal syntax=hgstatus |
364 | 361 |
365 " Make commands available. | 362 " Make commands available. |
366 call s:DefineMainCommands() | 363 call s:DefineMainCommands() |
367 | 364 |
368 " Add some nice commands. | 365 " Add some nice commands. |
369 command! -buffer Hgstatusedit :call s:HgStatus_FileEdit() | 366 command! -buffer Hgstatusedit :call s:HgStatus_FileEdit() |
370 command! -buffer -range Hgstatusaddremove :call s:HgStatus_AddRemove(<line1>, <line2>) | 367 command! -buffer Hgstatusdiff :call s:HgStatus_Diff(0) |
371 command! -buffer Hgstatusdiff :call s:HgStatus_Diff(0) | 368 command! -buffer Hgstatusvdiff :call s:HgStatus_Diff(1) |
372 command! -buffer Hgstatusvdiff :call s:HgStatus_Diff(1) | 369 command! -buffer Hgstatusrefresh :call s:HgStatus_Refresh() |
373 command! -buffer Hgstatusrefresh :call s:HgStatus_Refresh() | 370 command! -buffer -range Hgstatusaddremove :call s:HgStatus_AddRemove(<line1>, <line2>) |
371 command! -buffer -range=% -bang Hgstatuscommit :call s:HgStatus_Commit(<line1>, <line2>, <bang>0, 0) | |
372 command! -buffer -range=% -bang Hgstatusvcommit :call s:HgStatus_Commit(<line1>, <line2>, <bang>0, 1) | |
374 | 373 |
375 " Add some handy mappings. | 374 " Add some handy mappings. |
376 if g:lawrencium_define_mappings | 375 if g:lawrencium_define_mappings |
377 nnoremap <buffer> <silent> <cr> :Hgstatusedit<cr> | 376 nnoremap <buffer> <silent> <cr> :Hgstatusedit<cr> |
378 nnoremap <buffer> <silent> <C-N> :call search('^[MARC\!\?I ]\s.', 'We')<cr> | 377 nnoremap <buffer> <silent> <C-N> :call search('^[MARC\!\?I ]\s.', 'We')<cr> |
379 nnoremap <buffer> <silent> <C-P> :call search('^[MARC\!\?I ]\s.', 'Wbe')<cr> | 378 nnoremap <buffer> <silent> <C-P> :call search('^[MARC\!\?I ]\s.', 'Wbe')<cr> |
380 nnoremap <buffer> <silent> <C-D> :Hgstatusdiff<cr> | 379 nnoremap <buffer> <silent> <C-D> :Hgstatusdiff<cr> |
381 nnoremap <buffer> <silent> <C-V> :Hgstatusvdiff<cr> | 380 nnoremap <buffer> <silent> <C-V> :Hgstatusvdiff<cr> |
382 nnoremap <buffer> <silent> <C-A> :Hgstatusaddremove<cr> | 381 nnoremap <buffer> <silent> <C-A> :Hgstatusaddremove<cr> |
382 nnoremap <buffer> <silent> <C-S> :Hgstatuscommit<cr> | |
383 nnoremap <buffer> <silent> <C-R> :Hgstatusrefresh<cr> | 383 nnoremap <buffer> <silent> <C-R> :Hgstatusrefresh<cr> |
384 nnoremap <buffer> <silent> q :bdelete!<cr> | 384 nnoremap <buffer> <silent> q :bdelete!<cr> |
385 | |
386 vnoremap <buffer> <silent> <C-A> :Hgstatusaddremove<cr> | |
387 vnoremap <buffer> <silent> <C-S> :Hgstatuscommit<cr> | |
385 endif | 388 endif |
386 | 389 |
387 " Make sure the file is deleted with the buffer. | 390 " Make sure the file is deleted with the buffer. |
388 autocmd BufDelete <buffer> call s:HgStatus_CleanUp(expand('<afile>:p')) | 391 autocmd BufDelete <buffer> call s:HgStatus_CleanUp(expand('<afile>:p')) |
389 endfunction | 392 endfunction |
439 let l:repo = s:hg_repo() | 442 let l:repo = s:hg_repo() |
440 call l:repo.RunCommand('addremove', l:filenames) | 443 call l:repo.RunCommand('addremove', l:filenames) |
441 | 444 |
442 " Refresh the status window. | 445 " Refresh the status window. |
443 call s:HgStatus_Refresh() | 446 call s:HgStatus_Refresh() |
447 endfunction | |
448 | |
449 function! s:HgStatus_Commit(linestart, lineend, bang, vertical) abort | |
450 " Get the selected filenames. | |
451 let l:filenames = s:HgStatus_GetSelectedFiles(a:linestart, a:lineend, ['M', 'A', 'R']) | |
452 if len(l:filenames) == 0 | |
453 call s:error("No files to commit in selection or file.") | |
454 endif | |
455 | |
456 " Run `Hgcommit` on those paths. | |
457 call s:HgCommit(a:bang, a:vertical, l:filenames) | |
444 endfunction | 458 endfunction |
445 | 459 |
446 function! s:HgStatus_Diff(vertical) abort | 460 function! s:HgStatus_Diff(vertical) abort |
447 " Open the file and run `Hgdiff` on it. | 461 " Open the file and run `Hgdiff` on it. |
448 call s:HgStatus_FileEdit() | 462 call s:HgStatus_FileEdit() |
655 | 669 |
656 " }}} | 670 " }}} |
657 | 671 |
658 " Hgcommit {{{ | 672 " Hgcommit {{{ |
659 | 673 |
660 function! s:HgCommit(bang, vertical) abort | 674 function! s:HgCommit(bang, vertical, ...) abort |
661 " Get the repo we'll be committing into. | 675 " Get the repo we'll be committing into. |
662 let l:repo = s:hg_repo() | 676 let l:repo = s:hg_repo() |
677 | |
678 " Get the list of files to commit. | |
679 " It can either be several files passed as extra parameters, or an | |
680 " actual list passed as the first extra parameter. | |
681 let l:filenames = [] | |
682 if a:0 | |
683 let l:filenames = a:000 | |
684 if a:0 == 1 && type(a:1) == type([]) | |
685 let l:filenames = a:1 | |
686 endif | |
687 endif | |
663 | 688 |
664 " Open a commit message file. | 689 " Open a commit message file. |
665 let l:commit_path = s:tempname('hg-editor-', '.txt') | 690 let l:commit_path = s:tempname('hg-editor-', '.txt') |
666 let l:split = a:vertical ? 'vsplit' : 'split' | 691 let l:split = a:vertical ? 'vsplit' : 'split' |
667 execute l:split . ' ' . l:commit_path | 692 execute l:split . ' ' . l:commit_path |
668 call append(0, ['', '']) | 693 call append(0, ['', '']) |
669 call append(2, split(s:HgCommit_GenerateMessage(l:repo), '\n')) | 694 call append(2, split(s:HgCommit_GenerateMessage(l:repo, l:filenames), '\n')) |
670 call cursor(1, 1) | 695 call cursor(1, 1) |
671 | 696 |
672 " Setup the auto-command that will actually commit on write/exit, | 697 " Setup the auto-command that will actually commit on write/exit, |
673 " and make the buffer delete itself on exit. | 698 " and make the buffer delete itself on exit. |
674 let b:mercurial_dir = l:repo.root_dir | 699 let b:mercurial_dir = l:repo.root_dir |
700 let b:lawrencium_commit_files = l:filenames | |
675 setlocal bufhidden=delete | 701 setlocal bufhidden=delete |
676 setlocal syntax=hgcommit | 702 setlocal syntax=hgcommit |
677 if a:bang | 703 if a:bang |
678 autocmd BufDelete <buffer> call s:HgCommit_Execute(expand('<afile>:p'), 0) | 704 autocmd BufDelete <buffer> call s:HgCommit_Execute(expand('<afile>:p'), 0) |
679 else | 705 else |
692 \'?': 'not tracked', | 718 \'?': 'not tracked', |
693 \'I': 'ignored', | 719 \'I': 'ignored', |
694 \' ': '', | 720 \' ': '', |
695 \} | 721 \} |
696 | 722 |
697 function! s:HgCommit_GenerateMessage(repo) abort | 723 function! s:HgCommit_GenerateMessage(repo, filenames) abort |
698 let l:msg = "HG: Enter commit message. Lines beginning with 'HG:' are removed.\n" | 724 let l:msg = "HG: Enter commit message. Lines beginning with 'HG:' are removed.\n" |
699 let l:msg .= "HG: Leave message empty to abort commit.\n" | 725 let l:msg .= "HG: Leave message empty to abort commit.\n" |
700 let l:msg .= "HG: Write and quit buffer to proceed.\n" | 726 let l:msg .= "HG: Write and quit buffer to proceed.\n" |
701 let l:msg .= "HG: --\n" | 727 let l:msg .= "HG: --\n" |
702 let l:msg .= "HG: user: " . split(a:repo.RunCommand('showconfig ui.username'), '\n')[0] . "\n" | 728 let l:msg .= "HG: user: " . split(a:repo.RunCommand('showconfig ui.username'), '\n')[0] . "\n" |
703 let l:msg .= "HG: branch '" . split(a:repo.RunCommand('branch'), '\n')[0] . "'\n" | 729 let l:msg .= "HG: branch '" . split(a:repo.RunCommand('branch'), '\n')[0] . "'\n" |
704 | 730 |
705 let l:status_lines = split(a:repo.RunCommand('status'), "\n") | 731 if len(a:filenames) |
732 let l:status_lines = split(a:repo.RunCommand('status', a:filenames), "\n") | |
733 else | |
734 let l:status_lines = split(a:repo.RunCommand('status'), "\n") | |
735 endif | |
706 for l:line in l:status_lines | 736 for l:line in l:status_lines |
707 if l:line ==# '' | 737 if l:line ==# '' |
708 continue | 738 continue |
709 endif | 739 endif |
710 let l:type = matchstr(l:line, '\v^[MARC\!\?I ]') | 740 let l:type = matchstr(l:line, '\v^[MARC\!\?I ]') |
735 endif | 765 endif |
736 call writefile(l:lines, a:log_file) | 766 call writefile(l:lines, a:log_file) |
737 | 767 |
738 " Get the repo and commit with the given message. | 768 " Get the repo and commit with the given message. |
739 let l:repo = s:hg_repo() | 769 let l:repo = s:hg_repo() |
740 let l:output = l:repo.RunCommand('commit', '-l', a:log_file) | 770 let l:hg_args = ['-l', a:log_file] |
771 call extend(l:hg_args, b:lawrencium_commit_files) | |
772 let l:output = l:repo.RunCommand('commit', l:hg_args) | |
741 if a:show_output && l:output !~# '\v%^\s*%$' | 773 if a:show_output && l:output !~# '\v%^\s*%$' |
742 call s:trace("Output from hg commit:", 1) | 774 call s:trace("Output from hg commit:", 1) |
743 for l:output_line in split(l:output, '\n') | 775 for l:output_line in split(l:output, '\n') |
744 echom l:output_line | 776 echom l:output_line |
745 endfor | 777 endfor |
746 endif | 778 endif |
747 endfunction | 779 endfunction |
748 | 780 |
749 call s:AddMainCommand("-bang Hgcommit :call s:HgCommit(<bang>0, 0)") | 781 call s:AddMainCommand("-bang -nargs=* -complete=customlist,s:ListRepoFiles Hgcommit :call s:HgCommit(<bang>0, 0, <f-args>)") |
750 call s:AddMainCommand("-bang Hgvcommit :call s:HgCommit(<bang>0, 1)") | 782 call s:AddMainCommand("-bang -nargs=* -complete=customlist,s:ListRepoFiles Hgvcommit :call s:HgCommit(<bang>0, 1, <f-args>)") |
751 | 783 |
752 " }}} | 784 " }}} |
753 | 785 |
754 " Autoload Functions {{{ | 786 " Autoload Functions {{{ |
755 | 787 |