aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrej Zieger <jerdna-regeiz@users.noreply.github.com>2019-05-26 17:06:50 +0200
committerAndrej Zieger <jerdna-regeiz@users.noreply.github.com>2019-05-26 19:32:32 +0200
commit80f40f0203f5af167f8c77bf6b9f22a4d1abd6da (patch)
tree3fd67d3bca8a4dfb144ca27cf68c117050e28073 /src
parent0b9e57aca1ec12f35c2a2531be9769eff076c6b2 (diff)
downloadrneovim-80f40f0203f5af167f8c77bf6b9f22a4d1abd6da.tar.gz
rneovim-80f40f0203f5af167f8c77bf6b9f22a4d1abd6da.tar.bz2
rneovim-80f40f0203f5af167f8c77bf6b9f22a4d1abd6da.zip
lint
Diffstat (limited to 'src')
-rw-r--r--src/nvim/buffer.c6
-rw-r--r--src/nvim/buffer_defs.h28
-rw-r--r--src/nvim/edit.c11
-rw-r--r--src/nvim/eval.c439
-rw-r--r--src/nvim/fileio.c92
-rw-r--r--src/nvim/globals.h2
-rw-r--r--src/nvim/if_cscope.c23
-rw-r--r--src/nvim/mbyte.c38
-rw-r--r--src/nvim/memline.c57
-rw-r--r--src/nvim/message.c55
-rw-r--r--src/nvim/normal.c8
-rw-r--r--src/nvim/search.c14
-rw-r--r--src/nvim/sign.c1411
-rw-r--r--src/nvim/sign.h3
-rw-r--r--src/nvim/sign_defs.h25
15 files changed, 1033 insertions, 1179 deletions
diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c
index 39242b0575..078d4fe782 100644
--- a/src/nvim/buffer.c
+++ b/src/nvim/buffer.c
@@ -805,9 +805,9 @@ free_buffer_stuff(
vars_clear(&buf->b_vars->dv_hashtab); // free all internal variables
hash_init(&buf->b_vars->dv_hashtab);
buf_init_changedtick(buf);
- uc_clear(&buf->b_ucmds); // clear local user commands
- buf_delete_signs(buf, (char_u *)"*"); // delete any signs
- bufhl_clear_all(buf); // delete any highligts
+ uc_clear(&buf->b_ucmds); // clear local user commands
+ buf_delete_signs(buf, (char_u *)"*"); // delete any signs
+ bufhl_clear_all(buf); // delete any highligts
map_clear_int(buf, MAP_ALL_MODES, true, false); // clear local mappings
map_clear_int(buf, MAP_ALL_MODES, true, true); // clear local abbrevs
XFREE_CLEAR(buf->b_start_fenc);
diff --git a/src/nvim/buffer_defs.h b/src/nvim/buffer_defs.h
index 5e28a7b513..255aeb82b6 100644
--- a/src/nvim/buffer_defs.h
+++ b/src/nvim/buffer_defs.h
@@ -769,15 +769,15 @@ struct file_buffer {
* spell buffer - used for spell info, never displayed and doesn't have a
* file name.
*/
- bool b_help; /* TRUE for help file buffer (when set b_p_bt
- is "help") */
- bool b_spell; /* True for a spell file buffer, most fields
- are not used! Use the B_SPELL macro to
- access b_spell without #ifdef. */
+ bool b_help; // TRUE for help file buffer (when set b_p_bt
+ // is "help")
+ bool b_spell; // True for a spell file buffer, most fields
+ // are not used! Use the B_SPELL macro to
+ // access b_spell without #ifdef.
- synblock_T b_s; /* Info related to syntax highlighting. w_s
- * normally points to this, but some windows
- * may use a different synblock_T. */
+ synblock_T b_s; // Info related to syntax highlighting. w_s
+ // normally points to this, but some windows
+ // may use a different synblock_T.
signlist_T *b_signlist; // list of signs to draw
int b_signcols_max; // cached maximum number of sign columns
@@ -1144,12 +1144,12 @@ struct window_S {
int w_cline_row; /* starting row of the cursor line */
- colnr_T w_virtcol; /* column number of the cursor in the
- buffer line, as opposed to the column
- number we're at on the screen. This
- makes a difference on lines which span
- more than one screen line or when
- w_leftcol is non-zero */
+ colnr_T w_virtcol; // column number of the cursor in the
+ // buffer line, as opposed to the column
+ // number we're at on the screen. This
+ // makes a difference on lines which span
+ // more than one screen line or when
+ // w_leftcol is non-zero
/*
* w_wrow and w_wcol specify the cursor position in the window.
diff --git a/src/nvim/edit.c b/src/nvim/edit.c
index a8dd115074..bfd63aab7a 100644
--- a/src/nvim/edit.c
+++ b/src/nvim/edit.c
@@ -179,9 +179,9 @@ static int compl_no_insert = FALSE; /* FALSE: select & insert
static int compl_no_select = FALSE; /* FALSE: select & insert
TRUE: noselect */
-static int compl_used_match; /* Selected one of the matches. When
- FALSE the match was edited or using
- the longest common string. */
+static int compl_used_match; // Selected one of the matches. When
+ // FALSE the match was edited or using
+ // the longest common string.
static int compl_was_interrupted = FALSE; /* didn't finish finding
completions. */
@@ -2599,8 +2599,9 @@ void ins_compl_show_pum(void)
do {
if ((compl->cp_flags & ORIGINAL_TEXT) == 0
&& (compl_leader == NULL
- || ins_compl_equal(compl, compl_leader, lead_len)))
- ++compl_match_arraysize;
+ || ins_compl_equal(compl, compl_leader, lead_len))) {
+ compl_match_arraysize++;
+ }
compl = compl->cp_next;
} while (compl != NULL && compl != compl_first_match);
if (compl_match_arraysize == 0)
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index dded1a07f3..1d15e04218 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -1114,22 +1114,17 @@ static void restore_vimvar(int idx, typval_T *save_tv)
}
}
-/*
- * If there is a window for "curbuf", make it the current window.
- */
- static void
-find_win_for_curbuf(void)
+/// If there is a window for "curbuf", make it the current window.
+static void find_win_for_curbuf(void)
{
- wininfo_T *wip;
+ wininfo_T *wip;
- for (wip = curbuf->b_wininfo; wip != NULL; wip = wip->wi_next)
- {
- if (wip->wi_win != NULL)
- {
- curwin = wip->wi_win;
- break;
- }
+ for (wip = curbuf->b_wininfo; wip != NULL; wip = wip->wi_next) {
+ if (wip->wi_win != NULL) {
+ curwin = wip->wi_win;
+ break;
}
+ }
}
/*
@@ -1144,7 +1139,7 @@ list_T *eval_spell_expr(char_u *badword, char_u *expr)
list_T *list = NULL;
char_u *p = skipwhite(expr);
- /* Set "v:val" to the bad word. */
+ // Set "v:val" to the bad word.
prepare_vimvar(VV_VAL, &save_val);
vimvars[VV_VAL].vv_type = VAR_STRING;
vimvars[VV_VAL].vv_str = badword;
@@ -7202,7 +7197,7 @@ static buf_T *tv_get_buf(typval_T *tv, int curtab_only)
if (name[0] == '$' && name[1] == NUL)
return lastbuf;
- /* Ignore 'magic' and 'cpoptions' here to make scripts portable */
+ // Ignore 'magic' and 'cpoptions' here to make scripts portable
save_magic = p_magic;
p_magic = TRUE;
save_cpo = p_cpo;
@@ -7214,28 +7209,27 @@ static buf_T *tv_get_buf(typval_T *tv, int curtab_only)
p_magic = save_magic;
p_cpo = save_cpo;
- /* If not found, try expanding the name, like done for bufexists(). */
- if (buf == NULL)
+ // If not found, try expanding the name, like done for bufexists().
+ if (buf == NULL) {
buf = find_buffer(tv);
+ }
return buf;
}
-/*
- * Get the buffer from "arg" and give an error and return NULL if it is not
- * valid.
- */
- static buf_T *
-get_buf_arg(typval_T *arg)
+/// Get the buffer from "arg" and give an error and return NULL if it is not
+/// valid.
+static buf_T * get_buf_arg(typval_T *arg)
{
- buf_T *buf;
+ buf_T *buf;
- ++emsg_off;
- buf = tv_get_buf(arg, FALSE);
- --emsg_off;
- if (buf == NULL)
- EMSG2(_("E158: Invalid buffer name: %s"), tv_get_string(arg));
- return buf;
+ emsg_off++;
+ buf = tv_get_buf(arg, false);
+ emsg_off--;
+ if (buf == NULL) {
+ EMSG2(_("E158: Invalid buffer name: %s"), tv_get_string(arg));
+ }
+ return buf;
}
/*
@@ -8035,87 +8029,83 @@ static void f_dictwatcherdel(typval_T *argvars, typval_T *rettv, FunPtr fptr)
callback_free(&callback);
}
-/*
- * "deletebufline()" function
- */
- static void
-f_deletebufline(typval_T *argvars, typval_T *rettv, FunPtr fptr)
+/// "deletebufline()" function
+static void f_deletebufline(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
- buf_T *buf;
- linenr_T first, last;
- linenr_T lnum;
- long count;
- int is_curbuf;
- buf_T *curbuf_save = NULL;
- win_T *curwin_save = NULL;
+ buf_T *buf;
+ linenr_T first, last;
+ linenr_T lnum;
+ long count;
+ int is_curbuf;
+ buf_T *curbuf_save = NULL;
+ win_T *curwin_save = NULL;
- buf = tv_get_buf(&argvars[0], FALSE);
- if (buf == NULL)
- {
- rettv->vval.v_number = 1; /* FAIL */
- return;
- }
- is_curbuf = buf == curbuf;
+ buf = tv_get_buf(&argvars[0], false);
+ if (buf == NULL) {
+ rettv->vval.v_number = 1; // FAIL
+ return;
+ }
+ is_curbuf = buf == curbuf;
- first = tv_get_lnum_buf(&argvars[1], buf);
- if (argvars[2].v_type != VAR_UNKNOWN)
- last = tv_get_lnum_buf(&argvars[2], buf);
- else
- last = first;
+ first = tv_get_lnum_buf(&argvars[1], buf);
+ if (argvars[2].v_type != VAR_UNKNOWN) {
+ last = tv_get_lnum_buf(&argvars[2], buf);
+ } else {
+ last = first;
+ }
- if (buf->b_ml.ml_mfp == NULL || first < 1
- || first > buf->b_ml.ml_line_count || last < first)
- {
- rettv->vval.v_number = 1; /* FAIL */
- return;
- }
+ if (buf->b_ml.ml_mfp == NULL || first < 1
+ || first > buf->b_ml.ml_line_count || last < first) {
+ rettv->vval.v_number = 1; // FAIL
+ return;
+ }
- if (!is_curbuf)
- {
- curbuf_save = curbuf;
- curwin_save = curwin;
- curbuf = buf;
- find_win_for_curbuf();
- }
- if (last > curbuf->b_ml.ml_line_count)
- last = curbuf->b_ml.ml_line_count;
- count = last - first + 1;
-
- // When coming here from Insert mode, sync undo, so that this can be
- // undone separately from what was previously inserted.
- if (u_sync_once == 2)
- {
- u_sync_once = 1; // notify that u_sync() was called
- u_sync(TRUE);
- }
+ if (!is_curbuf) {
+ curbuf_save = curbuf;
+ curwin_save = curwin;
+ curbuf = buf;
+ find_win_for_curbuf();
+ }
+ if (last > curbuf->b_ml.ml_line_count) {
+ last = curbuf->b_ml.ml_line_count;
+ }
+ count = last - first + 1;
- if (u_save(first - 1, last + 1) == FAIL)
- {
- rettv->vval.v_number = 1; /* FAIL */
- return;
- }
-
- for (lnum = first; lnum <= last; ++lnum)
- ml_delete(first, TRUE);
-
- FOR_ALL_TAB_WINDOWS(tp, wp)
- if (wp->w_buffer == buf)
- {
- if (wp->w_cursor.lnum > last)
- wp->w_cursor.lnum -= count;
- else if (wp->w_cursor.lnum> first)
- wp->w_cursor.lnum = first;
- if (wp->w_cursor.lnum > wp->w_buffer->b_ml.ml_line_count)
- wp->w_cursor.lnum = wp->w_buffer->b_ml.ml_line_count;
- }
- check_cursor_col();
- deleted_lines_mark(first, count);
-
- if (!is_curbuf)
- {
- curbuf = curbuf_save;
- curwin = curwin_save;
+ // When coming here from Insert mode, sync undo, so that this can be
+ // undone separately from what was previously inserted.
+ if (u_sync_once == 2) {
+ u_sync_once = 1; // notify that u_sync() was called
+ u_sync(true);
+ }
+
+ if (u_save(first - 1, last + 1) == FAIL) {
+ rettv->vval.v_number = 1; // FAIL
+ return;
+ }
+
+ for (lnum = first; lnum <= last; lnum++) {
+ ml_delete(first, true);
+ }
+
+ FOR_ALL_TAB_WINDOWS(tp, wp) {
+ if (wp->w_buffer == buf) {
+ if (wp->w_cursor.lnum > last) {
+ wp->w_cursor.lnum -= count;
+ } else if (wp->w_cursor.lnum> first) {
+ wp->w_cursor.lnum = first;
+ }
+ if (wp->w_cursor.lnum > wp->w_buffer->b_ml.ml_line_count) {
+ wp->w_cursor.lnum = wp->w_buffer->b_ml.ml_line_count;
+ }
}
+ }
+ check_cursor_col();
+ deleted_lines_mark(first, count);
+
+ if (!is_curbuf) {
+ curbuf = curbuf_save;
+ curwin = curwin_save;
+ }
}
/*
@@ -15539,92 +15529,89 @@ static void f_shiftwidth(typval_T *argvars, typval_T *rettv, FunPtr fptr)
rettv->vval.v_number = get_sw_value(curbuf);
}
-/*
- * "sign_define()" function
- */
+/// "sign_define()" function
static void f_sign_define(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
- const char *name;
- dict_T *dict;
- char *icon = NULL;
- char *linehl = NULL;
- char *text = NULL;
- char *texthl = NULL;
- char *numhl = NULL;
+ const char *name;
+ dict_T *dict;
+ char *icon = NULL;
+ char *linehl = NULL;
+ char *text = NULL;
+ char *texthl = NULL;
+ char *numhl = NULL;
- rettv->vval.v_number = -1;
+ rettv->vval.v_number = -1;
- name = tv_get_string_chk(&argvars[0]);
- if (name == NULL)
- return;
+ name = tv_get_string_chk(&argvars[0]);
+ if (name == NULL) {
+ return;
+ }
- if (argvars[1].v_type != VAR_UNKNOWN)
- {
- if (argvars[1].v_type != VAR_DICT)
- {
- EMSG(_(e_dictreq));
- return;
- }
-
- // sign attributes
- dict = argvars[1].vval.v_dict;
- if (tv_dict_find(dict, "icon", -1) != NULL)
- icon = tv_dict_get_string(dict, "icon", TRUE);
- if (tv_dict_find(dict, "linehl", -1) != NULL)
- linehl = tv_dict_get_string(dict, "linehl", TRUE);
- if (tv_dict_find(dict, "text", -1) != NULL)
- text = tv_dict_get_string(dict, "text", TRUE);
- if (tv_dict_find(dict, "texthl", -1) != NULL)
- texthl = tv_dict_get_string(dict, "texthl", TRUE);
- if (tv_dict_find(dict, "numhl", -1) != NULL)
- numhl = tv_dict_get_string(dict, "numhl", TRUE);
- }
-
- if (sign_define_by_name((char_u *)name, (char_u *)icon, (char_u *)linehl,
- (char_u *)text, (char_u *)texthl, (char_u *)numhl)
- == OK) {
- rettv->vval.v_number = 0;
+ if (argvars[1].v_type != VAR_UNKNOWN) {
+ if (argvars[1].v_type != VAR_DICT) {
+ EMSG(_(e_dictreq));
+ return;
+ }
+
+ // sign attributes
+ dict = argvars[1].vval.v_dict;
+ if (tv_dict_find(dict, "icon", -1) != NULL) {
+ icon = tv_dict_get_string(dict, "icon", true);
+ }
+ if (tv_dict_find(dict, "linehl", -1) != NULL) {
+ linehl = tv_dict_get_string(dict, "linehl", true);
+ }
+ if (tv_dict_find(dict, "text", -1) != NULL) {
+ text = tv_dict_get_string(dict, "text", true);
+ }
+ if (tv_dict_find(dict, "texthl", -1) != NULL) {
+ texthl = tv_dict_get_string(dict, "texthl", true);
+ }
+ if (tv_dict_find(dict, "numhl", -1) != NULL) {
+ numhl = tv_dict_get_string(dict, "numhl", true);
}
+ }
+
+ if (sign_define_by_name((char_u *)name, (char_u *)icon, (char_u *)linehl,
+ (char_u *)text, (char_u *)texthl, (char_u *)numhl)
+ == OK) {
+ rettv->vval.v_number = 0;
+ }
- xfree(icon);
- xfree(linehl);
- xfree(text);
- xfree(texthl);
+ xfree(icon);
+ xfree(linehl);
+ xfree(text);
+ xfree(texthl);
}
-/*
- * "sign_getdefined()" function
- */
- static void
-f_sign_getdefined(typval_T *argvars, typval_T *rettv, FunPtr fptr)
+/// "sign_getdefined()" function
+static void f_sign_getdefined(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
- const char *name = NULL;
+ const char *name = NULL;
- tv_list_alloc_ret(rettv, 0);
+ tv_list_alloc_ret(rettv, 0);
- if (argvars[0].v_type != VAR_UNKNOWN)
- name = tv_get_string(&argvars[0]);
+ if (argvars[0].v_type != VAR_UNKNOWN) {
+ name = tv_get_string(&argvars[0]);
+ }
- sign_getlist((const char_u *)name, rettv->vval.v_list);
+ sign_getlist((const char_u *)name, rettv->vval.v_list);
}
-/*
- * "sign_getplaced()" function
- */
+/// "sign_getplaced()" function
static void f_sign_getplaced(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
- buf_T *buf = NULL;
- dict_T *dict;
- dictitem_T *di;
- linenr_T lnum = 0;
+ buf_T *buf = NULL;
+ dict_T *dict;
+ dictitem_T *di;
+ linenr_T lnum = 0;
int sign_id = 0;
const char *group = NULL;
- bool notanum = FALSE;
+ bool notanum = false;
tv_list_alloc_ret(rettv, 0);
- if (argvars[0].v_type != VAR_UNKNOWN)
- {
+ if (argvars[0].v_type != VAR_UNKNOWN) {
// get signs placed in the specified buffer
buf = get_buf_arg(&argvars[0]);
if (buf == NULL) {
@@ -15632,8 +15619,8 @@ static void f_sign_getplaced(typval_T *argvars, typval_T *rettv, FunPtr fptr)
}
if (argvars[1].v_type != VAR_UNKNOWN) {
- if (argvars[1].v_type != VAR_DICT ||
- ((dict = argvars[1].vval.v_dict) == NULL)) {
+ if (argvars[1].v_type != VAR_DICT
+ || ((dict = argvars[1].vval.v_dict) == NULL)) {
EMSG(_(e_dictreq));
return;
}
@@ -15652,30 +15639,29 @@ static void f_sign_getplaced(typval_T *argvars, typval_T *rettv, FunPtr fptr)
return;
}
}
- if ((di = tv_dict_find(dict, "group", -1)) != NULL)
- {
+ if ((di = tv_dict_find(dict, "group", -1)) != NULL) {
group = tv_get_string_chk(&di->di_tv);
- if (group == NULL)
+ if (group == NULL) {
return;
- if (*group == '\0') // empty string means global group
+ }
+ if (*group == '\0') { // empty string means global group
group = NULL;
+ }
}
}
}
- sign_get_placed(buf, lnum, sign_id, (const char_u*)group, rettv->vval.v_list);
+ sign_get_placed(buf, lnum, sign_id, (const char_u *)group,
+ rettv->vval.v_list);
}
-/*
- * "sign_jump()" function
- */
- static void
-f_sign_jump(typval_T *argvars, typval_T *rettv, FunPtr fptr)
+/// "sign_jump()" function
+static void f_sign_jump(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
- int sign_id;
+ int sign_id;
char *sign_group = NULL;
buf_T *buf;
- bool notanum = FALSE;
+ bool notanum = false;
rettv->vval.v_number = -1;
@@ -15684,18 +15670,18 @@ f_sign_jump(typval_T *argvars, typval_T *rettv, FunPtr fptr)
if (notanum) {
return;
}
- if (sign_id <= 0)
- {
+ if (sign_id <= 0) {
EMSG(_(e_invarg));
return;
}
// Sign group
- const char* sign_group_chk = tv_get_string_chk(&argvars[1]);
- if (sign_group_chk == NULL)
+ const char * sign_group_chk = tv_get_string_chk(&argvars[1]);
+ if (sign_group_chk == NULL) {
return;
+ }
if (sign_group_chk[0] == '\0') {
- sign_group = NULL; // global sign group
+ sign_group = NULL; // global sign group
} else {
sign_group = xstrdup(sign_group_chk);
if (sign_group == NULL) {
@@ -15705,18 +15691,17 @@ f_sign_jump(typval_T *argvars, typval_T *rettv, FunPtr fptr)
// Buffer to place the sign
buf = get_buf_arg(&argvars[2]);
- if (buf == NULL)
+ if (buf == NULL) {
goto cleanup;
+ }
- rettv->vval.v_number = sign_jump(sign_id, (char_u*)sign_group, buf);
+ rettv->vval.v_number = sign_jump(sign_id, (char_u *)sign_group, buf);
cleanup:
xfree(sign_group);
}
-/*
- * "sign_place()" function
- */
+/// "sign_place()" function
static void f_sign_place(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
int sign_id;
@@ -15727,7 +15712,7 @@ static void f_sign_place(typval_T *argvars, typval_T *rettv, FunPtr fptr)
dictitem_T *di;
linenr_T lnum = 0;
int prio = SIGN_DEF_PRIO;
- bool notanum = FALSE;
+ bool notanum = false;
rettv->vval.v_number = -1;
@@ -15747,9 +15732,9 @@ static void f_sign_place(typval_T *argvars, typval_T *rettv, FunPtr fptr)
return;
}
if (group_chk[0] == '\0') {
- group = NULL; // global sign group
+ group = NULL; // global sign group
} else {
- group = vim_strsave((const char_u*)group_chk);
+ group = vim_strsave((const char_u *)group_chk);
if (group == NULL) {
return;
}
@@ -15768,8 +15753,8 @@ static void f_sign_place(typval_T *argvars, typval_T *rettv, FunPtr fptr)
}
if (argvars[4].v_type != VAR_UNKNOWN) {
- if (argvars[4].v_type != VAR_DICT ||
- ((dict = argvars[4].vval.v_dict) == NULL)) {
+ if (argvars[4].v_type != VAR_DICT
+ || ((dict = argvars[4].vval.v_dict) == NULL)) {
EMSG(_(e_dictreq));
goto cleanup;
}
@@ -15791,7 +15776,8 @@ static void f_sign_place(typval_T *argvars, typval_T *rettv, FunPtr fptr)
}
}
- if (sign_place(&sign_id, group, (const char_u*)sign_name, buf, lnum, prio) == OK) {
+ if (sign_place(&sign_id, group, (const char_u *)sign_name, buf, lnum, prio)
+ == OK) {
rettv->vval.v_number = sign_id;
}
@@ -15799,86 +15785,75 @@ cleanup:
xfree(group);
}
-/*
- * "sign_undefine()" function
- */
- static void
-f_sign_undefine(typval_T *argvars, typval_T *rettv, FunPtr fptr)
+/// "sign_undefine()" function
+static void f_sign_undefine(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
const char *name;
rettv->vval.v_number = -1;
- if (argvars[0].v_type == VAR_UNKNOWN)
- {
+ if (argvars[0].v_type == VAR_UNKNOWN) {
// Free all the signs
free_signs();
rettv->vval.v_number = 0;
- }
- else
- {
+ } else {
// Free only the specified sign
name = tv_get_string_chk(&argvars[0]);
- if (name == NULL)
+ if (name == NULL) {
return;
+ }
- if (sign_undefine_by_name((const char_u*)name) == OK) {
+ if (sign_undefine_by_name((const char_u *)name) == OK) {
rettv->vval.v_number = 0;
}
}
}
-/*
- * "sign_unplace()" function
- */
+/// "sign_unplace()" function
static void f_sign_unplace(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
- dict_T *dict;
- dictitem_T *di;
- int sign_id = 0;
- buf_T *buf = NULL;
- char_u *group = NULL;
+ dict_T *dict;
+ dictitem_T *di;
+ int sign_id = 0;
+ buf_T *buf = NULL;
+ char_u *group = NULL;
rettv->vval.v_number = -1;
- if (argvars[0].v_type != VAR_STRING)
- {
+ if (argvars[0].v_type != VAR_STRING) {
EMSG(_(e_invarg));
return;
}
- const char* group_chk = tv_get_string(&argvars[0]);
+ const char *group_chk = tv_get_string(&argvars[0]);
if (group_chk[0] == '\0') {
- group = NULL; // global sign group
+ group = NULL; // global sign group
} else {
- group = vim_strsave((const char_u*)group_chk);
+ group = vim_strsave((const char_u *)group_chk);
if (group == NULL) {
return;
}
}
- if (argvars[1].v_type != VAR_UNKNOWN)
- {
- if (argvars[1].v_type != VAR_DICT)
- {
+ if (argvars[1].v_type != VAR_UNKNOWN) {
+ if (argvars[1].v_type != VAR_DICT) {
EMSG(_(e_dictreq));
goto cleanup;
}
dict = argvars[1].vval.v_dict;
- if ((di = tv_dict_find(dict, "buffer", -1)) != NULL)
- {
+ if ((di = tv_dict_find(dict, "buffer", -1)) != NULL) {
buf = get_buf_arg(&di->di_tv);
- if (buf == NULL)
+ if (buf == NULL) {
goto cleanup;
+ }
}
if (tv_dict_find(dict, "id", -1) != NULL) {
sign_id = tv_dict_get_number(dict, "id");
}
}
- if (buf == NULL)
- {
+ if (buf == NULL) {
// Delete the sign in all the buffers
FOR_ALL_BUFFERS(cbuf) {
if (sign_unplace(sign_id, group, cbuf, 0) == OK) {
diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c
index 3c45a1ad2e..f97ae8778d 100644
--- a/src/nvim/fileio.c
+++ b/src/nvim/fileio.c
@@ -2833,13 +2833,12 @@ buf_write (
//
XFREE_CLEAR(backup); // no backup file to delete
} else if (!p_bk) {
- /*
- * We are not going to keep the backup file, so don't
- * delete an existing one, and try to use another name instead.
- * Change one character, just before the extension.
- */
+ // We are not going to keep the backup file, so don't
+ // delete an existing one, and try to use another name instead.
+ // Change one character, just before the extension.
+ //
wp = backup + STRLEN(backup) - 1 - STRLEN(backup_ext);
- if (wp < backup) { /* empty file name ??? */
+ if (wp < backup) { // empty file name ???
wp = backup;
}
*wp = 'z';
@@ -2847,7 +2846,7 @@ buf_write (
&& os_fileinfo((char *)backup, &file_info_new)) {
--*wp;
}
- /* They all exist??? Must be something wrong. */
+ // They all exist??? Must be something wrong.
if (*wp == 'a') {
XFREE_CLEAR(backup);
}
@@ -2969,18 +2968,17 @@ nobackup:
}
}
if (backup != NULL) {
- /*
- * Delete any existing backup and move the current version
- * to the backup. For safety, we don't remove the backup
- * until the write has finished successfully. And if the
- * 'backup' option is set, leave it around.
- */
- /*
- * If the renaming of the original file to the backup file
- * works, quit here.
- */
- if (vim_rename(fname, backup) == 0)
+ // Delete any existing backup and move the current version
+ // to the backup. For safety, we don't remove the backup
+ // until the write has finished successfully. And if the
+ // 'backup' option is set, leave it around.
+
+ // If the renaming of the original file to the backup file
+ // works, quit here.
+ ///
+ if (vim_rename(fname, backup) == 0) {
break;
+ }
XFREE_CLEAR(backup); // don't do the rename below
}
@@ -2993,7 +2991,7 @@ nobackup:
}
#if defined(UNIX)
- /* When using ":w!" and the file was read-only: make it writable */
+ // When using ":w!" and the file was read-only: make it writable
if (forceit && perm >= 0 && !(perm & 0200)
&& file_info_old.stat.st_uid == getuid()
&& vim_strchr(p_cpo, CPO_FWRITE) == NULL) {
@@ -3003,12 +3001,12 @@ nobackup:
}
#endif
- /* When using ":w!" and writing to the current file, 'readonly' makes no
- * sense, reset it, unless 'Z' appears in 'cpoptions'. */
+ // When using ":w!" and writing to the current file, 'readonly' makes no
+ // sense, reset it, unless 'Z' appears in 'cpoptions'.
if (forceit && overwriting && vim_strchr(p_cpo, CPO_KEEPRO) == NULL) {
- buf->b_p_ro = FALSE;
- need_maketitle = TRUE; /* set window title later */
- status_redraw_all(); /* redraw status lines later */
+ buf->b_p_ro = false;
+ need_maketitle = true; // set window title later
+ status_redraw_all(); // redraw status lines later
}
if (end > buf->b_ml.ml_line_count)
@@ -3016,13 +3014,11 @@ nobackup:
if (buf->b_ml.ml_flags & ML_EMPTY)
start = end + 1;
- /*
- * If the original file is being overwritten, there is a small chance that
- * we crash in the middle of writing. Therefore the file is preserved now.
- * This makes all block numbers positive so that recovery does not need
- * the original file.
- * Don't do this if there is a backup file and we are exiting.
- */
+ // If the original file is being overwritten, there is a small chance that
+ // we crash in the middle of writing. Therefore the file is preserved now.
+ // This makes all block numbers positive so that recovery does not need
+ // the original file.
+ // Don't do this if there is a backup file and we are exiting.
if (reset_changed && !newfile && overwriting
&& !(exiting && backup != NULL)) {
ml_preserve(buf, false, !!p_fs);
@@ -3033,36 +3029,34 @@ nobackup:
}
- /* Default: write the file directly. May write to a temp file for
- * multi-byte conversion. */
+ // Default: write the file directly. May write to a temp file for
+ // multi-byte conversion.
wfname = fname;
- /* Check for forced 'fileencoding' from "++opt=val" argument. */
+ // Check for forced 'fileencoding' from "++opt=val" argument.
if (eap != NULL && eap->force_enc != 0) {
fenc = eap->cmd + eap->force_enc;
fenc = enc_canonize(fenc);
fenc_tofree = fenc;
- } else
+ } else {
fenc = buf->b_p_fenc;
+ }
- /*
- * Check if the file needs to be converted.
- */
+ // Check if the file needs to be converted.
converted = need_conversion(fenc);
- /*
- * Check if UTF-8 to UCS-2/4 or Latin1 conversion needs to be done. Or
- * Latin1 to Unicode conversion. This is handled in buf_write_bytes().
- * Prepare the flags for it and allocate bw_conv_buf when needed.
- */
+ // Check if UTF-8 to UCS-2/4 or Latin1 conversion needs to be done. Or
+ // Latin1 to Unicode conversion. This is handled in buf_write_bytes().
+ // Prepare the flags for it and allocate bw_conv_buf when needed.
if (converted && (enc_utf8 || STRCMP(p_enc, "latin1") == 0)) {
wb_flags = get_fio_flags(fenc);
if (wb_flags & (FIO_UCS2 | FIO_UCS4 | FIO_UTF16 | FIO_UTF8)) {
- /* Need to allocate a buffer to translate into. */
- if (wb_flags & (FIO_UCS2 | FIO_UTF16 | FIO_UTF8))
+ // Need to allocate a buffer to translate into.
+ if (wb_flags & (FIO_UCS2 | FIO_UTF16 | FIO_UTF8)) {
write_info.bw_conv_buflen = bufsize * 2;
- else /* FIO_UCS4 */
+ } else { // FIO_UCS4
write_info.bw_conv_buflen = bufsize * 4;
+ }
write_info.bw_conv_buf = verbose_try_malloc(write_info.bw_conv_buflen);
if (!write_info.bw_conv_buf) {
end = 0;
@@ -3074,10 +3068,8 @@ nobackup:
if (converted && wb_flags == 0) {
# ifdef USE_ICONV
- /*
- * Use iconv() conversion when conversion is needed and it's not done
- * internally.
- */
+ // Use iconv() conversion when conversion is needed and it's not done
+ // internally.
write_info.bw_iconv_fd = (iconv_t)my_iconv_open(fenc,
enc_utf8 ? (char_u *)"utf-8" : p_enc);
if (write_info.bw_iconv_fd != (iconv_t)-1) {
diff --git a/src/nvim/globals.h b/src/nvim/globals.h
index 8a6f0accda..3597467766 100644
--- a/src/nvim/globals.h
+++ b/src/nvim/globals.h
@@ -484,7 +484,7 @@ EXTERN buf_T *curbuf INIT(= NULL); // currently active buffer
// Iterate through all the signs placed in a buffer
#define FOR_ALL_SIGNS_IN_BUF(buf, sign) \
- for (sign = buf->b_signlist; sign != NULL; sign = sign->next)
+ for (sign = buf->b_signlist; sign != NULL; sign = sign->next) // NOLINT
/*
diff --git a/src/nvim/if_cscope.c b/src/nvim/if_cscope.c
index 84721ee96c..a3eabed8a0 100644
--- a/src/nvim/if_cscope.c
+++ b/src/nvim/if_cscope.c
@@ -1524,12 +1524,10 @@ static void cs_fill_results(char *tagstr, size_t totmatches, int *nummatches_a,
}
totsofar++;
-
- } /* for all matches */
+ } // for all matches
(void)cs_read_prompt(i);
-
- } /* for all cscope connections */
+ } // for all cscope connections
if (totsofar == 0) {
// No matches, free the arrays and return NULL in "*matches_p".
@@ -1541,20 +1539,25 @@ static void cs_fill_results(char *tagstr, size_t totmatches, int *nummatches_a,
*cntxts_p = cntxts;
xfree(buf);
-} /* cs_fill_results */
+} // cs_fill_results
/* get the requested path components */
static char *cs_pathcomponents(char *path)
{
- if (p_cspc == 0)
+ if (p_cspc == 0) {
return path;
+ }
char *s = path + strlen(path) - 1;
- for (int i = 0; i < p_cspc; ++i)
- while (s > path && *--s != '/') continue;
- if ((s > path && *s == '/'))
- ++s;
+ for (int i = 0; i < p_cspc; i++) {
+ while (s > path && *--s != '/') {
+ continue;
+ }
+ }
+ if ((s > path && *s == '/')) {
+ s++;
+ }
return s;
}
diff --git a/src/nvim/mbyte.c b/src/nvim/mbyte.c
index c161bad66f..683087bd7b 100644
--- a/src/nvim/mbyte.c
+++ b/src/nvim/mbyte.c
@@ -2085,31 +2085,31 @@ static char_u *iconv_string(const vimconv_T *const vcp, char_u *str,
to = (char *)result + done;
tolen = len - done - 2;
- /* Avoid a warning for systems with a wrong iconv() prototype by
- * casting the second argument to void *. */
+ // Avoid a warning for systems with a wrong iconv() prototype by
+ // casting the second argument to void *.
if (iconv(vcp->vc_fd, (void *)&from, &fromlen, &to, &tolen) != SIZE_MAX) {
- /* Finished, append a NUL. */
+ // Finished, append a NUL.
*to = NUL;
break;
}
- /* Check both ICONV_EINVAL and EINVAL, because the dynamically loaded
- * iconv library may use one of them. */
+ // Check both ICONV_EINVAL and EINVAL, because the dynamically loaded
+ // iconv library may use one of them.
if (!vcp->vc_fail && unconvlenp != NULL
&& (ICONV_ERRNO == ICONV_EINVAL || ICONV_ERRNO == EINVAL)) {
- /* Handle an incomplete sequence at the end. */
+ // Handle an incomplete sequence at the end.
*to = NUL;
*unconvlenp = fromlen;
break;
- }
- /* Check both ICONV_EILSEQ and EILSEQ, because the dynamically loaded
- * iconv library may use one of them. */
- else if (!vcp->vc_fail
- && (ICONV_ERRNO == ICONV_EILSEQ || ICONV_ERRNO == EILSEQ
- || ICONV_ERRNO == ICONV_EINVAL || ICONV_ERRNO == EINVAL)) {
- /* Can't convert: insert a '?' and skip a character. This assumes
- * conversion from 'encoding' to something else. In other
- * situations we don't know what to skip anyway. */
+ } else if (!vcp->vc_fail
+ && (ICONV_ERRNO == ICONV_EILSEQ || ICONV_ERRNO == EILSEQ
+ || ICONV_ERRNO == ICONV_EINVAL || ICONV_ERRNO == EINVAL)) {
+ // Check both ICONV_EILSEQ and EILSEQ, because the dynamically loaded
+ // iconv library may use one of them.
+
+ // Can't convert: insert a '?' and skip a character. This assumes
+ // conversion from 'encoding' to something else. In other
+ // situations we don't know what to skip anyway.
*to++ = '?';
if (utf_ptr2cells((char_u *)from) > 1) {
*to++ = '?';
@@ -2122,7 +2122,7 @@ static char_u *iconv_string(const vimconv_T *const vcp, char_u *str,
XFREE_CLEAR(result);
break;
}
- /* Not enough room or skipping illegal sequence. */
+ // Not enough room or skipping illegal sequence.
done = to - (char *)result;
}
@@ -2132,11 +2132,9 @@ static char_u *iconv_string(const vimconv_T *const vcp, char_u *str,
}
# if defined(DYNAMIC_ICONV)
-/*
- * Dynamically load the "iconv.dll" on Win32.
- */
+// Dynamically load the "iconv.dll" on Win32.
-#ifndef DYNAMIC_ICONV /* just generating prototypes */
+#ifndef DYNAMIC_ICONV // just generating prototypes
# define HINSTANCE int
#endif
static HINSTANCE hIconvDLL = 0;
diff --git a/src/nvim/memline.c b/src/nvim/memline.c
index a4d2feb5e3..a69669f680 100644
--- a/src/nvim/memline.c
+++ b/src/nvim/memline.c
@@ -3356,47 +3356,38 @@ static char *findswapname(buf_T *buf, char **dirp, char *old_fname,
break;
}
- /*
- * A file name equal to old_fname is OK to use.
- */
- if (old_fname != NULL && fnamecmp(fname, old_fname) == 0)
+ // A file name equal to old_fname is OK to use.
+ if (old_fname != NULL && fnamecmp(fname, old_fname) == 0) {
break;
+ }
- /*
- * get here when file already exists
- */
- if (fname[n - 2] == 'w' && fname[n - 1] == 'p') { /* first try */
- /*
- * If we get here the ".swp" file really exists.
- * Give an error message, unless recovering, no file name, we are
- * viewing a help file or when the path of the file is different
- * (happens when all .swp files are in one directory).
- */
+ // get here when file already exists
+ if (fname[n - 2] == 'w' && fname[n - 1] == 'p') { // first try
+ // If we get here the ".swp" file really exists.
+ // Give an error message, unless recovering, no file name, we are
+ // viewing a help file or when the path of the file is different
+ // (happens when all .swp files are in one directory).
if (!recoverymode && buf_fname != NULL
&& !buf->b_help && !(buf->b_flags & BF_DUMMY)) {
int fd;
struct block0 b0;
int differ = FALSE;
- /*
- * Try to read block 0 from the swap file to get the original
- * file name (and inode number).
- */
+ // Try to read block 0 from the swap file to get the original
+ // file name (and inode number).
fd = os_open(fname, O_RDONLY, 0);
if (fd >= 0) {
if (read_eintr(fd, &b0, sizeof(b0)) == sizeof(b0)) {
- /*
- * If the swapfile has the same directory as the
- * buffer don't compare the directory names, they can
- * have a different mountpoint.
- */
+ // If the swapfile has the same directory as the
+ // buffer don't compare the directory names, they can
+ // have a different mountpoint.
if (b0.b0_flags & B0_SAME_DIR) {
if (fnamecmp(path_tail(buf->b_ffname),
path_tail(b0.b0_fname)) != 0
- || !same_directory((char_u *) fname, buf->b_ffname)) {
- /* Symlinks may point to the same file even
- * when the name differs, need to check the
- * inode too. */
+ || !same_directory((char_u *)fname, buf->b_ffname)) {
+ // Symlinks may point to the same file even
+ // when the name differs, need to check the
+ // inode too.
expand_env(b0.b0_fname, NameBuff, MAXPATHL);
if (fnamecmp_ino(buf->b_ffname, NameBuff,
char_to_long(b0.b0_ino))) {
@@ -3404,10 +3395,8 @@ static char *findswapname(buf_T *buf, char **dirp, char *old_fname,
}
}
} else {
- /*
- * The name in the swap file may be
- * "~user/path/file". Expand it first.
- */
+ // The name in the swap file may be
+ // "~user/path/file". Expand it first.
expand_env(b0.b0_fname, NameBuff, MAXPATHL);
if (fnamecmp_ino(buf->b_ffname, NameBuff,
char_to_long(b0.b0_ino))) {
@@ -3418,9 +3407,9 @@ static char *findswapname(buf_T *buf, char **dirp, char *old_fname,
close(fd);
}
- /* give the ATTENTION message when there is an old swap file
- * for the current file, and the buffer was not recovered. */
- if (differ == FALSE && !(curbuf->b_flags & BF_RECOVERED)
+ // give the ATTENTION message when there is an old swap file
+ // for the current file, and the buffer was not recovered. */
+ if (differ == false && !(curbuf->b_flags & BF_RECOVERED)
&& vim_strchr(p_shm, SHM_ATTENTION) == NULL) {
int choice = 0;
diff --git a/src/nvim/message.c b/src/nvim/message.c
index 077c28eb2c..190a268be7 100644
--- a/src/nvim/message.c
+++ b/src/nvim/message.c
@@ -1082,16 +1082,14 @@ void wait_return(int redraw)
/* Put the character back in the typeahead buffer. Don't use the
* stuff buffer, because lmaps wouldn't work. */
ins_char_typebuf(c);
- do_redraw = TRUE; /* need a redraw even though there is
- typeahead */
+ do_redraw = true; // need a redraw even though there is
+ // typeahead
}
}
- redir_off = FALSE;
+ redir_off = false;
- /*
- * If the user hits ':', '?' or '/' we get a command line from the next
- * line.
- */
+ // If the user hits ':', '?' or '/' we get a command line from the next
+ // line.
if (c == ':' || c == '?' || c == '/') {
if (!exmode_active)
cmdline_row = msg_row;
@@ -1100,19 +1098,17 @@ void wait_return(int redraw)
msg_ext_keep_after_cmdline = true;
}
- /*
- * If the window size changed set_shellsize() will redraw the screen.
- * Otherwise the screen is only redrawn if 'redraw' is set and no ':'
- * typed.
- */
+ // If the window size changed set_shellsize() will redraw the screen.
+ // Otherwise the screen is only redrawn if 'redraw' is set and no ':'
+ // typed.
tmpState = State;
- State = oldState; /* restore State before set_shellsize */
+ State = oldState; // restore State before set_shellsize
setmouse();
msg_check();
- need_wait_return = FALSE;
- did_wait_return = TRUE;
- emsg_on_display = FALSE; /* can delete error message now */
- lines_left = -1; /* reset lines_left at next msg_start() */
+ need_wait_return = false;
+ did_wait_return = true;
+ emsg_on_display = false; // can delete error message now
+ lines_left = -1; // reset lines_left at next msg_start()
reset_last_sourcing();
if (keep_msg != NULL && vim_strsize(keep_msg) >=
(Rows - cmdline_row - 1) * Columns + sc_col) {
@@ -1183,25 +1179,25 @@ void msg_ext_set_kind(const char *msg_kind)
*/
void msg_start(void)
{
- int did_return = FALSE;
+ int did_return = false;
if (!msg_silent) {
XFREE_CLEAR(keep_msg); // don't display old message now
}
if (need_clr_eos) {
- /* Halfway an ":echo" command and getting an (error) message: clear
- * any text from the command. */
- need_clr_eos = FALSE;
+ // Halfway an ":echo" command and getting an (error) message: clear
+ // any text from the command.
+ need_clr_eos = false;
msg_clr_eos();
}
- if (!msg_scroll && full_screen) { /* overwrite last message */
+ if (!msg_scroll && full_screen) { // overwrite last message
msg_row = cmdline_row;
msg_col =
cmdmsg_rl ? Columns - 1 :
0;
- } else if (msg_didout) { /* start message on next line */
+ } else if (msg_didout) { // start message on next line
msg_putchar('\n');
did_return = TRUE;
if (exmode_active != EXMODE_NORMAL)
@@ -1210,7 +1206,7 @@ void msg_start(void)
if (!msg_didany || lines_left < 0)
msg_starthere();
if (msg_silent == 0) {
- msg_didout = FALSE; /* no output on current line yet */
+ msg_didout = false; // no output on current line yet
}
if (ui_has(kUIMessages)) {
@@ -2990,12 +2986,13 @@ int verbose_open(void)
*/
void give_warning(char_u *message, bool hl) FUNC_ATTR_NONNULL_ARG(1)
{
- /* Don't do this for ":silent". */
- if (msg_silent != 0)
+ // Don't do this for ":silent".
+ if (msg_silent != 0) {
return;
+ }
- /* Don't want a hit-enter prompt here. */
- ++no_wait_return;
+ // Don't want a hit-enter prompt here.
+ no_wait_return++;
set_vim_var_string(VV_WARNINGMSG, (char *)message, -1);
XFREE_CLEAR(keep_msg);
@@ -3013,7 +3010,7 @@ void give_warning(char_u *message, bool hl) FUNC_ATTR_NONNULL_ARG(1)
msg_nowait = true; // Don't wait for this message.
msg_col = 0;
- --no_wait_return;
+ no_wait_return--;
}
void give_warning2(char_u *const message, char_u *const a1, bool hl)
diff --git a/src/nvim/normal.c b/src/nvim/normal.c
index 50abd226fc..d6e78d9ce4 100644
--- a/src/nvim/normal.c
+++ b/src/nvim/normal.c
@@ -4213,10 +4213,10 @@ dozet:
set_fraction(curwin);
break;
- /* "z^", "z-" and "zb": put cursor at bottom of screen */
- case '^': /* Strange Vi behavior: <count>z^ finds line at top of window
- * when <count> is at bottom of window, and puts that one at
- * bottom of window. */
+ // "z^", "z-" and "zb": put cursor at bottom of screen
+ case '^': // Strange Vi behavior: <count>z^ finds line at top of window
+ // when <count> is at bottom of window, and puts that one at
+ // bottom of window.
if (cap->count0 != 0) {
scroll_cursor_bot(0, true);
curwin->w_cursor.lnum = curwin->w_topline;
diff --git a/src/nvim/search.c b/src/nvim/search.c
index 3bd222b3de..e64233985b 100644
--- a/src/nvim/search.c
+++ b/src/nvim/search.c
@@ -87,13 +87,13 @@ static struct spat spats[2] =
static int last_idx = 0; /* index in spats[] for RE_LAST */
-static char_u lastc[2] = {NUL, NUL}; /* last character searched for */
-static int lastcdir = FORWARD; /* last direction of character search */
-static int last_t_cmd = TRUE; /* last search t_cmd */
+static char_u lastc[2] = { NUL, NUL }; // last character searched for
+static int lastcdir = FORWARD; // last direction of character search
+static int last_t_cmd = true; // last search t_cmd
static char_u lastc_bytes[MB_MAXBYTES + 1];
-static int lastc_bytelen = 1; /* >1 for multi-byte char */
+static int lastc_bytelen = 1; // >1 for multi-byte char
-/* copy of spats[], for keeping the search patterns while executing autocmds */
+// copy of spats[], for keeping the search patterns while executing autocmds
static struct spat saved_spats[2];
// copy of spats[RE_SEARCH], for keeping the search patterns while incremental
// searching
@@ -101,8 +101,8 @@ static struct spat saved_last_search_spat;
static int saved_last_idx = 0;
static int saved_no_hlsearch = 0;
-static char_u *mr_pattern = NULL; /* pattern used by search_regcomp() */
-static int mr_pattern_alloced = FALSE; /* mr_pattern was allocated */
+static char_u *mr_pattern = NULL; // pattern used by search_regcomp()
+static int mr_pattern_alloced = false; // mr_pattern was allocated
/*
* Type used by find_pattern_in_path() to remember which included files have
diff --git a/src/nvim/sign.c b/src/nvim/sign.c
index 68d013f298..ac26fd0137 100644
--- a/src/nvim/sign.c
+++ b/src/nvim/sign.c
@@ -1,15 +1,10 @@
-/* vi:set ts=8 sts=4 sw=4 noet:
- *
- * VIM - Vi IMproved by Bram Moolenaar
- *
- * Do ":help uganda" in Vim to read copying and usage conditions.
- * Do ":help credits" in Vim to see a list of people who contributed.
- * See README.txt for an overview of the Vim source code.
- */
-
-/*
- * sign.c: functions for managing signs
- */
+// This is an open source non-commercial project. Dear PVS-Studio, please check
+// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
+
+//
+// sign.c: functions for managing with signs
+//
+
#include "nvim/vim.h"
#include "nvim/sign.h"
@@ -24,9 +19,7 @@
#include "nvim/screen.h"
#include "nvim/syntax.h"
-/*
- * Struct to hold the sign properties.
- */
+/// Struct to hold the sign properties.
typedef struct sign sign_T;
struct sign
@@ -36,7 +29,7 @@ struct sign
char_u *sn_name; // name of sign
char_u *sn_icon; // name of pixmap
# ifdef FEAT_SIGN_ICONS
- void *sn_image; // icon image
+ void *sn_image; // icon image
# endif
char_u *sn_text; // text used instead of pixmap
int sn_line_hl; // highlight ID for line
@@ -44,68 +37,62 @@ struct sign
int sn_num_hl; // highlight ID for line number
};
-static sign_T *first_sign = NULL;
-static int next_sign_typenr = 1;
+static sign_T *first_sign = NULL;
+static int next_sign_typenr = 1;
static void sign_list_defined(sign_T *sp);
static void sign_undefine(sign_T *sp, sign_T *sp_prev);
static char *cmds[] = {
- "define",
-#define SIGNCMD_DEFINE 0
- "undefine",
+ "define",
+#define SIGNCMD_DEFINE 0
+ "undefine",
#define SIGNCMD_UNDEFINE 1
- "list",
-#define SIGNCMD_LIST 2
- "place",
-#define SIGNCMD_PLACE 3
- "unplace",
-#define SIGNCMD_UNPLACE 4
- "jump",
-#define SIGNCMD_JUMP 5
- NULL
-#define SIGNCMD_LAST 6
+ "list",
+#define SIGNCMD_LIST 2
+ "place",
+#define SIGNCMD_PLACE 3
+ "unplace",
+#define SIGNCMD_UNPLACE 4
+ "jump",
+#define SIGNCMD_JUMP 5
+ NULL
+#define SIGNCMD_LAST 6
};
-static hashtab_T sg_table; // sign group (signgroup_T) hashtable
-static int next_sign_id = 1; // next sign id in the global group
+static hashtab_T sg_table; // sign group (signgroup_T) hashtable
+static int next_sign_id = 1; // next sign id in the global group
-/*
- * Initialize data needed for managing signs
- */
- void
-init_signs(void)
+/// Initialize data needed for managing signs
+void init_signs(void)
{
- hash_init(&sg_table); // sign group hash table
+ hash_init(&sg_table); // sign group hash table
}
-/*
- * A new sign in group 'groupname' is added. If the group is not present,
- * create it. Otherwise reference the group.
- */
+/// A new sign in group 'groupname' is added. If the group is not present,
+/// create it. Otherwise reference the group.
+///
static signgroup_T * sign_group_ref(const char_u *groupname)
{
- hash_T hash;
- hashitem_T *hi;
- signgroup_T *group;
+ hash_T hash;
+ hashitem_T *hi;
+ signgroup_T *group;
hash = hash_hash(groupname);
- hi = hash_lookup(&sg_table, (char*)groupname, STRLEN(groupname), hash);
- if (HASHITEM_EMPTY(hi))
- {
+ hi = hash_lookup(&sg_table, (char *)groupname, STRLEN(groupname), hash);
+ if (HASHITEM_EMPTY(hi)) {
// new group
group = (signgroup_T *)xmalloc(
(unsigned)(sizeof(signgroup_T) + STRLEN(groupname)));
- if (group == NULL)
+ if (group == NULL) {
return NULL;
+ }
STRCPY(group->sg_name, groupname);
group->refcount = 1;
- group->next_sign_id = 1;
+ group->next_sign_id = 1;
hash_add_item(&sg_table, hi, group->sg_name, hash);
- }
- else
- {
+ } else {
// existing group
group = HI2SG(hi);
group->refcount++;
@@ -114,22 +101,18 @@ static signgroup_T * sign_group_ref(const char_u *groupname)
return group;
}
-/*
- * A sign in group 'groupname' is removed. If all the signs in this group are
- * removed, then remove the group.
- */
+/// A sign in group 'groupname' is removed. If all the signs in this group are
+/// removed, then remove the group.
static void sign_group_unref(char_u *groupname)
{
- hashitem_T *hi;
- signgroup_T *group;
+ hashitem_T *hi;
+ signgroup_T *group;
hi = hash_find(&sg_table, groupname);
- if (!HASHITEM_EMPTY(hi))
- {
+ if (!HASHITEM_EMPTY(hi)) {
group = HI2SG(hi);
group->refcount--;
- if (group->refcount == 0)
- {
+ if (group->refcount == 0) {
// All the signs in this group are removed
hash_remove(&sg_table, hi);
xfree(group);
@@ -137,66 +120,57 @@ static void sign_group_unref(char_u *groupname)
}
}
-/*
- * Returns TRUE if 'sign' is in 'group'.
- * A sign can either be in the global group (sign->group == NULL)
- * or in a named group. If 'group' is '*', then the sign is part of the group.
- */
+/// Returns TRUE if 'sign' is in 'group'.
+/// A sign can either be in the global group (sign->group == NULL)
+/// or in a named group. If 'group' is '*', then the sign is part of the group.
int sign_in_group(signlist_T *sign, const char_u *group)
{
return ((group != NULL && STRCMP(group, "*") == 0)
- || (group == NULL && sign->group == NULL)
- || (group != NULL && sign->group != NULL
- && STRCMP(group, sign->group->sg_name) == 0));
+ || (group == NULL && sign->group == NULL)
+ || (group != NULL && sign->group != NULL
+ && STRCMP(group, sign->group->sg_name) == 0));
}
-/*
- * Get the next free sign identifier in the specified group
- */
- int
-sign_group_get_next_signid(buf_T *buf, const char_u *groupname)
+/// Get the next free sign identifier in the specified group
+int sign_group_get_next_signid(buf_T *buf, const char_u *groupname)
{
- int id = 1;
- signgroup_T *group = NULL;
- signlist_T *sign;
- hashitem_T *hi;
- int found = FALSE;
-
- if (groupname != NULL)
- {
- hi = hash_find(&sg_table, groupname);
- if (HASHITEM_EMPTY(hi))
- return id;
- group = HI2SG(hi);
- }
-
- // Search for the next usuable sign identifier
- while (!found)
- {
- if (group == NULL)
- id = next_sign_id++; // global group
- else
- id = group->next_sign_id++;
-
- // Check whether this sign is already placed in the buffer
- found = TRUE;
- FOR_ALL_SIGNS_IN_BUF(buf, sign)
- {
- if (id == sign->id && sign_in_group(sign, groupname))
- {
- found = FALSE; // sign identifier is in use
- break;
- }
- }
- }
-
- return id;
+ int id = 1;
+ signgroup_T *group = NULL;
+ signlist_T *sign;
+ hashitem_T *hi;
+ int found = false;
+
+ if (groupname != NULL) {
+ hi = hash_find(&sg_table, groupname);
+ if (HASHITEM_EMPTY(hi)) {
+ return id;
+ }
+ group = HI2SG(hi);
+ }
+
+ // Search for the next usuable sign identifier
+ while (!found) {
+ if (group == NULL) {
+ id = next_sign_id++; // global group
+ } else {
+ id = group->next_sign_id++;
+ }
+
+ // Check whether this sign is already placed in the buffer
+ found = true;
+ FOR_ALL_SIGNS_IN_BUF(buf, sign) {
+ if (id == sign->id && sign_in_group(sign, groupname)) {
+ found = false; // sign identifier is in use
+ break;
+ }
+ }
+ }
+
+ return id;
}
-/*
- * Insert a new sign into the signlist for buffer 'buf' between the 'prev' and
- * 'next' signs.
- */
+/// Insert a new sign into the signlist for buffer 'buf' between the 'prev' and
+/// 'next' signs.
static void insert_sign(
buf_T *buf, // buffer to store sign in
signlist_T *prev, // previous sign entry
@@ -208,59 +182,54 @@ static void insert_sign(
int typenr // typenr of sign we are adding
)
{
- signlist_T *newsign = xmalloc(sizeof(signlist_T));
- newsign->id = id;
- newsign->lnum = lnum;
- newsign->typenr = typenr;
- if (group != NULL)
- {
- newsign->group = sign_group_ref(group);
- if (newsign->group == NULL)
- {
- xfree(newsign);
- return;
- }
- }
- else
- newsign->group = NULL;
- newsign->priority = prio;
- newsign->next = next;
- newsign->prev = prev;
- if (next != NULL) {
- next->prev = newsign;
+ signlist_T *newsign = xmalloc(sizeof(signlist_T));
+ newsign->id = id;
+ newsign->lnum = lnum;
+ newsign->typenr = typenr;
+ if (group != NULL) {
+ newsign->group = sign_group_ref(group);
+ if (newsign->group == NULL) {
+ xfree(newsign);
+ return;
}
- buf->b_signcols_max = -1;
-
- if (prev == NULL) {
- // When adding first sign need to redraw the windows to create the
- // column for signs.
- if (buf->b_signlist == NULL) {
- redraw_buf_later(buf, NOT_VALID);
- changed_cline_bef_curs();
- }
+ } else {
+ newsign->group = NULL;
+ }
+ newsign->priority = prio;
+ newsign->next = next;
+ newsign->prev = prev;
+ if (next != NULL) {
+ next->prev = newsign;
+ }
+ buf->b_signcols_max = -1;
- // first sign in signlist
- buf->b_signlist = newsign;
- }
- else {
- prev->next = newsign;
+ if (prev == NULL) {
+ // When adding first sign need to redraw the windows to create the
+ // column for signs.
+ if (buf->b_signlist == NULL) {
+ redraw_buf_later(buf, NOT_VALID);
+ changed_cline_bef_curs();
}
+
+ // first sign in signlist
+ buf->b_signlist = newsign;
+ } else {
+ prev->next = newsign;
+ }
}
-/*
- * Insert a new sign sorted by line number and sign priority.
- */
+/// Insert a new sign sorted by line number and sign priority.
static void insert_sign_by_lnum_prio(
- buf_T *buf, // buffer to store sign in
- signlist_T *prev, // previous sign entry
- int id, // sign ID
- const char_u *group, // sign group; NULL for global group
- int prio, // sign priority
- linenr_T lnum, // line number which gets the mark
- int typenr // typenr of sign we are adding
+ buf_T *buf, // buffer to store sign in
+ signlist_T *prev, // previous sign entry
+ int id, // sign ID
+ const char_u *group, // sign group; NULL for global group
+ int prio, // sign priority
+ linenr_T lnum, // line number which gets the mark
+ int typenr // typenr of sign we are adding
)
{
- signlist_T *sign;
+ signlist_T *sign;
// keep signs sorted by lnum and by priority: insert new sign at
// the proper position in the list for this lnum.
@@ -276,69 +245,66 @@ static void insert_sign_by_lnum_prio(
insert_sign(buf, prev, sign, id, group, prio, lnum, typenr);
}
-/*
- * Get the name of a sign by its typenr.
- */
+/// Get the name of a sign by its typenr.
char_u * sign_typenr2name(int typenr)
{
sign_T *sp;
- for (sp = first_sign; sp != NULL; sp = sp->sn_next)
- if (sp->sn_typenr == typenr)
+ for (sp = first_sign; sp != NULL; sp = sp->sn_next) {
+ if (sp->sn_typenr == typenr) {
return sp->sn_name;
+ }
+ }
return (char_u *)_("[Deleted]");
}
-/*
- * Return information about a sign in a Dict
- */
+/// Return information about a sign in a Dict
dict_T * sign_get_info(signlist_T *sign)
{
- dict_T *d;
+ dict_T *d;
if ((d = tv_dict_alloc()) == NULL) {
return NULL;
}
tv_dict_add_nr(d, S_LEN("id"), sign->id);
- tv_dict_add_str(d, S_LEN("group"),
- (sign->group == NULL) ? (char*)"" : (char*)sign->group->sg_name);
+ tv_dict_add_str(d, S_LEN("group"), ((sign->group == NULL)
+ ? (char *)""
+ : (char *)sign->group->sg_name));
tv_dict_add_nr(d, S_LEN("lnum"), sign->lnum);
- tv_dict_add_str(d, S_LEN("name"), (char*)sign_typenr2name(sign->typenr));
+ tv_dict_add_str(d, S_LEN("name"), (char *)sign_typenr2name(sign->typenr));
tv_dict_add_nr(d, S_LEN("priority"), sign->priority);
return d;
}
-/*
- * Add the sign into the signlist. Find the right spot to do it though.
- */
+/// Add the sign into the signlist. Find the right spot to do it though.
void buf_addsign(
buf_T *buf, // buffer to store sign in
int id, // sign ID
- const char_u *groupname, // sign group
+ const char_u *groupname, // sign group
int prio, // sign priority
linenr_T lnum, // line number which gets the mark
int typenr // typenr of sign we are adding
)
{
- signlist_T *sign; // a sign in the signlist
- signlist_T *prev; // the previous sign
+ signlist_T *sign; // a sign in the signlist
+ signlist_T *prev; // the previous sign
- prev = NULL;
- FOR_ALL_SIGNS_IN_BUF(buf, sign) {
- if (lnum == sign->lnum && id == sign->id
- && sign_in_group(sign, groupname)) {
- // Update an existing sign
- sign->typenr = typenr;
- return;
- } else if (lnum < sign->lnum) {
- insert_sign_by_lnum_prio(buf, prev, id, groupname, prio, lnum, typenr);
- return;
- }
- prev = sign;
+ prev = NULL;
+ FOR_ALL_SIGNS_IN_BUF(buf, sign) {
+ if (lnum == sign->lnum && id == sign->id
+ && sign_in_group(sign, groupname)) {
+ // Update an existing sign
+ sign->typenr = typenr;
+ return;
+ } else if (lnum < sign->lnum) {
+ insert_sign_by_lnum_prio(buf, prev, id, groupname, prio, lnum, typenr);
+ return;
}
+ prev = sign;
+ }
- insert_sign_by_lnum_prio(buf, prev, id, groupname, prio, lnum, typenr);
+ insert_sign_by_lnum_prio(buf, prev, id, groupname, prio, lnum, typenr);
}
// For an existing, placed sign "markId" change the type to "typenr".
@@ -384,13 +350,13 @@ int buf_getsigntype(buf_T *buf, linenr_T lnum, SignType type,
FOR_ALL_SIGNS_IN_BUF(buf, sign) {
if (sign->lnum == lnum
- && (type == SIGN_ANY
- || (type == SIGN_TEXT
- && sign_get_text(sign->typenr) != NULL)
- || (type == SIGN_LINEHL
- && sign_get_attr(sign->typenr, SIGN_LINEHL) != 0)
- || (type == SIGN_NUMHL
- && sign_get_attr(sign->typenr, SIGN_NUMHL) != 0))) {
+ && (type == SIGN_ANY
+ || (type == SIGN_TEXT
+ && sign_get_text(sign->typenr) != NULL)
+ || (type == SIGN_LINEHL
+ && sign_get_attr(sign->typenr, SIGN_LINEHL) != 0)
+ || (type == SIGN_NUMHL
+ && sign_get_attr(sign->typenr, SIGN_NUMHL) != 0))) {
matches[nr_matches] = sign;
nr_matches++;
// signlist is sorted with most important (priority, id), thus we
@@ -412,22 +378,20 @@ int buf_getsigntype(buf_T *buf, linenr_T lnum, SignType type,
return 0;
}
-/*
- * Delete sign 'id' in group 'group' from buffer 'buf'.
- * If 'id' is zero, then delete all the signs in group 'group'. Otherwise
- * delete only the specified sign.
- * If 'group' is '*', then delete the sign in all the groups. If 'group' is
- * NULL, then delete the sign in the global group. Otherwise delete the sign in
- * the specified group.
- * Returns the line number of the deleted sign. If multiple signs are deleted,
- * then returns the line number of the last sign deleted.
- */
+/// Delete sign 'id' in group 'group' from buffer 'buf'.
+/// If 'id' is zero, then delete all the signs in group 'group'. Otherwise
+/// delete only the specified sign.
+/// If 'group' is '*', then delete the sign in all the groups. If 'group' is
+/// NULL, then delete the sign in the global group. Otherwise delete the sign in
+/// the specified group.
+/// Returns the line number of the deleted sign. If multiple signs are deleted,
+/// then returns the line number of the last sign deleted.
linenr_T buf_delsign(
- buf_T *buf, // buffer sign is stored in
- linenr_T atlnum, // sign at this line, 0 - at any line
- int id, // sign id
- char_u *group// sign group
- )
+ buf_T *buf, // buffer sign is stored in
+ linenr_T atlnum, // sign at this line, 0 - at any line
+ int id, // sign id
+ char_u *group // sign group
+)
{
signlist_T **lastp; // pointer to pointer to current sign
signlist_T *sign; // a sign in a b_signlist
@@ -447,12 +411,13 @@ linenr_T buf_delsign(
next->prev = sign->prev;
}
lnum = sign->lnum;
- if (sign->group != NULL)
+ if (sign->group != NULL) {
sign_group_unref(sign->group->sg_name);
+ }
xfree(sign);
redraw_buf_line_later(buf, lnum);
// Check whether only one sign needs to be deleted
- // If deleting a sign with a specific identifier in a particular
+ // If deleting a sign with a specific identifier in a particular
// group or deleting any sign at a particular line number, delete
// only one sign.
if (group == NULL
@@ -476,11 +441,9 @@ linenr_T buf_delsign(
}
-/*
- * Find the line number of the sign with the requested id in group 'group'. If
- * the sign does not exist, return 0 as the line number. This will still let
- * the correct file get loaded.
- */
+/// Find the line number of the sign with the requested id in group 'group'. If
+/// the sign does not exist, return 0 as the line number. This will still let
+/// the correct file get loaded.
int buf_findsign(
buf_T *buf, // buffer to store sign in
int id, // sign ID
@@ -490,7 +453,7 @@ int buf_findsign(
signlist_T *sign; // a sign in the signlist
FOR_ALL_SIGNS_IN_BUF(buf, sign) {
- if (sign->id == id && sign_in_group(sign, group)){
+ if (sign->id == id && sign_in_group(sign, group)) {
return (int)sign->lnum;
}
}
@@ -498,17 +461,15 @@ int buf_findsign(
return 0;
}
-/*
- * Return the sign at line 'lnum' in buffer 'buf'. Returns NULL if a sign is
- * not found at the line. If 'groupname' is NULL, searches in the global group.
- */
+/// Return the sign at line 'lnum' in buffer 'buf'. Returns NULL if a sign is
+/// not found at the line. If 'groupname' is NULL, searches in the global group.
static signlist_T * buf_getsign_at_line(
- buf_T *buf, // buffer whose sign we are searching for
- linenr_T lnum, // line number of sign
- char_u *groupname // sign group name
+ buf_T *buf, // buffer whose sign we are searching for
+ linenr_T lnum, // line number of sign
+ char_u *groupname // sign group name
)
{
- signlist_T *sign; // a sign in the signlist
+ signlist_T *sign; // a sign in the signlist
FOR_ALL_SIGNS_IN_BUF(buf, sign) {
if (sign->lnum == lnum && sign_in_group(sign, groupname)) {
@@ -519,9 +480,7 @@ static signlist_T * buf_getsign_at_line(
return NULL;
}
-/*
- * Return the identifier of the sign at line number 'lnum' in buffer 'buf'.
- */
+/// Return the identifier of the sign at line number 'lnum' in buffer 'buf'.
int buf_findsign_id(
buf_T *buf, // buffer whose sign we are searching for
linenr_T lnum, // line number of sign
@@ -538,18 +497,16 @@ int buf_findsign_id(
return 0;
}
-/*
- * Delete signs in buffer "buf".
- */
+/// Delete signs in buffer "buf".
void buf_delete_signs(buf_T *buf, char_u *group)
{
- signlist_T *sign;
- signlist_T **lastp; // pointer to pointer to current sign
+ signlist_T *sign;
+ signlist_T **lastp; // pointer to pointer to current sign
signlist_T *next;
// When deleting the last sign need to redraw the windows to remove the
// sign column. Not when curwin is NULL (this means we're exiting).
- if (buf->b_signlist != NULL && curwin != NULL){
+ if (buf->b_signlist != NULL && curwin != NULL) {
changed_cline_bef_curs();
}
@@ -572,98 +529,97 @@ void buf_delete_signs(buf_T *buf, char_u *group)
buf->b_signcols_max = -1;
}
-/*
- * List placed signs for "rbuf". If "rbuf" is NULL do it for all buffers.
- */
+/// List placed signs for "rbuf". If "rbuf" is NULL do it for all buffers.
void sign_list_placed(buf_T *rbuf, char_u *sign_group)
{
- buf_T *buf;
- signlist_T *sign;
- char lbuf[MSG_BUF_LEN];
- char group[MSG_BUF_LEN];
-
- MSG_PUTS_TITLE(_("\n--- Signs ---"));
- msg_putchar('\n');
- if (rbuf == NULL) {
- buf = firstbuf;
- } else {
- buf = rbuf;
+ buf_T *buf;
+ signlist_T *sign;
+ char lbuf[MSG_BUF_LEN];
+ char group[MSG_BUF_LEN];
+
+ MSG_PUTS_TITLE(_("\n--- Signs ---"));
+ msg_putchar('\n');
+ if (rbuf == NULL) {
+ buf = firstbuf;
+ } else {
+ buf = rbuf;
+ }
+ while (buf != NULL && !got_int) {
+ if (buf->b_signlist != NULL) {
+ vim_snprintf(lbuf, MSG_BUF_LEN, _("Signs for %s:"), buf->b_fname);
+ MSG_PUTS_ATTR(lbuf, HL_ATTR(HLF_D));
+ msg_putchar('\n');
}
- while (buf != NULL && !got_int) {
- if (buf->b_signlist != NULL) {
- vim_snprintf(lbuf, MSG_BUF_LEN, _("Signs for %s:"), buf->b_fname);
- MSG_PUTS_ATTR(lbuf, HL_ATTR(HLF_D));
- msg_putchar('\n');
- }
- FOR_ALL_SIGNS_IN_BUF(buf, sign) {
- if (got_int) {
- break;
- }
- if (!sign_in_group(sign, sign_group)) {
- continue;
- }
- if (sign->group != NULL) {
- vim_snprintf(group, MSG_BUF_LEN, _(" group=%s"),
- sign->group->sg_name);
- } else {
- group[0] = '\0';
- }
- vim_snprintf(lbuf, MSG_BUF_LEN,
- _(" line=%ld id=%d%s name=%s priority=%d"),
- (long)sign->lnum, sign->id, group,
- sign_typenr2name(sign->typenr), sign->priority);
- MSG_PUTS(lbuf);
- msg_putchar('\n');
- }
- if (rbuf != NULL) {
- break;
- }
- buf = buf->b_next;
+ FOR_ALL_SIGNS_IN_BUF(buf, sign) {
+ if (got_int) {
+ break;
+ }
+ if (!sign_in_group(sign, sign_group)) {
+ continue;
+ }
+ if (sign->group != NULL) {
+ vim_snprintf(group, MSG_BUF_LEN, _(" group=%s"),
+ sign->group->sg_name);
+ } else {
+ group[0] = '\0';
+ }
+ vim_snprintf(lbuf, MSG_BUF_LEN,
+ _(" line=%ld id=%d%s name=%s priority=%d"),
+ (long)sign->lnum, sign->id, group,
+ sign_typenr2name(sign->typenr), sign->priority);
+ MSG_PUTS(lbuf);
+ msg_putchar('\n');
+ }
+ if (rbuf != NULL) {
+ break;
}
+ buf = buf->b_next;
+ }
}
-/*
- * Adjust a placed sign for inserted/deleted lines.
- */
-void sign_mark_adjust(linenr_T line1, linenr_T line2, long amount, long amount_after)
+/// Adjust a placed sign for inserted/deleted lines.
+void sign_mark_adjust(
+ linenr_T line1,
+ linenr_T line2,
+ long amount,
+ long amount_after
+)
{
- signlist_T *sign; // a sign in a b_signlist
- linenr_T new_lnum; // new line number to assign to sign
+ signlist_T *sign; // a sign in a b_signlist
+ linenr_T new_lnum; // new line number to assign to sign
- curbuf->b_signcols_max = -1;
+ curbuf->b_signcols_max = -1;
- FOR_ALL_SIGNS_IN_BUF(curbuf, sign) {
- new_lnum = sign->lnum;
- if (sign->lnum >= line1 && sign->lnum <= line2) {
- if (amount != MAXLNUM) {
- new_lnum += amount;
- }
- } else if (sign->lnum > line2) {
- new_lnum += amount_after;
- }
- // If the new sign line number is past the last line in the buffer,
- // then don't adjust the line number. Otherwise, it will always be past
- // the last line and will not be visible.
- if (sign->lnum >= line1 && new_lnum <= curbuf->b_ml.ml_line_count) {
- sign->lnum = new_lnum;
- }
+ FOR_ALL_SIGNS_IN_BUF(curbuf, sign) {
+ new_lnum = sign->lnum;
+ if (sign->lnum >= line1 && sign->lnum <= line2) {
+ if (amount != MAXLNUM) {
+ new_lnum += amount;
+ }
+ } else if (sign->lnum > line2) {
+ new_lnum += amount_after;
+ }
+ // If the new sign line number is past the last line in the buffer,
+ // then don't adjust the line number. Otherwise, it will always be past
+ // the last line and will not be visible.
+ if (sign->lnum >= line1 && new_lnum <= curbuf->b_ml.ml_line_count) {
+ sign->lnum = new_lnum;
}
+ }
}
-/*
- * Find index of a ":sign" subcmd from its name.
- * "*end_cmd" must be writable.
- */
+/// Find index of a ":sign" subcmd from its name.
+/// "*end_cmd" must be writable.
static int sign_cmd_idx(
char_u *begin_cmd, // begin of sign subcmd
char_u *end_cmd // just after sign subcmd
- )
+)
{
int idx;
char_u save = *end_cmd;
*end_cmd = (char_u)NUL;
- for (idx = 0; ; ++idx) {
+ for (idx = 0; ; idx++) {
if (cmds[idx] == NULL || STRCMP(begin_cmd, cmds[idx]) == 0) {
break;
}
@@ -672,234 +628,217 @@ static int sign_cmd_idx(
return idx;
}
-/*
- * Find a sign by name. Also returns pointer to the previous sign.
- */
+/// Find a sign by name. Also returns pointer to the previous sign.
static sign_T * sign_find(const char_u *name, sign_T **sp_prev)
{
- sign_T *sp;
+ sign_T *sp;
- if (sp_prev != NULL)
- *sp_prev = NULL;
- for (sp = first_sign; sp != NULL; sp = sp->sn_next)
- {
- if (STRCMP(sp->sn_name, name) == 0)
- break;
- if (sp_prev != NULL)
- *sp_prev = sp;
+ if (sp_prev != NULL) {
+ *sp_prev = NULL;
+ }
+ for (sp = first_sign; sp != NULL; sp = sp->sn_next) {
+ if (STRCMP(sp->sn_name, name) == 0) {
+ break;
+ }
+ if (sp_prev != NULL) {
+ *sp_prev = sp;
}
+ }
- return sp;
+ return sp;
}
-/*
- * Allocate a new sign
- */
- static sign_T *
-alloc_new_sign(char_u *name)
+/// Allocate a new sign
+static sign_T * alloc_new_sign(char_u *name)
{
- sign_T *sp;
- sign_T *lp;
- int start = next_sign_typenr;
-
- // Allocate a new sign.
- sp = xcalloc(1, sizeof(sign_T));
-
- // Check that next_sign_typenr is not already being used.
- // This only happens after wrapping around. Hopefully
- // another one got deleted and we can use its number.
- for (lp = first_sign; lp != NULL; ) {
- if (lp->sn_typenr == next_sign_typenr) {
- ++next_sign_typenr;
- if (next_sign_typenr == MAX_TYPENR) {
- next_sign_typenr = 1;
- }
- if (next_sign_typenr == start) {
- xfree(sp);
- EMSG(_("E612: Too many signs defined"));
- return NULL;
- }
- lp = first_sign; // start all over
- continue;
- }
- lp = lp->sn_next;
- }
-
- sp->sn_typenr = next_sign_typenr;
- if (++next_sign_typenr == MAX_TYPENR)
- next_sign_typenr = 1; // wrap around
-
- sp->sn_name = vim_strsave(name);
-
- return sp;
+ sign_T *sp;
+ sign_T *lp;
+ int start = next_sign_typenr;
+
+ // Allocate a new sign.
+ sp = xcalloc(1, sizeof(sign_T));
+
+ // Check that next_sign_typenr is not already being used.
+ // This only happens after wrapping around. Hopefully
+ // another one got deleted and we can use its number.
+ for (lp = first_sign; lp != NULL; ) {
+ if (lp->sn_typenr == next_sign_typenr) {
+ next_sign_typenr++;
+ if (next_sign_typenr == MAX_TYPENR) {
+ next_sign_typenr = 1;
+ }
+ if (next_sign_typenr == start) {
+ xfree(sp);
+ EMSG(_("E612: Too many signs defined"));
+ return NULL;
+ }
+ lp = first_sign; // start all over
+ continue;
+ }
+ lp = lp->sn_next;
+ }
+
+ sp->sn_typenr = next_sign_typenr;
+ if (++next_sign_typenr == MAX_TYPENR) {
+ next_sign_typenr = 1; // wrap around
+ }
+
+ sp->sn_name = vim_strsave(name);
+
+ return sp;
}
-/*
- * Initialize the icon information for a new sign
- */
- static void
-sign_define_init_icon(sign_T *sp, char_u *icon)
+/// Initialize the icon information for a new sign
+static void sign_define_init_icon(sign_T *sp, char_u *icon)
{
- xfree(sp->sn_icon);
- sp->sn_icon = vim_strsave(icon);
- backslash_halve(sp->sn_icon);
+ xfree(sp->sn_icon);
+ sp->sn_icon = vim_strsave(icon);
+ backslash_halve(sp->sn_icon);
# ifdef FEAT_SIGN_ICONS
- if (gui.in_use)
- {
- out_flush();
- if (sp->sn_image != NULL)
- gui_mch_destroy_sign(sp->sn_image);
- sp->sn_image = gui_mch_register_sign(sp->sn_icon);
+ if (gui.in_use) {
+ out_flush();
+ if (sp->sn_image != NULL) {
+ gui_mch_destroy_sign(sp->sn_image);
}
+ sp->sn_image = gui_mch_register_sign(sp->sn_icon);
+ }
# endif
}
-/*
- * Initialize the text for a new sign
- */
- static int
-sign_define_init_text(sign_T *sp, char_u *text)
+/// Initialize the text for a new sign
+static int sign_define_init_text(sign_T *sp, char_u *text)
{
- char_u *s;
- char_u *endp;
- int cells;
- size_t len;
-
- endp = text + (int)STRLEN(text);
- for (s = text; s + 1 < endp; ++s) {
- if (*s == '\\')
- {
- // Remove a backslash, so that it is possible
- // to use a space.
- STRMOVE(s, s + 1);
- --endp;
- }
- }
- // Count cells and check for non-printable chars
- cells = 0;
- for (s = text; s < endp; s += (*mb_ptr2len)(s)) {
- if (!vim_isprintc(utf_ptr2char(s))) {
- break;
- }
- cells += utf_ptr2cells(s);
- }
- // Currently must be one or two display cells
- if (s != endp || cells < 1 || cells > 2) {
- EMSG2(_("E239: Invalid sign text: %s"), text);
- return FAIL;
- }
-
- xfree(sp->sn_text);
- // Allocate one byte more if we need to pad up
- // with a space.
- len = (size_t)(endp - text + ((cells == 1) ? 1 : 0));
- sp->sn_text = vim_strnsave(text, len);
-
- if (cells == 1)
- STRCPY(sp->sn_text + len - 1, " ");
+ char_u *s;
+ char_u *endp;
+ int cells;
+ size_t len;
+
+ endp = text + (int)STRLEN(text);
+ for (s = text; s + 1 < endp; s++) {
+ if (*s == '\\') {
+ // Remove a backslash, so that it is possible
+ // to use a space.
+ STRMOVE(s, s + 1);
+ endp--;
+ }
+ }
+ // Count cells and check for non-printable chars
+ cells = 0;
+ for (s = text; s < endp; s += (*mb_ptr2len)(s)) {
+ if (!vim_isprintc(utf_ptr2char(s))) {
+ break;
+ }
+ cells += utf_ptr2cells(s);
+ }
+ // Currently must be one or two display cells
+ if (s != endp || cells < 1 || cells > 2) {
+ EMSG2(_("E239: Invalid sign text: %s"), text);
+ return FAIL;
+ }
- return OK;
+ xfree(sp->sn_text);
+ // Allocate one byte more if we need to pad up
+ // with a space.
+ len = (size_t)(endp - text + ((cells == 1) ? 1 : 0));
+ sp->sn_text = vim_strnsave(text, len);
+
+ if (cells == 1) {
+ STRCPY(sp->sn_text + len - 1, " ");
+ }
+
+ return OK;
}
-/*
- * Define a new sign or update an existing sign
- */
+/// Define a new sign or update an existing sign
int sign_define_by_name(
- char_u *name,
- char_u *icon,
- char_u *linehl,
- char_u *text,
- char_u *texthl,
- char_u *numhl
+ char_u *name,
+ char_u *icon,
+ char_u *linehl,
+ char_u *text,
+ char_u *texthl,
+ char_u *numhl
)
{
- sign_T *sp_prev;
- sign_T *sp;
-
- sp = sign_find(name, &sp_prev);
- if (sp == NULL)
- {
- sp = alloc_new_sign(name);
- if (sp == NULL) {
- return FAIL;
- }
+ sign_T *sp_prev;
+ sign_T *sp;
- // add the new sign to the list of signs
- if (sp_prev == NULL) {
- first_sign = sp;
- } else {
- sp_prev->sn_next = sp;
- }
+ sp = sign_find(name, &sp_prev);
+ if (sp == NULL) {
+ sp = alloc_new_sign(name);
+ if (sp == NULL) {
+ return FAIL;
}
- // set values for a defined sign.
- if (icon != NULL)
- {
- sign_define_init_icon(sp, icon);
+ // add the new sign to the list of signs
+ if (sp_prev == NULL) {
+ first_sign = sp;
+ } else {
+ sp_prev->sn_next = sp;
}
+ }
- if (text != NULL && (sign_define_init_text(sp, text) == FAIL)) {
- return FAIL;
- }
+ // set values for a defined sign.
+ if (icon != NULL) {
+ sign_define_init_icon(sp, icon);
+ }
+
+ if (text != NULL && (sign_define_init_text(sp, text) == FAIL)) {
+ return FAIL;
+ }
- if (linehl != NULL)
- sp->sn_line_hl = syn_check_group(linehl, (int)STRLEN(linehl));
+ if (linehl != NULL) {
+ sp->sn_line_hl = syn_check_group(linehl, (int)STRLEN(linehl));
+ }
- if (texthl != NULL)
- sp->sn_text_hl = syn_check_group(texthl, (int)STRLEN(texthl));
+ if (texthl != NULL) {
+ sp->sn_text_hl = syn_check_group(texthl, (int)STRLEN(texthl));
+ }
- if (numhl != NULL)
- sp->sn_num_hl = syn_check_group(numhl, (int)STRLEN(numhl));
+ if (numhl != NULL) {
+ sp->sn_num_hl = syn_check_group(numhl, (int)STRLEN(numhl));
+ }
- return OK;
+ return OK;
}
-/*
- * Free the sign specified by 'name'.
- */
- int
-sign_undefine_by_name(const char_u *name)
+/// Free the sign specified by 'name'.
+int sign_undefine_by_name(const char_u *name)
{
- sign_T *sp_prev;
- sign_T *sp;
+ sign_T *sp_prev;
+ sign_T *sp;
- sp = sign_find(name, &sp_prev);
- if (sp == NULL)
- {
- EMSG2(_("E155: Unknown sign: %s"), name);
- return FAIL;
- }
- sign_undefine(sp, sp_prev);
+ sp = sign_find(name, &sp_prev);
+ if (sp == NULL) {
+ EMSG2(_("E155: Unknown sign: %s"), name);
+ return FAIL;
+ }
+ sign_undefine(sp, sp_prev);
- return OK;
+ return OK;
}
-/*
- * List the signs matching 'name'
- */
- static void
-sign_list_by_name(char_u *name)
+/// List the signs matching 'name'
+static void sign_list_by_name(char_u *name)
{
- sign_T *sp;
+ sign_T *sp;
- sp = sign_find(name, NULL);
- if (sp != NULL)
- sign_list_defined(sp);
- else
- EMSG2(_("E155: Unknown sign: %s"), name);
+ sp = sign_find(name, NULL);
+ if (sp != NULL) {
+ sign_list_defined(sp);
+ } else {
+ EMSG2(_("E155: Unknown sign: %s"), name);
+ }
}
-/*
- * Place a sign at the specified file location or update a sign.
- */
+/// Place a sign at the specified file location or update a sign.
int sign_place(
- int *sign_id,
- const char_u *sign_group,
- const char_u *sign_name,
- buf_T *buf,
- linenr_T lnum,
- int prio
+ int *sign_id,
+ const char_u *sign_group,
+ const char_u *sign_name,
+ buf_T *buf,
+ linenr_T lnum,
+ int prio
)
{
sign_T *sp;
@@ -914,13 +853,11 @@ int sign_place(
break;
}
}
- if (sp == NULL)
- {
+ if (sp == NULL) {
EMSG2(_("E155: Unknown sign: %s"), sign_name);
return FAIL;
}
- if (*sign_id == 0)
- {
+ if (*sign_id == 0) {
*sign_id = sign_group_get_next_signid(buf, sign_group);
}
@@ -942,22 +879,18 @@ int sign_place(
return OK;
}
-/*
- * Unplace the specified sign
- */
- int
-sign_unplace(int sign_id, char_u *sign_group, buf_T *buf, linenr_T atlnum)
+/// Unplace the specified sign
+int sign_unplace(int sign_id, char_u *sign_group, buf_T *buf, linenr_T atlnum)
{
- if (buf->b_signlist == NULL) { // No signs in the buffer
- return OK;
- }
- if (sign_id == 0)
- {
+ if (buf->b_signlist == NULL) { // No signs in the buffer
+ return OK;
+ }
+ if (sign_id == 0) {
// Delete all the signs in the specified buffer
redraw_buf_later(buf, NOT_VALID);
buf_delete_signs(buf, sign_group);
} else {
- linenr_T lnum;
+ linenr_T lnum;
// Delete only the specified signs
lnum = buf_delsign(buf, atlnum, sign_id, sign_group);
@@ -969,13 +902,11 @@ sign_unplace(int sign_id, char_u *sign_group, buf_T *buf, linenr_T atlnum)
return OK;
}
-
-/*
- * Unplace the sign at the current cursor line.
- */
+
+/// Unplace the sign at the current cursor line.
static void sign_unplace_at_cursor(char_u *groupname)
{
- int id = -1;
+ int id = -1;
id = buf_findsign_id(curwin->w_buffer, curwin->w_cursor.lnum, groupname);
if (id > 0) {
@@ -985,9 +916,7 @@ static void sign_unplace_at_cursor(char_u *groupname)
}
}
-/*
- * Jump to a sign.
- */
+/// Jump to a sign.
linenr_T sign_jump(int sign_id, char_u *sign_group, buf_T *buf)
{
linenr_T lnum;
@@ -998,12 +927,11 @@ linenr_T sign_jump(int sign_id, char_u *sign_group, buf_T *buf)
}
// goto a sign ...
- if (buf_jump_open_win(buf) != NULL)
- { // ... in a current window
+ if (buf_jump_open_win(buf) != NULL) { // ... in a current window
curwin->w_cursor.lnum = lnum;
check_cursor_lnum();
beginline(BL_WHITE);
- } else { // ... not currently in a window
+ } else { // ... not currently in a window
if (buf->b_fname == NULL) {
EMSG(_("E934: Cannot jump to a buffer that does not have a name"));
return -1;
@@ -1011,7 +939,7 @@ linenr_T sign_jump(int sign_id, char_u *sign_group, buf_T *buf)
size_t cmdlen = STRLEN(buf->b_fname) + 24;
char *cmd = xmallocz(cmdlen);
snprintf(cmd, cmdlen, "e +%" PRId64 " %s",
- (int64_t)lnum, buf->b_fname);
+ (int64_t)lnum, buf->b_fname);
do_cmdline_cmd(cmd);
xfree(cmd);
}
@@ -1021,19 +949,17 @@ linenr_T sign_jump(int sign_id, char_u *sign_group, buf_T *buf)
return lnum;
}
-/*
- * ":sign define {name} ..." command
- */
+/// ":sign define {name} ..." command
static void sign_define_cmd(char_u *sign_name, char_u *cmdline)
{
- char_u *arg;
- char_u *p = cmdline;
- char_u *icon = NULL;
- char_u *text = NULL;
- char_u *linehl = NULL;
- char_u *texthl = NULL;
- char_u *numhl = NULL;
- int failed = FALSE;
+ char_u *arg;
+ char_u *p = cmdline;
+ char_u *icon = NULL;
+ char_u *text = NULL;
+ char_u *linehl = NULL;
+ char_u *texthl = NULL;
+ char_u *numhl = NULL;
+ int failed = false;
// set values for a defined sign.
for (;;) {
@@ -1059,7 +985,7 @@ static void sign_define_cmd(char_u *sign_name, char_u *cmdline)
numhl = vim_strnsave(arg, (size_t)(p - arg));
} else {
EMSG2(_(e_invarg2), arg);
- failed = TRUE;
+ failed = true;
break;
}
}
@@ -1075,20 +1001,17 @@ static void sign_define_cmd(char_u *sign_name, char_u *cmdline)
xfree(numhl);
}
-/*
- * ":sign place" command
- */
+/// ":sign place" command
static void sign_place_cmd(
- buf_T *buf,
- linenr_T lnum,
- char_u *sign_name,
- int id,
- char_u *group,
- int prio
- )
+ buf_T *buf,
+ linenr_T lnum,
+ char_u *sign_name,
+ int id,
+ char_u *group,
+ int prio
+)
{
- if (id <= 0)
- {
+ if (id <= 0) {
// List signs placed in a file/buffer
// :sign place file={fname}
// :sign place group={group} file={fname}
@@ -1117,15 +1040,13 @@ static void sign_place_cmd(
}
}
-/*
- * ":sign unplace" command
- */
+/// ":sign unplace" command
static void sign_unplace_cmd(
- buf_T *buf,
- linenr_T lnum,
- char_u *sign_name,
- int id,
- char_u *group
+ buf_T *buf,
+ linenr_T lnum,
+ char_u *sign_name,
+ int id,
+ char_u *group
)
{
if (lnum >= 0 || sign_name != NULL || (group != NULL && *group == '\0')) {
@@ -1133,8 +1054,7 @@ static void sign_unplace_cmd(
return;
}
- if (id == -2)
- {
+ if (id == -2) {
if (buf != NULL) {
// :sign unplace * file={fname}
// :sign unplace * group={group} file={fname}
@@ -1163,8 +1083,7 @@ static void sign_unplace_cmd(
// :sign unplace {id} group=* buffer={nr}
sign_unplace(id, group, buf, 0);
} else {
- if (id == -1)
- {
+ if (id == -1) {
// :sign unplace group={group}
// :sign unplace group=*
sign_unplace_at_cursor(group);
@@ -1180,20 +1099,18 @@ static void sign_unplace_cmd(
}
}
-/*
- * Jump to a placed sign commands:
- * :sign jump {id} file={fname}
- * :sign jump {id} buffer={nr}
- * :sign jump {id} group={group} file={fname}
- * :sign jump {id} group={group} buffer={nr}
- */
+/// Jump to a placed sign commands:
+/// :sign jump {id} file={fname}
+/// :sign jump {id} buffer={nr}
+/// :sign jump {id} group={group} file={fname}
+/// :sign jump {id} group={group} buffer={nr}
static void sign_jump_cmd(
- buf_T *buf,
- linenr_T lnum,
- char_u *sign_name,
- int id,
- char_u *group
- )
+ buf_T *buf,
+ linenr_T lnum,
+ char_u *sign_name,
+ int id,
+ char_u *group
+)
{
if (sign_name == NULL && group == NULL && id == -1) {
EMSG(_(e_argreq));
@@ -1211,112 +1128,108 @@ static void sign_jump_cmd(
(void)sign_jump(id, group, buf);
}
-/*
- * Parse the command line arguments for the ":sign place", ":sign unplace" and
- * ":sign jump" commands.
- * The supported arguments are: line={lnum} name={name} group={group}
- * priority={prio} and file={fname} or buffer={nr}.
- */
+/// Parse the command line arguments for the ":sign place", ":sign unplace" and
+/// ":sign jump" commands.
+/// The supported arguments are: line={lnum} name={name} group={group}
+/// priority={prio} and file={fname} or buffer={nr}.
static int parse_sign_cmd_args(
- int cmd,
- char_u *arg,
- char_u **sign_name,
- int *signid,
- char_u **group,
- int *prio,
- buf_T **buf,
- linenr_T *lnum
+ int cmd,
+ char_u *arg,
+ char_u **sign_name,
+ int *signid,
+ char_u **group,
+ int *prio,
+ buf_T **buf,
+ linenr_T *lnum
)
{
- char_u *arg1;
- char_u *name;
- char_u *filename = NULL;
- int lnum_arg = FALSE;
-
- // first arg could be placed sign id
- arg1 = arg;
- if (ascii_isdigit(*arg)) {
- *signid = getdigits_int(&arg);
- if (!ascii_iswhite(*arg) && *arg != NUL) {
- *signid = -1;
- arg = arg1;
- } else {
- arg = skipwhite(arg);
- }
+ char_u *arg1;
+ char_u *name;
+ char_u *filename = NULL;
+ int lnum_arg = false;
+
+ // first arg could be placed sign id
+ arg1 = arg;
+ if (ascii_isdigit(*arg)) {
+ *signid = getdigits_int(&arg);
+ if (!ascii_iswhite(*arg) && *arg != NUL) {
+ *signid = -1;
+ arg = arg1;
+ } else {
+ arg = skipwhite(arg);
}
+ }
- while (*arg != NUL) {
- if (STRNCMP(arg, "line=", 5) == 0) {
- arg += 5;
- *lnum = atoi((char *)arg);
- arg = skiptowhite(arg);
- lnum_arg = TRUE;
- } else if (STRNCMP(arg, "*", 1) == 0 && cmd == SIGNCMD_UNPLACE) {
- if (*signid != -1) {
- EMSG(_(e_invarg));
- return FAIL;
- }
- *signid = -2;
- arg = skiptowhite(arg + 1);
- } else if (STRNCMP(arg, "name=", 5) == 0) {
- arg += 5;
- name = arg;
- arg = skiptowhite(arg);
- if (*arg != NUL) {
- *arg++ = NUL;
- }
- while (name[0] == '0' && name[1] != NUL) {
- ++name;
- }
- *sign_name = name;
- } else if (STRNCMP(arg, "group=", 6) == 0) {
- arg += 6;
- *group = arg;
- arg = skiptowhite(arg);
- if (*arg != NUL) {
- *arg++ = NUL;
- }
- } else if (STRNCMP(arg, "priority=", 9) == 0) {
- arg += 9;
- *prio = atoi((char *)arg);
- arg = skiptowhite(arg);
- } else if (STRNCMP(arg, "file=", 5) == 0) {
- arg += 5;
- filename = arg;
- *buf = buflist_findname_exp(arg);
- break;
- } else if (STRNCMP(arg, "buffer=", 7) == 0) {
- arg += 7;
- filename = arg;
- *buf = buflist_findnr(getdigits_int(&arg));
- if (*skipwhite(arg) != NUL) {
- EMSG(_(e_trailing));
- }
- break;
- } else {
+ while (*arg != NUL) {
+ if (STRNCMP(arg, "line=", 5) == 0) {
+ arg += 5;
+ *lnum = atoi((char *)arg);
+ arg = skiptowhite(arg);
+ lnum_arg = true;
+ } else if (STRNCMP(arg, "*", 1) == 0 && cmd == SIGNCMD_UNPLACE) {
+ if (*signid != -1) {
EMSG(_(e_invarg));
return FAIL;
}
- arg = skipwhite(arg);
- }
-
- if (filename != NULL && *buf == NULL) {
- EMSG2(_("E158: Invalid buffer name: %s"), filename);
+ *signid = -2;
+ arg = skiptowhite(arg + 1);
+ } else if (STRNCMP(arg, "name=", 5) == 0) {
+ arg += 5;
+ name = arg;
+ arg = skiptowhite(arg);
+ if (*arg != NUL) {
+ *arg++ = NUL;
+ }
+ while (name[0] == '0' && name[1] != NUL) {
+ name++;
+ }
+ *sign_name = name;
+ } else if (STRNCMP(arg, "group=", 6) == 0) {
+ arg += 6;
+ *group = arg;
+ arg = skiptowhite(arg);
+ if (*arg != NUL) {
+ *arg++ = NUL;
+ }
+ } else if (STRNCMP(arg, "priority=", 9) == 0) {
+ arg += 9;
+ *prio = atoi((char *)arg);
+ arg = skiptowhite(arg);
+ } else if (STRNCMP(arg, "file=", 5) == 0) {
+ arg += 5;
+ filename = arg;
+ *buf = buflist_findname_exp(arg);
+ break;
+ } else if (STRNCMP(arg, "buffer=", 7) == 0) {
+ arg += 7;
+ filename = arg;
+ *buf = buflist_findnr(getdigits_int(&arg));
+ if (*skipwhite(arg) != NUL) {
+ EMSG(_(e_trailing));
+ }
+ break;
+ } else {
+ EMSG(_(e_invarg));
return FAIL;
}
+ arg = skipwhite(arg);
+ }
- // If the filename is not supplied for the sign place or the sign jump
- // command, then use the current buffer.
- if (filename == NULL && ((cmd == SIGNCMD_PLACE && lnum_arg)
- || cmd == SIGNCMD_JUMP)) {
- *buf = curwin->w_buffer;
- }
- return OK;
+ if (filename != NULL && *buf == NULL) {
+ EMSG2(_("E158: Invalid buffer name: %s"), filename);
+ return FAIL;
+ }
+
+ // If the filename is not supplied for the sign place or the sign jump
+ // command, then use the current buffer.
+ if (filename == NULL && ((cmd == SIGNCMD_PLACE && lnum_arg)
+ || cmd == SIGNCMD_JUMP)) {
+ *buf = curwin->w_buffer;
+ }
+ return OK;
}
-/*
- * ":sign" command
- */
+/// ":sign" command
void ex_sign(exarg_T *eap)
{
char_u *arg = eap->arg;
@@ -1343,7 +1256,7 @@ void ex_sign(exarg_T *eap)
} else if (*arg == NUL) {
EMSG(_("E156: Missing sign name"));
} else {
- char_u *name;
+ char_u *name;
// Isolate the sign name. If it's a number skip leading zeroes,
// so that "099" and "99" are the same sign. But keep "0".
@@ -1379,8 +1292,9 @@ void ex_sign(exarg_T *eap)
// Parse command line arguments
if (parse_sign_cmd_args(idx, arg, &sign_name, &id, &group, &prio,
- &buf, &lnum) == FAIL)
+ &buf, &lnum) == FAIL) {
return;
+ }
if (idx == SIGNCMD_PLACE) {
sign_place_cmd(buf, lnum, sign_name, id, group, prio);
@@ -1392,9 +1306,7 @@ void ex_sign(exarg_T *eap)
}
}
-/*
- * Return information about a specified sign
- */
+/// Return information about a specified sign
static void sign_getinfo(sign_T *sp, dict_T *retdict)
{
const char *p;
@@ -1407,21 +1319,21 @@ static void sign_getinfo(sign_T *sp, dict_T *retdict)
tv_dict_add_str(retdict, S_LEN("text"), (char *)sp->sn_text);
}
if (sp->sn_line_hl > 0) {
- p = get_highlight_name_ext(NULL, sp->sn_line_hl - 1, FALSE);
+ p = get_highlight_name_ext(NULL, sp->sn_line_hl - 1, false);
if (p == NULL) {
p = "NONE";
}
tv_dict_add_str(retdict, S_LEN("linehl"), (char *)p);
}
if (sp->sn_text_hl > 0) {
- p = get_highlight_name_ext(NULL, sp->sn_text_hl - 1, FALSE);
+ p = get_highlight_name_ext(NULL, sp->sn_text_hl - 1, false);
if (p == NULL) {
p = "NONE";
}
tv_dict_add_str(retdict, S_LEN("texthl"), (char *)p);
}
if (sp->sn_num_hl > 0) {
- p = get_highlight_name_ext(NULL, sp->sn_num_hl - 1, FALSE);
+ p = get_highlight_name_ext(NULL, sp->sn_num_hl - 1, false);
if (p == NULL) {
p = "NONE";
}
@@ -1429,14 +1341,12 @@ static void sign_getinfo(sign_T *sp, dict_T *retdict)
}
}
-/*
- * If 'name' is NULL, return a list of all the defined signs.
- * Otherwise, return information about the specified sign.
- */
+/// If 'name' is NULL, return a list of all the defined signs.
+/// Otherwise, return information about the specified sign.
void sign_getlist(const char_u *name, list_T *retlist)
{
- sign_T *sp = first_sign;
- dict_T *dict;
+ sign_T *sp = first_sign;
+ dict_T *dict;
if (name != NULL) {
sp = sign_find(name, NULL);
@@ -1452,7 +1362,7 @@ void sign_getlist(const char_u *name, list_T *retlist)
tv_list_append_dict(retlist, dict);
sign_getinfo(sp, dict);
- if (name != NULL) { // handle only the specified sign
+ if (name != NULL) { // handle only the specified sign
break;
}
}
@@ -1462,8 +1372,8 @@ void sign_getlist(const char_u *name, list_T *retlist)
list_T *get_buffer_signs(buf_T *buf)
FUNC_ATTR_NONNULL_RET FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT
{
- signlist_T *sign;
- dict_T *d;
+ signlist_T *sign;
+ dict_T *d;
list_T *const l = tv_list_alloc(kListLenMayKnow);
FOR_ALL_SIGNS_IN_BUF(buf, sign) {
@@ -1474,9 +1384,7 @@ list_T *get_buffer_signs(buf_T *buf)
return l;
}
-/*
- * Return information about all the signs placed in a buffer
- */
+/// Return information about all the signs placed in a buffer
static void sign_get_placed_in_buf(
buf_T *buf,
linenr_T lnum,
@@ -1484,10 +1392,10 @@ static void sign_get_placed_in_buf(
const char_u *sign_group,
list_T *retlist)
{
- dict_T *d;
- list_T *l;
- signlist_T *sign;
- dict_T *sdict;
+ dict_T *d;
+ list_T *l;
+ signlist_T *sign;
+ dict_T *sdict;
if ((d = tv_dict_alloc()) == NULL) {
return;
@@ -1516,17 +1424,16 @@ static void sign_get_placed_in_buf(
}
}
-/*
- * Get a list of signs placed in buffer 'buf'. If 'num' is non-zero, return the
- * sign placed at the line number. If 'lnum' is zero, return all the signs
- * placed in 'buf'. If 'buf' is NULL, return signs placed in all the buffers.
- */
+/// Get a list of signs placed in buffer 'buf'. If 'num' is non-zero, return the
+/// sign placed at the line number. If 'lnum' is zero, return all the signs
+/// placed in 'buf'. If 'buf' is NULL, return signs placed in all the buffers.
void sign_get_placed(
buf_T *buf,
linenr_T lnum,
int sign_id,
const char_u *sign_group,
- list_T *retlist)
+ list_T *retlist
+)
{
if (buf != NULL) {
sign_get_placed_in_buf(buf, lnum, sign_id, sign_group, retlist);
@@ -1540,24 +1447,21 @@ void sign_get_placed(
}
# if defined(FEAT_SIGN_ICONS) || defined(PROTO)
-/*
- * Allocate the icons. Called when the GUI has started. Allows defining
- * signs before it starts.
- */
- void
-sign_gui_started(void)
+/// Allocate the icons. Called when the GUI has started. Allows defining
+/// signs before it starts.
+void sign_gui_started(void)
{
- sign_T *sp;
+ sign_T *sp;
- for (sp = first_sign; sp != NULL; sp = sp->sn_next)
- if (sp->sn_icon != NULL)
- sp->sn_image = gui_mch_register_sign(sp->sn_icon);
+ for (sp = first_sign; sp != NULL; sp = sp->sn_next) {
+ if (sp->sn_icon != NULL) {
+ sp->sn_image = gui_mch_register_sign(sp->sn_icon);
+ }
+ }
}
# endif
-/*
- * List one sign.
- */
+/// List one sign.
static void sign_list_defined(sign_T *sp)
{
smsg("sign %s", sp->sn_name);
@@ -1602,18 +1506,17 @@ static void sign_list_defined(sign_T *sp)
}
}
-/*
- * Undefine a sign and free its memory.
- */
+/// Undefine a sign and free its memory.
static void sign_undefine(sign_T *sp, sign_T *sp_prev)
{
xfree(sp->sn_name);
xfree(sp->sn_icon);
xfree(sp->sn_text);
- if (sp_prev == NULL)
+ if (sp_prev == NULL) {
first_sign = sp->sn_next;
- else
+ } else {
sp_prev->sn_next = sp->sn_next;
+ }
xfree(sp);
}
@@ -1647,37 +1550,37 @@ int sign_get_attr(int typenr, SignType type)
return 0;
}
-/*
- * Get text mark for sign "typenr".
- * Returns NULL if there isn't one.
- */
+/// Get text mark for sign "typenr".
+/// Returns NULL if there isn't one.
char_u * sign_get_text(int typenr)
{
- sign_T *sp;
+ sign_T *sp;
- for (sp = first_sign; sp != NULL; sp = sp->sn_next)
- if (sp->sn_typenr == typenr)
- return sp->sn_text;
- return NULL;
+ for (sp = first_sign; sp != NULL; sp = sp->sn_next) {
+ if (sp->sn_typenr == typenr) {
+ return sp->sn_text;
+ }
+ }
+ return NULL;
}
# if defined(FEAT_SIGN_ICONS) || defined(PROTO)
- void *
-sign_get_image(
- int typenr) // the attribute which may have a sign
+void * sign_get_image(
+ int typenr // the attribute which may have a sign
+)
{
- sign_T *sp;
+ sign_T *sp;
- for (sp = first_sign; sp != NULL; sp = sp->sn_next)
- if (sp->sn_typenr == typenr)
- return sp->sn_image;
- return NULL;
+ for (sp = first_sign; sp != NULL; sp = sp->sn_next) {
+ if (sp->sn_typenr == typenr) {
+ return sp->sn_image;
+ }
+ }
+ return NULL;
}
# endif
-/*
- * Undefine/free all signs.
- */
+/// Undefine/free all signs.
void free_signs(void)
{
while (first_sign != NULL) {
@@ -1687,19 +1590,18 @@ void free_signs(void)
static enum
{
- EXP_SUBCMD, // expand :sign sub-commands
- EXP_DEFINE, // expand :sign define {name} args
- EXP_PLACE, // expand :sign place {id} args
- EXP_UNPLACE, // expand :sign unplace"
- EXP_SIGN_NAMES // expand with name of placed signs
+ EXP_SUBCMD, // expand :sign sub-commands
+ EXP_DEFINE, // expand :sign define {name} args
+ EXP_PLACE, // expand :sign place {id} args
+ EXP_UNPLACE, // expand :sign unplace"
+ EXP_SIGN_NAMES // expand with name of placed signs
} expand_what;
/// Function given to ExpandGeneric() to obtain the sign command
/// expansion.
char_u * get_sign_name(expand_T *xp, int idx)
{
- switch (expand_what)
- {
+ switch (expand_what) {
case EXP_SUBCMD:
return (char_u *)cmds[idx];
case EXP_DEFINE: {
@@ -1731,9 +1633,7 @@ char_u * get_sign_name(expand_T *xp, int idx)
}
}
-/*
- * Handle command line completion for :sign command.
- */
+/// Handle command line completion for :sign command.
void set_context_in_sign_cmd(expand_T *xp, char_u *arg)
{
char_u *p;
@@ -1748,10 +1648,11 @@ void set_context_in_sign_cmd(expand_T *xp, char_u *arg)
xp->xp_pattern = arg;
end_subcmd = skiptowhite(arg);
- if (*end_subcmd == NUL)
+ if (*end_subcmd == NUL) {
// expand subcmd name
// :sign {subcmd}<CTRL-D>
return;
+ }
cmd_idx = sign_cmd_idx(arg, end_subcmd);
@@ -1760,16 +1661,14 @@ void set_context_in_sign_cmd(expand_T *xp, char_u *arg)
// begin_subcmd_args
begin_subcmd_args = skipwhite(end_subcmd);
p = skiptowhite(begin_subcmd_args);
- if (*p == NUL)
- {
+ if (*p == NUL) {
//
// Expand first argument of subcmd when possible.
// For ":jump {id}" and ":unplace {id}", we could
// possibly expand the ids of all signs already placed.
//
xp->xp_pattern = begin_subcmd_args;
- switch (cmd_idx)
- {
+ switch (cmd_idx) {
case SIGNCMD_LIST:
case SIGNCMD_UNDEFINE:
// :sign list <CTRL-D>
@@ -1789,8 +1688,7 @@ void set_context_in_sign_cmd(expand_T *xp, char_u *arg)
// p
// Loop until reaching last argument.
- do
- {
+ do {
p = skipwhite(p);
last = p;
p = skiptowhite(p);
@@ -1804,8 +1702,7 @@ void set_context_in_sign_cmd(expand_T *xp, char_u *arg)
if (p == NULL) {
// Expand last argument name (before equal sign).
xp->xp_pattern = last;
- switch (cmd_idx)
- {
+ switch (cmd_idx) {
case SIGNCMD_DEFINE:
expand_what = EXP_DEFINE;
break;
@@ -1819,13 +1716,10 @@ void set_context_in_sign_cmd(expand_T *xp, char_u *arg)
default:
xp->xp_context = EXPAND_NOTHING;
}
- }
- else
- {
- // Expand last argument value (after equal sign).
+ } else {
+ // Expand last argument value (after equal sign).
xp->xp_pattern = p + 1;
- switch (cmd_idx)
- {
+ switch (cmd_idx) {
case SIGNCMD_DEFINE:
if (STRNCMP(last, "texthl", p - last) == 0
|| STRNCMP(last, "linehl", p - last) == 0
@@ -1838,10 +1732,11 @@ void set_context_in_sign_cmd(expand_T *xp, char_u *arg)
}
break;
case SIGNCMD_PLACE:
- if (STRNCMP(last, "name", p - last) == 0)
+ if (STRNCMP(last, "name", p - last) == 0) {
expand_what = EXP_SIGN_NAMES;
- else
+ } else {
xp->xp_context = EXPAND_NOTHING;
+ }
break;
default:
xp->xp_context = EXPAND_NOTHING;
diff --git a/src/nvim/sign.h b/src/nvim/sign.h
index 6b1ee7e30e..e3a5a27c74 100644
--- a/src/nvim/sign.h
+++ b/src/nvim/sign.h
@@ -2,6 +2,9 @@
#define NVIM_SIGN_H
#include <stdbool.h>
+#include "nvim/buffer_defs.h"
+#include "nvim/ex_cmds_defs.h"
+#include "nvim/sign_defs.h"
#ifdef INCLUDE_GENERATED_DECLARATIONS
diff --git a/src/nvim/sign_defs.h b/src/nvim/sign_defs.h
index e9c2312ae9..687c15bbd6 100644
--- a/src/nvim/sign_defs.h
+++ b/src/nvim/sign_defs.h
@@ -2,36 +2,37 @@
#define NVIM_SIGN_DEFS_H
#include "nvim/pos.h"
+#include "nvim/types.h"
// signs: line annotations
// Sign group
typedef struct signgroup_S
{
- uint16_t refcount; // number of signs in this group
+ uint16_t refcount; // number of signs in this group
int next_sign_id; // next sign id for this group
- char_u sg_name[1]; // sign group name
+ char_u sg_name[1]; // sign group name
} signgroup_T;
// Macros to get the sign group structure from the group name
-#define SGN_KEY_OFF offsetof(signgroup_T, sg_name)
-#define HI2SG(hi) ((signgroup_T *)((hi)->hi_key - SGN_KEY_OFF))
+#define SGN_KEY_OFF offsetof(signgroup_T, sg_name)
+#define HI2SG(hi) ((signgroup_T *)((hi)->hi_key - SGN_KEY_OFF))
typedef struct signlist signlist_T;
struct signlist
{
- int id; // unique identifier for each placed sign
- linenr_T lnum; // line number which has this sign
- int typenr; // typenr of sign
- signgroup_T *group; // sign group
- int priority; // priority for highlighting
- signlist_T *next; // next signlist entry
- signlist_T *prev; // previous entry -- for easy reordering
+ int id; // unique identifier for each placed sign
+ linenr_T lnum; // line number which has this sign
+ int typenr; // typenr of sign
+ signgroup_T *group; // sign group
+ int priority; // priority for highlighting
+ signlist_T *next; // next signlist entry
+ signlist_T *prev; // previous entry -- for easy reordering
};
// Default sign priority for highlighting
-#define SIGN_DEF_PRIO 10
+#define SIGN_DEF_PRIO 10
// type argument for buf_getsigntype() and sign_get_attr()
typedef enum {