aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/sign.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nvim/sign.c')
-rw-r--r--src/nvim/sign.c98
1 files changed, 60 insertions, 38 deletions
diff --git a/src/nvim/sign.c b/src/nvim/sign.c
index 9c517098b9..d0c093d93a 100644
--- a/src/nvim/sign.c
+++ b/src/nvim/sign.c
@@ -5,20 +5,42 @@
// sign.c: functions for managing with signs
//
+#include <inttypes.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
#include "nvim/ascii.h"
#include "nvim/buffer.h"
+#include "nvim/buffer_defs.h"
#include "nvim/charset.h"
#include "nvim/cursor.h"
#include "nvim/drawscreen.h"
#include "nvim/edit.h"
#include "nvim/eval/funcs.h"
+#include "nvim/eval/typval.h"
+#include "nvim/eval/typval_defs.h"
+#include "nvim/ex_cmds_defs.h"
#include "nvim/ex_docmd.h"
#include "nvim/fold.h"
+#include "nvim/gettext.h"
+#include "nvim/globals.h"
+#include "nvim/hashtab.h"
+#include "nvim/highlight_defs.h"
#include "nvim/highlight_group.h"
+#include "nvim/macros.h"
+#include "nvim/mbyte.h"
+#include "nvim/memline_defs.h"
+#include "nvim/memory.h"
+#include "nvim/message.h"
#include "nvim/move.h"
#include "nvim/option.h"
+#include "nvim/pos.h"
#include "nvim/sign.h"
-#include "nvim/syntax.h"
+#include "nvim/sign_defs.h"
+#include "nvim/strings.h"
+#include "nvim/types.h"
#include "nvim/vim.h"
#include "nvim/window.h"
@@ -77,7 +99,7 @@ static signgroup_T *sign_group_ref(const char *groupname)
hashitem_T *hi;
signgroup_T *group;
- hash = hash_hash((char_u *)groupname);
+ hash = hash_hash(groupname);
hi = hash_lookup(&sg_table, (char *)groupname, strlen(groupname), hash);
if (HASHITEM_EMPTY(hi)) {
// new group
@@ -86,7 +108,7 @@ static signgroup_T *sign_group_ref(const char *groupname)
STRCPY(group->sg_name, groupname);
group->sg_refcount = 1;
group->sg_next_sign_id = 1;
- hash_add_item(&sg_table, hi, (char_u *)group->sg_name, hash);
+ hash_add_item(&sg_table, hi, group->sg_name, hash);
} else {
// existing group
group = HI2SG(hi);
@@ -100,17 +122,17 @@ static signgroup_T *sign_group_ref(const char *groupname)
/// removed, then remove the group.
static void sign_group_unref(char *groupname)
{
- signgroup_T *group;
-
hashitem_T *hi = hash_find(&sg_table, groupname);
- if (!HASHITEM_EMPTY(hi)) {
- group = HI2SG(hi);
- group->sg_refcount--;
- if (group->sg_refcount == 0) {
- // All the signs in this group are removed
- hash_remove(&sg_table, hi);
- xfree(group);
- }
+ if (HASHITEM_EMPTY(hi)) {
+ return;
+ }
+
+ signgroup_T *group = HI2SG(hi);
+ group->sg_refcount--;
+ if (group->sg_refcount == 0) {
+ // All the signs in this group are removed
+ hash_remove(&sg_table, hi);
+ xfree(group);
}
}
@@ -1193,27 +1215,27 @@ static void sign_define_cmd(char *sign_name, char *cmdline)
break;
}
p = skiptowhite_esc(arg);
- if (STRNCMP(arg, "icon=", 5) == 0) {
+ if (strncmp(arg, "icon=", 5) == 0) {
arg += 5;
XFREE_CLEAR(icon);
icon = xstrnsave(arg, (size_t)(p - arg));
- } else if (STRNCMP(arg, "text=", 5) == 0) {
+ } else if (strncmp(arg, "text=", 5) == 0) {
arg += 5;
XFREE_CLEAR(text);
text = xstrnsave(arg, (size_t)(p - arg));
- } else if (STRNCMP(arg, "linehl=", 7) == 0) {
+ } else if (strncmp(arg, "linehl=", 7) == 0) {
arg += 7;
XFREE_CLEAR(linehl);
linehl = xstrnsave(arg, (size_t)(p - arg));
- } else if (STRNCMP(arg, "texthl=", 7) == 0) {
+ } else if (strncmp(arg, "texthl=", 7) == 0) {
arg += 7;
XFREE_CLEAR(texthl);
texthl = xstrnsave(arg, (size_t)(p - arg));
- } else if (STRNCMP(arg, "culhl=", 6) == 0) {
+ } else if (strncmp(arg, "culhl=", 6) == 0) {
arg += 6;
XFREE_CLEAR(culhl);
culhl = xstrnsave(arg, (size_t)(p - arg));
- } else if (STRNCMP(arg, "numhl=", 6) == 0) {
+ } else if (strncmp(arg, "numhl=", 6) == 0) {
arg += 6;
XFREE_CLEAR(numhl);
numhl = xstrnsave(arg, (size_t)(p - arg));
@@ -1271,7 +1293,7 @@ static void sign_place_cmd(buf_T *buf, linenr_T lnum, char *sign_name, int id, c
}
/// ":sign unplace" command
-static void sign_unplace_cmd(buf_T *buf, linenr_T lnum, char *sign_name, int id, char *group)
+static void sign_unplace_cmd(buf_T *buf, linenr_T lnum, const char *sign_name, int id, char *group)
{
if (lnum >= 0 || sign_name != NULL || (group != NULL && *group == '\0')) {
emsg(_(e_invarg));
@@ -1328,7 +1350,7 @@ static void sign_unplace_cmd(buf_T *buf, linenr_T lnum, char *sign_name, int id,
/// :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 *sign_name, int id, char *group)
+static void sign_jump_cmd(buf_T *buf, linenr_T lnum, const char *sign_name, int id, char *group)
{
if (sign_name == NULL && group == NULL && id == -1) {
emsg(_(e_argreq));
@@ -1371,19 +1393,19 @@ static int parse_sign_cmd_args(int cmd, char *arg, char **sign_name, int *signid
}
while (*arg != NUL) {
- if (STRNCMP(arg, "line=", 5) == 0) {
+ if (strncmp(arg, "line=", 5) == 0) {
arg += 5;
*lnum = atoi(arg);
arg = skiptowhite(arg);
lnum_arg = true;
- } else if (STRNCMP(arg, "*", 1) == 0 && cmd == SIGNCMD_UNPLACE) {
+ } 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) {
+ } else if (strncmp(arg, "name=", 5) == 0) {
arg += 5;
name = arg;
arg = skiptowhite(arg);
@@ -1394,23 +1416,23 @@ static int parse_sign_cmd_args(int cmd, char *arg, char **sign_name, int *signid
name++;
}
*sign_name = name;
- } else if (STRNCMP(arg, "group=", 6) == 0) {
+ } 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) {
+ } else if (strncmp(arg, "priority=", 9) == 0) {
arg += 9;
*prio = atoi(arg);
arg = skiptowhite(arg);
- } else if (STRNCMP(arg, "file=", 5) == 0) {
+ } else if (strncmp(arg, "file=", 5) == 0) {
arg += 5;
filename = arg;
*buf = buflist_findname_exp(arg);
break;
- } else if (STRNCMP(arg, "buffer=", 7) == 0) {
+ } else if (strncmp(arg, "buffer=", 7) == 0) {
arg += 7;
filename = arg;
*buf = buflist_findnr(getdigits_int(&arg, true, 0));
@@ -1878,23 +1900,23 @@ void set_context_in_sign_cmd(expand_T *xp, char *arg)
xp->xp_pattern = p + 1;
switch (cmd_idx) {
case SIGNCMD_DEFINE:
- if (STRNCMP(last, "texthl", 6) == 0
- || STRNCMP(last, "linehl", 6) == 0
- || STRNCMP(last, "culhl", 5) == 0
- || STRNCMP(last, "numhl", 5) == 0) {
+ if (strncmp(last, "texthl", 6) == 0
+ || strncmp(last, "linehl", 6) == 0
+ || strncmp(last, "culhl", 5) == 0
+ || strncmp(last, "numhl", 5) == 0) {
xp->xp_context = EXPAND_HIGHLIGHT;
- } else if (STRNCMP(last, "icon", 4) == 0) {
+ } else if (strncmp(last, "icon", 4) == 0) {
xp->xp_context = EXPAND_FILES;
} else {
xp->xp_context = EXPAND_NOTHING;
}
break;
case SIGNCMD_PLACE:
- if (STRNCMP(last, "name", 4) == 0) {
+ if (strncmp(last, "name", 4) == 0) {
expand_what = EXP_SIGN_NAMES;
- } else if (STRNCMP(last, "group", 5) == 0) {
+ } else if (strncmp(last, "group", 5) == 0) {
expand_what = EXP_SIGN_GROUPS;
- } else if (STRNCMP(last, "file", 4) == 0) {
+ } else if (strncmp(last, "file", 4) == 0) {
xp->xp_context = EXPAND_BUFFERS;
} else {
xp->xp_context = EXPAND_NOTHING;
@@ -1902,9 +1924,9 @@ void set_context_in_sign_cmd(expand_T *xp, char *arg)
break;
case SIGNCMD_UNPLACE:
case SIGNCMD_JUMP:
- if (STRNCMP(last, "group", 5) == 0) {
+ if (strncmp(last, "group", 5) == 0) {
expand_what = EXP_SIGN_GROUPS;
- } else if (STRNCMP(last, "file", 4) == 0) {
+ } else if (strncmp(last, "file", 4) == 0) {
xp->xp_context = EXPAND_BUFFERS;
} else {
xp->xp_context = EXPAND_NOTHING;