Patch 9.0.0350
Problem:    :echowindow does not work in a compiled function.
Solution:   Handle the expression at compile time.
Files:      src/vim9compile.c, src/vim9.h, src/vim9execute.c,
            src/vim9cmds.c, src/ex_docmd.c, src/proto/ex_docmd.pro,
            src/channel.c, src/popupwin.c, src/proto/popupwin.pro,
            src/testdir/test_vim9_disassemble.vim,
            src/testdir/test_vim9_script.vim


*** ../vim-9.0.0349/src/vim9compile.c   2022-08-24 16:30:30.690752449 +0100
--- src/vim9compile.c   2022-09-01 15:41:48.305050277 +0100
***************
*** 3251,3260 ****
  
            case CMD_echo:
            case CMD_echon:
-           case CMD_execute:
-           case CMD_echomsg:
-           case CMD_echoerr:
            case CMD_echoconsole:
                    line = compile_mult_expr(p, ea.cmdidx, &cctx);
                    break;
  
--- 3251,3263 ----
  
            case CMD_echo:
            case CMD_echon:
            case CMD_echoconsole:
+           case CMD_echoerr:
+           case CMD_echomsg:
+ #ifdef HAS_MESSAGE_WINDOW
+           case CMD_echowindow:
+ #endif
+           case CMD_execute:
                    line = compile_mult_expr(p, ea.cmdidx, &cctx);
                    break;
  
*** ../vim-9.0.0349/src/vim9.h  2022-05-17 15:59:25.000000000 +0100
--- src/vim9.h  2022-09-01 15:33:20.216795598 +0100
***************
*** 25,30 ****
--- 25,31 ----
      ISN_EXECUTE,    // :execute with isn_arg.number items on top of stack
      ISN_ECHOMSG,    // :echomsg with isn_arg.number items on top of stack
      ISN_ECHOCONSOLE, // :echoconsole with isn_arg.number items on top of stack
+     ISN_ECHOWINDOW, // :echowindow with isn_arg.number items on top of stack
      ISN_ECHOERR,    // :echoerr with isn_arg.number items on top of stack
      ISN_RANGE,            // compute range from isn_arg.string, push to stack
      ISN_SUBSTITUTE, // :s command with expression
*** ../vim-9.0.0349/src/vim9execute.c   2022-07-18 17:48:46.380542879 +0100
--- src/vim9execute.c   2022-09-01 15:48:23.887919735 +0100
***************
*** 2858,2867 ****
--- 2858,2869 ----
  
            // :execute {string} ...
            // :echomsg {string} ...
+           // :echowindow {string} ...
            // :echoconsole {string} ...
            // :echoerr {string} ...
            case ISN_EXECUTE:
            case ISN_ECHOMSG:
+           case ISN_ECHOWINDOW:
            case ISN_ECHOCONSOLE:
            case ISN_ECHOERR:
                {
***************
*** 2932,2937 ****
--- 2934,2947 ----
                                msg_attr(ga.ga_data, echo_attr);
                                out_flush();
                            }
+ #ifdef HAS_MESSAGE_WINDOW
+                           else if (iptr->isn_type == ISN_ECHOWINDOW)
+                           {
+                               start_echowindow();
+                               msg_attr(ga.ga_data, echo_attr);
+                               end_echowindow();
+                           }
+ #endif
                            else if (iptr->isn_type == ISN_ECHOCONSOLE)
                            {
                                ui_write(ga.ga_data, (int)STRLEN(ga.ga_data),
***************
*** 5570,5575 ****
--- 5580,5589 ----
                smsg("%s%4d ECHOMSG %lld", pfx, current,
                                          (varnumber_T)(iptr->isn_arg.number));
                break;
+           case ISN_ECHOWINDOW:
+               smsg("%s%4d ECHOWINDOW %lld", pfx, current,
+                                         (varnumber_T)(iptr->isn_arg.number));
+               break;
            case ISN_ECHOCONSOLE:
                smsg("%s%4d ECHOCONSOLE %lld", pfx, current,
                                          (varnumber_T)(iptr->isn_arg.number));
*** ../vim-9.0.0349/src/vim9cmds.c      2022-08-14 21:46:03.686021093 +0100
--- src/vim9cmds.c      2022-09-01 15:42:15.825060050 +0100
***************
*** 1735,1740 ****
--- 1735,1744 ----
            generate_MULT_EXPR(cctx, ISN_EXECUTE, count);
        else if (cmdidx == CMD_echomsg)
            generate_MULT_EXPR(cctx, ISN_ECHOMSG, count);
+ #ifdef HAS_MESSAGE_WINDOW
+       else if (cmdidx == CMD_echowindow)
+           generate_MULT_EXPR(cctx, ISN_ECHOWINDOW, count);
+ #endif
        else if (cmdidx == CMD_echoconsole)
            generate_MULT_EXPR(cctx, ISN_ECHOCONSOLE, count);
        else
*** ../vim-9.0.0349/src/ex_docmd.c      2022-09-01 12:58:46.580970180 +0100
--- src/ex_docmd.c      2022-09-01 15:47:26.992101004 +0100
***************
*** 8349,8359 ****
  }
  
  /*
!  * ":redraw": force redraw
   */
      void
  ex_redraw(exarg_T *eap)
  {
      int               r = RedrawingDisabled;
      int               p = p_lz;
  
--- 8349,8368 ----
  }
  
  /*
!  * ":redraw": force redraw, with clear for ":redraw!".
   */
      void
  ex_redraw(exarg_T *eap)
  {
+     redraw_cmd(eap->forceit);
+ }
+ 
+ /*
+  * ":redraw": force redraw, with clear if "clear" is TRUE.
+  */
+     void
+ redraw_cmd(int clear)
+ {
      int               r = RedrawingDisabled;
      int               p = p_lz;
  
***************
*** 8361,8367 ****
      p_lz = FALSE;
      validate_cursor();
      update_topline();
!     update_screen(eap->forceit ? UPD_CLEAR : VIsual_active ? UPD_INVERTED : 
0);
      if (need_maketitle)
        maketitle();
  #if defined(MSWIN) && (!defined(FEAT_GUI_MSWIN) || defined(VIMDLL))
--- 8370,8376 ----
      p_lz = FALSE;
      validate_cursor();
      update_topline();
!     update_screen(clear ? UPD_CLEAR : VIsual_active ? UPD_INVERTED : 0);
      if (need_maketitle)
        maketitle();
  #if defined(MSWIN) && (!defined(FEAT_GUI_MSWIN) || defined(VIMDLL))
*** ../vim-9.0.0349/src/proto/ex_docmd.pro      2022-06-27 23:15:04.000000000 
+0100
--- src/proto/ex_docmd.pro      2022-09-01 15:47:21.336119928 +0100
***************
*** 55,60 ****
--- 55,61 ----
  void do_sleep(long msec, int hide_cursor);
  void ex_may_print(exarg_T *eap);
  void ex_redraw(exarg_T *eap);
+ void redraw_cmd(int clear);
  int vim_mkdir_emsg(char_u *name, int prot);
  FILE *open_exfile(char_u *fname, int forceit, char *mode);
  void update_topline_cursor(void);
*** ../vim-9.0.0349/src/channel.c       2022-08-30 19:48:17.198760230 +0100
--- src/channel.c       2022-09-01 15:47:00.592190781 +0100
***************
*** 2731,2742 ****
      }
      else if (STRCMP(cmd, "redraw") == 0)
      {
-       exarg_T ea;
- 
        ch_log(channel, "redraw");
!       CLEAR_FIELD(ea);
!       ea.forceit = *arg != NUL;
!       ex_redraw(&ea);
        showruler(FALSE);
        setcursor();
        out_flush_cursor(TRUE, FALSE);
--- 2731,2738 ----
      }
      else if (STRCMP(cmd, "redraw") == 0)
      {
        ch_log(channel, "redraw");
!       redraw_cmd(*arg != NUL);
        showruler(FALSE);
        setcursor();
        out_flush_cursor(TRUE, FALSE);
*** ../vim-9.0.0349/src/popupwin.c      2022-08-31 14:46:07.911016920 +0100
--- src/popupwin.c      2022-09-01 15:45:36.136504932 +0100
***************
*** 4529,4534 ****
--- 4529,4559 ----
        popup_hide(message_win);
  }
  
+ /*
+  * Invoked before outputting a message for ":echowindow".
+  */
+     void
+ start_echowindow(void)
+ {
+     in_echowindow = TRUE;
+ }
+ 
+ /*
+  * Invoked after outputting a message for ":echowindow".
+  */
+     void
+ end_echowindow(void)
+ {
+     // show the message window now
+     redraw_cmd(FALSE);
+ 
+     // do not overwrite messages
+     // TODO: only for message window
+     msg_didout = TRUE;
+     if (msg_col == 0)
+       msg_col = 1;
+     in_echowindow = FALSE;
+ }
  #endif
  
  /*
*** ../vim-9.0.0349/src/proto/popupwin.pro      2022-08-31 14:46:07.911016920 
+0100
--- src/proto/popupwin.pro      2022-09-01 15:42:55.833073763 +0100
***************
*** 67,72 ****
--- 67,74 ----
  void popup_show_message_win(void);
  int popup_message_win_visible(void);
  void popup_hide_message_win(void);
+ void start_echowindow(void);
+ void end_echowindow(void);
  int popup_win_closed(win_T *win);
  void popup_set_title(win_T *wp);
  void popup_update_preview_title(void);
*** ../vim-9.0.0349/src/testdir/test_vim9_disassemble.vim       2022-08-29 
22:31:15.923685244 +0100
--- src/testdir/test_vim9_disassemble.vim       2022-09-01 15:55:52.190913466 
+0100
***************
*** 2274,2279 ****
--- 2274,2281 ----
    echomsg 'some' 'message'
    echoconsole 'nothing'
    echoerr 'went' .. 'wrong'
+   var local = 'window'
+   echowin 'in' local
  enddef
  
  def Test_disassemble_echomsg()
***************
*** 2289,2295 ****
          "echoerr 'went' .. 'wrong'\\_s*" ..
          '\d PUSHS "wentwrong"\_s*' ..
          '\d ECHOERR 1\_s*' ..
!         '\d RETURN void',
          res)
  enddef
  
--- 2291,2304 ----
          "echoerr 'went' .. 'wrong'\\_s*" ..
          '\d PUSHS "wentwrong"\_s*' ..
          '\d ECHOERR 1\_s*' ..
!         "var local = 'window'\\_s*" ..
!         '\d\+ PUSHS "window"\_s*' ..
!         '\d\+ STORE $0\_s*' ..
!         "echowin 'in' local\\_s*" ..
!         '\d\+ PUSHS "in"\_s*' ..
!         '\d\+ LOAD $0\_s*' ..
!         '\d\+ ECHOWINDOW 2\_s*' ..
!         '\d\+ RETURN void',
          res)
  enddef
  
*** ../vim-9.0.0349/src/testdir/test_vim9_script.vim    2022-08-29 
22:31:15.923685244 +0100
--- src/testdir/test_vim9_script.vim    2022-09-01 15:30:52.472680102 +0100
***************
*** 2011,2016 ****
--- 2011,2023 ----
    # output goes anywhere
  enddef
  
+ def Test_echowindow_cmd()
+   var local = 'local'
+   echowindow 'something' local # comment
+   # output goes in message window
+   popup_clear()
+ enddef
+ 
  def Test_for_outside_of_function()
    var lines =<< trim END
      vim9script
*** ../vim-9.0.0349/src/version.c       2022-09-01 15:00:17.992986820 +0100
--- src/version.c       2022-09-01 15:31:25.376708178 +0100
***************
*** 709,710 ****
--- 709,712 ----
  {   /* Add new patch number below this line */
+ /**/
+     350,
  /**/

-- 
            |

Ceci n'est pas une pipe.

 /// 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/20220901150131.09C861C0CD2%40moolenaar.net.

Raspunde prin e-mail lui