Skip to content

Commit 40385db

Browse files
committed
patch 8.1.0253: saving and restoring window title does not always work
Problem: Saving and restoring window title does not always work. Solution: Use the stack push and pop commands. (Kouichi Iwamoto, closes #3059)
1 parent de3b367 commit 40385db

14 files changed

Lines changed: 110 additions & 22 deletions

File tree

runtime/doc/term.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,10 @@ Added by Vim (there are no standard codes for these):
352352
t_SH set cursor shape *t_SH* *'t_SH'*
353353
t_RC request terminal cursor blinking *t_RC* *'t_RC'*
354354
t_RS request terminal cursor style *t_RS* *'t_RS'*
355+
t_ST save window title to stack *t_ST* *'t_ST'*
356+
t_RT restore window title from stack *t_RT* *'t_RT'*
357+
t_Si save icon text to stack *t_Si* *'t_Si'*
358+
t_Ri restore icon text from stack *t_Ri* *'t_Ri'*
355359

356360
Some codes have a start, middle and end part. The start and end are defined
357361
by the termcap option, the middle part is text.

src/buffer.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3798,7 +3798,8 @@ value_changed(char_u *str, char_u **last)
37983798
if (str == NULL)
37993799
{
38003800
*last = NULL;
3801-
mch_restore_title(last == &lasttitle ? 1 : 2);
3801+
mch_restore_title(
3802+
last == &lasttitle ? SAVE_RESTORE_TITLE : SAVE_RESTORE_ICON);
38023803
}
38033804
else
38043805
{

src/ex_docmd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7750,7 +7750,7 @@ ex_stop(exarg_T *eap)
77507750
stoptermcap();
77517751
out_flush(); /* needed for SUN to restore xterm buffer */
77527752
#ifdef FEAT_TITLE
7753-
mch_restore_title(3); /* restore window titles */
7753+
mch_restore_title(SAVE_RESTORE_BOTH); /* restore window titles */
77547754
#endif
77557755
ui_suspend(); /* call machine specific function */
77567756
#ifdef FEAT_TITLE

src/main.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,10 @@ vim_main2(void)
706706
scroll_region_reset(); /* In case Rows changed */
707707
scroll_start(); /* may scroll the screen to the right position */
708708

709+
#ifdef FEAT_TITLE
710+
term_push_title(SAVE_RESTORE_BOTH);
711+
#endif
712+
709713
/*
710714
* Don't clear the screen when starting in Ex mode, unless using the GUI.
711715
*/

src/option.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3192,17 +3192,21 @@ static struct vimoption options[] =
31923192
p_term("t_RB", T_RBG)
31933193
p_term("t_RC", T_CRC)
31943194
p_term("t_RI", T_CRI)
3195+
p_term("t_Ri", T_SRI)
31953196
p_term("t_RS", T_CRS)
3197+
p_term("t_RT", T_CRT)
31963198
p_term("t_RV", T_CRV)
31973199
p_term("t_Sb", T_CSB)
31983200
p_term("t_SC", T_CSC)
31993201
p_term("t_se", T_SE)
32003202
p_term("t_Sf", T_CSF)
32013203
p_term("t_SH", T_CSH)
32023204
p_term("t_SI", T_CSI)
3205+
p_term("t_Si", T_SSI)
32033206
p_term("t_so", T_SO)
32043207
p_term("t_SR", T_CSR)
32053208
p_term("t_sr", T_SR)
3209+
p_term("t_ST", T_CST)
32063210
p_term("t_Te", T_STE)
32073211
p_term("t_te", T_TE)
32083212
p_term("t_ti", T_TI)
@@ -10414,7 +10418,7 @@ clear_termoptions(void)
1041410418
mch_setmouse(FALSE); /* switch mouse off */
1041510419
#endif
1041610420
#ifdef FEAT_TITLE
10417-
mch_restore_title(3); /* restore window titles */
10421+
mch_restore_title(SAVE_RESTORE_BOTH); /* restore window titles */
1041810422
#endif
1041910423
#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
1042010424
/* When starting the GUI close the display opened for the clipboard.
@@ -11219,8 +11223,8 @@ buf_copy_options(buf_T *buf, int flags)
1121911223
buf->b_p_isk = NULL;
1122011224
}
1122111225
/*
11222-
* Always free the allocated strings.
11223-
* If not already initialized, set 'readonly' and copy 'fileformat'.
11226+
* Always free the allocated strings. If not already initialized,
11227+
* reset 'readonly' and copy 'fileformat'.
1122411228
*/
1122511229
if (!buf->b_p_initialized)
1122611230
{

src/os_amiga.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -617,14 +617,14 @@ mch_settitle(char_u *title, char_u *icon)
617617
/*
618618
* Restore the window/icon title.
619619
* which is one of:
620-
* 1 Just restore title
621-
* 2 Just restore icon (which we don't have)
622-
* 3 Restore title and icon (which we don't have)
620+
* SAVE_RESTORE_TITLE Just restore title
621+
* SAVE_RESTORE_ICON Just restore icon (which we don't have)
622+
* SAVE_RESTORE_BOTH Restore title and icon (which we don't have)
623623
*/
624624
void
625625
mch_restore_title(int which)
626626
{
627-
if (which & 1)
627+
if (which & SAVE_RESTORE_TITLE)
628628
mch_settitle(oldwindowtitle, NULL);
629629
}
630630

@@ -907,7 +907,7 @@ mch_exit(int r)
907907
}
908908

909909
#ifdef FEAT_TITLE
910-
mch_restore_title(3); /* restore window title */
910+
mch_restore_title(SAVE_RESTORE_BOTH); /* restore window title */
911911
#endif
912912

913913
ml_close_all(TRUE); /* remove all memfiles */

src/os_mswin.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -304,9 +304,9 @@ mch_settitle(
304304
/*
305305
* Restore the window/icon title.
306306
* which is one of:
307-
* 1: Just restore title
308-
* 2: Just restore icon (which we don't have)
309-
* 3: Restore title and icon (which we don't have)
307+
* SAVE_RESTORE_TITLE: Just restore title
308+
* SAVE_RESTORE_ICON: Just restore icon (which we don't have)
309+
* SAVE_RESTORE_BOTH: Restore title and icon (which we don't have)
310310
*/
311311
void
312312
mch_restore_title(int which UNUSED)

src/os_unix.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2336,17 +2336,21 @@ mch_settitle(char_u *title, char_u *icon)
23362336
/*
23372337
* Restore the window/icon title.
23382338
* "which" is one of:
2339-
* 1 only restore title
2340-
* 2 only restore icon
2341-
* 3 restore title and icon
2339+
* SAVE_RESTORE_TITLE only restore title
2340+
* SAVE_RESTORE_ICON only restore icon
2341+
* SAVE_RESTORE_BOTH restore title and icon
23422342
*/
23432343
void
23442344
mch_restore_title(int which)
23452345
{
23462346
/* only restore the title or icon when it has been set */
2347-
mch_settitle(((which & 1) && did_set_title) ?
2347+
mch_settitle(((which & SAVE_RESTORE_TITLE) && did_set_title) ?
23482348
(oldtitle ? oldtitle : p_titleold) : NULL,
2349-
((which & 2) && did_set_icon) ? oldicon : NULL);
2349+
((which & SAVE_RESTORE_ICON) && did_set_icon) ? oldicon : NULL);
2350+
2351+
// pop and push from/to the stack
2352+
term_pop_title(which);
2353+
term_push_title(which);
23502354
}
23512355

23522356
#endif /* FEAT_TITLE */
@@ -3412,7 +3416,9 @@ mch_exit(int r)
34123416
{
34133417
settmode(TMODE_COOK);
34143418
#ifdef FEAT_TITLE
3415-
mch_restore_title(3); /* restore xterm title and icon name */
3419+
// restore xterm title and icon name
3420+
mch_restore_title(SAVE_RESTORE_BOTH);
3421+
term_pop_title(SAVE_RESTORE_BOTH);
34163422
#endif
34173423
/*
34183424
* When t_ti is not empty but it doesn't cause swapping terminal

src/os_win32.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2695,7 +2695,7 @@ mch_exit(int r)
26952695
if (g_fWindInitCalled)
26962696
{
26972697
#ifdef FEAT_TITLE
2698-
mch_restore_title(3);
2698+
mch_restore_title(SAVE_RESTORE_BOTH);
26992699
/*
27002700
* Restore both the small and big icons of the console window to
27012701
* what they were at startup. Don't do this when the window is

src/proto/term.pro

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ void term_bg_color(int n);
3131
void term_fg_rgb_color(guicolor_T rgb);
3232
void term_bg_rgb_color(guicolor_T rgb);
3333
void term_settitle(char_u *title);
34+
void term_push_title(int which);
35+
void term_pop_title(int which);
3436
void ttest(int pairs);
3537
void add_long_to_buf(long_u val, char_u *dst);
3638
void check_shellsize(void);

0 commit comments

Comments
 (0)