Skip to content
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

Adding <silent> to a working cnoremap <expr> causes remapping to break #11501

Closed
craigmac opened this issue Nov 4, 2022 · 6 comments
Closed
Labels

Comments

@craigmac
Copy link

craigmac commented Nov 4, 2022

Steps to reproduce

  1. vim --clean
  2. :cnoremap <silent><expr> <C-p> wildmenumode() ? '<C-p>' : '<Up>'
  3. :cnoremap <silent><expr> <C-n> wildmenumode() ? '<C-n>': '<Down>'
  4. :edit <Tab>
  5. Move around with <C-n/p> and see the command-line string grow with added ... (periods).

Expected behaviour

Adding <silent> shouldn't do this. If you try the mappings without it:

:cnoremap <expr> <C-p> wildmenumode() ? '<C-p>' : '<Up>'
:cnoremap <expr> <C-n> wildmenumode() ? '<C-n>': '<Down>'

No periods are appended to the command-line string.

Version of Vim

9.0.0049

Environment

macOS 12.6.1
Alacritty latest
$TERM is 'alacritty'

Logs and stack traces

No response

@brammool
Copy link
Contributor

brammool commented Nov 6, 2022 via email

@craigmac
Copy link
Author

craigmac commented Nov 7, 2022

Yeah, I've just left it out as a workaround, just wanted to report the unexpected behaviour, in case it's an easy fix.

@zeertzjq
Copy link
Member

zeertzjq commented Nov 8, 2022

Why is this unexpected? Isn't this exactly what <silent> is intended to do?

@craigmac
Copy link
Author

My docs say:

					                             *:map-<silent>* *:map-silent*
To define a mapping which will not be echoed on the command line, add
"<silent>" as the first argument.  Example: >
	:map <silent> ,h /Header<CR>
The search string will not be echoed when using this mapping. 

I interpreted that to apply to my mapping above as well, so maybe the docs should make a note that it doesn't always apply, and that it is possible a mapping triggers a 'completion pending' state, which will append '...' to the command-line, regardless of the <silent>

@brammool
Copy link
Contributor

That the dots show up is because this happens to only check the msg_silent flag, but in this case the cmd_silent flag is set.
I can also check the cmd_silent flag, with the results that the dots are not displayed.

However, this doesn't make it work: Since your command to move up/down in the list of matches has "silent" applied, the command line won't be updated. Thus the "silent" does not only apply to evaluating the expression, it also applies to where the result of the expression (the CTRL-P or key) is used.

What you probably want is that the redraw of the command line is not suppressed. If I reset cmd_silent before calling redrawcmd() then the dots are also cleared. But that's just for this specific case. Normally cmd_silent is cleared when getting the next character, not while still working on the previous one. Or someway halfway working on the previous one.
And then there is the possibility that this wasn't the last character of the mapping, it really was intended to be done silently, and perhaps another one is following.

So, I don't really know how to make a change that fixes this without breaking something else. I'll see if adding something to the help makes it clearer.

zeertzjq added a commit to zeertzjq/neovim that referenced this issue Nov 14, 2022
Problem:    A silent mapping may cause dots on the command line.
Solution:   Don't show dots for completion if they are not going to be removed
            again. (closes vim/vim#11501)

vim/vim@698a00f

Co-authored-by: Bram Moolenaar <Bram@vim.org>
zeertzjq added a commit to neovim/neovim that referenced this issue Nov 14, 2022
…ne (#21061)

Problem:    A silent mapping may cause dots on the command line.
Solution:   Don't show dots for completion if they are not going to be removed
            again. (closes vim/vim#11501)

vim/vim@698a00f

Co-authored-by: Bram Moolenaar <Bram@vim.org>
@craigmac
Copy link
Author

Well that was quick, thank you very much!

yesean pushed a commit to yesean/neovim that referenced this issue Mar 25, 2023
…ne (neovim#21061)

Problem:    A silent mapping may cause dots on the command line.
Solution:   Don't show dots for completion if they are not going to be removed
            again. (closes vim/vim#11501)

vim/vim@698a00f

Co-authored-by: Bram Moolenaar <Bram@vim.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants