Shougo / unite.vim

:dragon: Unite and create user interfaces
http://www.vim.org/scripts/script.php?script_id=3396
Other
2.85k stars 223 forks source link

Fix conflict with popup menu #1239

Closed bimlas closed 6 years ago

bimlas commented 6 years ago

Reason for this pull request: I'm developing a Vim plugin which can be used to search files by tag name where tags are part of filenames. A feature of it is to use inside Unite.

screenshot_20180616_175943

When popupmenu (completion menu) is shown, disable Unite insert mode mappings because those conflicting with menu navigating mappings (<C-n>, <C-p>, <C-j>, etc.).

I tried to refactor in to a function, but it's not prettier:

call s:pum_safe_map('imap <buffer>', '<TAB>',
      \ '<Plug>(unite_choose_action)')

function! s:pum_safe_map(mode, lhs, rhs) abort "{{{
  execute a:mode.' '.a:lhs.' pumvisible() ? "'.a:lhs.'" : "'.a:rhs.'"'
endfunction

Besides this it can be rigid; changing the quotes in rhs will produce error. For example using " in rhs instead of ':

call s:pum_safe_map('inoremap <silent><buffer><expr> ', '<C-d>',
      \ 'unite#do_actioc("delete")'

It would evaulate to:

inoremap <silent><buffer><expr> <C-d> pumvisible() ? "<C-d>" : "unite#do_actioc("delete")"

This is the broken part: "unite#do_actioc("delete")"