New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is there a possibility to determine whether an entry in the popupmenu is selected or not? #2004
Comments
Technically, that could be possible, but...
Basically, when a pop-up menu returns, it should convey only the decision the user made with the menu, i.e., whether an item or items were selected or whether the selection itself was canceled, to the upper part of the software hierarchy, not anything more than that. Pop-up menus should not dictate what the upper part has to do. Otherwise, the responsibility and independency of each module would get made light, ending up a codebase hard to maintain or extend in the long run. For instance, how can pop-up menus know about the notion of newline a priori? That's surely a thing they needn't know about. So, IMHO, the introduction of " |
Thanks for your thoughts on this. I can see the point of your first paragraph. But I do not necessarily agree that a popupmenu shouldn't do more than what you say. Furthermore, I am not sure about your anticipated problems you described in the second paragraph. Can you explain it more explicitly? What do you mean with module? Which codebase is hard to maintain (vim or plugin)? Why does a popupmenu must know something about the notion of newline? I want to expand my motivation a little bit more by the means of an example: I have defined for LaTeX a snippet named
However, the word My point here is that a popupmenu could provide more advanced functionality by attaching to a word an optional behaviour which is only available if the popupmenu is active. A popupmenu provides instantaneous explanation about this optional behaviour and therefore should be predictable by the user. Also for clarification I had auto-completion plugins such as neocomplete/deoplete in mind where the popumenu is not opened by the user. I think as long as the user does not select anything in the popupmenu, he wants to ignore the suggestions or functionality provided by it. If the user decides there is a something in the popupmenu he wants to complete he uses a key such From my point of view the popmenu is a separate layer/mode the user is in. Certain mappings have a different meaning compared to when the popupmenu is closed (e.g.
And as far as I can see, no one has to use |
I think that, for what you want to achieve, you may use fun! TestCompletedItem()
if pumvisible()
echomsg string(v:completed_item)
else
return "\<cr>"
endif
endf
inoremap <expr> <cr> TestCompletedItem() See also |
@lifepillar THANK YOU VERY MUCH! This looks very much like what I want. My new " inoremap <CR> --- {{{2
" 1. when pumvisible & entry selected, which is a snippet, <CR> triggers snippet expansion,
" 2. when pumvisible & entry selected, which is not a snippet, <CR> only closes pum
" 3. when pumvisible & no entry selected, <CR> closes pum and inserts newline
" 4. when pum not visible, <CR> inserts only a newline
function! s:ExpandSnippetOrClosePumOrReturnNewline()
if pumvisible()
if !empty(v:completed_item)
let snippet = UltiSnips#ExpandSnippet()
if g:ulti_expand_res > 0
return snippet
else
return "\<C-y>"
endif
else
return "\<C-y>\<CR>"
endif
else
return "\<CR>"
endif
endfunction
inoremap <silent> <CR> <C-r>=<SID>ExpandSnippetOrClosePumOrReturnNewline()<CR> I've clarified the behaviour of Do you know if it is sufficient to verify that the dictionary is empty? |
That should be enough: as far as I know, when the dictionary is empty, it means that the user has not selected an item or has cancelled the completion with ctrl-e. |
I found in some cases, after the completion is cancelled with C-e, the |
After some testing, I found that |
@brglng From
You may want to check fun! TestCompletedItem()
echomsg string(v:completed_item)
endf
autocmd CompleteDone * call TestCompletedItem() |
@brglng after 8.1.1068 you can use |
I have following mapping in my vimrc:
I would like to replace
pumvisible()
with something likepumselected()
. By default no entry is selected in the popup menu. As long as the user does not select one, pressing<CR>
should insert a newline. However, this behavior should change if the user selects an entry. In this case ultisnips should try to expand if possible.The text was updated successfully, but these errors were encountered: