Mercurial > vim-lawrencium
changeset 46:6a4f5200d8da
`:Hg!` command changes:
- Ability to edit in a normal buffer instead of the preview window.
- Set syntax coloring according to the Mercurial command.
- Updated the documentation.
Miscellaneous cleanup.
New pretty banner in the documentation.
New "global settings" section in the documentation.
Added `graphlog` syntax file.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Wed, 07 Nov 2012 07:14:15 -0800 |
parents | ea0ae8f6af81 |
children | 85e39bdd7089 |
files | doc/lawrencium.txt plugin/lawrencium.vim resources/hg_command_file_types.vim syntax/hggraphlog.vim |
diffstat | 4 files changed, 163 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/doc/lawrencium.txt Tue Aug 28 21:37:53 2012 -0700 +++ b/doc/lawrencium.txt Wed Nov 07 07:14:15 2012 -0800 @@ -1,6 +1,23 @@ *lawrencium.txt* Mercurial wrapper for VIM + LLLLLLLLLLL ~ + L:::::::::L ~ + L:::::::::L ~ + LL:::::::LL ~ + L:::::L rrrrr rrrrrrrrr ~ + L:::::L r::::rrr:::::::::r ~ + L:::::L r:::::::::::::::::r ~ + L:::::L rr::::::rrrrr::::::r ~ + L:::::L r:::::r r:::::r ~ + L:::::L r:::::r rrrrrrr ~ + L:::::L r:::::r ~ + L:::::L LLLLLLr:::::r ~ + LL:::::::LLLLLLLLL:::::Lr:::::r ~ + L::::::::::::::::::::::Lr:::::r ~ + L::::::::::::::::::::::Lr:::::r ~ + LLLLLLLLLLLLLLLLLLLLLLLLrrrrrrr ~ + LAWRENCIUM REFERENCE MANUAL by Ludovic Chabant @@ -10,6 +27,7 @@ 1. Introduction |lawrencium-intro| 2. Commands |lawrencium-commands| 3. Status Window |lawrencium-status-window| +4. Global Settings |lawrencium-global-settings| ============================================================================= @@ -38,14 +56,21 @@ file belongs to, and it will auto-complete any standard command or option. - Also, unless the `lawrencium_auto_cd` global is set to + Also, unless the |lawrencium_auto_cd| global is set to `0`, it will temporarily set the current directory to be the root of the repository so that auto-completed filenames work out of the box. *:Hg!* :Hg! {args} Like |:Hg|, but the output of the command is placed in - a temp file and edited in the |preview-window|. + a temp file and edited in the |preview-window|, unless + the |lawrencium_hg_bang_edit_command| global setting + specifies that another type of window or buffer should + be used. + + Once the output is open in a buffer, Lawrencium will + try to set the file type according to the Mercurial + command that was run. See |lawrencium_hg_commands_file_types|. *:Hgcd* :Hgcd[!] {path} |:cd| relative to the root of the repository. @@ -101,7 +126,7 @@ 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 +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. @@ -167,4 +192,53 @@ q Quit the status window. + +============================================================================= +4. Global Settings *lawrencium-global-settings* + +The following global settings can be defined in your |vimrc| to change the +default behaviour of Lawrencium. + + *lawrencium_hg_executable* +g:lawrencium_hg_executable + Defines the executable to run when running Mercurial + commands. + Defaults to simply `hg`. + + *lawrencium_auto_cd* +g:lawrencium_auto_cd Specifies whether the current working directory should + be set to the repository's root while running |:Hg| + commands so that auto-completion works magically with + repository relative paths. + Defaults to `1`. + + *lawrencium_define_mappings* +g:lawrencium_define_mappings + Specifies whether Lawrencium should define default + keyboard shortcuts. + Defaults to `1`. + + *lawrencium_hg_bang_edit_command* +g:lawrencium_hg_bang_edit_command + Defines the Vim command to run when using the |:Hg!| + command (with the bang) in order to show the output. + + Defaults to |pedit|, which opens the output of the + command in the |preview-window|. A good alternative + is to use |edit|, to open the output in a normal + buffer. + + *lawrencium_hg_commands_file_types* +g:lawrencium_hg_commands_file_types + Defines the |file-types| that Lawrencium should use + when editing the output of |:Hg!| based on the + Mercurial command that was used. + + By default, unless overridden, the following commands + map to the following file types: + + diff diff + graphlog graphlog + + vim:tw=78:et:ft=help:norl:
--- a/plugin/lawrencium.vim Tue Aug 28 21:37:53 2012 -0700 +++ b/plugin/lawrencium.vim Wed Nov 07 07:14:15 2012 -0800 @@ -32,6 +32,10 @@ let g:lawrencium_define_mappings = 1 endif +if !exists('g:lawrencium_hg_bang_edit_command') + let g:lawrencium_hg_bang_edit_command = 'pedit' +endif + " }}} " Utility {{{ @@ -313,9 +317,23 @@ if a:bang " Open the output of the command in a temp file. let l:temp_file = s:tempname('hg-output-', '.txt') - execute 'pedit ' . l:temp_file + execute g:lawrencium_hg_bang_edit_command . ' ' . l:temp_file wincmd p call append(0, split(l:output, '\n')) + call cursor(1, 1) + + " Make it a temp buffer + setlocal bufhidden=delete + setlocal buftype=nofile + + " Try to find a nice syntax to set given the current command. + let l:command_name = s:GetHgCommandName(a:000) + if l:command_name != '' && exists('g:lawrencium_hg_commands_file_types') + let l:file_type = get(g:lawrencium_hg_commands_file_types, l:command_name, '') + if l:file_type != '' + execute 'setlocal ft=' . l:file_type + endif + endif else " Just print out the output of the command. echo l:output @@ -330,6 +348,12 @@ call s:error("Can't find the Mercurial usage file. Auto-completion will be disabled in Lawrencium.") endif +" Include the command file type mappings. +let s:file_type_mappings = expand("<sfile>:h:h") . '/resources/hg_command_file_types.vim' +if filereadable(s:file_type_mappings) + execute "source " . s:file_type_mappings +endif + function! s:CompleteHg(ArgLead, CmdLine, CursorPos) " Don't do anything if the usage file was not sourced. if !exists('g:lawrencium_hg_commands') || !exists('g:lawrencium_hg_options') @@ -351,15 +375,11 @@ " Try completing a command (note that there could be global options before " the command name). if a:CmdLine =~# '\v^Hg\s+(\-[a-zA-Z0-9\-_]+\s+)*[a-zA-Z]+$' - echom " - matched command" return filter(keys(g:lawrencium_hg_commands), "v:val[0:strlen(l:arglead)-1] ==# l:arglead") endif " Try completing a command's options. let l:cmd = matchstr(a:CmdLine, '\v(^Hg\s+(\-[a-zA-Z0-9\-_]+\s+)*)@<=[a-zA-Z]+') - if strlen(l:cmd) > 0 - echom " - matched command option for " . l:cmd . " with : " . l:arglead - endif if strlen(l:cmd) > 0 && l:arglead[0] ==# '-' if has_key(g:lawrencium_hg_commands, l:cmd) " Return both command options and global options together. @@ -376,6 +396,15 @@ return s:ListRepoFiles(a:ArgLead, a:CmdLine, a:CursorPos) endfunction +function! s:GetHgCommandName(args) abort + for l:a in a:args + if stridx(l:a, '-') != 0 + return l:a + endif + endfor + return '' +endfunction + call s:AddMainCommand("-bang -complete=customlist,s:CompleteHg -nargs=* Hg :call s:Hg(<bang>0, <f-args>)") " }}} @@ -451,7 +480,6 @@ let l:status_text = l:repo.RunCommand('status') " Replace the contents of the current buffer with it, and refresh. - echo "Writing to " . expand('%:p') let l:path = expand('%:p') let l:status_lines = split(l:status_text, '\n') call writefile(l:status_lines, l:path)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/resources/hg_command_file_types.vim Wed Nov 07 07:14:15 2012 -0800 @@ -0,0 +1,9 @@ +" LAWRENCIUM - MERCURIAL COMMANDS FILE TYPES +" +if !exists('g:lawrencium_hg_commands_file_types') + g:lawrencium_hg_commands_file_types = {} +endif + +let g:lawrencium_hg_commands_file_types.diff = 'diff' +let g:lawrencium_hg_commands_file_types.glog = 'hggraphlog' +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/syntax/hggraphlog.vim Wed Nov 07 07:14:15 2012 -0800 @@ -0,0 +1,43 @@ +" Vim syntax file +" Language: hg graphlog output +" Maintainer: Ludovic Chabant <ludovic@chabant.com> +" Filenames: <none> + +if exists("b:current_syntax") + finish +endif + +syn case match + +syn match hggraphlogBranch /^|\(\( .*\)\|$\)/he=s+1 +syn match hggraphlogBranchMerge /^|[\\\/]/ +syn match hggraphlogNode /^o .*/he=s+1 + +syn match hggraphlogBranch2 / |\(\( .*\)\|$\)/he=s+2 contained containedin=hggraphlogBranch,hggraphlogNode +syn match hggraphlogBranch2Merge / |[\\\/]/ contained containedin=hggraphlogBranch +syn match hggraphlogNode2 / o .*/he=s+2 contained containedin=hggraphlogBranch + +syn match hggraphlogBranch3 / | |\(\( .*\)\|$\)/ms=s+3,he=s+4 contained containedin=hggraphlogBranch2,hggraphlogNode2 +syn match hggraphlogBranch3Merge / | |[\\\/]/ms=s+3 contained containedin=hggraphlogBranch2 +syn match hggraphlogNode3 / | o .*/ms=s+3,he=s+4 contained containedin=hggraphlogBranch2 + +syn match hggraphlogBranch4 / | | |\(\( .*\)\|$\)/ms=s+5,he=s+6 contained containedin=hggraphlogBranch3,hggraphlogNode3 +syn match hggraphlogBranch4Merge / | | |[\\\/]/ms=s+5 contained containedin=hggraphlogBranch3 +syn match hggraphlogNode4 / | | o .*/ms=s+5,he=s+6 contained containedin=hggraphlogBranch3 + +syn match hggraphlogHead /^@\s/he=e-1 + +hi def link hggraphlogBranch hlLevel1 +hi def link hggraphlogBranchMerge hlLevel1 +hi def link hggraphlogNode hlLevel1 +hi def link hggraphlogBranch2 hlLevel2 +hi def link hggraphlogBranch2Merge hlLevel2 +hi def link hggraphlogNode2 hlLevel2 +hi def link hggraphlogBranch3 hlLevel3 +hi def link hggraphlogBranch3Merge hlLevel3 +hi def link hggraphlogNode3 hlLevel3 +hi def link hggraphlogBranch4 hlLevel4 +hi def link hggraphlogBranch4Merge hlLevel4 +hi def link hggraphlogNode4 hlLevel4 +hi def link hggraphlogHead PreProc +