Patch 8.1.0253
Problem:    Saving and restoring window title does not always work.
Solution:   Use the stack push and pop commands. (Kouichi Iwamoto,
            closes #3059)
Files:      runtime/doc/term.txt, src/main.c, src/option.c, src/os_unix.c,
            src/proto/term.pro, src/term.c, src/term.h, src/vim.h,
            src/buffer.c, src/ex_docmd.c, src/os_amiga.c,
            src/os_mswin.c, src/os_win32.c

*** ../vim-8.1.0252/runtime/doc/term.txt        2018-05-17 13:42:03.000000000 
+0200
--- runtime/doc/term.txt        2018-08-07 22:02:48.947042241 +0200
***************
*** 342,347 ****
--- 352,361 ----
        t_SH    set cursor shape                                *t_SH* *'t_SH'*
        t_RC    request terminal cursor blinking                *t_RC* *'t_RC'*
        t_RS    request terminal cursor style                   *t_RS* *'t_RS'*
+       t_ST    save window title to stack                      *t_ST* *'t_ST'*
+       t_RT    restore window title from stack                 *t_RT* *'t_RT'*
+       t_Si    save icon text to stack                         *t_Si* *'t_Si'*
+       t_Ri    restore icon text from stack                    *t_Ri* *'t_Ri'*
  
  Some codes have a start, middle and end part.  The start and end are defined
  by the termcap option, the middle part is text.
*** ../vim-8.1.0252/src/main.c  2018-07-29 17:35:19.497750288 +0200
--- src/main.c  2018-08-07 22:11:50.444370658 +0200
***************
*** 706,711 ****
--- 706,715 ----
        scroll_region_reset();          /* In case Rows changed */
      scroll_start();   /* may scroll the screen to the right position */
  
+ #ifdef FEAT_TITLE
+     term_push_title(SAVE_RESTORE_BOTH);
+ #endif
+ 
      /*
       * Don't clear the screen when starting in Ex mode, unless using the GUI.
       */
*** ../vim-8.1.0252/src/option.c        2018-07-23 04:11:37.652969757 +0200
--- src/option.c        2018-08-07 22:26:59.391401674 +0200
***************
*** 3192,3198 ****
--- 3192,3200 ----
      p_term("t_RB", T_RBG)
      p_term("t_RC", T_CRC)
      p_term("t_RI", T_CRI)
+     p_term("t_Ri", T_SRI)
      p_term("t_RS", T_CRS)
+     p_term("t_RT", T_CRT)
      p_term("t_RV", T_CRV)
      p_term("t_Sb", T_CSB)
      p_term("t_SC", T_CSC)
***************
*** 3200,3208 ****
--- 3202,3212 ----
      p_term("t_Sf", T_CSF)
      p_term("t_SH", T_CSH)
      p_term("t_SI", T_CSI)
+     p_term("t_Si", T_SSI)
      p_term("t_so", T_SO)
      p_term("t_SR", T_CSR)
      p_term("t_sr", T_SR)
+     p_term("t_ST", T_CST)
      p_term("t_Te", T_STE)
      p_term("t_te", T_TE)
      p_term("t_ti", T_TI)
***************
*** 10414,10420 ****
      mch_setmouse(FALSE);          /* switch mouse off */
  #endif
  #ifdef FEAT_TITLE
!     mch_restore_title(3);         /* restore window titles */
  #endif
  #if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
      /* When starting the GUI close the display opened for the clipboard.
--- 10418,10424 ----
      mch_setmouse(FALSE);          /* switch mouse off */
  #endif
  #ifdef FEAT_TITLE
!     mch_restore_title(SAVE_RESTORE_BOTH);    /* restore window titles */
  #endif
  #if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
      /* When starting the GUI close the display opened for the clipboard.
***************
*** 11219,11226 ****
                buf->b_p_isk = NULL;
            }
            /*
!            * Always free the allocated strings.
!            * If not already initialized, set 'readonly' and copy 'fileformat'.
             */
            if (!buf->b_p_initialized)
            {
--- 11223,11230 ----
                buf->b_p_isk = NULL;
            }
            /*
!            * Always free the allocated strings.  If not already initialized,
!            * reset 'readonly' and copy 'fileformat'.
             */
            if (!buf->b_p_initialized)
            {
*** ../vim-8.1.0252/src/os_unix.c       2018-08-07 17:38:36.991674646 +0200
--- src/os_unix.c       2018-08-07 22:15:19.147259744 +0200
***************
*** 2336,2352 ****
  /*
   * Restore the window/icon title.
   * "which" is one of:
!  *  1  only restore title
!  *  2  only restore icon
!  *  3  restore title and icon
   */
      void
  mch_restore_title(int which)
  {
      /* only restore the title or icon when it has been set */
!     mch_settitle(((which & 1) && did_set_title) ?
                        (oldtitle ? oldtitle : p_titleold) : NULL,
!                             ((which & 2) && did_set_icon) ? oldicon : NULL);
  }
  
  #endif /* FEAT_TITLE */
--- 2336,2356 ----
  /*
   * Restore the window/icon title.
   * "which" is one of:
!  *  SAVE_RESTORE_TITLE only restore title
!  *  SAVE_RESTORE_ICON  only restore icon
!  *  SAVE_RESTORE_BOTH  restore title and icon
   */
      void
  mch_restore_title(int which)
  {
      /* only restore the title or icon when it has been set */
!     mch_settitle(((which & SAVE_RESTORE_TITLE) && did_set_title) ?
                        (oldtitle ? oldtitle : p_titleold) : NULL,
!              ((which & SAVE_RESTORE_ICON) && did_set_icon) ? oldicon : NULL);
! 
!     // pop and push from/to the stack
!     term_pop_title(which);
!     term_push_title(which);
  }
  
  #endif /* FEAT_TITLE */
***************
*** 3412,3418 ****
      {
        settmode(TMODE_COOK);
  #ifdef FEAT_TITLE
!       mch_restore_title(3);   /* restore xterm title and icon name */
  #endif
        /*
         * When t_ti is not empty but it doesn't cause swapping terminal
--- 3416,3424 ----
      {
        settmode(TMODE_COOK);
  #ifdef FEAT_TITLE
!       // restore xterm title and icon name
!       mch_restore_title(SAVE_RESTORE_BOTH);
!       term_pop_title(SAVE_RESTORE_BOTH);
  #endif
        /*
         * When t_ti is not empty but it doesn't cause swapping terminal
*** ../vim-8.1.0252/src/proto/term.pro  2018-08-07 17:38:36.995674625 +0200
--- src/proto/term.pro  2018-08-07 22:14:11.971620330 +0200
***************
*** 31,36 ****
--- 31,38 ----
  void term_fg_rgb_color(guicolor_T rgb);
  void term_bg_rgb_color(guicolor_T rgb);
  void term_settitle(char_u *title);
+ void term_push_title(int which);
+ void term_pop_title(int which);
  void ttest(int pairs);
  void add_long_to_buf(long_u val, char_u *dst);
  void check_shellsize(void);
*** ../vim-8.1.0252/src/term.c  2018-08-07 17:38:36.995674625 +0200
--- src/term.c  2018-08-07 22:13:41.603782475 +0200
***************
*** 922,927 ****
--- 922,931 ----
  #  endif
      {(int)KS_CBE,     IF_EB("\033[?2004h", ESC_STR "[?2004h")},
      {(int)KS_CBD,     IF_EB("\033[?2004l", ESC_STR "[?2004l")},
+     {(int)KS_CST,     IF_EB("\033[22;2t", ESC_STR "[22;2t")},
+     {(int)KS_CRT,     IF_EB("\033[23;2t", ESC_STR "[23;2t")},
+     {(int)KS_SSI,     IF_EB("\033[22;1t", ESC_STR "[22;1t")},
+     {(int)KS_SRI,     IF_EB("\033[23;1t", ESC_STR "[23;1t")},
  
      {K_UP,            IF_EB("\033O*A", ESC_STR "O*A")},
      {K_DOWN,          IF_EB("\033O*B", ESC_STR "O*B")},
***************
*** 1600,1605 ****
--- 1604,1611 ----
                        {KS_8F, "8f"}, {KS_8B, "8b"},
                        {KS_CBE, "BE"}, {KS_CBD, "BD"},
                        {KS_CPS, "PS"}, {KS_CPE, "PE"},
+                       {KS_CST, "ST"}, {KS_CRT, "RT"},
+                       {KS_SSI, "Si"}, {KS_SRI, "Ri"},
                        {(enum SpecialKey)0, NULL}
                    };
      int                   i;
***************
*** 2974,2979 ****
--- 2980,3024 ----
      out_str(T_FS);                    /* set title end */
      out_flush();
  }
+ 
+ /*
+  * Tell the terminal to push (save) the title and/or icon, so that it can be
+  * popped (restored) later.
+  */
+     void
+ term_push_title(int which)
+ {
+     if ((which & SAVE_RESTORE_TITLE) && *T_CST != NUL)
+     {
+       OUT_STR(T_CST);
+       out_flush();
+     }
+ 
+     if ((which & SAVE_RESTORE_ICON) && *T_SSI != NUL)
+     {
+       OUT_STR(T_SSI);
+       out_flush();
+     }
+ }
+ 
+ /*
+  * Tell the terminal to pop the title and/or icon.
+  */
+     void
+ term_pop_title(int which)
+ {
+     if ((which & SAVE_RESTORE_TITLE) && *T_CRT != NUL)
+     {
+       OUT_STR(T_CRT);
+       out_flush();
+     }
+ 
+     if ((which & SAVE_RESTORE_ICON) && *T_SRI != NUL)
+     {
+       OUT_STR(T_SRI);
+       out_flush();
+     }
+ }
  #endif
  
  /*
*** ../vim-8.1.0252/src/term.h  2017-10-14 22:14:45.000000000 +0200
--- src/term.h  2018-08-07 22:02:48.951042224 +0200
***************
*** 101,110 ****
      KS_CBE,   /* enable bracketed paste mode */
      KS_CBD,   /* disable bracketed paste mode */
      KS_CPS,   /* start of bracketed paste */
!     KS_CPE    /* end of bracketed paste */
  };
  
! #define KS_LAST           KS_CPE
  
  /*
   * the terminal capabilities are stored in this array
--- 101,114 ----
      KS_CBE,   /* enable bracketed paste mode */
      KS_CBD,   /* disable bracketed paste mode */
      KS_CPS,   /* start of bracketed paste */
!     KS_CPE,   /* end of bracketed paste */
!     KS_CST,   /* save window title */
!     KS_CRT,   /* restore window title */
!     KS_SSI,   /* save icon text */
!     KS_SRI    /* restore icon text */
  };
  
! #define KS_LAST           KS_SRI
  
  /*
   * the terminal capabilities are stored in this array
***************
*** 196,201 ****
--- 200,209 ----
  #define T_BD  (TERM_STR(KS_CBD))      /* disable bracketed paste mode */
  #define T_PS  (TERM_STR(KS_CPS))      /* start of bracketed paste */
  #define T_PE  (TERM_STR(KS_CPE))      /* end of bracketed paste */
+ #define T_CST (TERM_STR(KS_CST))      /* save window title */
+ #define T_CRT (TERM_STR(KS_CRT))      /* restore window title */
+ #define T_SSI (TERM_STR(KS_SSI))      /* save icon text */
+ #define T_SRI (TERM_STR(KS_SRI))      /* restore icon text */
  
  #define TMODE_COOK  0 /* terminal mode for external cmds and Ex mode */
  #define TMODE_SLEEP 1 /* terminal mode for sleeping (cooked but no echo) */
*** ../vim-8.1.0252/src/vim.h   2018-07-29 16:09:14.644945560 +0200
--- src/vim.h   2018-08-07 22:14:06.727648372 +0200
***************
*** 2548,2551 ****
--- 2548,2563 ----
  #define TERM_START_FORCEIT    2
  #define TERM_START_SYSTEM     4
  
+ #if defined(HAVE_DROP_FILE) \
+       || (defined(FEAT_GUI_GTK) && defined(FEAT_DND)) \
+       || defined(FEAT_GUI_MSWIN) \
+       || defined(FEAT_GUI_MAC)
+ # define HAVE_HANDLE_DROP
+ #endif
+ 
+ // Used for icon/title save and restore.
+ #define SAVE_RESTORE_TITLE    1
+ #define SAVE_RESTORE_ICON     2
+ #define SAVE_RESTORE_BOTH     (SAVE_RESTORE_TITLE | SAVE_RESTORE_ICON)
+ 
  #endif /* VIM__H */
*** ../vim-8.1.0252/src/buffer.c        2018-08-05 13:22:22.474562651 +0200
--- src/buffer.c        2018-08-07 22:15:46.499112220 +0200
***************
*** 3798,3804 ****
        if (str == NULL)
        {
            *last = NULL;
!           mch_restore_title(last == &lasttitle ? 1 : 2);
        }
        else
        {
--- 3798,3805 ----
        if (str == NULL)
        {
            *last = NULL;
!           mch_restore_title(
!                 last == &lasttitle ? SAVE_RESTORE_TITLE : SAVE_RESTORE_ICON);
        }
        else
        {
*** ../vim-8.1.0252/src/ex_docmd.c      2018-08-01 17:53:04.689381294 +0200
--- src/ex_docmd.c      2018-08-07 22:16:05.727008287 +0200
***************
*** 7750,7756 ****
        stoptermcap();
        out_flush();            /* needed for SUN to restore xterm buffer */
  #ifdef FEAT_TITLE
!       mch_restore_title(3);   /* restore window titles */
  #endif
        ui_suspend();           /* call machine specific function */
  #ifdef FEAT_TITLE
--- 7750,7756 ----
        stoptermcap();
        out_flush();            /* needed for SUN to restore xterm buffer */
  #ifdef FEAT_TITLE
!       mch_restore_title(SAVE_RESTORE_BOTH);   /* restore window titles */
  #endif
        ui_suspend();           /* call machine specific function */
  #ifdef FEAT_TITLE
*** ../vim-8.1.0252/src/os_amiga.c      2018-03-04 16:16:34.000000000 +0100
--- src/os_amiga.c      2018-08-07 22:17:36.474515466 +0200
***************
*** 617,630 ****
  /*
   * Restore the window/icon title.
   * which is one of:
!  *  1  Just restore title
!  *  2  Just restore icon (which we don't have)
!  *  3  Restore title and icon (which we don't have)
   */
      void
  mch_restore_title(int which)
  {
!     if (which & 1)
        mch_settitle(oldwindowtitle, NULL);
  }
  
--- 617,630 ----
  /*
   * Restore the window/icon title.
   * which is one of:
!  *  SAVE_RESTORE_TITLE  Just restore title
!  *  SAVE_RESTORE_ICON   Just restore icon (which we don't have)
!  *  SAVE_RESTORE_BOTH   Restore title and icon (which we don't have)
   */
      void
  mch_restore_title(int which)
  {
!     if (which & SAVE_RESTORE_TITLE)
        mch_settitle(oldwindowtitle, NULL);
  }
  
***************
*** 907,913 ****
      }
  
  #ifdef FEAT_TITLE
!     mch_restore_title(3);         /* restore window title */
  #endif
  
      ml_close_all(TRUE);                   /* remove all memfiles */
--- 907,913 ----
      }
  
  #ifdef FEAT_TITLE
!     mch_restore_title(SAVE_RESTORE_BOTH);    /* restore window title */
  #endif
  
      ml_close_all(TRUE);                   /* remove all memfiles */
*** ../vim-8.1.0252/src/os_mswin.c      2018-05-13 17:28:51.000000000 +0200
--- src/os_mswin.c      2018-08-07 22:18:09.022337873 +0200
***************
*** 304,312 ****
  /*
   * Restore the window/icon title.
   * which is one of:
!  *  1: Just restore title
!  *  2: Just restore icon (which we don't have)
!  *  3: Restore title and icon (which we don't have)
   */
      void
  mch_restore_title(int which UNUSED)
--- 304,312 ----
  /*
   * Restore the window/icon title.
   * which is one of:
!  *  SAVE_RESTORE_TITLE: Just restore title
!  *  SAVE_RESTORE_ICON:  Just restore icon (which we don't have)
!  *  SAVE_RESTORE_BOTH:  Restore title and icon (which we don't have)
   */
      void
  mch_restore_title(int which UNUSED)
*** ../vim-8.1.0252/src/os_win32.c      2018-08-07 20:47:02.756848221 +0200
--- src/os_win32.c      2018-08-07 22:18:29.258227246 +0200
***************
*** 2695,2701 ****
      if (g_fWindInitCalled)
      {
  #ifdef FEAT_TITLE
!       mch_restore_title(3);
        /*
         * Restore both the small and big icons of the console window to
         * what they were at startup.  Don't do this when the window is
--- 2695,2701 ----
      if (g_fWindInitCalled)
      {
  #ifdef FEAT_TITLE
!       mch_restore_title(SAVE_RESTORE_BOTH);
        /*
         * Restore both the small and big icons of the console window to
         * what they were at startup.  Don't do this when the window is
*** ../vim-8.1.0252/src/version.c       2018-08-07 21:54:27.725813349 +0200
--- src/version.c       2018-08-07 22:04:25.166600764 +0200
***************
*** 796,797 ****
--- 796,799 ----
  {   /* Add new patch number below this line */
+ /**/
+     253,
  /**/

-- 
       [Autumn changed into Winter ... Winter changed into Spring ...  Spring
       changed back into Autumn and Autumn gave Winter and Spring a miss and
       went straight on into Summer ...  Until one day ...]
                 "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            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].
For more options, visit https://groups.google.com/d/optout.

Raspunde prin e-mail lui