Skip to content

Commit

Permalink
patch 9.0.0321: cannot use the message popup window directly
Browse files Browse the repository at this point in the history
Problem:    Cannot use the message popup window directly.
Solution:   Add ":echowindow".
  • Loading branch information
brammool committed Aug 29, 2022
1 parent 54acb90 commit 37fef16
Show file tree
Hide file tree
Showing 14 changed files with 114 additions and 31 deletions.
10 changes: 10 additions & 0 deletions runtime/doc/eval.txt
Expand Up @@ -3821,6 +3821,16 @@ text...
:echomsg "It's a Zizzer Zazzer Zuzz, as you can plainly see."
< See |:echo-redraw| to avoid the message disappearing
when the screen is redrawn.

*:echow* *:echowin* *:echowindow*
:echow[indow] {expr1} ..
Like |:echomsg| but when the messages popup window is
available the message is displayed there. This means
it will show for three seconds and avoid a
|hit-enter| prompt.
The message window is available when Vim was compiled
with the +timer and the +popupwin features.

*:echoe* *:echoerr*
:echoe[rr] {expr1} .. Echo the expression(s) as an error message, saving the
message in the |message-history|. When used in a
Expand Down
14 changes: 11 additions & 3 deletions src/eval.c
Expand Up @@ -2078,7 +2078,8 @@ set_context_for_expression(
if ((cmdidx == CMD_execute
|| cmdidx == CMD_echo
|| cmdidx == CMD_echon
|| cmdidx == CMD_echomsg)
|| cmdidx == CMD_echomsg
|| cmdidx == CMD_echowindow)
&& xp->xp_context == EXPAND_EXPRESSION)
{
for (;;)
Expand Down Expand Up @@ -6709,6 +6710,7 @@ get_echo_attr(void)
/*
* ":execute expr1 ..." execute the result of an expression.
* ":echomsg expr1 ..." Print a message
* ":echowindow expr1 ..." Print a message in the messages window
* ":echoerr expr1 ..." Print an error
* ":echoconsole expr1 ..." Print a message on stdout
* Each gets spaces around each argument and a newline at the end for
Expand All @@ -6726,6 +6728,9 @@ ex_execute(exarg_T *eap)
long start_lnum = SOURCING_LNUM;

ga_init2(&ga, 1, 80);
#ifdef HAS_MESSAGE_WINDOW
in_echowindow = (eap->cmdidx == CMD_echowindow);
#endif

if (eap->skip)
++emsg_skip;
Expand Down Expand Up @@ -6780,15 +6785,17 @@ ex_execute(exarg_T *eap)
// use the first line of continuation lines for messages
SOURCING_LNUM = start_lnum;

if (eap->cmdidx == CMD_echomsg || eap->cmdidx == CMD_echoerr)
if (eap->cmdidx == CMD_echomsg
|| eap->cmdidx == CMD_echowindow
|| eap->cmdidx == CMD_echoerr)
{
// Mark the already saved text as finishing the line, so that what
// follows is displayed on a new line when scrolling back at the
// more prompt.
msg_sb_eol();
}

if (eap->cmdidx == CMD_echomsg)
if (eap->cmdidx == CMD_echomsg || eap->cmdidx == CMD_echowindow)
{
msg_attr(ga.ga_data, echo_attr);
out_flush();
Expand Down Expand Up @@ -6835,6 +6842,7 @@ ex_execute(exarg_T *eap)
if (msg_col == 0)
msg_col = 1;
}
in_echowindow = FALSE;
#endif
set_nextcmd(eap, arg);
}
Expand Down
46 changes: 23 additions & 23 deletions src/ex_cmdidxs.h
Expand Up @@ -10,27 +10,27 @@ static const unsigned short cmdidxs1[26] =
/* c */ 45,
/* d */ 112,
/* e */ 137,
/* f */ 165,
/* g */ 182,
/* h */ 188,
/* i */ 197,
/* j */ 217,
/* k */ 219,
/* l */ 224,
/* m */ 287,
/* n */ 305,
/* o */ 325,
/* p */ 337,
/* q */ 376,
/* r */ 379,
/* s */ 399,
/* t */ 469,
/* u */ 515,
/* v */ 526,
/* w */ 547,
/* x */ 561,
/* y */ 571,
/* z */ 572
/* f */ 166,
/* g */ 183,
/* h */ 189,
/* i */ 198,
/* j */ 218,
/* k */ 220,
/* l */ 225,
/* m */ 288,
/* n */ 306,
/* o */ 326,
/* p */ 338,
/* q */ 377,
/* r */ 380,
/* s */ 400,
/* t */ 470,
/* u */ 516,
/* v */ 527,
/* w */ 548,
/* x */ 562,
/* y */ 572,
/* z */ 573
};

/*
Expand All @@ -45,7 +45,7 @@ static const unsigned char cmdidxs2[26][26] =
/* b */ { 2, 0, 0, 5, 6, 8, 0, 0, 0, 0, 0, 9, 10, 11, 12, 13, 0, 14, 0, 0, 0, 0, 23, 0, 0, 0 },
/* c */ { 3, 12, 16, 18, 20, 22, 25, 0, 0, 0, 0, 33, 38, 41, 47, 57, 59, 60, 61, 0, 63, 0, 66, 0, 0, 0 },
/* d */ { 0, 0, 0, 0, 0, 0, 0, 0, 8, 18, 0, 19, 0, 0, 20, 0, 0, 22, 23, 0, 0, 0, 0, 0, 0, 0 },
/* e */ { 1, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 8, 10, 11, 0, 0, 0, 0, 0, 0, 0, 22, 0, 23, 0, 0 },
/* e */ { 1, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 9, 11, 12, 0, 0, 0, 0, 0, 0, 0, 23, 0, 24, 0, 0 },
/* f */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0, 16, 0, 0, 0, 0, 0 },
/* g */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 2, 0, 0, 4, 5, 0, 0, 0, 0 },
/* h */ { 5, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
Expand All @@ -69,4 +69,4 @@ static const unsigned char cmdidxs2[26][26] =
/* z */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
};

static const int command_count = 589;
static const int command_count = 590;
3 changes: 3 additions & 0 deletions src/ex_cmds.h
Expand Up @@ -548,6 +548,9 @@ EXCMD(CMD_echoconsole, "echoconsole", ex_execute,
EXCMD(CMD_echon, "echon", ex_echo,
EX_EXTRA|EX_NOTRLCOM|EX_EXPR_ARG|EX_SBOXOK|EX_CMDWIN|EX_LOCK_OK,
ADDR_NONE),
EXCMD(CMD_echowindow, "echowindow", ex_execute,
EX_EXTRA|EX_NOTRLCOM|EX_EXPR_ARG|EX_SBOXOK|EX_CMDWIN|EX_LOCK_OK,
ADDR_NONE),
EXCMD(CMD_else, "else", ex_else,
EX_TRLBAR|EX_SBOXOK|EX_CMDWIN|EX_LOCK_OK|EX_WHOLE,
ADDR_NONE),
Expand Down
7 changes: 7 additions & 0 deletions src/ex_getln.c
Expand Up @@ -3872,6 +3872,8 @@ redrawcmdprompt(void)
void
redrawcmd(void)
{
int save_in_echowindow = in_echowindow;

if (cmd_silent)
return;

Expand All @@ -3883,6 +3885,9 @@ redrawcmd(void)
return;
}

// Do not put this in the message window.
in_echowindow = FALSE;

sb_text_restart_cmdline();
msg_start();
redrawcmdprompt();
Expand All @@ -3906,6 +3911,8 @@ redrawcmd(void)
// Typing ':' at the more prompt may set skip_redraw. We don't want this
// in cmdline mode
skip_redraw = FALSE;

in_echowindow = save_in_echowindow;
}

void
Expand Down
1 change: 1 addition & 0 deletions src/globals.h
Expand Up @@ -236,6 +236,7 @@ EXTERN int uncaught_emsg; // number of times emsg() was
EXTERN int did_emsg_syntax; // did_emsg set because of a
// syntax error
EXTERN int called_emsg; // always incremented by emsg()
EXTERN int in_echowindow; // executing ":echowindow"
EXTERN int ex_exitval INIT(= 0); // exit value for ex mode
EXTERN int emsg_on_display INIT(= FALSE); // there is an error message
EXTERN int rc_did_emsg INIT(= FALSE); // vim_regcomp() called emsg()
Expand Down
8 changes: 5 additions & 3 deletions src/message.c
Expand Up @@ -1438,7 +1438,8 @@ use_message_window(void)
#ifdef HAS_MESSAGE_WINDOW
// TRUE if there is no command line showing ('cmdheight' is zero and not
// already editing or showing a message) use a popup window for messages.
return p_ch == 0 && cmdline_row >= Rows;
// Also when using ":echowindow".
return (p_ch == 0 && cmdline_row >= Rows) || in_echowindow;
#else
return FALSE;
#endif
Expand Down Expand Up @@ -1484,8 +1485,9 @@ msg_start(void)
#ifdef HAS_MESSAGE_WINDOW
if (use_message_window())
{
if (popup_message_win_visible() && msg_col > 0
&& (msg_scroll || !full_screen))
if (popup_message_win_visible()
&& ((msg_col > 0 && (msg_scroll || !full_screen))
|| in_echowindow))
{
win_T *wp = popup_get_message_win();

Expand Down
3 changes: 2 additions & 1 deletion src/popupwin.c
Expand Up @@ -1302,7 +1302,8 @@ popup_adjust_position(win_T *wp)
}
if (wp->w_popup_pos == POPPOS_BOTTOM)
// assume that each buffer line takes one screen line
wp->w_winrow = MAX(Rows - wp->w_buffer->b_ml.ml_line_count - 1, 0);
wp->w_winrow = MAX(cmdline_row
- wp->w_buffer->b_ml.ml_line_count - 1, 0);

if (!use_wantcol)
center_hor = TRUE;
Expand Down
2 changes: 1 addition & 1 deletion src/structs.h
Expand Up @@ -2606,7 +2606,7 @@ typedef enum {
POPPOS_BOTRIGHT,
POPPOS_TOPRIGHT,
POPPOS_CENTER,
POPPOS_BOTTOM, // bottom of popup at bottom of screen
POPPOS_BOTTOM, // bottom of popup just above the command line
POPPOS_NONE
} poppos_T;

Expand Down
8 changes: 8 additions & 0 deletions src/testdir/dumps/Test_echowindow_1.dump
@@ -0,0 +1,8 @@
>s+0&#ffffff0|o|m|e| |t|e|x|t| @65
|~+0#4040ff13&| @73
|~| @73
|~| @73
|~| @73
|═+0#e000002&@74
|f|i|r|s|t| |l|i|n|e| @64
| +0#0000000&@56|1|,|1| @10|A|l@1|
8 changes: 8 additions & 0 deletions src/testdir/dumps/Test_echowindow_2.dump
@@ -0,0 +1,8 @@
>s+0&#ffffff0|o|m|e| |t|e|x|t| @65
|~+0#4040ff13&| @73
|~| @73
|~| @73
|═+0#e000002&@74
|f|i|r|s|t| |l|i|n|e| @64
|s|e|c|o|n|d| |l|i|n|e| @63
| +0#0000000&@56|1|,|1| @10|A|l@1|
8 changes: 8 additions & 0 deletions src/testdir/dumps/Test_echowindow_3.dump
@@ -0,0 +1,8 @@
>s+0&#ffffff0|o|m|e| |t|e|x|t| @65
|~+0#4040ff13&| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
| +0#0000000&@56|1|,|1| @10|A|l@1|
25 changes: 25 additions & 0 deletions src/testdir/test_messages.vim
Expand Up @@ -537,5 +537,30 @@ func Test_cmdheight_zero_shell()
set cmdheight&
endfunc

func Test_echowindow()
CheckScreendump

let lines =<< trim END
call setline(1, 'some text')
func ShowMessage(arg)
echowindow a:arg
endfunc
echowindow 'first line'
END
call writefile(lines, 'XtestEchowindow')
let buf = RunVimInTerminal('-S XtestEchowindow', #{rows: 8})
call VerifyScreenDump(buf, 'Test_echowindow_1', {})

call term_sendkeys(buf, ":call ShowMessage('second line')\<CR>")
call VerifyScreenDump(buf, 'Test_echowindow_2', {})

call term_sendkeys(buf, ":call popup_clear()\<CR>")
call VerifyScreenDump(buf, 'Test_echowindow_3', {})

" clean up
call StopVimInTerminal(buf)
call delete('XtestEchowindow')
endfunc


" vim: shiftwidth=2 sts=2 expandtab
2 changes: 2 additions & 0 deletions src/version.c
Expand Up @@ -707,6 +707,8 @@ static char *(features[]) =

static int included_patches[] =
{ /* Add new patch number below this line */
/**/
321,
/**/
320,
/**/
Expand Down

0 comments on commit 37fef16

Please sign in to comment.