Mercurial > vim-lawrencium
comparison plugin/lawrencium.vim @ 91:e21a1819ab27
New command to export a patch and allow existing log command to take options.
* Hglogexport command takes patch name as input. If the env variable
HG_EXPORT_PATCH_DIR is set, then the patch will be created under it.
Otherwise, it will be created in the directory from which vim
was launched.
* HgLog command takes options that can be passed to hg log command.
E.g., the following command will list just 3 logs by user bob.
:Hglog -u bob -l 3
Testing:
* Patch gets created under the right directory when env variable is set
and not set.
* Hglog command honors -u and -l options. It also works when current
file name is given as input --> :Hglog % -u bob -l 3
author | Kannan Rajah <krajah@maprtech.com> |
---|---|
date | Sat, 05 Jul 2014 17:16:42 -0700 |
parents | 777063310a8d |
children | e856f8dc22a8 |
comparison
equal
deleted
inserted
replaced
90:777063310a8d | 91:e21a1819ab27 |
---|---|
36 let g:lawrencium_auto_close_buffers = 1 | 36 let g:lawrencium_auto_close_buffers = 1 |
37 endif | 37 endif |
38 | 38 |
39 if !exists('g:lawrencium_annotate_width_offset') | 39 if !exists('g:lawrencium_annotate_width_offset') |
40 let g:lawrencium_annotate_width_offset = 0 | 40 let g:lawrencium_annotate_width_offset = 0 |
41 endif | |
42 | |
43 if !exists('g:lawrencium_status_win_split_above') | |
44 let g:lawrencium_status_win_split_above = 0 | |
45 endif | |
46 | |
47 if !exists('g:lawrencium_status_win_split_even') | |
48 let g:lawrencium_status_win_split_even = 0 | |
41 endif | 49 endif |
42 | 50 |
43 " }}} | 51 " }}} |
44 | 52 |
45 " Utility {{{ | 53 " Utility {{{ |
593 | 601 |
594 " Log (`hg log`) | 602 " Log (`hg log`) |
595 let s:log_style_file = expand("<sfile>:h:h") . "/resources/hg_log.style" | 603 let s:log_style_file = expand("<sfile>:h:h") . "/resources/hg_log.style" |
596 | 604 |
597 function! s:read_lawrencium_log(repo, path_parts, full_path) abort | 605 function! s:read_lawrencium_log(repo, path_parts, full_path) abort |
606 let l:log_opts = join(split(a:path_parts['value'], ',')) | |
607 let l:log_cmd = "log " . l:log_opts | |
608 | |
598 if a:path_parts['path'] == '' | 609 if a:path_parts['path'] == '' |
599 call a:repo.ReadCommandOutput('log', '--style', shellescape(s:log_style_file)) | 610 call a:repo.ReadCommandOutput(l:log_cmd, '--style', shellescape(s:log_style_file)) |
600 else | 611 else |
601 call a:repo.ReadCommandOutput('log', '--style', shellescape(s:log_style_file), a:full_path) | 612 call a:repo.ReadCommandOutput(l:log_cmd, '--style', shellescape(s:log_style_file), a:full_path) |
602 endif | 613 endif |
603 setlocal filetype=hglog | 614 setlocal filetype=hglog |
604 endfunction | 615 endfunction |
605 | 616 |
606 " Diff revisions (`hg diff`) | 617 " Diff revisions (`hg diff`) |
870 " Get the repo and the Lawrencium path for `hg status`. | 881 " Get the repo and the Lawrencium path for `hg status`. |
871 let l:repo = s:hg_repo() | 882 let l:repo = s:hg_repo() |
872 let l:status_path = l:repo.GetLawrenciumPath('', 'status', '') | 883 let l:status_path = l:repo.GetLawrenciumPath('', 'status', '') |
873 | 884 |
874 " Open the Lawrencium buffer in a new split window of the right size. | 885 " Open the Lawrencium buffer in a new split window of the right size. |
875 execute "rightbelow split " . l:status_path | 886 if g:lawrencium_status_win_split_above |
887 execute "leftabove split " . l:status_path | |
888 else | |
889 execute "rightbelow split " . l:status_path | |
890 endif | |
891 | |
876 if (line('$') == 1 && getline(1) == '') | 892 if (line('$') == 1 && getline(1) == '') |
877 " Buffer is empty, which means there are not changes... | 893 " Buffer is empty, which means there are not changes... |
878 " Quit and display a message. | 894 " Quit and display a message. |
879 " TODO: figure out why the first `echom` doesn't show when alone. | 895 " TODO: figure out why the first `echom` doesn't show when alone. |
880 bdelete | 896 bdelete |
882 echom "" | 898 echom "" |
883 return | 899 return |
884 endif | 900 endif |
885 | 901 |
886 execute "setlocal winfixheight" | 902 execute "setlocal winfixheight" |
887 execute "setlocal winheight=" . (line('$') + 1) | 903 if !g:lawrencium_status_win_split_even |
888 execute "resize " . (line('$') + 1) | 904 execute "setlocal winheight=" . (line('$') + 1) |
905 execute "resize " . (line('$') + 1) | |
906 endif | |
889 | 907 |
890 " Add some nice commands. | 908 " Add some nice commands. |
891 command! -buffer Hgstatusedit :call s:HgStatus_FileEdit(0) | 909 command! -buffer Hgstatusedit :call s:HgStatus_FileEdit(0) |
892 command! -buffer Hgstatusdiff :call s:HgStatus_Diff(0) | 910 command! -buffer Hgstatusdiff :call s:HgStatus_Diff(0) |
893 command! -buffer Hgstatusvdiff :call s:HgStatus_Diff(1) | 911 command! -buffer Hgstatusvdiff :call s:HgStatus_Diff(1) |
1478 | 1496 |
1479 function! s:HgLog(vertical, ...) abort | 1497 function! s:HgLog(vertical, ...) abort |
1480 " Get the file or directory to get the log from. | 1498 " Get the file or directory to get the log from. |
1481 " (empty string is for the whole repository) | 1499 " (empty string is for the whole repository) |
1482 let l:repo = s:hg_repo() | 1500 let l:repo = s:hg_repo() |
1483 if a:0 > 0 | 1501 if a:0 > 0 && matchstr(a:1, '\v-*') == "" |
1484 let l:path = l:repo.GetRelativePath(expand(a:1)) | 1502 let l:path = l:repo.GetRelativePath(expand(a:1)) |
1485 else | 1503 else |
1486 let l:path = '' | 1504 let l:path = '' |
1487 endif | 1505 endif |
1488 | 1506 |
1489 " Get the Lawrencium path for this `hg log`, | 1507 " Get the Lawrencium path for this `hg log`, |
1490 " open it in a preview window and jump to it. | 1508 " open it in a preview window and jump to it. |
1491 let l:log_path = l:repo.GetLawrenciumPath(l:path, 'log', '') | 1509 if a:0 > 0 && l:path != "" |
1510 let l:log_opts = join(a:000[1:-1], ',') | |
1511 else | |
1512 let l:log_opts = join(a:000, ',') | |
1513 endif | |
1514 | |
1515 let l:log_path = l:repo.GetLawrenciumPath(l:path, 'log', l:log_opts) | |
1492 if a:vertical | 1516 if a:vertical |
1493 execute 'vertical pedit ' . l:log_path | 1517 execute 'vertical pedit ' . l:log_path |
1494 else | 1518 else |
1495 execute 'pedit ' . l:log_path | 1519 execute 'pedit ' . l:log_path |
1496 endif | 1520 endif |
1497 wincmd P | 1521 wincmd P |
1498 | 1522 |
1499 " Add some other nice commands and mappings. | 1523 " Add some other nice commands and mappings. |
1500 let l:is_file = (l:path != '' && filereadable(l:repo.GetFullPath(l:path))) | 1524 let l:is_file = (l:path != '' && filereadable(l:repo.GetFullPath(l:path))) |
1525 command! -buffer -nargs=+ Hglogexport :call s:HgLog_ExportPatch(<f-args>) | |
1501 command! -buffer -nargs=* Hglogdiffsum :call s:HgLog_DiffSummary(1, <f-args>) | 1526 command! -buffer -nargs=* Hglogdiffsum :call s:HgLog_DiffSummary(1, <f-args>) |
1502 command! -buffer -nargs=* Hglogvdiffsum :call s:HgLog_DiffSummary(2, <f-args>) | 1527 command! -buffer -nargs=* Hglogvdiffsum :call s:HgLog_DiffSummary(2, <f-args>) |
1503 command! -buffer -nargs=* Hglogtabdiffsum :call s:HgLog_DiffSummary(3, <f-args>) | 1528 command! -buffer -nargs=* Hglogtabdiffsum :call s:HgLog_DiffSummary(3, <f-args>) |
1504 if l:is_file | 1529 if l:is_file |
1505 command! -buffer Hglogrevedit :call s:HgLog_FileRevEdit() | 1530 command! -buffer Hglogrevedit :call s:HgLog_FileRevEdit() |
1602 call s:throw("Can't parse revision number from line: " . l:line) | 1627 call s:throw("Can't parse revision number from line: " . l:line) |
1603 endif | 1628 endif |
1604 return l:rev | 1629 return l:rev |
1605 endfunction | 1630 endfunction |
1606 | 1631 |
1632 function! s:HgLog_ExportPatch(...) abort | |
1633 let l:patch_name = a:1 | |
1634 if !empty($HG_EXPORT_PATCH_DIR) | |
1635 let l:is_patch_relative = (matchstr(l:patch_name, '\v^/') == "") | |
1636 " Use the patch dir only if user has specified a relative path | |
1637 " Only works on Unix. Not sure how to check on Windows. | |
1638 if l:is_patch_relative | |
1639 let l:patch_name = $HG_EXPORT_PATCH_DIR . "/" . l:patch_name | |
1640 endif | |
1641 endif | |
1642 | |
1643 if a:0 == 2 | |
1644 let l:rev = a:2 | |
1645 else | |
1646 let l:rev = s:HgLog_GetSelectedRev() | |
1647 endif | |
1648 | |
1649 let l:repo = s:hg_repo() | |
1650 let l:export_args = ['-o', l:patch_name, '-r', l:rev] | |
1651 | |
1652 call l:repo.RunCommand('export', l:export_args) | |
1653 | |
1654 echom "Created patch: " . l:patch_name | |
1655 endfunction | |
1656 | |
1607 call s:AddMainCommand("Hglogthis :call s:HgLog(0, '%:p')") | 1657 call s:AddMainCommand("Hglogthis :call s:HgLog(0, '%:p')") |
1608 call s:AddMainCommand("Hgvlogthis :call s:HgLog(1, '%:p')") | 1658 call s:AddMainCommand("Hgvlogthis :call s:HgLog(1, '%:p')") |
1609 call s:AddMainCommand("-nargs=? -complete=customlist,s:ListRepoFiles Hglog :call s:HgLog(0, <f-args>)") | 1659 call s:AddMainCommand("-nargs=* -complete=customlist,s:ListRepoFiles Hglog :call s:HgLog(0, <f-args>)") |
1610 call s:AddMainCommand("-nargs=? -complete=customlist,s:ListRepoFiles Hgvlog :call s:HgLog(1, <f-args>)") | 1660 call s:AddMainCommand("-nargs=* -complete=customlist,s:ListRepoFiles Hgvlog :call s:HgLog(1, <f-args>)") |
1611 | 1661 |
1612 " }}} | 1662 " }}} |
1613 | 1663 |
1614 " Hgannotate {{{ | 1664 " Hgannotate {{{ |
1615 | 1665 |