Patch 8.2.4338
Problem:    An error from an expression mapping messes up the display.
Solution:   When the expression results in an empty string return K_IGNORE.
            In cmdline mode redraw the command line. (closes #9726)
Files:      src/getchar.c, src/testdir/test_mapping.vim,
            src/testdir/dumps/Test_map_expr_2.dump,
            src/testdir/dumps/Test_map_expr_3.dump,
            src/testdir/dumps/Test_map_expr_4.dump


*** ../vim-8.2.4337/src/getchar.c       2022-02-03 13:32:59.266208214 +0000
--- src/getchar.c       2022-02-10 14:02:40.186192202 +0000
***************
*** 2840,2845 ****
--- 2840,2846 ----
            int save_may_garbage_collect = may_garbage_collect;
            int was_screen_col = screen_cur_col;
            int was_screen_row = screen_cur_row;
+           int prev_did_emsg = did_emsg;
  
            vgetc_busy = 0;
            may_garbage_collect = FALSE;
***************
*** 2852,2857 ****
--- 2853,2881 ----
            windgoto(was_screen_row, was_screen_col);
            out_flush();
  
+           // If an error was displayed and the expression returns an empty
+           // string, generate a <Nop> to allow for a redraw.
+           if (prev_did_emsg != did_emsg
+                                      && (map_str == NULL || *map_str == NUL))
+           {
+               char_u  buf[4];
+ 
+               vim_free(map_str);
+               buf[0] = K_SPECIAL;
+               buf[1] = KS_EXTRA;
+               buf[2] = KE_IGNORE;
+               buf[3] = NUL;
+               map_str = vim_strsave(buf);
+               if (State & CMDLINE)
+               {
+                   // redraw the command below the error
+                   msg_didout = TRUE;
+                   if (msg_row < cmdline_row)
+                       msg_row = cmdline_row;
+                   redrawcmd();
+               }
+           }
+ 
            vgetc_busy = save_vgetc_busy;
            may_garbage_collect = save_may_garbage_collect;
        }
*** ../vim-8.2.4337/src/testdir/test_mapping.vim        2022-01-29 
21:45:30.485921485 +0000
--- src/testdir/test_mapping.vim        2022-02-10 13:48:20.947061723 +0000
***************
*** 549,554 ****
--- 549,586 ----
    call delete('XtestExprMap')
  endfunc
  
+ func Test_expr_map_error()
+   CheckScreendump
+ 
+   let lines =<< trim END
+       func Func()
+         throw 'test'
+         return ''
+       endfunc
+ 
+       nnoremap <expr> <F2> Func()
+       cnoremap <expr> <F2> Func()
+ 
+       call test_override('ui_delay', 10)
+   END
+   call writefile(lines, 'XtestExprMap')
+   let buf = RunVimInTerminal('-S XtestExprMap', #{rows: 10})
+   call TermWait(buf)
+   call term_sendkeys(buf, "\<F2>")
+   call TermWait(buf)
+   call term_sendkeys(buf, "\<CR>")
+   call VerifyScreenDump(buf, 'Test_map_expr_2', {})
+ 
+   call term_sendkeys(buf, ":abc\<F2>")
+   call VerifyScreenDump(buf, 'Test_map_expr_3', {})
+   call term_sendkeys(buf, "\<Esc>0")
+   call VerifyScreenDump(buf, 'Test_map_expr_4', {})
+ 
+   " clean up
+   call StopVimInTerminal(buf)
+   call delete('XtestExprMap')
+ endfunc
+ 
  " Test for mapping errors
  func Test_map_error()
    call assert_fails('unmap', 'E474:')
*** ../vim-8.2.4337/src/testdir/dumps/Test_map_expr_2.dump      2022-02-10 
14:03:10.910166634 +0000
--- src/testdir/dumps/Test_map_expr_2.dump      2022-02-10 13:24:41.448895720 
+0000
***************
*** 0 ****
--- 1,10 ----
+ > +0&#ffffff0@74
+ |~+0#4040ff13&| @73
+ |~| @73
+ |~| @73
+ |~| @73
+ |~| @73
+ |~| @73
+ |~| @73
+ |~| @73
+ | +0#0000000&@56|0|,|0|-|1| @8|A|l@1| 
*** ../vim-8.2.4337/src/testdir/dumps/Test_map_expr_3.dump      2022-02-10 
14:06:18.734014139 +0000
--- src/testdir/dumps/Test_map_expr_3.dump      2022-02-10 13:32:59.616554980 
+0000
***************
*** 0 ****
--- 1,10 ----
+ |~+0#4040ff13#ffffff0| @73
+ |~| @73
+ |~| @73
+ |~| @73
+ |~| @73
+ |:+0#0000000&|a|b|c| @70
+ |E+0#ffffff16#e000002|r@1|o|r| |d|e|t|e|c|t|e|d| |w|h|i|l|e| 
|p|r|o|c|e|s@1|i|n|g| |f|u|n|c|t|i|o|n| |F|u|n|c|[|1|]|.@1|f|u|n|c|t|i|o|n| 
|F|u|n|c|:| +0#0000000#ffffff0@10
+ |l+0#af5f00255&|i|n|e| @3|1|:| +0#0000000&@64
+ |E+0#ffffff16#e000002|6|0|5|:| |E|x|c|e|p|t|i|o|n| |n|o|t| |c|a|u|g|h|t|:| 
|t|e|s|t| +0#0000000#ffffff0@42
+ |:|a|b|c> @70
*** ../vim-8.2.4337/src/testdir/dumps/Test_map_expr_4.dump      2022-02-10 
14:06:18.738014139 +0000
--- src/testdir/dumps/Test_map_expr_4.dump      2022-02-10 13:36:46.400428725 
+0000
***************
*** 0 ****
--- 1,10 ----
+ > +0&#ffffff0@74
+ |~+0#4040ff13&| @73
+ |~| @73
+ |~| @73
+ |~| @73
+ |~| @73
+ |~| @73
+ |~| @73
+ |~| @73
+ | +0#0000000&@56|0|,|0|-|1| @8|A|l@1| 
*** ../vim-8.2.4337/src/version.c       2022-02-09 15:20:35.275193729 +0000
--- src/version.c       2022-02-10 13:20:24.125136315 +0000
***************
*** 748,749 ****
--- 748,751 ----
  {   /* Add new patch number below this line */
+ /**/
+     4338,
  /**/

-- 
How To Keep A Healthy Level Of Insanity:
13. Go to a poetry recital and ask why the poems don't rhyme.

 /// Bram Moolenaar -- [email protected] -- 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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/20220210140830.3155F1C12B8%40moolenaar.net.

Raspunde prin e-mail lui