comparison src/buffer.c @ 14087:1d25a3e8e03c v8.1.0061

patch 8.1.0061: window title is wrong after resetting and setting 'title' commit https://github.com/vim/vim/commit/84a9308511871d9ff94c91a1c6badb92300ded98 Author: Bram Moolenaar <Bram@vim.org> Date: Sat Jun 16 22:58:15 2018 +0200 patch 8.1.0061: window title is wrong after resetting and setting 'title' Problem: Window title is wrong after resetting and setting 'title'. Solution: Move resetting the title into maketitle(). (Jason Franklin)
author Christian Brabandt <cb@256bit.org>
date Sat, 16 Jun 2018 23:00:08 +0200
parents afce2005fdc8
children 2ad722003b36
comparison
equal deleted inserted replaced
14086:56f44a087b09 14087:1d25a3e8e03c
36 static int buf_same_ino(buf_T *buf, stat_T *stp); 36 static int buf_same_ino(buf_T *buf, stat_T *stp);
37 #else 37 #else
38 static int otherfile_buf(buf_T *buf, char_u *ffname); 38 static int otherfile_buf(buf_T *buf, char_u *ffname);
39 #endif 39 #endif
40 #ifdef FEAT_TITLE 40 #ifdef FEAT_TITLE
41 static int ti_change(char_u *str, char_u **last); 41 static int value_changed(char_u *str, char_u **last);
42 #endif 42 #endif
43 static int append_arg_number(win_T *wp, char_u *buf, int buflen, int add_file); 43 static int append_arg_number(win_T *wp, char_u *buf, int buflen, int add_file);
44 static void free_buffer(buf_T *); 44 static void free_buffer(buf_T *);
45 static void free_buffer_stuff(buf_T *buf, int free_options); 45 static void free_buffer_stuff(buf_T *buf, int free_options);
46 static void clear_wininfo(buf_T *buf); 46 static void clear_wininfo(buf_T *buf);
3543 else 3543 else
3544 vim_snprintf((char *)buf, buflen, "%d-%d", col, vcol); 3544 vim_snprintf((char *)buf, buflen, "%d-%d", col, vcol);
3545 } 3545 }
3546 3546
3547 #if defined(FEAT_TITLE) || defined(PROTO) 3547 #if defined(FEAT_TITLE) || defined(PROTO)
3548 /*
3549 * put file name in title bar of window and in icon title
3550 */
3551
3552 static char_u *lasttitle = NULL; 3548 static char_u *lasttitle = NULL;
3553 static char_u *lasticon = NULL; 3549 static char_u *lasticon = NULL;
3554 3550
3551 /*
3552 * Put the file name in the title bar and icon of the window.
3553 */
3555 void 3554 void
3556 maketitle(void) 3555 maketitle(void)
3557 { 3556 {
3558 char_u *p; 3557 char_u *p;
3559 char_u *t_str = NULL; 3558 char_u *title_str = NULL;
3560 char_u *i_name; 3559 char_u *icon_str = NULL;
3561 char_u *i_str = NULL;
3562 int maxlen = 0; 3560 int maxlen = 0;
3563 int len; 3561 int len;
3564 int mustset; 3562 int mustset;
3565 char_u buf[IOSIZE]; 3563 char_u buf[IOSIZE];
3566 int off; 3564 int off;
3572 return; 3570 return;
3573 } 3571 }
3574 3572
3575 need_maketitle = FALSE; 3573 need_maketitle = FALSE;
3576 if (!p_title && !p_icon && lasttitle == NULL && lasticon == NULL) 3574 if (!p_title && !p_icon && lasttitle == NULL && lasticon == NULL)
3577 return; 3575 return; // nothing to do
3578 3576
3579 if (p_title) 3577 if (p_title)
3580 { 3578 {
3581 if (p_titlelen > 0) 3579 if (p_titlelen > 0)
3582 { 3580 {
3583 maxlen = p_titlelen * Columns / 100; 3581 maxlen = p_titlelen * Columns / 100;
3584 if (maxlen < 10) 3582 if (maxlen < 10)
3585 maxlen = 10; 3583 maxlen = 10;
3586 } 3584 }
3587 3585
3588 t_str = buf; 3586 title_str = buf;
3589 if (*p_titlestring != NUL) 3587 if (*p_titlestring != NUL)
3590 { 3588 {
3591 #ifdef FEAT_STL_OPT 3589 #ifdef FEAT_STL_OPT
3592 if (stl_syntax & STL_IN_TITLE) 3590 if (stl_syntax & STL_IN_TITLE)
3593 { 3591 {
3596 3594
3597 # ifdef FEAT_EVAL 3595 # ifdef FEAT_EVAL
3598 use_sandbox = was_set_insecurely((char_u *)"titlestring", 0); 3596 use_sandbox = was_set_insecurely((char_u *)"titlestring", 0);
3599 # endif 3597 # endif
3600 called_emsg = FALSE; 3598 called_emsg = FALSE;
3601 build_stl_str_hl(curwin, t_str, sizeof(buf), 3599 build_stl_str_hl(curwin, title_str, sizeof(buf),
3602 p_titlestring, use_sandbox, 3600 p_titlestring, use_sandbox,
3603 0, maxlen, NULL, NULL); 3601 0, maxlen, NULL, NULL);
3604 if (called_emsg) 3602 if (called_emsg)
3605 set_string_option_direct((char_u *)"titlestring", -1, 3603 set_string_option_direct((char_u *)"titlestring", -1,
3606 (char_u *)"", OPT_FREE, SID_ERROR); 3604 (char_u *)"", OPT_FREE, SID_ERROR);
3607 called_emsg |= save_called_emsg; 3605 called_emsg |= save_called_emsg;
3608 } 3606 }
3609 else 3607 else
3610 #endif 3608 #endif
3611 t_str = p_titlestring; 3609 title_str = p_titlestring;
3612 } 3610 }
3613 else 3611 else
3614 { 3612 {
3615 /* format: "fname + (path) (1 of 2) - VIM" */ 3613 /* format: "fname + (path) (1 of 2) - VIM" */
3616 3614
3712 if (vim_strsize(buf) > maxlen) 3710 if (vim_strsize(buf) > maxlen)
3713 trunc_string(buf, buf, maxlen, IOSIZE); 3711 trunc_string(buf, buf, maxlen, IOSIZE);
3714 } 3712 }
3715 } 3713 }
3716 } 3714 }
3717 mustset = ti_change(t_str, &lasttitle); 3715 mustset = value_changed(title_str, &lasttitle);
3718 3716
3719 if (p_icon) 3717 if (p_icon)
3720 { 3718 {
3721 i_str = buf; 3719 icon_str = buf;
3722 if (*p_iconstring != NUL) 3720 if (*p_iconstring != NUL)
3723 { 3721 {
3724 #ifdef FEAT_STL_OPT 3722 #ifdef FEAT_STL_OPT
3725 if (stl_syntax & STL_IN_ICON) 3723 if (stl_syntax & STL_IN_ICON)
3726 { 3724 {
3729 3727
3730 # ifdef FEAT_EVAL 3728 # ifdef FEAT_EVAL
3731 use_sandbox = was_set_insecurely((char_u *)"iconstring", 0); 3729 use_sandbox = was_set_insecurely((char_u *)"iconstring", 0);
3732 # endif 3730 # endif
3733 called_emsg = FALSE; 3731 called_emsg = FALSE;
3734 build_stl_str_hl(curwin, i_str, sizeof(buf), 3732 build_stl_str_hl(curwin, icon_str, sizeof(buf),
3735 p_iconstring, use_sandbox, 3733 p_iconstring, use_sandbox,
3736 0, 0, NULL, NULL); 3734 0, 0, NULL, NULL);
3737 if (called_emsg) 3735 if (called_emsg)
3738 set_string_option_direct((char_u *)"iconstring", -1, 3736 set_string_option_direct((char_u *)"iconstring", -1,
3739 (char_u *)"", OPT_FREE, SID_ERROR); 3737 (char_u *)"", OPT_FREE, SID_ERROR);
3740 called_emsg |= save_called_emsg; 3738 called_emsg |= save_called_emsg;
3741 } 3739 }
3742 else 3740 else
3743 #endif 3741 #endif
3744 i_str = p_iconstring; 3742 icon_str = p_iconstring;
3745 } 3743 }
3746 else 3744 else
3747 { 3745 {
3748 if (buf_spname(curbuf) != NULL) 3746 if (buf_spname(curbuf) != NULL)
3749 i_name = buf_spname(curbuf); 3747 p = buf_spname(curbuf);
3750 else /* use file name only in icon */ 3748 else /* use file name only in icon */
3751 i_name = gettail(curbuf->b_ffname); 3749 p = gettail(curbuf->b_ffname);
3752 *i_str = NUL; 3750 *icon_str = NUL;
3753 /* Truncate name at 100 bytes. */ 3751 /* Truncate name at 100 bytes. */
3754 len = (int)STRLEN(i_name); 3752 len = (int)STRLEN(p);
3755 if (len > 100) 3753 if (len > 100)
3756 { 3754 {
3757 len -= 100; 3755 len -= 100;
3758 #ifdef FEAT_MBYTE 3756 #ifdef FEAT_MBYTE
3759 if (has_mbyte) 3757 if (has_mbyte)
3760 len += (*mb_tail_off)(i_name, i_name + len) + 1; 3758 len += (*mb_tail_off)(p, p + len) + 1;
3761 #endif 3759 #endif
3762 i_name += len; 3760 p += len;
3763 } 3761 }
3764 STRCPY(i_str, i_name); 3762 STRCPY(icon_str, p);
3765 trans_characters(i_str, IOSIZE); 3763 trans_characters(icon_str, IOSIZE);
3766 } 3764 }
3767 } 3765 }
3768 3766
3769 mustset |= ti_change(i_str, &lasticon); 3767 mustset |= value_changed(icon_str, &lasticon);
3770 3768
3771 if (mustset) 3769 if (mustset)
3772 resettitle(); 3770 resettitle();
3773 } 3771 }
3774 3772
3775 /* 3773 /*
3776 * Used for title and icon: Check if "str" differs from "*last". Set "*last" 3774 * Used for title and icon: Check if "str" differs from "*last". Set "*last"
3777 * from "str" if it does. 3775 * from "str" if it does.
3778 * Return TRUE when "*last" changed. 3776 * Return TRUE if resettitle() is to be called.
3779 */ 3777 */
3780 static int 3778 static int
3781 ti_change(char_u *str, char_u **last) 3779 value_changed(char_u *str, char_u **last)
3782 { 3780 {
3783 if ((str == NULL) != (*last == NULL) 3781 if ((str == NULL) != (*last == NULL)
3784 || (str != NULL && *last != NULL && STRCMP(str, *last) != 0)) 3782 || (str != NULL && *last != NULL && STRCMP(str, *last) != 0))
3785 { 3783 {
3786 vim_free(*last); 3784 vim_free(*last);
3787 if (str == NULL) 3785 if (str == NULL)
3786 {
3788 *last = NULL; 3787 *last = NULL;
3788 mch_restore_title(last == &lasttitle ? 1 : 2);
3789 }
3789 else 3790 else
3791 {
3790 *last = vim_strsave(str); 3792 *last = vim_strsave(str);
3791 return TRUE; 3793 return TRUE;
3794 }
3792 } 3795 }
3793 return FALSE; 3796 return FALSE;
3794 } 3797 }
3795 3798
3796 /* 3799 /*