Skip to content

Commit

Permalink
patch 8.2.3699: the +title feature adds a lot of #ifdef but little code
Browse files Browse the repository at this point in the history
Problem:    The +title feature adds a lot of #ifdef but little code.
Solution:   Graduate the +title feature.
  • Loading branch information
brammool committed Nov 29, 2021
1 parent 0c359af commit 651fca8
Show file tree
Hide file tree
Showing 34 changed files with 56 additions and 244 deletions.
12 changes: 0 additions & 12 deletions runtime/doc/options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4190,8 +4190,6 @@ A jump table for the options with a short description can be found at |Q_op|.
*'icon'* *'noicon'*
'icon' boolean (default off, on when title can be restored)
global
{not available when compiled without the |+title|
feature}
When on, the icon text of the window will be set to the value of
'iconstring' (if it is not empty), or to the name of the file
currently being edited. Only the last part of the name is used.
Expand All @@ -4208,8 +4206,6 @@ A jump table for the options with a short description can be found at |Q_op|.
*'iconstring'*
'iconstring' string (default "")
global
{not available when compiled without the |+title|
feature}
When this option is not empty, it will be used for the icon text of
the window. This happens only when the 'icon' option is on.
Only works if the terminal supports setting window icon text
Expand Down Expand Up @@ -8141,8 +8137,6 @@ A jump table for the options with a short description can be found at |Q_op|.
*'title'* *'notitle'*
'title' boolean (default off, on when title can be restored)
global
{not available when compiled without the |+title|
feature}
When on, the title of the window will be set to the value of
'titlestring' (if it is not empty), or to:
filename [+=-] (path) - VIM
Expand Down Expand Up @@ -8176,8 +8170,6 @@ A jump table for the options with a short description can be found at |Q_op|.
*'titlelen'*
'titlelen' number (default 85)
global
{not available when compiled without the |+title|
feature}
Gives the percentage of 'columns' to use for the length of the window
title. When the title is longer, only the end of the path name is
shown. A '<' character before the path name is used to indicate this.
Expand All @@ -8191,8 +8183,6 @@ A jump table for the options with a short description can be found at |Q_op|.
*'titleold'*
'titleold' string (default "Thanks for flying Vim")
global
{only available when compiled with the |+title|
feature}
This option will be used for the window title when exiting Vim if the
original title cannot be restored. Only happens if 'title' is on or
'titlestring' is not empty.
Expand All @@ -8201,8 +8191,6 @@ A jump table for the options with a short description can be found at |Q_op|.
*'titlestring'*
'titlestring' string (default "")
global
{not available when compiled without the |+title|
feature}
When this option is not empty, it will be used for the title of the
window. This happens only when the 'title' option is on.
Only works if the terminal supports setting window titles (currently
Expand Down
2 changes: 1 addition & 1 deletion runtime/doc/various.txt
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ N *+textobjects* |text-objects| selection
N *+textprop* |text-properties|
*+tgetent* non-Unix only: able to use external termcap
N *+timers* the |timer_start()| function
N *+title* Setting the window 'title' and 'icon'
N *+title* Setting the window 'title' and 'icon'; Always enabled
N *+toolbar* |gui-toolbar|
T *+user_commands* User-defined commands. |user-commands|
Always enabled since 8.1.1210.
Expand Down
2 changes: 0 additions & 2 deletions src/alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -421,9 +421,7 @@ free_all_mem(void)
# endif
}

# ifdef FEAT_TITLE
free_titles();
# endif
# if defined(FEAT_SEARCHPATH)
free_findfile();
# endif
Expand Down
6 changes: 0 additions & 6 deletions src/arglist.c
Original file line number Diff line number Diff line change
Expand Up @@ -770,9 +770,7 @@ ex_argedit(exarg_T *eap)

if (do_arglist(eap->arg, AL_ADD, i, TRUE) == FAIL)
return;
#ifdef FEAT_TITLE
maketitle();
#endif

if (curwin->w_arg_idx == 0
&& (curbuf->b_ml.ml_flags & ML_EMPTY)
Expand All @@ -792,9 +790,7 @@ ex_argadd(exarg_T *eap)
do_arglist(eap->arg, AL_ADD,
eap->addr_count > 0 ? (int)eap->line2 : curwin->w_arg_idx + 1,
FALSE);
#ifdef FEAT_TITLE
maketitle();
#endif
}

/*
Expand Down Expand Up @@ -853,9 +849,7 @@ ex_argdelete(exarg_T *eap)
}
else
do_arglist(eap->arg, AL_DEL, 0, FALSE);
#ifdef FEAT_TITLE
maketitle();
#endif
}

/*
Expand Down
2 changes: 0 additions & 2 deletions src/autocmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -2253,10 +2253,8 @@ apply_autocmds_group(
|| event == EVENT_VIMLEAVE
|| event == EVENT_VIMLEAVEPRE))
{
#ifdef FEAT_TITLE
if (curbuf->b_changed != save_changed)
need_maketitle = TRUE;
#endif
curbuf->b_changed = save_changed;
}

Expand Down
8 changes: 0 additions & 8 deletions src/buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ static int buf_same_ino(buf_T *buf, stat_T *stp);
#else
static int otherfile_buf(buf_T *buf, char_u *ffname);
#endif
#ifdef FEAT_TITLE
static int value_changed(char_u *str, char_u **last);
#endif
static int append_arg_number(win_T *wp, char_u *buf, int buflen, int add_file);
static void free_buffer(buf_T *);
static void free_buffer_stuff(buf_T *buf, int free_options);
Expand Down Expand Up @@ -1856,9 +1854,7 @@ enter_buffer(buf_T *buf)
buflist_getfpos();

check_arg_idx(curwin); // check for valid arg_idx
#ifdef FEAT_TITLE
maketitle();
#endif
// when autocmds didn't change it
if (curwin->w_topline == 1 && !curwin->w_topline_was_set)
scroll_cursor_halfway(FALSE); // redisplay at correct position
Expand Down Expand Up @@ -3461,9 +3457,7 @@ buf_name_changed(buf_T *buf)

if (curwin->w_buffer == buf)
check_arg_idx(curwin); // check file name for arg list
#ifdef FEAT_TITLE
maketitle(); // set window title
#endif
status_redraw_all(); // status lines need to be redrawn
fmarks_check_names(buf); // check named file marks
ml_timestamp(buf); // reset timestamp
Expand Down Expand Up @@ -3780,7 +3774,6 @@ col_print(
vim_snprintf((char *)buf, buflen, "%d-%d", col, vcol);
}

#if defined(FEAT_TITLE) || defined(PROTO)
static char_u *lasttitle = NULL;
static char_u *lasticon = NULL;

Expand Down Expand Up @@ -4045,7 +4038,6 @@ free_titles(void)
}
# endif

#endif // FEAT_TITLE

#if defined(FEAT_STL_OPT) || defined(FEAT_GUI_TABLINE) || defined(PROTO)

Expand Down
2 changes: 0 additions & 2 deletions src/bufwrite.c
Original file line number Diff line number Diff line change
Expand Up @@ -1630,9 +1630,7 @@ buf_write(
if (forceit && overwriting && vim_strchr(p_cpo, CPO_KEEPRO) == NULL)
{
buf->b_p_ro = FALSE;
#ifdef FEAT_TITLE
need_maketitle = TRUE; // set window title later
#endif
status_redraw_all(); // redraw status lines later
}

Expand Down
4 changes: 0 additions & 4 deletions src/change.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,7 @@ changed_internal(void)
ml_setflags(curbuf);
check_status(curbuf);
redraw_tabline = TRUE;
#ifdef FEAT_TITLE
need_maketitle = TRUE; // set window title later
#endif
}

#ifdef FEAT_EVAL
Expand Down Expand Up @@ -892,9 +890,7 @@ unchanged(buf_T *buf, int ff, int always_inc_changedtick)
save_file_ff(buf);
check_status(buf);
redraw_tabline = TRUE;
#ifdef FEAT_TITLE
need_maketitle = TRUE; // set window title later
#endif
++CHANGEDTICK(buf);
}
else if (always_inc_changedtick)
Expand Down
7 changes: 3 additions & 4 deletions src/drawscreen.c
Original file line number Diff line number Diff line change
Expand Up @@ -610,15 +610,14 @@ showruler(int always)
win_redr_ruler(curwin, always, FALSE);
#endif

#ifdef FEAT_TITLE
if (need_maketitle
# ifdef FEAT_STL_OPT
#ifdef FEAT_STL_OPT
|| (p_icon && (stl_syntax & STL_IN_ICON))
|| (p_title && (stl_syntax & STL_IN_TITLE))
# endif
#endif
)
maketitle();
#endif

// Redraw the tab pages line if needed.
if (redraw_tabline)
draw_tabline();
Expand Down
8 changes: 1 addition & 7 deletions src/evalfunc.c
Original file line number Diff line number Diff line change
Expand Up @@ -5787,13 +5787,7 @@ f_has(typval_T *argvars, typval_T *rettv)
0
#endif
},
{"title",
#ifdef FEAT_TITLE
1
#else
0
#endif
},
{"title", 1},
{"toolbar",
#ifdef FEAT_TOOLBAR
1
Expand Down
2 changes: 0 additions & 2 deletions src/ex_cmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -3082,9 +3082,7 @@ do_ecmd(
// Even when cursor didn't move we need to recompute topline.
changed_line_abv_curs();

#ifdef FEAT_TITLE
maketitle();
#endif
#if defined(FEAT_PROP_POPUP) && defined(FEAT_QUICKFIX)
if (WIN_IS_POPUP(curwin) && curwin->w_p_pvw && retval != FAIL)
popup_set_title(curwin);
Expand Down
10 changes: 0 additions & 10 deletions src/ex_docmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -6205,14 +6205,10 @@ ex_stop(exarg_T *eap)
out_flush();
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
maketitle();
resettitle(); // force updating the title
#endif
starttermcap();
scroll_start(); // scroll screen before redrawing
redraw_later_clear();
Expand Down Expand Up @@ -7047,14 +7043,10 @@ do_exedit(
{
if (eap->do_ecmd_cmd != NULL)
do_cmd_argument(eap->do_ecmd_cmd);
#ifdef FEAT_TITLE
n = curwin->w_arg_idx_invalid;
#endif
check_arg_idx(curwin);
#ifdef FEAT_TITLE
if (n != curwin->w_arg_idx_invalid)
maketitle();
#endif
}

/*
Expand Down Expand Up @@ -8178,10 +8170,8 @@ ex_redraw(exarg_T *eap)
validate_cursor();
update_topline();
update_screen(eap->forceit ? CLEAR : VIsual_active ? INVERTED : 0);
#ifdef FEAT_TITLE
if (need_maketitle)
maketitle();
#endif
#if defined(MSWIN) && (!defined(FEAT_GUI_MSWIN) || defined(VIMDLL))
# ifdef VIMDLL
if (!gui.in_use)
Expand Down
14 changes: 6 additions & 8 deletions src/feature.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
* +insert_expand CTRL-N/CTRL-P/CTRL-X in insert mode.
* +modify_fname modifiers for file name. E.g., "%:p:h".
* +comments 'comments' option.
* +title 'title' and 'icon' options
*
* Obsolete:
* +tag_old_static Old style static tags: "file:tag file ..".
Expand Down Expand Up @@ -360,24 +361,21 @@
#endif

/*
* +title 'title' and 'icon' options
* +statusline 'statusline', 'rulerformat' and special format of
* 'titlestring' and 'iconstring' options.
* +byte_offset '%o' in 'statusline' and builtin functions line2byte()
* and byte2line().
* Note: Required for Macintosh.
*/
#if defined(FEAT_NORMAL)
# define FEAT_TITLE
#endif

#ifdef FEAT_NORMAL
# define FEAT_STL_OPT
# ifndef FEAT_CMDL_INFO
# define FEAT_CMDL_INFO // 'ruler' is required for 'statusline'
# endif
#endif

/*
* +byte_offset '%o' in 'statusline' and builtin functions line2byte()
* and byte2line().
* Note: Required for Macintosh.
*/
#ifdef FEAT_NORMAL
# define FEAT_BYTEOFF
#endif
Expand Down
15 changes: 11 additions & 4 deletions src/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,7 @@ EXTERN int no_wait_return INIT(= 0); // don't wait for return for now
EXTERN int need_wait_return INIT(= 0); // need to wait for return later
EXTERN int did_wait_return INIT(= FALSE); // wait_return() was used and
// nothing written since then
#ifdef FEAT_TITLE
EXTERN int need_maketitle INIT(= TRUE); // call maketitle() soon
#endif

EXTERN int quit_more INIT(= FALSE); // 'q' hit at "--more--" msg
#if defined(UNIX) || defined(VMS) || defined(MACOS_X)
Expand Down Expand Up @@ -1037,17 +1035,26 @@ EXTERN vimconv_T output_conv; // type of output conversion
*/
// length of char in bytes, including following composing chars
EXTERN int (*mb_ptr2len)(char_u *p) INIT(= latin_ptr2len);

// idem, with limit on string length
EXTERN int (*mb_ptr2len_len)(char_u *p, int size) INIT(= latin_ptr2len_len);

// byte length of char
EXTERN int (*mb_char2len)(int c) INIT(= latin_char2len);
// convert char to bytes, return the length

// Convert char "c" to bytes in "buf", return the length. "buf" must have room
// for at least 6 bytes.
EXTERN int (*mb_char2bytes)(int c, char_u *buf) INIT(= latin_char2bytes);

EXTERN int (*mb_ptr2cells)(char_u *p) INIT(= latin_ptr2cells);
EXTERN int (*mb_ptr2cells_len)(char_u *p, int size) INIT(= latin_ptr2cells_len);
EXTERN int (*mb_char2cells)(int c) INIT(= latin_char2cells);
EXTERN int (*mb_off2cells)(unsigned off, unsigned max_off) INIT(= latin_off2cells);
EXTERN int (*mb_ptr2char)(char_u *p) INIT(= latin_ptr2char);

// Byte offset from "p" to the start of a character, including any composing
// characters. "base" must be the start of the string, which must be NUL
// terminated.
EXTERN int (*mb_head_off)(char_u *base, char_u *p) INIT(= latin_head_off);

# if defined(USE_ICONV) && defined(DYNAMIC_ICONV)
Expand Down Expand Up @@ -1402,7 +1409,7 @@ EXTERN struct subs_expr_S *substitute_instr INIT(= NULL);
// table to store parsed 'wildmode'
EXTERN char_u wim_flags[4];

#if defined(FEAT_TITLE) && defined(FEAT_STL_OPT)
#if defined(FEAT_STL_OPT)
// whether titlestring and iconstring contains statusline syntax
# define STL_IN_ICON 1
# define STL_IN_TITLE 2
Expand Down
Loading

0 comments on commit 651fca8

Please sign in to comment.