# HG changeset patch # User Ludovic Chabant # Date 1324881630 28800 # Node ID 3a0f7bb6ea64d64cfc946d9210b14f13d4165162 # Parent 1ce59d5aa5e9dda7f508518f6e5c533ee46f101d Hgstatus window improvements and bug fixes: - `addremove` command replaces `add`, and can run on a selection range. - Lawrencium commands are available (along with in the diff windows). - Default mappings are optional. - Updated documentation. diff -r 1ce59d5aa5e9 -r 3a0f7bb6ea64 doc/lawrencium.txt --- a/doc/lawrencium.txt Tue Dec 20 16:16:52 2011 -0800 +++ b/doc/lawrencium.txt Sun Dec 25 22:40:30 2011 -0800 @@ -9,6 +9,7 @@ 1. Introduction |lawrencium-intro| 2. Commands |lawrencium-commands| +3. Status Window |lawrencium-status-window| ============================================================================= @@ -55,13 +56,9 @@ *:Hgstatus* :Hgstatus Shows the output of 'hg status' in the - |preview-window|. - You can navigate to the next/previous file with - and , open a file with , diff the local file - with the parent revision with and , - depending on whether you want a horizontal or vertical - split window, add an untracked file with , and - refresh the window with . + |preview-window|. Some extra-commands, along with some + default mappins, are available in this window. See + |lawrencium-status-window|. *:Hgdiff* :Hgdiff Diffs the current file against its parent revision. @@ -87,5 +84,48 @@ +============================================================================= +3. Status Window *lawrencium-status-window* + +The `hg status` window opened by Lawrencium has a few special commands +defined in it. Also, unless the global `lawrencium_define_mappings` is set to +`0`, some commands are mapped to keyboard shortcuts, as detailed in the +following descriptions. + + + *:Hgstatusedit* +:Hgstatusedit Open the file mentioned on the current line. + Mapped to . + + *:Hgstatusaddremove* +:Hgstatusaddremove Run `hg addremove` on the file mentioned on the + current line, or on the lines currently selected in + visual selection mode (see |visual-start|). + Mapped to . + + *:Hgstatusdiff* +:Hgstatusdiff Open a diff window on the file mentioned on the + current line, between the working directory version + and the parent revision version. Similar to running + |:Hgdiff| on that file. + Mapped to . + + *:Hgstatusvdiff* +:Hgstatusvdiff Similar to |:Hgstatusdiff|, but use a vertical split. + Similar to running |:Hgvdiff| on that file. + Mapped to . + + *:Hgstatusrefresh* +:Hgstatusrefresh Refreshes the status window by running `hg status` + again. + Mapped to . + + *lawrencium-status-mappings* +A few other mappings are available in the status window: + + Jump to the next filename. + Jump to the previous filename. + q Quit the status window. + vim:tw=78:et:ft=help:norl: diff -r 1ce59d5aa5e9 -r 3a0f7bb6ea64 plugin/lawrencium.vim --- a/plugin/lawrencium.vim Tue Dec 20 16:16:52 2011 -0800 +++ b/plugin/lawrencium.vim Sun Dec 25 22:40:30 2011 -0800 @@ -24,6 +24,10 @@ let g:lawrencium_trace = 0 endif +if !exists('g:lawrencium_define_mappings') + let g:lawrencium_define_mappings = 1 +endif + " }}} " Utility {{{ @@ -138,8 +142,14 @@ " Runs a Mercurial command in the repo function! s:HgRepo.RunCommand(command, ...) abort + " If there's only one argument, and it's a list, then use that as the + " argument list. + let l:arg_list = a:000 + if a:0 == 1 && type(a:1) == type([]) + let l:arg_list = a:1 + endif let l:hg_command = g:lawrencium_hg_executable . ' --repository ' . shellescape(s:stripslash(self.root_dir)) - let l:hg_command = l:hg_command . ' ' . a:command . ' ' . join(a:000, ' ') + let l:hg_command = l:hg_command . ' ' . a:command . ' ' . join(l:arg_list, ' ') call s:trace("Running Mercurial command: " . l:hg_command) return system(l:hg_command) endfunction @@ -337,6 +347,7 @@ execute "pedit " . l:temp_file wincmd p call append(0, l:status_lines) + call cursor(1, 1) " Make it a nice size. execute "setlocal previewheight=" . l:preview_height " Make sure it's deleted when we exit the window. @@ -345,21 +356,33 @@ " Setup the buffer correctly: readonly, and with the correct repo linked " to it. let b:mercurial_dir = l:repo.root_dir - setlocal buftype=nofile setlocal nomodified setlocal nomodifiable setlocal readonly + setlocal buftype=nofile setlocal syntax=hgstatus - + + " Make commands available. + call s:DefineMainCommands() + + " Add some nice commands. + command! -buffer Hgstatusedit :call s:HgStatus_FileEdit() + command! -buffer -range Hgstatusaddremove :call s:HgStatus_AddRemove(, ) + command! -buffer Hgstatusdiff :call s:HgStatus_Diff(0) + command! -buffer Hgstatusvdiff :call s:HgStatus_Diff(1) + command! -buffer Hgstatusrefresh :call s:HgStatus_Refresh() + " Add some handy mappings. - nnoremap :call search('^[MARC\!\?I ]\s.', 'We') - nnoremap :call search('^[MARC\!\?I ]\s.','Wbe') - nnoremap :call HgStatus_FileEdit() - nnoremap :call HgStatus_FileDiff(0) - nnoremap :call HgStatus_FileDiff(1) - nnoremap :call HgStatus_FileAdd() - nnoremap :call HgStatus_Refresh() - nnoremap q :bdelete + if g:lawrencium_define_mappings + nnoremap :Hgstatusedit + nnoremap :call search('^[MARC\!\?I ]\s.', 'We') + nnoremap :call search('^[MARC\!\?I ]\s.', 'Wbe') + nnoremap :Hgstatusdiff + nnoremap :Hgstatusvdiff + nnoremap :Hgstatusaddremove + nnoremap :Hgstatusrefresh + nnoremap q :bdelete! + endif " Make sure the file is deleted with the buffer. autocmd BufDelete call s:HgStatus_CleanUp(expand(':p')) @@ -389,7 +412,7 @@ function! s:HgStatus_FileEdit() abort " Get the path of the file the cursor is on. - let l:filename = s:HgStatus_GetSelectedPath() + let l:filename = s:HgStatus_GetSelectedFile() " If the file is already open in a window, jump to that window. " Otherwise, jump to the previous window and open it there. @@ -405,40 +428,59 @@ execute 'edit ' . l:filename endfunction -function! s:HgStatus_FileAdd() abort - " Get the path of the file the cursor is on, and its status. - let l:filename = s:HgStatus_GetSelectedPath() - let l:status = s:HgStatus_GetSelectedStatus() - if l:status !=# '?' - call s:error("Not an untracked file: " . l:filename) +function! s:HgStatus_AddRemove(linestart, lineend) abort + " Get the selected filenames. + let l:filenames = s:HgStatus_GetSelectedFiles(a:linestart, a:lineend, ['!', '?']) + if len(l:filenames) == 0 + call s:error("No files to add or remove in selection or current line.") endif - " Add the file. + " Run `addremove` on those paths. let l:repo = s:hg_repo() - call l:repo.RunCommand('add', l:filename) + call l:repo.RunCommand('addremove', l:filenames) " Refresh the status window. call s:HgStatus_Refresh() endfunction -function! s:HgStatus_FileDiff(vertical) abort +function! s:HgStatus_Diff(vertical) abort " Open the file and run `Hgdiff` on it. call s:HgStatus_FileEdit() call s:HgDiff('%:p', a:vertical) endfunction -function! s:HgStatus_GetSelectedPath() abort - let l:repo = s:hg_repo() - let l:line = getline('.') - " Yay, awesome, Vim's regex syntax is fucked up like shit, especially for - " look-aheads and look-behinds. See for yourself: - let l:filename = matchstr(l:line, '\v(^[MARC\!\?I ]\s)@<=.*') - let l:filename = l:repo.GetFullPath(l:filename) - return l:filename +function! s:HgStatus_GetSelectedFile() abort + let l:filenames = s:HgStatus_GetSelectedFiles() + return l:filenames[0] endfunction -function! s:HgStatus_GetSelectedStatus() abort - let l:line = getline('.') +function! s:HgStatus_GetSelectedFiles(...) abort + if a:0 >= 2 + let l:lines = getline(a:1, a:2) + else + let l:lines = [] + call add(l:lines, getline('.')) + endif + let l:filenames = [] + let l:repo = s:hg_repo() + for line in l:lines + if a:0 >= 3 + let l:status = s:HgStatus_GetFileStatus(line) + if index(a:3, l:status) < 0 + continue + endif + endif + " Yay, awesome, Vim's regex syntax is fucked up like shit, especially for + " look-aheads and look-behinds. See for yourself: + let l:filename = matchstr(l:line, '\v(^[MARC\!\?I ]\s)@<=.*') + let l:filename = l:repo.GetFullPath(l:filename) + call add(l:filenames, l:filename) + endfor + return l:filenames +endfunction + +function! s:HgStatus_GetFileStatus(...) abort + let l:line = a:0 ? a:1 : getline('.') return matchstr(l:line, '\v^[MARC\!\?I ]') endfunction @@ -512,6 +554,8 @@ let b:mercurial_dir = l:repo.root_dir " Make sure it's deleted when we move away from it. setlocal bufhidden=delete + " Make commands available. + call s:DefineMainCommands() endif " Get the second file and open it too. @@ -529,6 +573,8 @@ let b:mercurial_dir = l:repo.root_dir " Make sure it's deleted when we move away from it. setlocal bufhidden=delete + " Make commands available. + call s:DefineMainCommands() endif endfunction @@ -633,6 +679,8 @@ else autocmd BufDelete call s:HgCommit_Execute(expand(':p'), 1) endif + " Make commands available. + call s:DefineMainCommands() endfunction let s:hg_status_messages = {