Allow mapping overrides

Not bothering with the read only buffer maps for now but it would
certainly make sense to.

References https://github.com/tpope/vim-fugitive/issues/761
This commit is contained in:
Tim Pope 2018-05-06 19:11:34 -04:00
parent b34083549e
commit b1df5f1226

View File

@ -108,6 +108,31 @@ function! s:recall() abort
return rev return rev
endfunction endfunction
function! s:map(mode, lhs, rhs, ...) abort
let flags = (a:0 ? a:1 : '') . (a:rhs =~# '^<Plug>' ? '' : '<script>')
if flags =~# '<unique>' && !empty(mapcheck(a:lhs, a:mode))
return
endif
let head = a:lhs
let tail = ''
let keys = get(g:, a:mode.'remap', {})
if type(keys) != type({})
return
endif
while !empty(head)
if has_key(keys, head)
let head = keys[head]
if empty(head)
return
endif
break
endif
let tail = matchstr(head, '<[^<>]*>$\|.$') . tail
let head = substitute(head, '<[^<>]*>$\|.$', '', '')
endwhile
exe a:mode.'map <buffer>' flags head.tail a:rhs
endfunction
function! s:add_methods(namespace, method_names) abort function! s:add_methods(namespace, method_names) abort
for name in a:method_names for name in a:method_names
let s:{a:namespace}_prototype[name] = s:function('s:'.a:namespace.'_'.name) let s:{a:namespace}_prototype[name] = s:function('s:'.a:namespace.'_'.name)
@ -212,8 +237,8 @@ function! fugitive#detect(path) abort
endtry endtry
endif endif
if !exists('g:fugitive_no_maps') if !exists('g:fugitive_no_maps')
cnoremap <buffer> <expr> <C-R><C-G> fnameescape(<SID>recall()) call s:map('c', '<C-R><C-G>', 'fnameescape(<SID>recall())', '<expr>')
nnoremap <buffer> <silent> y<C-G> :call setreg(v:register, <SID>recall())<CR> call s:map('n', 'y<C-G>', ':call setreg(v:register, <SID>recall())<CR>', '<silent>')
endif endif
let buffer = fugitive#buffer() let buffer = fugitive#buffer()
if expand('%:p') =~# '://' if expand('%:p') =~# '://'
@ -2818,11 +2843,12 @@ augroup END
nnoremap <SID>: :<C-U><C-R>=v:count ? v:count : ''<CR> nnoremap <SID>: :<C-U><C-R>=v:count ? v:count : ''<CR>
function! s:GFInit(...) abort function! s:GFInit(...) abort
cnoremap <buffer> <expr> <Plug><cfile> fugitive#cfile() cnoremap <buffer> <expr> <Plug><cfile> fugitive#cfile()
if !exists('g:fugitive_no_maps') && empty(mapcheck('gf', 'n')) if !exists('g:fugitive_no_maps')
nmap <buffer> <silent> gf <SID>:find <Plug><cfile><CR> call s:map('n', 'gf', '<SID>:find <Plug><cfile><CR>', '<silent><unique>')
nmap <buffer> <silent> <C-W>f <SID>:sfind <Plug><cfile><CR> call s:map('n', '<C-W>f', '<SID>:sfind <Plug><cfile><CR>', '<silent><unique>')
nmap <buffer> <silent> <C-W><C-F> <SID>:sfind <Plug><cfile><CR> call s:map('n', '<C-W><C-F>', '<SID>:sfind <Plug><cfile><CR>', '<silent><unique>')
nmap <buffer> <silent> <C-W>gf <SID>:tabfind <Plug><cfile><CR> call s:map('n', '<C-W>gf', '<SID>:tabfind <Plug><cfile><CR>', '<silent><unique>')
call s:map('c', '<C-R><C-F>', '<Plug><cfile>', '<silent><unique>')
endif endif
endfunction endfunction