Skip to content

Commit ba936f6

Browse files
luukvbaalbrammool
authored andcommitted
patch 9.0.1061: cannot display 'showcmd' somewhere else
Problem: Cannot display 'showcmd' somewhere else. Solution: Add the 'showcmdloc' option. (Luuk van Baal, closes #11684)
1 parent 3d473ee commit ba936f6

19 files changed

+152
-18
lines changed

runtime/doc/options.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7220,9 +7220,25 @@ A jump table for the options with a short description can be found at |Q_op|.
72207220
- When selecting more than one line, the number of lines.
72217221
- When selecting a block, the size in screen characters:
72227222
{lines}x{columns}.
7223+
This information can be displayed in an alternative location using the
7224+
'showcmdloc' option.
72237225
NOTE: This option is set to the Vi default value when 'compatible' is
72247226
set and to the Vim default value when 'compatible' is reset.
72257227

7228+
*'showcmdloc'* *'sloc'*
7229+
'showcmdloc' 'sloc' string (default "last")
7230+
This option can be used to display the (partially) entered command in
7231+
another location. Possible values are:
7232+
last Last line of the screen (default).
7233+
statusline Status line of the current window.
7234+
tabline First line of the screen if 'showtabine' is enabled.
7235+
Setting this option to "statusline" or "tabline" means that these will
7236+
be redrawn whenever the command changes, which can be on every key
7237+
pressed.
7238+
The %S 'statusline' item can be used in 'statusline' or 'tabline' to
7239+
place the text. Without a custom 'statusline' or 'tabline' it will be
7240+
displayed in a convenient location.
7241+
72267242
*'showfulltag'* *'sft'* *'noshowfulltag'* *'nosft'*
72277243
'showfulltag' 'sft' boolean (default off)
72287244
global
@@ -7720,6 +7736,7 @@ A jump table for the options with a short description can be found at |Q_op|.
77207736
P S Percentage through file of displayed window. This is like the
77217737
percentage described for 'ruler'. Always 3 in length, unless
77227738
translated.
7739+
S S 'showcmd' content, see 'showcmdloc'.
77237740
a S Argument list status as in default title. ({current} of {max})
77247741
Empty if the argument file count is zero or one.
77257742
{ NF Evaluate expression between '%{' and '}' and substitute result.

src/buffer.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4775,6 +4775,11 @@ build_stl_str_hl(
47754775
get_rel_pos(wp, str, TMPLEN);
47764776
break;
47774777

4778+
case STL_SHOWCMD:
4779+
if (p_sc && STRCMP(opt_name, p_sloc) == 0)
4780+
str = showcmd_buf;
4781+
break;
4782+
47784783
case STL_ARGLISTSTAT:
47794784
fillable = FALSE;
47804785
buf_tmp[0] = 0;

src/drawscreen.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,6 @@ static void redraw_custom_statusline(win_T *wp);
7373
static int did_update_one_window;
7474
#endif
7575

76-
static void win_redr_status(win_T *wp, int ignore_pum);
77-
7876
/*
7977
* Based on the current value of curwin->w_topline, transfer a screenfull
8078
* of stuff from Filemem to ScreenLines[], and update curwin->w_botline.
@@ -423,7 +421,7 @@ statusline_row(win_T *wp)
423421
* If "ignore_pum" is TRUE, also redraw statusline when the popup menu is
424422
* displayed.
425423
*/
426-
static void
424+
void
427425
win_redr_status(win_T *wp, int ignore_pum UNUSED)
428426
{
429427
int row;
@@ -548,6 +546,16 @@ win_redr_status(win_T *wp, int ignore_pum UNUSED)
548546
- 1 + wp->w_wincol), attr);
549547

550548
win_redr_ruler(wp, TRUE, ignore_pum);
549+
550+
// Draw the 'showcmd' information if 'showcmdloc' == "statusline".
551+
if (p_sc && *p_sloc == 's')
552+
{
553+
int width = MIN(10, this_ru_col - len - 2);
554+
555+
if (width > 0)
556+
screen_puts_len(showcmd_buf, width, row,
557+
wp->w_wincol + this_ru_col - width - 1, attr);
558+
}
551559
}
552560

553561
/*

src/globals.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2038,3 +2038,7 @@ EXTERN int skip_win_fix_cursor INIT(= FALSE);
20382038
EXTERN int skip_win_fix_scroll INIT(= FALSE);
20392039
// Skip update_topline() call while executing win_fix_scroll().
20402040
EXTERN int skip_update_topline INIT(= FALSE);
2041+
2042+
// 'showcmd' buffer shared between normal.c and statusline.c
2043+
#define SHOWCMD_BUFLEN (SHOWCMD_COLS + 1 + 30)
2044+
EXTERN char_u showcmd_buf[SHOWCMD_BUFLEN];

src/normal.c

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1574,8 +1574,6 @@ may_clear_cmdline(void)
15741574
* Routines for displaying a partly typed command
15751575
*/
15761576

1577-
#define SHOWCMD_BUFLEN (SHOWCMD_COLS + 1 + 30)
1578-
static char_u showcmd_buf[SHOWCMD_BUFLEN];
15791577
static char_u old_showcmd_buf[SHOWCMD_BUFLEN]; // For push_showcmd()
15801578
static int showcmd_is_clear = TRUE;
15811579
static int showcmd_visual = FALSE;
@@ -1798,22 +1796,25 @@ pop_showcmd(void)
17981796
static void
17991797
display_showcmd(void)
18001798
{
1801-
int len;
1799+
int len = (int)STRLEN(showcmd_buf);
18021800

1801+
showcmd_is_clear = (len == 0);
18031802
cursor_off();
18041803

1805-
len = (int)STRLEN(showcmd_buf);
1806-
if (len == 0)
1807-
showcmd_is_clear = TRUE;
1808-
else
1804+
if (*p_sloc == 's')
1805+
win_redr_status(curwin, FALSE);
1806+
else if (*p_sloc == 't')
1807+
draw_tabline();
1808+
else // 'showcmdloc' is "last" or empty
18091809
{
1810-
screen_puts(showcmd_buf, (int)Rows - 1, sc_col, 0);
1811-
showcmd_is_clear = FALSE;
1812-
}
1810+
if (!showcmd_is_clear)
1811+
screen_puts(showcmd_buf, (int)Rows - 1, sc_col, 0);
18131812

1814-
// clear the rest of an old message by outputting up to SHOWCMD_COLS
1815-
// spaces
1816-
screen_puts((char_u *)" " + len, (int)Rows - 1, sc_col + len, 0);
1813+
// clear the rest of an old message by outputting up to SHOWCMD_COLS
1814+
// spaces
1815+
screen_puts((char_u *)" " + len,
1816+
(int)Rows - 1, sc_col + len, 0);
1817+
}
18171818

18181819
setcursor(); // put cursor back where it belongs
18191820
}

src/option.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,14 +343,15 @@ typedef enum {
343343
#define STL_ALTPERCENT 'P' // percentage as TOP BOT ALL or NN%
344344
#define STL_ARGLISTSTAT 'a' // argument list status as (x of y)
345345
#define STL_PAGENUM 'N' // page number (when printing)
346+
#define STL_SHOWCMD 'S' // 'showcmd' buffer
346347
#define STL_VIM_EXPR '{' // start of expression to substitute
347348
#define STL_MIDDLEMARK '=' // separation between left and right
348349
#define STL_TRUNCMARK '<' // truncation mark if line is too long
349350
#define STL_USER_HL '*' // highlight from (User)1..9 or 0
350351
#define STL_HIGHLIGHT '#' // highlight name
351352
#define STL_TABPAGENR 'T' // tab page label nr
352353
#define STL_TABCLOSENR 'X' // tab page close nr
353-
#define STL_ALL ((char_u *) "fFtcvVlLknoObBrRhHmYyWwMqpPaN{#")
354+
#define STL_ALL ((char_u *) "fFtcvVlLknoObBrRhHmYyWwMqpPaNS{#")
354355

355356
// flags used for parsed 'wildmode'
356357
#define WIM_FULL 0x01
@@ -892,6 +893,7 @@ EXTERN int p_sn; // 'shortname'
892893
EXTERN char_u *p_sbr; // 'showbreak'
893894
#endif
894895
EXTERN int p_sc; // 'showcmd'
896+
EXTERN char_u *p_sloc; // 'showcmdloc'
895897
EXTERN int p_sft; // 'showfulltag'
896898
EXTERN int p_sm; // 'showmatch'
897899
EXTERN int p_smd; // 'showmode'

src/optiondefs.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2240,6 +2240,9 @@ static struct vimoption options[] =
22402240
(char_u *)TRUE
22412241
#endif
22422242
} SCTX_INIT},
2243+
{"showcmdloc", "sloc", P_STRING|P_RSTAT,
2244+
(char_u *)&p_sloc, PV_NONE,
2245+
{(char_u *)"last", (char_u *)"last"} SCTX_INIT},
22432246
{"showfulltag", "sft", P_BOOL|P_VI_DEF,
22442247
(char_u *)&p_sft, PV_NONE,
22452248
{(char_u *)FALSE, (char_u *)0L} SCTX_INIT},

src/optionstr.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ static char *(p_scl_values[]) = {"yes", "no", "auto", "number", NULL};
9393
#if defined(MSWIN) && defined(FEAT_TERMINAL)
9494
static char *(p_twt_values[]) = {"winpty", "conpty", "", NULL};
9595
#endif
96+
static char *(p_sloc_values[]) = {"last", "statusline", "tabline", NULL};
9697

9798
static int check_opt_strings(char_u *val, char **values, int list);
9899
static int opt_strings_flags(char_u *val, char **values, unsigned *flagp, int list);
@@ -1894,6 +1895,12 @@ did_set_string_option(
18941895
}
18951896
#endif
18961897

1898+
// 'showcmdloc'
1899+
else if (varp == &p_sloc)
1900+
{
1901+
if (check_opt_strings(p_sloc, p_sloc_values, FALSE) != OK)
1902+
errmsg = e_invalid_argument;
1903+
}
18971904

18981905
#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_MSWIN)
18991906
// 'toolbar'

src/proto/drawscreen.pro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* drawscreen.c */
22
int update_screen(int type_arg);
33
int statusline_row(win_T *wp);
4+
void win_redr_status(win_T *wp, int ignore_pum);
45
void showruler(int always);
56
void win_redr_ruler(win_T *wp, int always, int ignore_pum);
67
void after_updating_screen(int may_resize_shell);

src/screen.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4389,8 +4389,18 @@ draw_tabline(void)
43894389
c = ' ';
43904390
screen_fill(0, 1, col, (int)Columns, c, c, attr_fill);
43914391

4392+
// Draw the 'showcmd' information if 'showcmdloc' == "tabline".
4393+
if (p_sc && *p_sloc == 't')
4394+
{
4395+
int width = MIN(10, (int)Columns - col - (tabcount > 1) * 3);
4396+
4397+
if (width > 0)
4398+
screen_puts_len(showcmd_buf, width, 0, (int)Columns
4399+
- width - (tabcount > 1) * 2, attr_nosel);
4400+
}
4401+
43924402
// Put an "X" for closing the current tab if there are several.
4393-
if (first_tabpage->tp_next != NULL)
4403+
if (tabcount > 1)
43944404
{
43954405
screen_putchar('X', 0, (int)Columns - 1, attr_nosel);
43964406
TabPageIdxs[Columns - 1] = -999;

0 commit comments

Comments
 (0)