aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/api/private/helpers.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nvim/api/private/helpers.c')
-rw-r--r--src/nvim/api/private/helpers.c52
1 files changed, 25 insertions, 27 deletions
diff --git a/src/nvim/api/private/helpers.c b/src/nvim/api/private/helpers.c
index aa9b3f5f18..521ec11906 100644
--- a/src/nvim/api/private/helpers.c
+++ b/src/nvim/api/private/helpers.c
@@ -770,7 +770,7 @@ void modify_keymap(Buffer buffer, bool is_unmap, String mode, String lhs,
MapArguments parsed_args;
memset(&parsed_args, 0, sizeof(parsed_args));
if (parse_keymap_opts(opts, &parsed_args, err)) {
- goto FAIL_AND_FREE;
+ goto fail_and_free;
}
parsed_args.buffer = !global;
@@ -782,14 +782,14 @@ void modify_keymap(Buffer buffer, bool is_unmap, String mode, String lhs,
err_msg = "LHS exceeds maximum map length: %s";
err_arg = lhs.data;
err_type = kErrorTypeValidation;
- goto FAIL_WITH_MESSAGE;
+ goto fail_with_message;
}
if (mode.size > 1) {
err_msg = "Shortname is too long: %s";
err_arg = mode.data;
err_type = kErrorTypeValidation;
- goto FAIL_WITH_MESSAGE;
+ goto fail_with_message;
}
int mode_val; // integer value of the mapping mode, to be passed to do_map()
char_u *p = (char_u *)((mode.size) ? mode.data : "m");
@@ -797,15 +797,14 @@ void modify_keymap(Buffer buffer, bool is_unmap, String mode, String lhs,
mode_val = get_map_mode(&p, true); // mapmode-ic
} else {
mode_val = get_map_mode(&p, false);
- if (mode_val == VISUAL + SELECTMODE + NORMAL + OP_PENDING) {
- // get_map_mode will treat "unrecognized" mode shortnames like "map"
- // if it does, and the given shortname wasn't "m" or " ", then error
- if (STRNCMP(p, "m", 2) && STRNCMP(p, " ", 2)) {
- err_msg = "Invalid mode shortname: %s";
- err_arg = (char *)p;
- err_type = kErrorTypeValidation;
- goto FAIL_WITH_MESSAGE;
- }
+ if ((mode_val == VISUAL + SELECTMODE + NORMAL + OP_PENDING)
+ && mode.size > 0) {
+ // get_map_mode() treats unrecognized mode shortnames as ":map".
+ // This is an error unless the given shortname was empty string "".
+ err_msg = "Invalid mode shortname: \"%s\"";
+ err_arg = (char *)p;
+ err_type = kErrorTypeValidation;
+ goto fail_with_message;
}
}
@@ -813,7 +812,7 @@ void modify_keymap(Buffer buffer, bool is_unmap, String mode, String lhs,
err_msg = "Invalid (empty) LHS";
err_arg = "";
err_type = kErrorTypeValidation;
- goto FAIL_WITH_MESSAGE;
+ goto fail_with_message;
}
bool is_noremap = parsed_args.noremap;
@@ -829,16 +828,16 @@ void modify_keymap(Buffer buffer, bool is_unmap, String mode, String lhs,
err_msg = "Parsing of nonempty RHS failed: %s";
err_arg = rhs.data;
err_type = kErrorTypeException;
- goto FAIL_WITH_MESSAGE;
+ goto fail_with_message;
}
} else if (is_unmap && parsed_args.rhs_len) {
err_msg = "Gave nonempty RHS in unmap command: %s";
err_arg = (char *)parsed_args.rhs;
err_type = kErrorTypeValidation;
- goto FAIL_WITH_MESSAGE;
+ goto fail_with_message;
}
- // buf_do_map_explicit reads noremap/unmap as its own argument
+ // buf_do_map() reads noremap/unmap as its own argument.
int maptype_val = 0;
if (is_unmap) {
maptype_val = 1;
@@ -846,23 +845,22 @@ void modify_keymap(Buffer buffer, bool is_unmap, String mode, String lhs,
maptype_val = 2;
}
- switch (buf_do_map_explicit(maptype_val, &parsed_args, mode_val,
- 0, target_buf)) {
+ switch (buf_do_map(maptype_val, &parsed_args, mode_val, 0, target_buf)) {
case 0:
break;
case 1:
api_set_error(err, kErrorTypeException, (char *)e_invarg, 0);
- goto FAIL_AND_FREE;
+ goto fail_and_free;
case 2:
api_set_error(err, kErrorTypeException, (char *)e_nomap, 0);
- goto FAIL_AND_FREE;
+ goto fail_and_free;
case 5:
api_set_error(err, kErrorTypeException,
"E227: mapping already exists for %s", parsed_args.lhs);
- goto FAIL_AND_FREE;
+ goto fail_and_free;
default:
assert(false && "Unrecognized return code!");
- goto FAIL_AND_FREE;
+ goto fail_and_free;
} // switch
xfree(lhs_buf);
@@ -872,10 +870,10 @@ void modify_keymap(Buffer buffer, bool is_unmap, String mode, String lhs,
return;
-FAIL_WITH_MESSAGE:
+fail_with_message:
api_set_error(err, err_type, err_msg, err_arg);
-FAIL_AND_FREE:
+fail_and_free:
xfree(lhs_buf);
xfree(rhs_buf);
xfree(parsed_args.rhs);
@@ -913,7 +911,7 @@ Integer parse_keymap_opts(Dictionary opts, MapArguments *out, Error *err)
err_msg = "Gave non-boolean value for an opt: %s";
err_arg = optname;
err_type = kErrorTypeValidation;
- goto FAIL_WITH_MESSAGE;
+ goto fail_with_message;
}
bool was_valid_opt = false;
@@ -961,13 +959,13 @@ Integer parse_keymap_opts(Dictionary opts, MapArguments *out, Error *err)
err_msg = "Invalid key: %s";
err_arg = optname;
err_type = kErrorTypeValidation;
- goto FAIL_WITH_MESSAGE;
+ goto fail_with_message;
}
} // for
return 0;
-FAIL_WITH_MESSAGE:
+fail_with_message:
api_set_error(err, err_type, err_msg, err_arg);
return 1;
}