On 2023-06-19, Bram Moolenaar wrote:
> Gary Johnson wrote:
> 
> > On 2023-06-15, Bram Moolenaar wrote:
> > > > On 2023-06-15, Bram Moolenaar wrote:
> > > > > > Help for :map-<silent> says that with <silent>, the right side of
> > > > > > a mapping will not be echoed on the command line, but messages from
> > > > > > the executed command are still given.  This works with :nmap but not
> > > > > > with :vmap.  I would expect it to work with :vmap as well.
> > > > > > 
> > > > > > Steps to reproduce
> > > > > > 
> > > > > >  1. Put the following in a file, say foo.vim.
> > > > > > 
> > > > > >         nmap <silent> gx :call DebugSilent()<CR>
> > > > > >         vmap <silent> gx :call DebugSilent()<CR>
> > > > > >         function DebugSilent()
> > > > > >             echomsg "from DebugSilent"
> > > > > >         endfunction
> > > > > > 
> > > > > >  2. Start vim and source that file.
> > > > > > 
> > > > > >         $ vim -N --clean
> > > > > >         :so foo.vim
> > > > > > 
> > > > > >  3. Enter some word into the current buffer.
> > > > > > 
> > > > > >  4. Visually select that word.
> > > > > > 
> > > > > >         viw
> > > > > > 
> > > > > >  5. Type the mapping.
> > > > > > 
> > > > > >         gx
> > > > > > 
> > > > > >  6. Note that no message appears, or just flashes by briefly.
> > > > > > 
> > > > > >  7. Execute :messages to verify that the message was generated and
> > > > > >     saved in message history.
> > > > > > 
> > > > > >  8. Without visually selecting the word, type the mapping.
> > > > > > 
> > > > > >         gx
> > > > > > 
> > > > > >  9. Note that the message does appear in the command line and
> > > > > >     remains there.
> > > > > > 
> > > > > > Expected behavior
> > > > > > 
> > > > > >     I expect the message to remain in the command line after the
> > > > > >     execution of the vmap just as it does for a normal map.
> > > > > 
> > > > > It appears to work as you expect when 'cmdheight' is 2 or more.
> > > > > 
> > > > > Most likely the message is cleared when the "-- VISUAL --" mode 
> > > > > message
> > > > > is removed.  Setting 'noshowmode' helps.
> > > > > 
> > > > > This should not happen though, when the message overwrites the mode 
> > > > > then
> > > > > there is no need later to clear the mode message.
> > > > 
> > > > I would expect it to work like gf (which itself is inconsistent).
> > > > If I put the cursor over "later" in the paragraph above and type
> > > > gf, I get a persistent error message in the command line:
> > > > 
> > > >     E447: Can't find file "later" in path
> > > > 
> > > > If I visually-select "later" with viw and type gf, I get the same
> > > > message, but it appears for only about one second.  It seems like it
> > > > should also persist, but at least I see it and can look in :messages
> > > > to read it again.
> > > > 
> > > > 'cmdheight' doesn't seem to affect the behavior of gf, but setting
> > > > 'noshowmode' does "fix" it.  It would be nice if visual mode could
> > > > be made smarter about clearing "-- VISUAL --" when that message has
> > > > been overwritten, or at least leave it for a second or two as
> > > > {Visual}gf does.
> > > 
> > > The patch I made first had a strict condition of where the message is
> > > displayed.  The "gf" error message is on a different line, causing that
> > > condition not to be true.  I'll fix that.
> > 
> > Your second patch seems to work fine, but the problem in my original
> > mapping and function remained.  I finally found and fixed the
> > problem, but I don't understand what's going on.
> > 
> > This test mapping and function (from the original problem report)
> > now works fine when I move the cursor over a word and type "viwgx".
> > 
> >     vmap <silent> gx :call DebugSilent()<CR>
> >     function DebugSilent()
> >         echomsg "from DebugSilent"
> >     endfunction
> > 
> > But if I add this :normal command to the function, the message
> > disappears.
> > 
> >     function DebugSilent()
> >         normal gvy
> >         echomsg "from DebugSilent"
> >     endfunction
> 
> When the "normal" command is executed Vim is still in Visual mode.  In
> that mode "gv" is an error.  I'm not sure how an error is handled in
> this specific situation, but a flag may be set that causes what follows
> to work differently.
> 
> > If I add :silent in front of the :normal command, the message
> > persists again as desired.
> > 
> >     function DebugSilent()
> >         silent normal gvy
> >         echomsg "from DebugSilent"
> >     endfunction
> > 
> > I don't understand why the :normal command affects a message echoed
> > _after_ the :normal command.
> 
> That is unexpected, ":silent" should not suppress the error, only
> ":silent!" should have that effect.  I currently don't have time to look
> into this.  Best is to avoid the error caused by "gv", hopefully then
> your problems won't occur.

The gv doesn't generate an error message and without it, my function
doesn't yank anything.

I now have a version of my actual function that behaves as I want it
to, so in that sense, the problem has been solved.  Thank you for
looking into it to the extent that you did and for your help.

If you do ever have the time and inclination to look at this
further, I can show you the actual function (it's only 17 lines), if
that would help at all.

Regards,
Gary

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/20230620161340.GG6600%40phoenix.

Raspunde prin e-mail lui