aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/syntax.c
diff options
context:
space:
mode:
authordundargoc <gocdundar@gmail.com>2023-12-28 13:42:24 +0100
committerdundargoc <33953936+dundargoc@users.noreply.github.com>2023-12-30 12:45:38 +0100
commitc89292fcb7f2ebf06efb7c1d00c28f34c6f68fec (patch)
treeb1257a572495337ca936c47839bb08aa45528c84 /src/nvim/syntax.c
parentd634cd5b0bc3ac6bdf285432f74a1c10f12b6031 (diff)
downloadrneovim-c89292fcb7f2ebf06efb7c1d00c28f34c6f68fec.tar.gz
rneovim-c89292fcb7f2ebf06efb7c1d00c28f34c6f68fec.tar.bz2
rneovim-c89292fcb7f2ebf06efb7c1d00c28f34c6f68fec.zip
refactor: follow style guide
Diffstat (limited to 'src/nvim/syntax.c')
-rw-r--r--src/nvim/syntax.c122
1 files changed, 46 insertions, 76 deletions
diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c
index 41c9703f3b..4c74682432 100644
--- a/src/nvim/syntax.c
+++ b/src/nvim/syntax.c
@@ -340,10 +340,10 @@ void syntax_start(win_T *wp, linenr_T lnum)
if (VALID_STATE(&current_state)
&& current_lnum < lnum
&& current_lnum < syn_buf->b_ml.ml_line_count) {
- (void)syn_finish_line(false);
+ syn_finish_line(false);
if (!current_state_stored) {
current_lnum++;
- (void)store_current_state();
+ store_current_state();
}
// If the current_lnum is now the same as "lnum", keep the current
@@ -401,7 +401,7 @@ void syntax_start(win_T *wp, linenr_T lnum)
}
while (current_lnum < lnum) {
syn_start_line();
- (void)syn_finish_line(false);
+ syn_finish_line(false);
current_lnum++;
// If we parsed at least "minlines" lines or started at a valid
@@ -490,23 +490,16 @@ static void clear_current_state(void)
// 3. Simply start on a given number of lines above "lnum".
static void syn_sync(win_T *wp, linenr_T start_lnum, synstate_T *last_valid)
{
- buf_T *curbuf_save;
- win_T *curwin_save;
pos_T cursor_save;
- int idx;
linenr_T lnum;
- linenr_T end_lnum;
linenr_T break_lnum;
- bool had_sync_point;
stateitem_T *cur_si;
synpat_T *spp;
- char *line;
int found_flags = 0;
int found_match_idx = 0;
linenr_T found_current_lnum = 0;
int found_current_col = 0;
lpos_T found_m_endpos;
- colnr_T prev_current_col;
// Clear any current state that might be hanging around.
invalidate_current_state();
@@ -543,14 +536,14 @@ static void syn_sync(win_T *wp, linenr_T start_lnum, synstate_T *last_valid)
if (syn_block->b_syn_sync_flags & SF_CCOMMENT) {
// Need to make syn_buf the current buffer for a moment, to be able to
// use find_start_comment().
- curwin_save = curwin;
+ win_T *curwin_save = curwin;
curwin = wp;
- curbuf_save = curbuf;
+ buf_T *curbuf_save = curbuf;
curbuf = syn_buf;
// Skip lines that end in a backslash.
for (; start_lnum > 1; start_lnum--) {
- line = ml_get(start_lnum - 1);
+ char *line = ml_get(start_lnum - 1);
if (*line == NUL || *(line + strlen(line) - 1) != '\\') {
break;
}
@@ -566,7 +559,7 @@ static void syn_sync(win_T *wp, linenr_T start_lnum, synstate_T *last_valid)
// defines the comment.
// Restrict the search for the end of a comment to b_syn_sync_maxlines.
if (find_start_comment((int)syn_block->b_syn_sync_maxlines) != NULL) {
- for (idx = syn_block->b_syn_patterns.ga_len; --idx >= 0;) {
+ for (int idx = syn_block->b_syn_patterns.ga_len; --idx >= 0;) {
if (SYN_ITEMS(syn_block)[idx].sp_syn.id
== syn_block->b_syn_sync_id
&& SYN_ITEMS(syn_block)[idx].sp_type == SPTYPE_START) {
@@ -593,7 +586,7 @@ static void syn_sync(win_T *wp, linenr_T start_lnum, synstate_T *last_valid)
found_m_endpos.lnum = 0;
found_m_endpos.col = 0;
- end_lnum = start_lnum;
+ linenr_T end_lnum = start_lnum;
lnum = start_lnum;
while (--lnum > break_lnum) {
// This can take a long time: break when CTRL-C pressed.
@@ -621,7 +614,7 @@ static void syn_sync(win_T *wp, linenr_T start_lnum, synstate_T *last_valid)
for (current_lnum = lnum; current_lnum < end_lnum; current_lnum++) {
syn_start_line();
while (true) {
- had_sync_point = syn_finish_line(true);
+ bool had_sync_point = syn_finish_line(true);
// When a sync point has been found, remember where, and
// continue to look for another one, further on in the line.
if (had_sync_point && current_state.ga_len) {
@@ -660,7 +653,7 @@ static void syn_sync(win_T *wp, linenr_T start_lnum, synstate_T *last_valid)
// syn_current_attr() will have skipped the check for
// an item that ends here, need to do that now. Be
// careful not to go past the NUL.
- prev_current_col = current_col;
+ colnr_T prev_current_col = current_col;
if (syn_getcurline()[current_col] != NUL) {
current_col++;
}
@@ -697,7 +690,7 @@ static void syn_sync(win_T *wp, linenr_T start_lnum, synstate_T *last_valid)
}
current_col = found_m_endpos.col;
current_lnum = found_m_endpos.lnum;
- (void)syn_finish_line(false);
+ syn_finish_line(false);
current_lnum++;
} else {
current_lnum = start_lnum;
@@ -1149,7 +1142,7 @@ static synstate_T *store_current_state(void)
// Add a new entry
// If no free items, cleanup the array first.
if (syn_block->b_sst_freecount == 0) {
- (void)syn_stack_cleanup();
+ syn_stack_cleanup();
// "sp" may have been moved to the freelist now
sp = syn_stack_find_entry(current_lnum);
}
@@ -1369,7 +1362,7 @@ bool syntax_check_changed(linenr_T lnum)
if (sp != NULL && sp->sst_lnum == lnum) {
// finish the previous line (needed when not all of the line was
// drawn)
- (void)syn_finish_line(false);
+ syn_finish_line(false);
// Compare the current state with the previously saved state of
// the line.
@@ -1379,7 +1372,7 @@ bool syntax_check_changed(linenr_T lnum)
// Store the current state in b_sst_array[] for later use.
current_lnum++;
- (void)store_current_state();
+ store_current_state();
}
}
@@ -1395,7 +1388,7 @@ bool syntax_check_changed(linenr_T lnum)
static bool syn_finish_line(const bool syncing)
{
while (!current_finished) {
- (void)syn_current_attr(syncing, false, NULL, false);
+ syn_current_attr(syncing, false, NULL, false);
// When syncing, and found some item, need to check the item.
if (syncing && current_state.ga_len) {
@@ -1518,7 +1511,7 @@ static int syn_current_attr(const bool syncing, const bool displaying, bool *con
// If we found a match after the last column, use it.
if (next_match_idx >= 0 && next_match_col >= (int)current_col
&& next_match_col != MAXCOL) {
- (void)push_next_match();
+ push_next_match();
}
current_finished = true;
@@ -2416,8 +2409,8 @@ static void find_endpos(int idx, lpos_T *startpos, lpos_T *m_endpos, lpos_T *hl_
regmatch.rmm_ic = spp->sp_ic;
regmatch.regprog = spp->sp_prog;
- int r = syn_regexec(&regmatch, startpos->lnum, lc_col,
- IF_SYN_TIME(&spp->sp_time));
+ bool r = syn_regexec(&regmatch, startpos->lnum, lc_col,
+ IF_SYN_TIME(&spp->sp_time));
spp->sp_prog = regmatch.regprog;
if (r) {
if (best_idx == -1 || regmatch.startpos[0].col
@@ -2663,7 +2656,7 @@ static char *syn_getcurline(void)
// Call vim_regexec() to find a match with "rmp" in "syn_buf".
// Returns true when there is a match.
-static int syn_regexec(regmmatch_T *rmp, linenr_T lnum, colnr_T col, syn_time_T *st)
+static bool syn_regexec(regmmatch_T *rmp, linenr_T lnum, colnr_T col, syn_time_T *st)
{
int timed_out = 0;
proftime_T pt;
@@ -3367,7 +3360,7 @@ static void syn_list_one(const int id, const bool syncing, const bool link_only)
continue;
}
- (void)syn_list_header(did_header, 0, id, true);
+ syn_list_header(did_header, 0, id, true);
did_header = true;
last_matchgroup = 0;
if (spp->sp_type == SPTYPE_MATCH) {
@@ -3420,7 +3413,7 @@ static void syn_list_one(const int id, const bool syncing, const bool link_only)
// list the link, if there is one
if (highlight_link_id(id - 1) && (did_header || link_only) && !got_int) {
- (void)syn_list_header(did_header, 0, id, true);
+ syn_list_header(did_header, 0, id, true);
msg_puts_attr("links to", attr);
msg_putchar(' ');
msg_outtrans(highlight_group_name(highlight_link_id(id - 1) - 1), 0);
@@ -3642,23 +3635,17 @@ static bool syn_list_keywords(const int id, const hashtab_T *const ht, bool did_
static void syn_clear_keyword(int id, hashtab_T *ht)
{
- hashitem_T *hi;
- keyentry_T *kp;
- keyentry_T *kp_prev;
- keyentry_T *kp_next;
- int todo;
-
hash_lock(ht);
- todo = (int)ht->ht_used;
- for (hi = ht->ht_array; todo > 0; hi++) {
+ int todo = (int)ht->ht_used;
+ for (hashitem_T *hi = ht->ht_array; todo > 0; hi++) {
if (HASHITEM_EMPTY(hi)) {
continue;
}
todo--;
- kp_prev = NULL;
- for (kp = HI2KE(hi); kp != NULL;) {
+ keyentry_T *kp_prev = NULL;
+ for (keyentry_T *kp = HI2KE(hi); kp != NULL;) {
if (kp->k_syn.id == id) {
- kp_next = kp->ke_next;
+ keyentry_T *kp_next = kp->ke_next;
if (kp_prev == NULL) {
if (kp_next == NULL) {
hash_remove(ht, hi);
@@ -3684,16 +3671,13 @@ static void syn_clear_keyword(int id, hashtab_T *ht)
// Clear a whole keyword table.
static void clear_keywtab(hashtab_T *ht)
{
- hashitem_T *hi;
- int todo;
- keyentry_T *kp;
keyentry_T *kp_next;
- todo = (int)ht->ht_used;
- for (hi = ht->ht_array; todo > 0; hi++) {
+ int todo = (int)ht->ht_used;
+ for (hashitem_T *hi = ht->ht_array; todo > 0; hi++) {
if (!HASHITEM_EMPTY(hi)) {
todo--;
- for (kp = HI2KE(hi); kp != NULL; kp = kp_next) {
+ for (keyentry_T *kp = HI2KE(hi); kp != NULL; kp = kp_next) {
kp_next = kp->ke_next;
xfree(kp->next_list);
xfree(kp->k_syn.cont_in_list);
@@ -3789,9 +3773,7 @@ static char *get_group_name(char *arg, char **name_end)
/// Return NULL for any error;
static char *get_syn_options(char *arg, syn_opt_arg_T *opt, int *conceal_char, int skip)
{
- int syn_id;
int len = 0;
- char *p;
int fidx;
static const struct flag {
char *name;
@@ -3835,7 +3817,7 @@ static char *get_syn_options(char *arg, syn_opt_arg_T *opt, int *conceal_char, i
}
for (fidx = ARRAY_SIZE(flagtab); --fidx >= 0;) {
- p = flagtab[fidx].name;
+ char *p = flagtab[fidx].name;
int i;
for (i = 0, len = 0; p[i] != NUL; i += 2, len++) {
if (arg[len] != p[i] && arg[len] != p[i + 1]) {
@@ -3904,7 +3886,7 @@ static char *get_syn_options(char *arg, syn_opt_arg_T *opt, int *conceal_char, i
if (strcmp(gname, "NONE") == 0) {
*opt->sync_idx = NONE_IDX;
} else {
- syn_id = syn_name2id(gname);
+ int syn_id = syn_name2id(gname);
int i;
for (i = curwin->w_s->b_syn_patterns.ga_len; --i >= 0;) {
if (SYN_ITEMS(curwin->w_s)[i].sp_syn.id == syn_id
@@ -3960,10 +3942,7 @@ static void syn_cmd_include(exarg_T *eap, int syncing)
char *arg = eap->arg;
int sgl_id = 1;
char *group_name_end;
- char *rest;
const char *errormsg = NULL;
- int prev_toplvl_grp;
- int prev_syn_inc_tag;
bool source = false;
eap->nextcmd = find_nextcmd(arg);
@@ -3973,7 +3952,7 @@ static void syn_cmd_include(exarg_T *eap, int syncing)
if (arg[0] == '@') {
arg++;
- rest = get_group_name(arg, &group_name_end);
+ char *rest = get_group_name(arg, &group_name_end);
if (rest == NULL) {
emsg(_("E397: Filename required"));
return;
@@ -4009,9 +3988,9 @@ static void syn_cmd_include(exarg_T *eap, int syncing)
emsg(_("E847: Too many syntax includes"));
return;
}
- prev_syn_inc_tag = current_syn_inc_tag;
+ int prev_syn_inc_tag = current_syn_inc_tag;
current_syn_inc_tag = ++running_syn_inc_tag;
- prev_toplvl_grp = curwin->w_s->b_syn_topgrp;
+ int prev_toplvl_grp = curwin->w_s->b_syn_topgrp;
curwin->w_s->b_syn_topgrp = sgl_id;
if (source
? do_source(eap->arg, false, DOSO_NONE, NULL) == FAIL
@@ -4028,15 +4007,11 @@ static void syn_cmd_keyword(exarg_T *eap, int syncing)
char *arg = eap->arg;
char *group_name_end;
int syn_id;
- char *rest;
char *keyword_copy = NULL;
- char *p;
- char *kw;
syn_opt_arg_T syn_opt_arg;
- int cnt;
int conceal_char = NUL;
- rest = get_group_name(arg, &group_name_end);
+ char *rest = get_group_name(arg, &group_name_end);
if (rest != NULL) {
if (eap->skip) {
@@ -4059,8 +4034,8 @@ static void syn_cmd_keyword(exarg_T *eap, int syncing)
// The options given apply to ALL keywords, so all options must be
// found before keywords can be created.
// 1: collect the options and copy the keywords to keyword_copy.
- cnt = 0;
- p = keyword_copy;
+ int cnt = 0;
+ char *p = keyword_copy;
for (; rest != NULL && !ends_excmd(*rest); rest = skipwhite(rest)) {
rest = get_syn_options(rest, &syn_opt_arg, &conceal_char, eap->skip);
if (rest == NULL || ends_excmd(*rest)) {
@@ -4082,7 +4057,7 @@ static void syn_cmd_keyword(exarg_T *eap, int syncing)
syn_incl_toplevel(syn_id, &syn_opt_arg.flags);
// 2: Add an entry for each keyword.
- for (kw = keyword_copy; --cnt >= 0; kw += strlen(kw) + 1) {
+ for (char *kw = keyword_copy; --cnt >= 0; kw += strlen(kw) + 1) {
for (p = vim_strchr(kw, '[');;) {
if (p != NULL) {
*p = NUL;
@@ -4233,7 +4208,6 @@ static void syn_cmd_region(exarg_T *eap, int syncing)
char *rest; // next arg, NULL on error
char *key_end;
char *key = NULL;
- char *p;
int item;
#define ITEM_START 0
#define ITEM_SKIP 1
@@ -4316,7 +4290,7 @@ static void syn_cmd_region(exarg_T *eap, int syncing)
}
if (item == ITEM_MATCHGROUP) {
- p = skiptowhite(rest);
+ char *p = skiptowhite(rest);
if ((p - rest == 4 && strncmp(rest, "NONE", 4) == 0) || eap->skip) {
matchgroup_id = 0;
} else {
@@ -4643,7 +4617,6 @@ static void syn_cmd_cluster(exarg_T *eap, int syncing)
{
char *arg = eap->arg;
char *group_name_end;
- char *rest;
bool got_clstr = false;
int opt_len;
int list_op;
@@ -4653,7 +4626,7 @@ static void syn_cmd_cluster(exarg_T *eap, int syncing)
return;
}
- rest = get_group_name(arg, &group_name_end);
+ char *rest = get_group_name(arg, &group_name_end);
if (rest != NULL) {
int scl_id = syn_check_cluster(arg, (int)(group_name_end - arg));
@@ -4720,7 +4693,6 @@ static void init_syn_patterns(void)
/// @return a pointer to the next argument, or NULL in case of an error.
static char *get_syn_pattern(char *arg, synpat_T *ci)
{
- int *p;
int idx;
// need at least three chars
@@ -4757,7 +4729,7 @@ static char *get_syn_pattern(char *arg, synpat_T *ci)
}
}
if (idx >= 0) {
- p = &(ci->sp_offsets[idx]);
+ int *p = &(ci->sp_offsets[idx]);
if (idx != SPO_LC_OFF) {
switch (end[3]) {
case 's':
@@ -5123,10 +5095,8 @@ static int16_t *copy_id_list(const int16_t *const list)
static int in_id_list(stateitem_T *cur_si, int16_t *list, struct sp_syn *ssp, int contained)
{
int retval;
- int16_t *scl_list;
int16_t id = ssp->id;
static int depth = 0;
- int r;
// If ssp has a "containedin" list and "cur_si" is in it, return true.
if (cur_si != NULL && ssp->cont_in_list != NULL
@@ -5189,12 +5159,12 @@ static int in_id_list(stateitem_T *cur_si, int16_t *list, struct sp_syn *ssp, in
return retval;
}
if (item >= SYNID_CLUSTER) {
- scl_list = SYN_CLSTR(syn_block)[item - SYNID_CLUSTER].scl_list;
+ int16_t *scl_list = SYN_CLSTR(syn_block)[item - SYNID_CLUSTER].scl_list;
// restrict recursiveness to 30 to avoid an endless loop for a
// cluster that includes itself (indirectly)
if (scl_list != NULL && depth < 30) {
depth++;
- r = in_id_list(NULL, scl_list, ssp, contained);
+ int r = in_id_list(NULL, scl_list, ssp, contained);
depth--;
if (r) {
return retval;
@@ -5437,7 +5407,7 @@ int syn_get_id(win_T *wp, linenr_T lnum, colnr_T col, int trans, bool *spellp, i
next_match_idx = -1;
}
- (void)get_syntax_attr(col, spellp, keep_state);
+ get_syntax_attr(col, spellp, keep_state);
return trans ? current_trans_id : current_id;
}
@@ -5459,7 +5429,7 @@ int syn_get_concealed_id(win_T *wp, linenr_T lnum, colnr_T col)
{
int seqnr;
- (void)syn_get_id(wp, lnum, col, false, NULL, false);
+ syn_get_id(wp, lnum, col, false, NULL, false);
int syntax_flags = get_syntax_info(&seqnr);
if (syntax_flags & HL_CONCEAL) {
@@ -5519,7 +5489,7 @@ int syn_get_foldlevel(win_T *wp, linenr_T lnum)
int cur_level = level;
int low_level = cur_level;
while (!current_finished) {
- (void)syn_current_attr(false, false, NULL, false);
+ syn_current_attr(false, false, NULL, false);
cur_level = syn_cur_foldlevel();
if (cur_level < low_level) {
low_level = cur_level;