Re: Bug in :vmap

2023-06-20 Fir de Conversatie Gary Johnson
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- says that with , 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  gx :call DebugSilent()
> > > > > > vmap  gx :call DebugSilent()
> > > > > > 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  gx :call DebugSilent()
> > 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 w

Re: Bug in :vmap

2023-06-19 Fir de Conversatie Bram Moolenaar


Gary Johnson wrote:

> On 2023-06-15, Bram Moolenaar wrote:
> > > On 2023-06-15, Bram Moolenaar wrote:
> > > > > Help for :map- says that with , 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  gx :call DebugSilent()
> > > > > vmap  gx :call DebugSilent()
> > > > > 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  gx :call DebugSilent()
> 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.

-- 
hundred-and-one symptoms of being an internet addict:
193. You ask your girlfriend to drive home so you can sit back with
 your PDA and download the information to your laptop

 /// Bram Moolenaar -- b...@moolenaar.net -- http://www.Moolenaar.net   \\\
///  \\\
\\\sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
 \\\help me help AIDS vic

Re: Bug in :vmap

2023-06-15 Fir de Conversatie Gary Johnson
On 2023-06-15, Bram Moolenaar wrote:
> > On 2023-06-15, Bram Moolenaar wrote:
> > > > Help for :map- says that with , 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  gx :call DebugSilent()
> > > > vmap  gx :call DebugSilent()
> > > > 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  gx :call DebugSilent()
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

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.

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/20230615204451.GE6600%40phoenix.


Re: Bug in :vmap

2023-06-15 Fir de Conversatie Bram Moolenaar


> On 2023-06-15, Bram Moolenaar wrote:
> > > Help for :map- says that with , 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  gx :call DebugSilent()
> > > vmap  gx :call DebugSilent()
> > > 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.

-- 
hundred-and-one symptoms of being an internet addict:
178. You look for an icon to double-click to open your bedroom window.

 /// Bram Moolenaar -- b...@moolenaar.net -- http://www.Moolenaar.net   \\\
///  \\\
\\\sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
 \\\help me help AIDS victims -- http://ICCF-Holland.org///

-- 
-- 
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/20230615174529.46E361C0D56%40moolenaar.net.


Re: Bug in :vmap

2023-06-15 Fir de Conversatie Gary Johnson
On 2023-06-15, Bram Moolenaar wrote:
> > Help for :map- says that with , 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  gx :call DebugSilent()
> > vmap  gx :call DebugSilent()
> > 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.

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/20230615162716.GC6600%40phoenix.


Re: Bug in :vmap

2023-06-15 Fir de Conversatie Bram Moolenaar


> Help for :map- says that with , 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  gx :call DebugSilent()
> vmap  gx :call DebugSilent()
> 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.

-- 
If Microsoft would build a car...
... The airbag system would ask "are you SURE?" before deploying.

 /// Bram Moolenaar -- b...@moolenaar.net -- http://www.Moolenaar.net   \\\
///  \\\
\\\sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
 \\\help me help AIDS victims -- http://ICCF-Holland.org///

-- 
-- 
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/20230615153522.738AB1C0D56%40moolenaar.net.


Bug in :vmap

2023-06-14 Fir de Conversatie Gary Johnson
Help for :map- says that with , 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  gx :call DebugSilent()
vmap  gx :call DebugSilent()
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.

Version of Vim
9.0.1632

Environment

 Operating system:  Ubuntu 20.04
 Terminal:  XTerm(380)
 Value of $TERM:xterm-256color
 Shell: bash 5.0.17

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/20230614231223.GB6600%40phoenix.