0
0
mirror of https://github.com/vim/vim.git synced 2025-09-27 04:14:06 -04:00

patch 9.0.1245: code is indented more than necessary

Problem:    Code is indented more than necessary.
Solution:   Use an early return where it makes sense. (Yegappan Lakshmanan,
            closes #11879)
This commit is contained in:
Yegappan Lakshmanan
2023-01-25 21:05:38 +00:00
committed by Bram Moolenaar
parent 0f843ef091
commit 032713f829
9 changed files with 965 additions and 959 deletions

262
src/tag.c
View File

@@ -3263,16 +3263,16 @@ static garray_T tag_fnames = GA_EMPTY;
static void static void
found_tagfile_cb(char_u *fname, void *cookie UNUSED) found_tagfile_cb(char_u *fname, void *cookie UNUSED)
{ {
if (ga_grow(&tag_fnames, 1) == OK) if (ga_grow(&tag_fnames, 1) == FAIL)
{ return;
char_u *tag_fname = vim_strsave(fname);
char_u *tag_fname = vim_strsave(fname);
#ifdef BACKSLASH_IN_FILENAME #ifdef BACKSLASH_IN_FILENAME
slash_adjust(tag_fname); slash_adjust(tag_fname);
#endif #endif
simplify_filename(tag_fname); simplify_filename(tag_fname);
((char_u **)(tag_fnames.ga_data))[tag_fnames.ga_len++] = tag_fname; ((char_u **)(tag_fnames.ga_data))[tag_fnames.ga_len++] = tag_fname;
}
} }
#if defined(EXITFREE) || defined(PROTO) #if defined(EXITFREE) || defined(PROTO)
@@ -3587,54 +3587,54 @@ parse_match(
tagp->tagline = 0; tagp->tagline = 0;
tagp->command_end = NULL; tagp->command_end = NULL;
if (retval == OK) if (retval != OK)
return retval;
// Try to find a kind field: "kind:<kind>" or just "<kind>"
p = tagp->command;
if (find_extra(&p) == OK)
{ {
// Try to find a kind field: "kind:<kind>" or just "<kind>" if (p > tagp->command && p[-1] == '|')
p = tagp->command; tagp->command_end = p - 1; // drop trailing bar
if (find_extra(&p) == OK) else
{ tagp->command_end = p;
if (p > tagp->command && p[-1] == '|') p += 2; // skip ";\""
tagp->command_end = p - 1; // drop trailing bar if (*p++ == TAB)
else // Accept ASCII alphabetic kind characters and any multi-byte
tagp->command_end = p; // character.
p += 2; // skip ";\"" while (ASCII_ISALPHA(*p) || mb_ptr2len(p) > 1)
if (*p++ == TAB) {
// Accept ASCII alphabetic kind characters and any multi-byte if (STRNCMP(p, "kind:", 5) == 0)
// character. tagp->tagkind = p + 5;
while (ASCII_ISALPHA(*p) || mb_ptr2len(p) > 1) else if (STRNCMP(p, "user_data:", 10) == 0)
{ tagp->user_data = p + 10;
if (STRNCMP(p, "kind:", 5) == 0) else if (STRNCMP(p, "line:", 5) == 0)
tagp->tagkind = p + 5; tagp->tagline = atoi((char *)p + 5);
else if (STRNCMP(p, "user_data:", 10) == 0) if (tagp->tagkind != NULL && tagp->user_data != NULL)
tagp->user_data = p + 10; break;
else if (STRNCMP(p, "line:", 5) == 0) pc = vim_strchr(p, ':');
tagp->tagline = atoi((char *)p + 5); pt = vim_strchr(p, '\t');
if (tagp->tagkind != NULL && tagp->user_data != NULL) if (pc == NULL || (pt != NULL && pc > pt))
break; tagp->tagkind = p;
pc = vim_strchr(p, ':'); if (pt == NULL)
pt = vim_strchr(p, '\t'); break;
if (pc == NULL || (pt != NULL && pc > pt)) p = pt;
tagp->tagkind = p; MB_PTR_ADV(p);
if (pt == NULL) }
break; }
p = pt; if (tagp->tagkind != NULL)
MB_PTR_ADV(p); {
} for (p = tagp->tagkind;
} *p && *p != '\t' && *p != '\r' && *p != '\n'; MB_PTR_ADV(p))
if (tagp->tagkind != NULL) ;
{ tagp->tagkind_end = p;
for (p = tagp->tagkind; }
*p && *p != '\t' && *p != '\r' && *p != '\n'; MB_PTR_ADV(p)) if (tagp->user_data != NULL)
; {
tagp->tagkind_end = p; for (p = tagp->user_data;
} *p && *p != '\t' && *p != '\r' && *p != '\n'; MB_PTR_ADV(p))
if (tagp->user_data != NULL) ;
{ tagp->user_data_end = p;
for (p = tagp->user_data;
*p && *p != '\t' && *p != '\r' && *p != '\n'; MB_PTR_ADV(p))
;
tagp->user_data_end = p;
}
} }
return retval; return retval;
} }
@@ -4372,94 +4372,94 @@ get_tags(list_T *list, char_u *pat, char_u *buf_fname)
ret = find_tags(pat, &num_matches, &matches, ret = find_tags(pat, &num_matches, &matches,
TAG_REGEXP | TAG_NOIC, (int)MAXCOL, buf_fname); TAG_REGEXP | TAG_NOIC, (int)MAXCOL, buf_fname);
if (ret == OK && num_matches > 0) if (ret != OK || num_matches <= 0)
return ret;
for (i = 0; i < num_matches; ++i)
{ {
for (i = 0; i < num_matches; ++i) if (parse_match(matches[i], &tp) == FAIL)
{ {
if (parse_match(matches[i], &tp) == FAIL) vim_free(matches[i]);
continue;
}
is_static = test_for_static(&tp);
// Skip pseudo-tag lines.
if (STRNCMP(tp.tagname, "!_TAG_", 6) == 0)
{
vim_free(matches[i]);
continue;
}
if ((dict = dict_alloc()) == NULL)
{
ret = FAIL;
vim_free(matches[i]);
break;
}
if (list_append_dict(list, dict) == FAIL)
ret = FAIL;
full_fname = tag_full_fname(&tp);
if (add_tag_field(dict, "name", tp.tagname, tp.tagname_end) == FAIL
|| add_tag_field(dict, "filename", full_fname,
NULL) == FAIL
|| add_tag_field(dict, "cmd", tp.command,
tp.command_end) == FAIL
|| add_tag_field(dict, "kind", tp.tagkind,
tp.tagkind_end) == FAIL
|| dict_add_number(dict, "static", is_static) == FAIL)
ret = FAIL;
vim_free(full_fname);
if (tp.command_end != NULL)
{
for (p = tp.command_end + 3;
*p != NUL && *p != '\n' && *p != '\r'; MB_PTR_ADV(p))
{ {
vim_free(matches[i]); if (p == tp.tagkind || (p + 5 == tp.tagkind
continue; && STRNCMP(p, "kind:", 5) == 0))
} // skip "kind:<kind>" and "<kind>"
p = tp.tagkind_end - 1;
is_static = test_for_static(&tp); else if (STRNCMP(p, "file:", 5) == 0)
// skip "file:" (static tag)
// Skip pseudo-tag lines. p += 4;
if (STRNCMP(tp.tagname, "!_TAG_", 6) == 0) else if (!VIM_ISWHITE(*p))
{
vim_free(matches[i]);
continue;
}
if ((dict = dict_alloc()) == NULL)
{
ret = FAIL;
vim_free(matches[i]);
break;
}
if (list_append_dict(list, dict) == FAIL)
ret = FAIL;
full_fname = tag_full_fname(&tp);
if (add_tag_field(dict, "name", tp.tagname, tp.tagname_end) == FAIL
|| add_tag_field(dict, "filename", full_fname,
NULL) == FAIL
|| add_tag_field(dict, "cmd", tp.command,
tp.command_end) == FAIL
|| add_tag_field(dict, "kind", tp.tagkind,
tp.tagkind_end) == FAIL
|| dict_add_number(dict, "static", is_static) == FAIL)
ret = FAIL;
vim_free(full_fname);
if (tp.command_end != NULL)
{
for (p = tp.command_end + 3;
*p != NUL && *p != '\n' && *p != '\r'; MB_PTR_ADV(p))
{ {
if (p == tp.tagkind || (p + 5 == tp.tagkind char_u *s, *n;
&& STRNCMP(p, "kind:", 5) == 0)) int len;
// skip "kind:<kind>" and "<kind>"
p = tp.tagkind_end - 1;
else if (STRNCMP(p, "file:", 5) == 0)
// skip "file:" (static tag)
p += 4;
else if (!VIM_ISWHITE(*p))
{
char_u *s, *n;
int len;
// Add extra field as a dict entry. Fields are // Add extra field as a dict entry. Fields are
// separated by Tabs. // separated by Tabs.
n = p; n = p;
while (*p != NUL && *p >= ' ' && *p < 127 && *p != ':') while (*p != NUL && *p >= ' ' && *p < 127 && *p != ':')
++p;
len = (int)(p - n);
if (*p == ':' && len > 0)
{
s = ++p;
while (*p != NUL && *p >= ' ')
++p; ++p;
len = (int)(p - n); n[len] = NUL;
if (*p == ':' && len > 0) if (add_tag_field(dict, (char *)n, s, p) == FAIL)
{ ret = FAIL;
s = ++p; n[len] = ':';
while (*p != NUL && *p >= ' ')
++p;
n[len] = NUL;
if (add_tag_field(dict, (char *)n, s, p) == FAIL)
ret = FAIL;
n[len] = ':';
}
else
// Skip field without colon.
while (*p != NUL && *p >= ' ')
++p;
if (*p == NUL)
break;
} }
else
// Skip field without colon.
while (*p != NUL && *p >= ' ')
++p;
if (*p == NUL)
break;
} }
} }
vim_free(matches[i]);
} }
vim_free(matches);
vim_free(matches[i]);
} }
vim_free(matches);
return ret; return ret;
} }

View File

@@ -1644,24 +1644,24 @@ set_color_count(int nr)
static void static void
may_adjust_color_count(int val) may_adjust_color_count(int val)
{ {
if (val != t_colors) if (val == t_colors)
{ return;
// Nr of colors changed, initialize highlighting and redraw everything.
// This causes a redraw, which usually clears the message. Try keeping
// the message if it might work.
set_keep_msg_from_hist();
set_color_count(val);
init_highlight(TRUE, FALSE);
#ifdef DEBUG_TERMRESPONSE
{
int r = redraw_asap(UPD_CLEAR);
log_tr("Received t_Co, redraw_asap(): %d", r); // Nr of colors changed, initialize highlighting and redraw everything.
} // This causes a redraw, which usually clears the message. Try keeping
#else // the message if it might work.
redraw_asap(UPD_CLEAR); set_keep_msg_from_hist();
#endif set_color_count(val);
init_highlight(TRUE, FALSE);
#ifdef DEBUG_TERMRESPONSE
{
int r = redraw_asap(UPD_CLEAR);
log_tr("Received t_Co, redraw_asap(): %d", r);
} }
#else
redraw_asap(UPD_CLEAR);
#endif
} }
#ifdef HAVE_TGETENT #ifdef HAVE_TGETENT
@@ -2419,13 +2419,14 @@ getlinecol(
{ {
char_u tbuf[TBUFSZ]; char_u tbuf[TBUFSZ];
if (T_NAME != NULL && *T_NAME != NUL && invoke_tgetent(tbuf, T_NAME) == NULL) if (T_NAME == NULL || *T_NAME == NUL
{ || invoke_tgetent(tbuf, T_NAME) != NULL)
if (*cp == 0) return;
*cp = tgetnum("co");
if (*rp == 0) if (*cp == 0)
*rp = tgetnum("li"); *cp = tgetnum("co");
} if (*rp == 0)
*rp = tgetnum("li");
} }
#endif // defined(HAVE_TGETENT) && defined(UNIX) #endif // defined(HAVE_TGETENT) && defined(UNIX)
@@ -2569,15 +2570,15 @@ term_is_8bit(char_u *name)
static int static int
term_7to8bit(char_u *p) term_7to8bit(char_u *p)
{ {
if (*p == ESC) if (*p != ESC)
{ return 0;
if (p[1] == '[')
return CSI; if (p[1] == '[')
if (p[1] == ']') return CSI;
return OSC; else if (p[1] == ']')
if (p[1] == 'O') return OSC;
return 0x8f; else if (p[1] == 'O')
} return 0x8f;
return 0; return 0;
} }
@@ -2712,27 +2713,27 @@ out_flush(void)
{ {
int len; int len;
if (out_pos != 0) if (out_pos == 0)
{ return;
// set out_pos to 0 before ui_write, to avoid recursiveness
len = out_pos; // set out_pos to 0 before ui_write, to avoid recursiveness
out_pos = 0; len = out_pos;
ui_write(out_buf, len, FALSE); out_pos = 0;
ui_write(out_buf, len, FALSE);
#ifdef FEAT_EVAL #ifdef FEAT_EVAL
if (ch_log_output != FALSE) if (ch_log_output != FALSE)
{ {
out_buf[len] = NUL; out_buf[len] = NUL;
ch_log(NULL, "raw %s output: \"%s\"", ch_log(NULL, "raw %s output: \"%s\"",
# ifdef FEAT_GUI # ifdef FEAT_GUI
(gui.in_use && !gui.dying && !gui.starting) ? "GUI" : (gui.in_use && !gui.dying && !gui.starting) ? "GUI" :
# endif # endif
"terminal", "terminal",
out_buf); out_buf);
if (ch_log_output == TRUE) if (ch_log_output == TRUE)
ch_log_output = FALSE; // only log once ch_log_output = FALSE; // only log once
}
#endif
} }
#endif
} }
/* /*
@@ -2846,66 +2847,66 @@ out_str_nf(char_u *s)
void void
out_str_cf(char_u *s) out_str_cf(char_u *s)
{ {
if (s != NULL && *s) if (s == NULL || *s == NUL)
{ return;
#ifdef HAVE_TGETENT #ifdef HAVE_TGETENT
char_u *p; char_u *p;
#endif #endif
#ifdef FEAT_GUI #ifdef FEAT_GUI
// Don't use tputs() when GUI is used, ncurses crashes. // Don't use tputs() when GUI is used, ncurses crashes.
if (gui.in_use) if (gui.in_use)
{ {
out_str_nf(s); out_str_nf(s);
return; return;
}
#endif
if (out_pos > OUT_SIZE - MAX_ESC_SEQ_LEN)
out_flush();
#ifdef HAVE_TGETENT
for (p = s; *s; ++s)
{
// flush just before delay command
if (*s == '$' && *(s + 1) == '<')
{
char_u save_c = *s;
int duration = atoi((char *)s + 2);
*s = NUL;
tputs((char *)p, 1, TPUTSFUNCAST out_char_nf);
*s = save_c;
out_flush();
# ifdef ELAPSED_FUNC
// Only sleep here if we can limit this happening in
// vim_beep().
p = vim_strchr(s, '>');
if (p == NULL || duration <= 0)
{
// can't parse the time, don't sleep here
p = s;
}
else
{
++p;
do_sleep(duration, FALSE);
}
# else
// Rely on the terminal library to sleep.
p = s;
# endif
break;
}
}
tputs((char *)p, 1, TPUTSFUNCAST out_char_nf);
#else
while (*s)
out_char_nf(*s++);
#endif
// For testing we write one string at a time.
if (p_wd)
out_flush();
} }
#endif
if (out_pos > OUT_SIZE - MAX_ESC_SEQ_LEN)
out_flush();
#ifdef HAVE_TGETENT
for (p = s; *s; ++s)
{
// flush just before delay command
if (*s == '$' && *(s + 1) == '<')
{
char_u save_c = *s;
int duration = atoi((char *)s + 2);
*s = NUL;
tputs((char *)p, 1, TPUTSFUNCAST out_char_nf);
*s = save_c;
out_flush();
# ifdef ELAPSED_FUNC
// Only sleep here if we can limit this happening in
// vim_beep().
p = vim_strchr(s, '>');
if (p == NULL || duration <= 0)
{
// can't parse the time, don't sleep here
p = s;
}
else
{
++p;
do_sleep(duration, FALSE);
}
# else
// Rely on the terminal library to sleep.
p = s;
# endif
break;
}
}
tputs((char *)p, 1, TPUTSFUNCAST out_char_nf);
#else
while (*s)
out_char_nf(*s++);
#endif
// For testing we write one string at a time.
if (p_wd)
out_flush();
} }
/* /*
@@ -2917,30 +2918,30 @@ out_str_cf(char_u *s)
void void
out_str(char_u *s) out_str(char_u *s)
{ {
if (s != NULL && *s) if (s == NULL || *s == NUL)
{ return;
#ifdef FEAT_GUI #ifdef FEAT_GUI
// Don't use tputs() when GUI is used, ncurses crashes. // Don't use tputs() when GUI is used, ncurses crashes.
if (gui.in_use) if (gui.in_use)
{ {
out_str_nf(s); out_str_nf(s);
return; return;
} }
#endif #endif
// avoid terminal strings being split up // avoid terminal strings being split up
if (out_pos > OUT_SIZE - MAX_ESC_SEQ_LEN) if (out_pos > OUT_SIZE - MAX_ESC_SEQ_LEN)
out_flush(); out_flush();
#ifdef HAVE_TGETENT #ifdef HAVE_TGETENT
tputs((char *)s, 1, TPUTSFUNCAST out_char_nf); tputs((char *)s, 1, TPUTSFUNCAST out_char_nf);
#else #else
while (*s) while (*s)
out_char_nf(*s++); out_char_nf(*s++);
#endif #endif
// For testing we write one string at a time. // For testing we write one string at a time.
if (p_wd) if (p_wd)
out_flush(); out_flush();
}
} }
/* /*
@@ -3468,13 +3469,12 @@ get_long_from_buf(char_u *buf, long_u *val)
*val = 0; *val = 0;
len = get_bytes_from_buf(buf, bytes, (int)sizeof(long_u)); len = get_bytes_from_buf(buf, bytes, (int)sizeof(long_u));
if (len != -1) if (len == -1)
return -1;
for (i = 0; i < (int)sizeof(long_u); i++)
{ {
for (i = 0; i < (int)sizeof(long_u); i++) shift = 8 * (sizeof(long_u) - 1 - i);
{ *val += (long_u)bytes[i] << shift;
shift = 8 * (sizeof(long_u) - 1 - i);
*val += (long_u)bytes[i] << shift;
}
} }
return len; return len;
} }
@@ -3598,19 +3598,19 @@ shell_resized_check(void)
int old_Rows = Rows; int old_Rows = Rows;
int old_Columns = Columns; int old_Columns = Columns;
if (!exiting if (exiting
#ifdef FEAT_GUI #ifdef FEAT_GUI
// Do not get the size when executing a shell command during // Do not get the size when executing a shell command during
// startup. // startup.
&& !gui.starting || gui.starting
#endif #endif
) )
{ return;
(void)ui_get_shellsize();
check_shellsize(); (void)ui_get_shellsize();
if (old_Rows != Rows || old_Columns != Columns) check_shellsize();
shell_resized(); if (old_Rows != Rows || old_Columns != Columns)
} shell_resized();
} }
/* /*
@@ -3843,101 +3843,101 @@ settmode(tmode_T tmode)
return; return;
#endif #endif
if (full_screen) if (!full_screen)
return;
/*
* When returning after calling a shell cur_tmode is TMODE_UNKNOWN,
* set the terminal to raw mode, even though we think it already is,
* because the shell program may have reset the terminal mode.
* When we think the terminal is normal, don't try to set it to
* normal again, because that causes problems (logout!) on some
* machines.
*/
if (tmode != cur_tmode)
{ {
/*
* When returning after calling a shell cur_tmode is TMODE_UNKNOWN,
* set the terminal to raw mode, even though we think it already is,
* because the shell program may have reset the terminal mode.
* When we think the terminal is normal, don't try to set it to
* normal again, because that causes problems (logout!) on some
* machines.
*/
if (tmode != cur_tmode)
{
#ifdef FEAT_TERMRESPONSE
# ifdef FEAT_GUI
if (!gui.in_use && !gui.starting)
# endif
{
// May need to check for T_CRV response and termcodes, it
// doesn't work in Cooked mode, an external program may get
// them.
if (tmode != TMODE_RAW && termrequest_any_pending())
(void)vpeekc_nomap();
check_for_codes_from_term();
}
#endif
if (tmode != TMODE_RAW)
mch_setmouse(FALSE); // switch mouse off
// Disable bracketed paste and modifyOtherKeys in cooked mode.
// Avoid doing this too often, on some terminals the codes are not
// handled properly.
if (termcap_active && tmode != TMODE_SLEEP
&& cur_tmode != TMODE_SLEEP)
{
MAY_WANT_TO_LOG_THIS;
if (tmode != TMODE_RAW)
{
out_str(T_BD); // disable bracketed paste mode
out_str_t_TE(); // possibly disables modifyOtherKeys
}
else
{
out_str_t_BE(); // enable bracketed paste mode (should
// be before mch_settmode().
out_str_t_TI(); // possibly enables modifyOtherKeys
}
}
out_flush();
mch_settmode(tmode); // machine specific function
cur_tmode = tmode;
if (tmode == TMODE_RAW)
setmouse(); // may switch mouse on
out_flush();
}
#ifdef FEAT_TERMRESPONSE
may_req_termresponse();
#endif
}
}
void
starttermcap(void)
{
if (full_screen && !termcap_active)
{
MAY_WANT_TO_LOG_THIS;
out_str(T_TI); // start termcap mode
out_str_t_TI(); // start "raw" mode
out_str(T_KS); // start "keypad transmit" mode
out_str_t_BE(); // enable bracketed paste mode
#if defined(UNIX) || defined(VMS)
// Enable xterm's focus reporting mode when 'esckeys' is set.
if (p_ek && *T_FE != NUL)
out_str(T_FE);
#endif
out_flush();
termcap_active = TRUE;
screen_start(); // don't know where cursor is now
#ifdef FEAT_TERMRESPONSE #ifdef FEAT_TERMRESPONSE
# ifdef FEAT_GUI # ifdef FEAT_GUI
if (!gui.in_use && !gui.starting) if (!gui.in_use && !gui.starting)
# endif # endif
{ {
may_req_termresponse(); // May need to check for T_CRV response and termcodes, it
// Immediately check for a response. If t_Co changes, we don't // doesn't work in Cooked mode, an external program may get
// want to redraw with wrong colors first. // them.
if (crv_status.tr_progress == STATUS_SENT) if (tmode != TMODE_RAW && termrequest_any_pending())
check_for_codes_from_term(); (void)vpeekc_nomap();
check_for_codes_from_term();
} }
#endif #endif
if (tmode != TMODE_RAW)
mch_setmouse(FALSE); // switch mouse off
// Disable bracketed paste and modifyOtherKeys in cooked mode.
// Avoid doing this too often, on some terminals the codes are not
// handled properly.
if (termcap_active && tmode != TMODE_SLEEP
&& cur_tmode != TMODE_SLEEP)
{
MAY_WANT_TO_LOG_THIS;
if (tmode != TMODE_RAW)
{
out_str(T_BD); // disable bracketed paste mode
out_str_t_TE(); // possibly disables modifyOtherKeys
}
else
{
out_str_t_BE(); // enable bracketed paste mode (should
// be before mch_settmode().
out_str_t_TI(); // possibly enables modifyOtherKeys
}
}
out_flush();
mch_settmode(tmode); // machine specific function
cur_tmode = tmode;
if (tmode == TMODE_RAW)
setmouse(); // may switch mouse on
out_flush();
} }
#ifdef FEAT_TERMRESPONSE
may_req_termresponse();
#endif
}
void
starttermcap(void)
{
if (!full_screen || termcap_active)
return;
MAY_WANT_TO_LOG_THIS;
out_str(T_TI); // start termcap mode
out_str_t_TI(); // start "raw" mode
out_str(T_KS); // start "keypad transmit" mode
out_str_t_BE(); // enable bracketed paste mode
#if defined(UNIX) || defined(VMS)
// Enable xterm's focus reporting mode when 'esckeys' is set.
if (p_ek && *T_FE != NUL)
out_str(T_FE);
#endif
out_flush();
termcap_active = TRUE;
screen_start(); // don't know where cursor is now
#ifdef FEAT_TERMRESPONSE
# ifdef FEAT_GUI
if (!gui.in_use && !gui.starting)
# endif
{
may_req_termresponse();
// Immediately check for a response. If t_Co changes, we don't
// want to redraw with wrong colors first.
if (crv_status.tr_progress == STATUS_SENT)
check_for_codes_from_term();
}
#endif
} }
void void
@@ -3945,63 +3945,64 @@ stoptermcap(void)
{ {
screen_stop_highlight(); screen_stop_highlight();
reset_cterm_colors(); reset_cterm_colors();
if (termcap_active)
{ if (!termcap_active)
return;
#ifdef FEAT_TERMRESPONSE #ifdef FEAT_TERMRESPONSE
# ifdef FEAT_GUI # ifdef FEAT_GUI
if (!gui.in_use && !gui.starting) if (!gui.in_use && !gui.starting)
# endif # endif
{
// May need to discard T_CRV, T_U7 or T_RBG response.
if (termrequest_any_pending())
{ {
// May need to discard T_CRV, T_U7 or T_RBG response.
if (termrequest_any_pending())
{
# ifdef UNIX # ifdef UNIX
// Give the terminal a chance to respond. // Give the terminal a chance to respond.
mch_delay(100L, 0); mch_delay(100L, 0);
# endif # endif
# ifdef TCIFLUSH # ifdef TCIFLUSH
// Discard data received but not read. // Discard data received but not read.
if (exiting) if (exiting)
tcflush(fileno(stdin), TCIFLUSH); tcflush(fileno(stdin), TCIFLUSH);
# endif # endif
}
// Check for termcodes first, otherwise an external program may
// get them.
check_for_codes_from_term();
} }
// Check for termcodes first, otherwise an external program may
// get them.
check_for_codes_from_term();
}
#endif #endif
MAY_WANT_TO_LOG_THIS; MAY_WANT_TO_LOG_THIS;
#if defined(UNIX) || defined(VMS) #if defined(UNIX) || defined(VMS)
// Disable xterm's focus reporting mode if 'esckeys' is set. // Disable xterm's focus reporting mode if 'esckeys' is set.
if (p_ek && *T_FD != NUL) if (p_ek && *T_FD != NUL)
out_str(T_FD); out_str(T_FD);
#endif #endif
out_str(T_BD); // disable bracketed paste mode out_str(T_BD); // disable bracketed paste mode
out_str(T_KE); // stop "keypad transmit" mode out_str(T_KE); // stop "keypad transmit" mode
out_flush(); out_flush();
termcap_active = FALSE; termcap_active = FALSE;
// Output t_te before t_TE, t_te may switch between main and alternate // Output t_te before t_TE, t_te may switch between main and alternate
// screen and following codes may work on the active screen only. // screen and following codes may work on the active screen only.
// //
// When using the Kitty keyboard protocol the main and alternate screen // When using the Kitty keyboard protocol the main and alternate screen
// use a separate state. If we are (or were) using the Kitty keyboard // use a separate state. If we are (or were) using the Kitty keyboard
// protocol and t_te is not empty (possibly switching screens) then // protocol and t_te is not empty (possibly switching screens) then
// output t_TE both before and after outputting t_te. // output t_TE both before and after outputting t_te.
if (*T_TE != NUL && (kitty_protocol_state == KKPS_ENABLED if (*T_TE != NUL && (kitty_protocol_state == KKPS_ENABLED
|| kitty_protocol_state == KKPS_DISABLED)) || kitty_protocol_state == KKPS_DISABLED))
out_str_t_TE(); // probably disables the kitty keyboard out_str_t_TE(); // probably disables the kitty keyboard
// protocol // protocol
out_str(T_TE); // stop termcap mode out_str(T_TE); // stop termcap mode
cursor_on(); // just in case it is still off cursor_on(); // just in case it is still off
out_str_t_TE(); // stop "raw" mode, modifyOtherKeys and out_str_t_TE(); // stop "raw" mode, modifyOtherKeys and
// Kitty keyboard protocol // Kitty keyboard protocol
screen_start(); // don't know where cursor is now screen_start(); // don't know where cursor is now
out_flush(); out_flush();
}
} }
#if defined(FEAT_TERMRESPONSE) || defined(PROTO) #if defined(FEAT_TERMRESPONSE) || defined(PROTO)
@@ -4219,13 +4220,13 @@ swapping_screen(void)
void void
scroll_start(void) scroll_start(void)
{ {
if (*T_VS != NUL && *T_CVS != NUL) if (*T_VS == NUL || *T_CVS == NUL)
{ return;
MAY_WANT_TO_LOG_THIS;
out_str(T_VS); MAY_WANT_TO_LOG_THIS;
out_str(T_CVS); out_str(T_VS);
screen_start(); // don't know where cursor is now out_str(T_CVS);
} screen_start(); // don't know where cursor is now
} }
// True if cursor is not visible // True if cursor is not visible
@@ -4355,13 +4356,13 @@ term_cursor_mode(int forced)
void void
term_cursor_color(char_u *color) term_cursor_color(char_u *color)
{ {
if (*T_CSC != NUL) if (*T_CSC == NUL)
{ return;
out_str(T_CSC); // set cursor color start
out_str_nf(color); out_str(T_CSC); // set cursor color start
out_str(T_CEC); // set cursor color end out_str_nf(color);
out_flush(); out_str(T_CEC); // set cursor color end
} out_flush();
} }
# endif # endif
@@ -4922,18 +4923,18 @@ modifiers2keycode(int modifiers, int *key, char_u *string)
{ {
int new_slen = 0; int new_slen = 0;
if (modifiers == 0)
return 0;
// Some keys have the modifier included. Need to handle that here to
// make mappings work. This may result in a special key, such as
// K_S_TAB.
*key = simplify_key(*key, &modifiers);
if (modifiers != 0) if (modifiers != 0)
{ {
// Some keys have the modifier included. Need to handle that here to string[new_slen++] = K_SPECIAL;
// make mappings work. This may result in a special key, such as string[new_slen++] = (int)KS_MODIFIER;
// K_S_TAB. string[new_slen++] = modifiers;
*key = simplify_key(*key, &modifiers);
if (modifiers != 0)
{
string[new_slen++] = K_SPECIAL;
string[new_slen++] = (int)KS_MODIFIER;
string[new_slen++] = modifiers;
}
} }
return new_slen; return new_slen;
} }
@@ -6523,12 +6524,12 @@ check_termcode(
void void
term_get_fg_color(char_u *r, char_u *g, char_u *b) term_get_fg_color(char_u *r, char_u *g, char_u *b)
{ {
if (rfg_status.tr_progress == STATUS_GOT) if (rfg_status.tr_progress != STATUS_GOT)
{ return;
*r = fg_r;
*g = fg_g; *r = fg_r;
*b = fg_b; *g = fg_g;
} *b = fg_b;
} }
/* /*
@@ -6537,12 +6538,12 @@ term_get_fg_color(char_u *r, char_u *g, char_u *b)
void void
term_get_bg_color(char_u *r, char_u *g, char_u *b) term_get_bg_color(char_u *r, char_u *g, char_u *b)
{ {
if (rbg_status.tr_progress == STATUS_GOT) if (rbg_status.tr_progress != STATUS_GOT)
{ return;
*r = bg_r;
*g = bg_g; *r = bg_r;
*b = bg_b; *g = bg_g;
} *b = bg_b;
} }
#endif #endif
@@ -7283,14 +7284,13 @@ find_first_tcap(
int code) int code)
{ {
tcap_entry_T *p = find_builtin_term(name); tcap_entry_T *p = find_builtin_term(name);
if (p != NULL) if (p == NULL)
return NULL;
while (p->bt_string != NULL)
{ {
while (p->bt_string != NULL) if (p->bt_entry == code)
{ return p;
if (p->bt_entry == code) ++p;
return p;
++p;
}
} }
return NULL; return NULL;
} }

View File

@@ -259,19 +259,19 @@ parse_termwinsize(win_T *wp, int *rows, int *cols)
*rows = 0; *rows = 0;
*cols = 0; *cols = 0;
if (*wp->w_p_tws != NUL) if (*wp->w_p_tws == NUL)
{ return FALSE;
char_u *p = vim_strchr(wp->w_p_tws, 'x');
// Syntax of value was already checked when it's set. char_u *p = vim_strchr(wp->w_p_tws, 'x');
if (p == NULL)
{ // Syntax of value was already checked when it's set.
minsize = TRUE; if (p == NULL)
p = vim_strchr(wp->w_p_tws, '*'); {
} minsize = TRUE;
*rows = atoi((char *)wp->w_p_tws); p = vim_strchr(wp->w_p_tws, '*');
*cols = atoi((char *)p + 1);
} }
*rows = atoi((char *)wp->w_p_tws);
*cols = atoi((char *)p + 1);
return minsize; return minsize;
} }
@@ -1620,21 +1620,20 @@ term_job_running_check(term_T *term, int check_job_status)
{ {
// Also consider the job finished when the channel is closed, to avoid a // Also consider the job finished when the channel is closed, to avoid a
// race condition when updating the title. // race condition when updating the title.
if (term != NULL if (term == NULL
&& term->tl_job != NULL || term->tl_job == NULL
&& channel_is_open(term->tl_job->jv_channel)) || !channel_is_open(term->tl_job->jv_channel))
{ return FALSE;
job_T *job = term->tl_job;
// Careful: Checking the job status may invoke callbacks, which close job_T *job = term->tl_job;
// the buffer and terminate "term". However, "job" will not be freed
// yet. // Careful: Checking the job status may invoke callbacks, which close
if (check_job_status) // the buffer and terminate "term". However, "job" will not be freed
job_status(job); // yet.
return (job->jv_status == JOB_STARTED if (check_job_status)
|| (job->jv_channel != NULL && job->jv_channel->ch_keep_open)); job_status(job);
} return (job->jv_status == JOB_STARTED
return FALSE; || (job->jv_channel != NULL && job->jv_channel->ch_keep_open));
} }
/* /*
@@ -1807,28 +1806,27 @@ equal_celattr(cellattr_T *a, cellattr_T *b)
static int static int
add_empty_scrollback(term_T *term, cellattr_T *fill_attr, int lnum) add_empty_scrollback(term_T *term, cellattr_T *fill_attr, int lnum)
{ {
if (ga_grow(&term->tl_scrollback, 1) == OK) if (ga_grow(&term->tl_scrollback, 1) == FAIL)
return FALSE;
sb_line_T *line = (sb_line_T *)term->tl_scrollback.ga_data
+ term->tl_scrollback.ga_len;
if (lnum > 0)
{ {
sb_line_T *line = (sb_line_T *)term->tl_scrollback.ga_data int i;
+ term->tl_scrollback.ga_len;
if (lnum > 0) for (i = 0; i < term->tl_scrollback.ga_len - lnum; ++i)
{ {
int i; *line = *(line - 1);
--line;
for (i = 0; i < term->tl_scrollback.ga_len - lnum; ++i)
{
*line = *(line - 1);
--line;
}
} }
line->sb_cols = 0;
line->sb_cells = NULL;
line->sb_fill_attr = *fill_attr;
++term->tl_scrollback.ga_len;
return OK;
} }
return FALSE; line->sb_cols = 0;
line->sb_cells = NULL;
line->sb_fill_attr = *fill_attr;
++term->tl_scrollback.ga_len;
return OK;
} }
/* /*
@@ -2409,43 +2407,43 @@ term_paste_register(int prev_c UNUSED)
return; return;
l = (list_T *)get_reg_contents(c, GREG_LIST); l = (list_T *)get_reg_contents(c, GREG_LIST);
if (l != NULL) if (l == NULL)
return;
type = get_reg_type(c, &reglen);
FOR_ALL_LIST_ITEMS(l, item)
{ {
type = get_reg_type(c, &reglen); char_u *s = tv_get_string(&item->li_tv);
FOR_ALL_LIST_ITEMS(l, item) #ifdef MSWIN
char_u *tmp = s;
if (!enc_utf8 && enc_codepage > 0)
{ {
char_u *s = tv_get_string(&item->li_tv); WCHAR *ret = NULL;
#ifdef MSWIN int length = 0;
char_u *tmp = s;
if (!enc_utf8 && enc_codepage > 0) MultiByteToWideChar_alloc(enc_codepage, 0, (char *)s,
(int)STRLEN(s), &ret, &length);
if (ret != NULL)
{ {
WCHAR *ret = NULL; WideCharToMultiByte_alloc(CP_UTF8, 0,
int length = 0; ret, length, (char **)&s, &length, 0, 0);
vim_free(ret);
MultiByteToWideChar_alloc(enc_codepage, 0, (char *)s,
(int)STRLEN(s), &ret, &length);
if (ret != NULL)
{
WideCharToMultiByte_alloc(CP_UTF8, 0,
ret, length, (char **)&s, &length, 0, 0);
vim_free(ret);
}
} }
}
#endif #endif
channel_send(curbuf->b_term->tl_job->jv_channel, PART_IN, channel_send(curbuf->b_term->tl_job->jv_channel, PART_IN,
s, (int)STRLEN(s), NULL); s, (int)STRLEN(s), NULL);
#ifdef MSWIN #ifdef MSWIN
if (tmp != s) if (tmp != s)
vim_free(s); vim_free(s);
#endif #endif
if (item->li_next != NULL || type == MLINE) if (item->li_next != NULL || type == MLINE)
channel_send(curbuf->b_term->tl_job->jv_channel, PART_IN, channel_send(curbuf->b_term->tl_job->jv_channel, PART_IN,
(char_u *)"\r", 1, NULL); (char_u *)"\r", 1, NULL);
}
list_free(l);
} }
list_free(l);
} }
/* /*
@@ -2615,18 +2613,18 @@ term_win_entered()
{ {
term_T *term = curbuf->b_term; term_T *term = curbuf->b_term;
if (term != NULL) if (term == NULL)
return;
if (term_use_loop_check(TRUE))
{ {
if (term_use_loop_check(TRUE)) reset_VIsual_and_resel();
{ if (State & MODE_INSERT)
reset_VIsual_and_resel(); stop_insert_mode = TRUE;
if (State & MODE_INSERT)
stop_insert_mode = TRUE;
}
mouse_was_outside = FALSE;
enter_mouse_col = mouse_col;
enter_mouse_row = mouse_row;
} }
mouse_was_outside = FALSE;
enter_mouse_col = mouse_col;
enter_mouse_row = mouse_row;
} }
void void
@@ -2634,16 +2632,16 @@ term_focus_change(int in_focus)
{ {
term_T *term = curbuf->b_term; term_T *term = curbuf->b_term;
if (term != NULL && term->tl_vterm != NULL) if (term == NULL || term->tl_vterm == NULL)
{ return;
VTermState *state = vterm_obtain_state(term->tl_vterm);
if (in_focus) VTermState *state = vterm_obtain_state(term->tl_vterm);
vterm_state_focus_in(state);
else if (in_focus)
vterm_state_focus_out(state); vterm_state_focus_in(state);
term_forward_output(term); else
} vterm_state_focus_out(state);
term_forward_output(term);
} }
/* /*
@@ -2886,13 +2884,13 @@ theend:
static void static void
may_toggle_cursor(term_T *term) may_toggle_cursor(term_T *term)
{ {
if (in_terminal_loop == term) if (in_terminal_loop != term)
{ return;
if (term->tl_cursor_visible)
cursor_on(); if (term->tl_cursor_visible)
else cursor_on();
cursor_off(); else
} cursor_off();
} }
/* /*
@@ -3320,27 +3318,27 @@ handle_resize(int rows, int cols, void *user)
static void static void
limit_scrollback(term_T *term, garray_T *gap, int update_buffer) limit_scrollback(term_T *term, garray_T *gap, int update_buffer)
{ {
if (gap->ga_len >= term->tl_buffer->b_p_twsl) if (gap->ga_len < term->tl_buffer->b_p_twsl)
return;
int todo = term->tl_buffer->b_p_twsl / 10;
int i;
curbuf = term->tl_buffer;
for (i = 0; i < todo; ++i)
{ {
int todo = term->tl_buffer->b_p_twsl / 10; vim_free(((sb_line_T *)gap->ga_data + i)->sb_cells);
int i;
curbuf = term->tl_buffer;
for (i = 0; i < todo; ++i)
{
vim_free(((sb_line_T *)gap->ga_data + i)->sb_cells);
if (update_buffer)
ml_delete(1);
}
curbuf = curwin->w_buffer;
gap->ga_len -= todo;
mch_memmove(gap->ga_data,
(sb_line_T *)gap->ga_data + todo,
sizeof(sb_line_T) * gap->ga_len);
if (update_buffer) if (update_buffer)
term->tl_scrollback_scrolled -= todo; ml_delete(1);
} }
curbuf = curwin->w_buffer;
gap->ga_len -= todo;
mch_memmove(gap->ga_data,
(sb_line_T *)gap->ga_data + todo,
sizeof(sb_line_T) * gap->ga_len);
if (update_buffer)
term->tl_scrollback_scrolled -= todo;
} }
/* /*
@@ -3371,78 +3369,78 @@ handle_pushline(int cols, const VTermScreenCell *cells, void *user)
limit_scrollback(term, gap, update_buffer); limit_scrollback(term, gap, update_buffer);
if (ga_grow(gap, 1) == OK) if (ga_grow(gap, 1) == FAIL)
return 0;
cellattr_T *p = NULL;
int len = 0;
int i;
int c;
int col;
int text_len;
char_u *text;
sb_line_T *line;
garray_T ga;
cellattr_T fill_attr = term->tl_default_color;
// do not store empty cells at the end
for (i = 0; i < cols; ++i)
if (cells[i].chars[0] != 0)
len = i + 1;
else
cell2cellattr(&cells[i], &fill_attr);
ga_init2(&ga, 1, 100);
if (len > 0)
p = ALLOC_MULT(cellattr_T, len);
if (p != NULL)
{ {
cellattr_T *p = NULL; for (col = 0; col < len; col += cells[col].width)
int len = 0;
int i;
int c;
int col;
int text_len;
char_u *text;
sb_line_T *line;
garray_T ga;
cellattr_T fill_attr = term->tl_default_color;
// do not store empty cells at the end
for (i = 0; i < cols; ++i)
if (cells[i].chars[0] != 0)
len = i + 1;
else
cell2cellattr(&cells[i], &fill_attr);
ga_init2(&ga, 1, 100);
if (len > 0)
p = ALLOC_MULT(cellattr_T, len);
if (p != NULL)
{ {
for (col = 0; col < len; col += cells[col].width) if (ga_grow(&ga, MB_MAXBYTES) == FAIL)
{ {
if (ga_grow(&ga, MB_MAXBYTES) == FAIL) ga.ga_len = 0;
{ break;
ga.ga_len = 0;
break;
}
for (i = 0; (c = cells[col].chars[i]) > 0 || i == 0; ++i)
ga.ga_len += utf_char2bytes(c == NUL ? ' ' : c,
(char_u *)ga.ga_data + ga.ga_len);
cell2cellattr(&cells[col], &p[col]);
} }
for (i = 0; (c = cells[col].chars[i]) > 0 || i == 0; ++i)
ga.ga_len += utf_char2bytes(c == NUL ? ' ' : c,
(char_u *)ga.ga_data + ga.ga_len);
cell2cellattr(&cells[col], &p[col]);
} }
if (ga_grow(&ga, 1) == FAIL)
{
if (update_buffer)
text = (char_u *)"";
else
text = vim_strsave((char_u *)"");
text_len = 0;
}
else
{
text = ga.ga_data;
text_len = ga.ga_len;
*(text + text_len) = NUL;
}
if (update_buffer)
add_scrollback_line_to_buffer(term, text, text_len);
line = (sb_line_T *)gap->ga_data + gap->ga_len;
line->sb_cols = len;
line->sb_cells = p;
line->sb_fill_attr = fill_attr;
if (update_buffer)
{
line->sb_text = NULL;
++term->tl_scrollback_scrolled;
ga_clear(&ga); // free the text
}
else
{
line->sb_text = text;
ga_init(&ga); // text is kept in tl_scrollback_postponed
}
++gap->ga_len;
} }
if (ga_grow(&ga, 1) == FAIL)
{
if (update_buffer)
text = (char_u *)"";
else
text = vim_strsave((char_u *)"");
text_len = 0;
}
else
{
text = ga.ga_data;
text_len = ga.ga_len;
*(text + text_len) = NUL;
}
if (update_buffer)
add_scrollback_line_to_buffer(term, text, text_len);
line = (sb_line_T *)gap->ga_data + gap->ga_len;
line->sb_cols = len;
line->sb_cells = p;
line->sb_fill_attr = fill_attr;
if (update_buffer)
{
line->sb_text = NULL;
++term->tl_scrollback_scrolled;
ga_clear(&ga); // free the text
}
else
{
line->sb_text = text;
ga_init(&ga); // text is kept in tl_scrollback_postponed
}
++gap->ga_len;
return 0; // ignored return 0; // ignored
} }
@@ -3612,17 +3610,16 @@ term_after_channel_closed(term_T *term)
int int
may_close_term_popup(void) may_close_term_popup(void)
{ {
if (popup_is_popup(curwin) && curbuf->b_term != NULL if (!popup_is_popup(curwin) || curbuf->b_term == NULL
&& !term_job_running_not_none(curbuf->b_term)) || term_job_running_not_none(curbuf->b_term))
{ return FAIL;
win_T *pwin = curwin;
if (win_valid(prevwin)) win_T *pwin = curwin;
win_enter(prevwin, FALSE);
popup_close_with_retval(pwin, 0); if (win_valid(prevwin))
return OK; win_enter(prevwin, FALSE);
} popup_close_with_retval(pwin, 0);
return FAIL; return OK;
} }
#endif #endif
@@ -4002,12 +3999,12 @@ term_did_update_window(win_T *wp)
{ {
term_T *term = wp->w_buffer->b_term; term_T *term = wp->w_buffer->b_term;
if (term != NULL && term->tl_vterm != NULL && !term->tl_normal_mode if (term == NULL || term->tl_vterm == NULL || term->tl_normal_mode
&& wp->w_redr_type == 0) || wp->w_redr_type != 0)
{ return;
term->tl_dirty_row_start = MAX_ROW;
term->tl_dirty_row_end = 0; term->tl_dirty_row_start = MAX_ROW;
} term->tl_dirty_row_end = 0;
} }
/* /*
@@ -4040,16 +4037,16 @@ term_change_in_curbuf(void)
{ {
term_T *term = curbuf->b_term; term_T *term = curbuf->b_term;
if (term_is_finished(curbuf) && term->tl_scrollback.ga_len > 0) if (!term_is_finished(curbuf) || term->tl_scrollback.ga_len <= 0)
{ return;
free_scrollback(term);
redraw_buf_later(term->tl_buffer, UPD_NOT_VALID);
// The buffer is now like a normal buffer, it cannot be easily free_scrollback(term);
// abandoned when changed. redraw_buf_later(term->tl_buffer, UPD_NOT_VALID);
set_string_option_direct((char_u *)"buftype", -1,
(char_u *)"", OPT_FREE|OPT_LOCAL, 0); // The buffer is now like a normal buffer, it cannot be easily
} // abandoned when changed.
set_string_option_direct((char_u *)"buftype", -1,
(char_u *)"", OPT_FREE|OPT_LOCAL, 0);
} }
/* /*
@@ -4908,34 +4905,34 @@ term_update_colors_all(void)
char_u * char_u *
term_get_status_text(term_T *term) term_get_status_text(term_T *term)
{ {
if (term->tl_status_text == NULL) if (term->tl_status_text != NULL)
{ return term->tl_status_text;
char_u *txt;
size_t len;
char_u *fname;
if (term->tl_normal_mode) char_u *txt;
{ size_t len;
if (term_job_running(term)) char_u *fname;
txt = (char_u *)_("Terminal");
else if (term->tl_normal_mode)
txt = (char_u *)_("Terminal-finished"); {
} if (term_job_running(term))
else if (term->tl_title != NULL) txt = (char_u *)_("Terminal");
txt = term->tl_title;
else if (term_none_open(term))
txt = (char_u *)_("active");
else if (term_job_running(term))
txt = (char_u *)_("running");
else else
txt = (char_u *)_("finished"); txt = (char_u *)_("Terminal-finished");
fname = buf_get_fname(term->tl_buffer);
len = 9 + STRLEN(fname) + STRLEN(txt);
term->tl_status_text = alloc(len);
if (term->tl_status_text != NULL)
vim_snprintf((char *)term->tl_status_text, len, "%s [%s]",
fname, txt);
} }
else if (term->tl_title != NULL)
txt = term->tl_title;
else if (term_none_open(term))
txt = (char_u *)_("active");
else if (term_job_running(term))
txt = (char_u *)_("running");
else
txt = (char_u *)_("finished");
fname = buf_get_fname(term->tl_buffer);
len = 9 + STRLEN(fname) + STRLEN(txt);
term->tl_status_text = alloc(len);
if (term->tl_status_text != NULL)
vim_snprintf((char *)term->tl_status_text, len, "%s [%s]",
fname, txt);
return term->tl_status_text; return term->tl_status_text;
} }
@@ -5236,11 +5233,11 @@ dump_is_corrupt(garray_T *gap)
static void static void
append_cell(garray_T *gap, cellattr_T *cell) append_cell(garray_T *gap, cellattr_T *cell)
{ {
if (ga_grow(gap, 1) == OK) if (ga_grow(gap, 1) == FAIL)
{ return;
*(((cellattr_T *)gap->ga_data) + gap->ga_len) = *cell;
++gap->ga_len; *(((cellattr_T *)gap->ga_data) + gap->ga_len) = *cell;
} ++gap->ga_len;
} }
static void static void
@@ -6036,15 +6033,15 @@ f_term_getcursor(typval_T *argvars, typval_T *rettv)
list_append_number(l, term->tl_cursor_pos.col + 1); list_append_number(l, term->tl_cursor_pos.col + 1);
d = dict_alloc(); d = dict_alloc();
if (d != NULL) if (d == NULL)
{ return;
dict_add_number(d, "visible", term->tl_cursor_visible);
dict_add_number(d, "blink", blink_state_is_inverted() dict_add_number(d, "visible", term->tl_cursor_visible);
? !term->tl_cursor_blink : term->tl_cursor_blink); dict_add_number(d, "blink", blink_state_is_inverted()
dict_add_number(d, "shape", term->tl_cursor_shape); ? !term->tl_cursor_blink : term->tl_cursor_blink);
dict_add_string(d, "color", cursor_color_get(term->tl_cursor_color)); dict_add_number(d, "shape", term->tl_cursor_shape);
list_append_dict(l, d); dict_add_string(d, "color", cursor_color_get(term->tl_cursor_color));
} list_append_dict(l, d);
} }
/* /*
@@ -7692,20 +7689,20 @@ term_free_vterm(term_T *term)
term_report_winsize(term_T *term, int rows, int cols) term_report_winsize(term_T *term, int rows, int cols)
{ {
// Use an ioctl() to report the new window size to the job. // Use an ioctl() to report the new window size to the job.
if (term->tl_job != NULL && term->tl_job->jv_channel != NULL) if (term->tl_job == NULL || term->tl_job->jv_channel == NULL)
{ return;
int fd = -1;
int part;
for (part = PART_OUT; part < PART_COUNT; ++part) int fd = -1;
{ int part;
fd = term->tl_job->jv_channel->ch_part[part].ch_fd;
if (mch_isatty(fd)) for (part = PART_OUT; part < PART_COUNT; ++part)
break; {
} fd = term->tl_job->jv_channel->ch_part[part].ch_fd;
if (part < PART_COUNT && mch_report_winsize(fd, rows, cols) == OK) if (mch_isatty(fd))
mch_signal_job(term->tl_job, (char_u *)"winch"); break;
} }
if (part < PART_COUNT && mch_report_winsize(fd, rows, cols) == OK)
mch_signal_job(term->tl_job, (char_u *)"winch");
} }
# endif # endif

View File

@@ -55,8 +55,10 @@ ga_concat_esc(garray_T *gap, char_u *p, int clen)
mch_memmove(buf, p, clen); mch_memmove(buf, p, clen);
buf[clen] = NUL; buf[clen] = NUL;
ga_concat(gap, buf); ga_concat(gap, buf);
return;
} }
else switch (*p)
switch (*p)
{ {
case BS: ga_concat(gap, (char_u *)"\\b"); break; case BS: ga_concat(gap, (char_u *)"\\b"); break;
case ESC: ga_concat(gap, (char_u *)"\\e"); break; case ESC: ga_concat(gap, (char_u *)"\\e"); break;

View File

@@ -752,26 +752,26 @@ check_auto_format(
int c = ' '; int c = ' ';
int cc; int cc;
if (did_add_space) if (!did_add_space)
return;
cc = gchar_cursor();
if (!WHITECHAR(cc))
// Somehow the space was removed already.
did_add_space = FALSE;
else
{ {
cc = gchar_cursor(); if (!end_insert)
if (!WHITECHAR(cc))
// Somehow the space was removed already.
did_add_space = FALSE;
else
{ {
if (!end_insert) inc_cursor();
{ c = gchar_cursor();
inc_cursor(); dec_cursor();
c = gchar_cursor(); }
dec_cursor(); if (c != NUL)
} {
if (c != NUL) // The space is no longer at the end of the line, delete it.
{ del_char(FALSE);
// The space is no longer at the end of the line, delete it. did_add_space = FALSE;
del_char(FALSE);
did_add_space = FALSE;
}
} }
} }
} }

View File

@@ -1939,28 +1939,28 @@ f_prop_type_delete(typval_T *argvars, typval_T *rettv UNUSED)
} }
hi = find_prop_type_hi(name, buf); hi = find_prop_type_hi(name, buf);
if (hi != NULL) if (hi == NULL)
return;
hashtab_T *ht;
proptype_T *prop = HI2PT(hi);
if (buf == NULL)
{ {
hashtab_T *ht; ht = global_proptypes;
proptype_T *prop = HI2PT(hi); VIM_CLEAR(global_proparray);
if (buf == NULL)
{
ht = global_proptypes;
VIM_CLEAR(global_proparray);
}
else
{
ht = buf->b_proptypes;
VIM_CLEAR(buf->b_proparray);
}
hash_remove(ht, hi, "prop type delete");
vim_free(prop);
// currently visibile text properties will disappear
redraw_all_later(UPD_CLEAR);
changed_window_setting_buf(buf == NULL ? curbuf : buf);
} }
else
{
ht = buf->b_proptypes;
VIM_CLEAR(buf->b_proparray);
}
hash_remove(ht, hi, "prop type delete");
vim_free(prop);
// currently visibile text properties will disappear
redraw_all_later(UPD_CLEAR);
changed_window_setting_buf(buf == NULL ? curbuf : buf);
} }
/* /*
@@ -1982,35 +1982,36 @@ f_prop_type_get(typval_T *argvars, typval_T *rettv)
semsg(_(e_invalid_argument_str), "\"\""); semsg(_(e_invalid_argument_str), "\"\"");
return; return;
} }
if (rettv_dict_alloc(rettv) == OK)
if (rettv_dict_alloc(rettv) == FAIL)
return;
proptype_T *prop = NULL;
buf_T *buf = NULL;
if (argvars[1].v_type != VAR_UNKNOWN)
{ {
proptype_T *prop = NULL; if (get_bufnr_from_arg(&argvars[1], &buf) == FAIL)
buf_T *buf = NULL; return;
if (argvars[1].v_type != VAR_UNKNOWN)
{
if (get_bufnr_from_arg(&argvars[1], &buf) == FAIL)
return;
}
prop = find_prop_type(name, buf);
if (prop != NULL)
{
dict_T *d = rettv->vval.v_dict;
if (prop->pt_hl_id > 0)
dict_add_string(d, "highlight", syn_id2name(prop->pt_hl_id));
dict_add_number(d, "priority", prop->pt_priority);
dict_add_number(d, "combine",
(prop->pt_flags & PT_FLAG_COMBINE) ? 1 : 0);
dict_add_number(d, "start_incl",
(prop->pt_flags & PT_FLAG_INS_START_INCL) ? 1 : 0);
dict_add_number(d, "end_incl",
(prop->pt_flags & PT_FLAG_INS_END_INCL) ? 1 : 0);
if (buf != NULL)
dict_add_number(d, "bufnr", buf->b_fnum);
}
} }
prop = find_prop_type(name, buf);
if (prop == NULL)
return;
dict_T *d = rettv->vval.v_dict;
if (prop->pt_hl_id > 0)
dict_add_string(d, "highlight", syn_id2name(prop->pt_hl_id));
dict_add_number(d, "priority", prop->pt_priority);
dict_add_number(d, "combine",
(prop->pt_flags & PT_FLAG_COMBINE) ? 1 : 0);
dict_add_number(d, "start_incl",
(prop->pt_flags & PT_FLAG_INS_START_INCL) ? 1 : 0);
dict_add_number(d, "end_incl",
(prop->pt_flags & PT_FLAG_INS_END_INCL) ? 1 : 0);
if (buf != NULL)
dict_add_number(d, "bufnr", buf->b_fnum);
} }
static void static void
@@ -2040,24 +2041,24 @@ f_prop_type_list(typval_T *argvars, typval_T *rettv UNUSED)
{ {
buf_T *buf = NULL; buf_T *buf = NULL;
if (rettv_list_alloc(rettv) == OK) if (rettv_list_alloc(rettv) == FAIL)
{ return;
if (in_vim9script() && check_for_opt_dict_arg(argvars, 0) == FAIL)
return;
if (argvars[0].v_type != VAR_UNKNOWN) if (in_vim9script() && check_for_opt_dict_arg(argvars, 0) == FAIL)
{ return;
if (get_bufnr_from_arg(&argvars[0], &buf) == FAIL)
return; if (argvars[0].v_type != VAR_UNKNOWN)
} {
if (buf == NULL) if (get_bufnr_from_arg(&argvars[0], &buf) == FAIL)
{ return;
if (global_proptypes != NULL)
list_types(global_proptypes, rettv->vval.v_list);
}
else if (buf->b_proptypes != NULL)
list_types(buf->b_proptypes, rettv->vval.v_list);
} }
if (buf == NULL)
{
if (global_proptypes != NULL)
list_types(global_proptypes, rettv->vval.v_list);
}
else if (buf->b_proptypes != NULL)
list_types(buf->b_proptypes, rettv->vval.v_list);
} }
/* /*

View File

@@ -302,47 +302,48 @@ f_strftime(typval_T *argvars, typval_T *rettv)
curtime = vim_localtime(&seconds, &tmval); curtime = vim_localtime(&seconds, &tmval);
// MSVC returns NULL for an invalid value of seconds. // MSVC returns NULL for an invalid value of seconds.
if (curtime == NULL) if (curtime == NULL)
rettv->vval.v_string = vim_strsave((char_u *)_("(Invalid)"));
else
{ {
# ifdef MSWIN rettv->vval.v_string = vim_strsave((char_u *)_("(Invalid)"));
WCHAR result_buf[256]; return;
WCHAR *wp;
wp = enc_to_utf16(p, NULL);
if (wp != NULL)
(void)wcsftime(result_buf, ARRAY_LENGTH(result_buf), wp, curtime);
else
result_buf[0] = NUL;
rettv->vval.v_string = utf16_to_enc(result_buf, NULL);
vim_free(wp);
# else
char_u result_buf[256];
vimconv_T conv;
char_u *enc;
conv.vc_type = CONV_NONE;
enc = enc_locale();
convert_setup(&conv, p_enc, enc);
if (conv.vc_type != CONV_NONE)
p = string_convert(&conv, p, NULL);
if (p == NULL || strftime((char *)result_buf, sizeof(result_buf),
(char *)p, curtime) == 0)
result_buf[0] = NUL;
if (conv.vc_type != CONV_NONE)
vim_free(p);
convert_setup(&conv, enc, p_enc);
if (conv.vc_type != CONV_NONE)
rettv->vval.v_string = string_convert(&conv, result_buf, NULL);
else
rettv->vval.v_string = vim_strsave(result_buf);
// Release conversion descriptors
convert_setup(&conv, NULL, NULL);
vim_free(enc);
# endif
} }
# ifdef MSWIN
WCHAR result_buf[256];
WCHAR *wp;
wp = enc_to_utf16(p, NULL);
if (wp != NULL)
(void)wcsftime(result_buf, ARRAY_LENGTH(result_buf), wp, curtime);
else
result_buf[0] = NUL;
rettv->vval.v_string = utf16_to_enc(result_buf, NULL);
vim_free(wp);
# else
char_u result_buf[256];
vimconv_T conv;
char_u *enc;
conv.vc_type = CONV_NONE;
enc = enc_locale();
convert_setup(&conv, p_enc, enc);
if (conv.vc_type != CONV_NONE)
p = string_convert(&conv, p, NULL);
if (p == NULL || strftime((char *)result_buf, sizeof(result_buf),
(char *)p, curtime) == 0)
result_buf[0] = NUL;
if (conv.vc_type != CONV_NONE)
vim_free(p);
convert_setup(&conv, enc, p_enc);
if (conv.vc_type != CONV_NONE)
rettv->vval.v_string = string_convert(&conv, result_buf, NULL);
else
rettv->vval.v_string = vim_strsave(result_buf);
// Release conversion descriptors
convert_setup(&conv, NULL, NULL);
vim_free(enc);
# endif
} }
# endif # endif
@@ -672,12 +673,12 @@ find_timer(long id)
{ {
timer_T *timer; timer_T *timer;
if (id >= 0) if (id < 0)
{ return NULL;
FOR_ALL_TIMERS(timer)
if (timer->tr_id == id) FOR_ALL_TIMERS(timer)
return timer; if (timer->tr_id == id)
} return timer;
return NULL; return NULL;
} }
@@ -791,7 +792,9 @@ timer_valid(timer_T *timer)
{ {
if (timer == NULL) if (timer == NULL)
return FALSE; return FALSE;
for (timer_T *t = first_timer; t != NULL; t = t->tr_next)
timer_T *t;
FOR_ALL_TIMERS(t)
if (t == timer) if (t == timer)
return TRUE; return TRUE;
return FALSE; return FALSE;
@@ -848,15 +851,16 @@ f_timer_pause(typval_T *argvars, typval_T *rettv UNUSED)
return; return;
if (argvars[0].v_type != VAR_NUMBER) if (argvars[0].v_type != VAR_NUMBER)
emsg(_(e_number_expected));
else
{ {
int paused = (int)tv_get_bool(&argvars[1]); emsg(_(e_number_expected));
return;
timer = find_timer((int)tv_get_number(&argvars[0]));
if (timer != NULL)
timer->tr_paused = paused;
} }
int paused = (int)tv_get_bool(&argvars[1]);
timer = find_timer((int)tv_get_number(&argvars[0]));
if (timer != NULL)
timer->tr_paused = paused;
} }
/* /*
@@ -904,14 +908,14 @@ f_timer_start(typval_T *argvars, typval_T *rettv)
timer = create_timer(msec, repeat); timer = create_timer(msec, repeat);
if (timer == NULL) if (timer == NULL)
free_callback(&callback);
else
{ {
set_callback(&timer->tr_callback, &callback); free_callback(&callback);
if (callback.cb_free_name) return;
vim_free(callback.cb_name);
rettv->vval.v_number = (varnumber_T)timer->tr_id;
} }
set_callback(&timer->tr_callback, &callback);
if (callback.cb_free_name)
vim_free(callback.cb_name);
rettv->vval.v_number = (varnumber_T)timer->tr_id;
} }
/* /*
@@ -1019,28 +1023,28 @@ time_msg(
static struct timeval start; static struct timeval start;
struct timeval now; struct timeval now;
if (time_fd != NULL) if (time_fd == NULL)
return;
if (strstr(mesg, "STARTING") != NULL)
{ {
if (strstr(mesg, "STARTING") != NULL) gettimeofday(&start, NULL);
{ prev_timeval = start;
gettimeofday(&start, NULL); fprintf(time_fd, "\n\ntimes in msec\n");
prev_timeval = start; fprintf(time_fd, " clock self+sourced self: sourced script\n");
fprintf(time_fd, "\n\ntimes in msec\n"); fprintf(time_fd, " clock elapsed: other lines\n\n");
fprintf(time_fd, " clock self+sourced self: sourced script\n");
fprintf(time_fd, " clock elapsed: other lines\n\n");
}
gettimeofday(&now, NULL);
time_diff(&start, &now);
if (((struct timeval *)tv_start) != NULL)
{
fprintf(time_fd, " ");
time_diff(((struct timeval *)tv_start), &now);
}
fprintf(time_fd, " ");
time_diff(&prev_timeval, &now);
prev_timeval = now;
fprintf(time_fd, ": %s\n", mesg);
} }
gettimeofday(&now, NULL);
time_diff(&start, &now);
if (((struct timeval *)tv_start) != NULL)
{
fprintf(time_fd, " ");
time_diff(((struct timeval *)tv_start), &now);
}
fprintf(time_fd, " ");
time_diff(&prev_timeval, &now);
prev_timeval = now;
fprintf(time_fd, ": %s\n", mesg);
} }
# endif // STARTUPTIME # endif // STARTUPTIME
#endif // FEAT_EVAL #endif // FEAT_EVAL

View File

@@ -52,57 +52,57 @@ alloc_string_tv(char_u *s)
void void
free_tv(typval_T *varp) free_tv(typval_T *varp)
{ {
if (varp != NULL) if (varp == NULL)
{ return;
switch (varp->v_type)
{
case VAR_FUNC:
func_unref(varp->vval.v_string);
// FALLTHROUGH
case VAR_STRING:
vim_free(varp->vval.v_string);
break;
case VAR_PARTIAL:
partial_unref(varp->vval.v_partial);
break;
case VAR_BLOB:
blob_unref(varp->vval.v_blob);
break;
case VAR_LIST:
list_unref(varp->vval.v_list);
break;
case VAR_DICT:
dict_unref(varp->vval.v_dict);
break;
case VAR_JOB:
#ifdef FEAT_JOB_CHANNEL
job_unref(varp->vval.v_job);
break;
#endif
case VAR_CHANNEL:
#ifdef FEAT_JOB_CHANNEL
channel_unref(varp->vval.v_channel);
break;
#endif
case VAR_CLASS:
class_unref(varp->vval.v_class);
break;
case VAR_OBJECT:
object_unref(varp->vval.v_object);
break;
case VAR_NUMBER: switch (varp->v_type)
case VAR_FLOAT: {
case VAR_ANY: case VAR_FUNC:
case VAR_UNKNOWN: func_unref(varp->vval.v_string);
case VAR_VOID: // FALLTHROUGH
case VAR_BOOL: case VAR_STRING:
case VAR_SPECIAL: vim_free(varp->vval.v_string);
case VAR_INSTR: break;
break; case VAR_PARTIAL:
} partial_unref(varp->vval.v_partial);
vim_free(varp); break;
case VAR_BLOB:
blob_unref(varp->vval.v_blob);
break;
case VAR_LIST:
list_unref(varp->vval.v_list);
break;
case VAR_DICT:
dict_unref(varp->vval.v_dict);
break;
case VAR_JOB:
#ifdef FEAT_JOB_CHANNEL
job_unref(varp->vval.v_job);
break;
#endif
case VAR_CHANNEL:
#ifdef FEAT_JOB_CHANNEL
channel_unref(varp->vval.v_channel);
break;
#endif
case VAR_CLASS:
class_unref(varp->vval.v_class);
break;
case VAR_OBJECT:
object_unref(varp->vval.v_object);
break;
case VAR_NUMBER:
case VAR_FLOAT:
case VAR_ANY:
case VAR_UNKNOWN:
case VAR_VOID:
case VAR_BOOL:
case VAR_SPECIAL:
case VAR_INSTR:
break;
} }
vim_free(varp);
} }
/* /*
@@ -111,70 +111,70 @@ free_tv(typval_T *varp)
void void
clear_tv(typval_T *varp) clear_tv(typval_T *varp)
{ {
if (varp != NULL) if (varp == NULL)
return;
switch (varp->v_type)
{ {
switch (varp->v_type) case VAR_FUNC:
{ func_unref(varp->vval.v_string);
case VAR_FUNC: // FALLTHROUGH
func_unref(varp->vval.v_string); case VAR_STRING:
// FALLTHROUGH VIM_CLEAR(varp->vval.v_string);
case VAR_STRING: break;
VIM_CLEAR(varp->vval.v_string); case VAR_PARTIAL:
break; partial_unref(varp->vval.v_partial);
case VAR_PARTIAL: varp->vval.v_partial = NULL;
partial_unref(varp->vval.v_partial); break;
varp->vval.v_partial = NULL; case VAR_BLOB:
break; blob_unref(varp->vval.v_blob);
case VAR_BLOB: varp->vval.v_blob = NULL;
blob_unref(varp->vval.v_blob); break;
varp->vval.v_blob = NULL; case VAR_LIST:
break; list_unref(varp->vval.v_list);
case VAR_LIST: varp->vval.v_list = NULL;
list_unref(varp->vval.v_list); break;
varp->vval.v_list = NULL; case VAR_DICT:
break; dict_unref(varp->vval.v_dict);
case VAR_DICT: varp->vval.v_dict = NULL;
dict_unref(varp->vval.v_dict); break;
varp->vval.v_dict = NULL; case VAR_NUMBER:
break; case VAR_BOOL:
case VAR_NUMBER: case VAR_SPECIAL:
case VAR_BOOL: varp->vval.v_number = 0;
case VAR_SPECIAL: break;
varp->vval.v_number = 0; case VAR_FLOAT:
break; varp->vval.v_float = 0.0;
case VAR_FLOAT: break;
varp->vval.v_float = 0.0; case VAR_JOB:
break;
case VAR_JOB:
#ifdef FEAT_JOB_CHANNEL #ifdef FEAT_JOB_CHANNEL
job_unref(varp->vval.v_job); job_unref(varp->vval.v_job);
varp->vval.v_job = NULL; varp->vval.v_job = NULL;
#endif #endif
break; break;
case VAR_CHANNEL: case VAR_CHANNEL:
#ifdef FEAT_JOB_CHANNEL #ifdef FEAT_JOB_CHANNEL
channel_unref(varp->vval.v_channel); channel_unref(varp->vval.v_channel);
varp->vval.v_channel = NULL; varp->vval.v_channel = NULL;
#endif #endif
break; break;
case VAR_INSTR: case VAR_INSTR:
VIM_CLEAR(varp->vval.v_instr); VIM_CLEAR(varp->vval.v_instr);
break; break;
case VAR_CLASS: case VAR_CLASS:
class_unref(varp->vval.v_class); class_unref(varp->vval.v_class);
varp->vval.v_class = NULL; varp->vval.v_class = NULL;
break; break;
case VAR_OBJECT: case VAR_OBJECT:
object_unref(varp->vval.v_object); object_unref(varp->vval.v_object);
varp->vval.v_object = NULL; varp->vval.v_object = NULL;
break; break;
case VAR_UNKNOWN: case VAR_UNKNOWN:
case VAR_ANY: case VAR_ANY:
case VAR_VOID: case VAR_VOID:
break; break;
}
varp->v_lock = 0;
} }
varp->v_lock = 0;
} }
/* /*

View File

@@ -695,6 +695,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
1245,
/**/ /**/
1244, 1244,
/**/ /**/