aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/mapping.c
diff options
context:
space:
mode:
authorJosh Rahm <joshuarahm@gmail.com>2024-11-25 19:15:05 +0000
committerJosh Rahm <joshuarahm@gmail.com>2024-11-25 19:27:38 +0000
commitc5d770d311841ea5230426cc4c868e8db27300a8 (patch)
treedd21f70127b4b8b5f109baefc8ecc5016f507c91 /src/nvim/mapping.c
parent9be89f131f87608f224f0ee06d199fcd09d32176 (diff)
parent081beb3659bd6d8efc3e977a160b1e72becbd8a2 (diff)
downloadrneovim-c5d770d311841ea5230426cc4c868e8db27300a8.tar.gz
rneovim-c5d770d311841ea5230426cc4c868e8db27300a8.tar.bz2
rneovim-c5d770d311841ea5230426cc4c868e8db27300a8.zip
Merge remote-tracking branch 'upstream/master' into mix_20240309
Diffstat (limited to 'src/nvim/mapping.c')
-rw-r--r--src/nvim/mapping.c30
1 files changed, 19 insertions, 11 deletions
diff --git a/src/nvim/mapping.c b/src/nvim/mapping.c
index e055ebc2fa..1a6b2c3581 100644
--- a/src/nvim/mapping.c
+++ b/src/nvim/mapping.c
@@ -239,9 +239,9 @@ static void showmap(mapblock_T *mp, bool local)
} while (len < 12);
if (mp->m_noremap == REMAP_NONE) {
- msg_puts_attr("*", HL_ATTR(HLF_8));
+ msg_puts_hl("*", HLF_8, false);
} else if (mp->m_noremap == REMAP_SCRIPT) {
- msg_puts_attr("&", HL_ATTR(HLF_8));
+ msg_puts_hl("&", HLF_8, false);
} else {
msg_putchar(' ');
}
@@ -256,10 +256,10 @@ static void showmap(mapblock_T *mp, bool local)
// the rhs, and not M-x etc, true gets both -- webb
if (mp->m_luaref != LUA_NOREF) {
char *str = nlua_funcref_str(mp->m_luaref, NULL);
- msg_puts_attr(str, HL_ATTR(HLF_8));
+ msg_puts_hl(str, HLF_8, false);
xfree(str);
} else if (mp->m_str[0] == NUL) {
- msg_puts_attr("<Nop>", HL_ATTR(HLF_8));
+ msg_puts_hl("<Nop>", HLF_8, false);
} else {
msg_outtrans_special(mp->m_str, false, 0);
}
@@ -568,6 +568,12 @@ static int buf_do_map(int maptype, MapArguments *args, int mode, bool is_abbrev,
mapblock_T **abbr_table = args->buffer ? &buf->b_first_abbr : &first_abbr;
mapblock_T *mp_result[2] = { NULL, NULL };
+ bool unmap_lhs_only = false;
+ if (maptype == MAPTYPE_UNMAP_LHS) {
+ unmap_lhs_only = true;
+ maptype = MAPTYPE_UNMAP;
+ }
+
// For ":noremap" don't remap, otherwise do remap.
int noremap = args->script ? REMAP_SCRIPT
: maptype == MAPTYPE_NOREMAP ? REMAP_NONE : REMAP_YES;
@@ -720,8 +726,8 @@ static int buf_do_map(int maptype, MapArguments *args, int mode, bool is_abbrev,
// entry with a matching 'to' part. This was done to allow ":ab foo bar"
// to be unmapped by typing ":unab foo", where "foo" will be replaced by
// "bar" because of the abbreviation.
- for (int round = 0; (round == 0 || maptype == MAPTYPE_UNMAP) && round <= 1
- && !did_it && !got_int; round++) {
+ const int num_rounds = maptype == MAPTYPE_UNMAP && !unmap_lhs_only ? 2 : 1;
+ for (int round = 0; round < num_rounds && !did_it && !got_int; round++) {
int hash_start, hash_end;
if ((round == 0 && has_lhs) || is_abbrev) {
// just use one hash
@@ -935,9 +941,11 @@ theend:
/// for :cabbr mode is MODE_CMDLINE
/// ```
///
-/// @param maptype MAPTYPE_MAP for |:map|
-/// MAPTYPE_UNMAP for |:unmap|
-/// MAPTYPE_NOREMAP for |:noremap|.
+/// @param maptype MAPTYPE_MAP for |:map| or |:abbr|
+/// MAPTYPE_UNMAP for |:unmap| or |:unabbr|
+/// MAPTYPE_NOREMAP for |:noremap| or |:noreabbr|
+/// MAPTYPE_UNMAP_LHS is like MAPTYPE_UNMAP, but doesn't try to match
+/// with {rhs} if there is no match with {lhs}.
/// @param arg C-string containing the arguments of the map/abbrev
/// command, i.e. everything except the initial `:[X][nore]map`.
/// - Cannot be a read-only string; it will be modified.
@@ -2348,7 +2356,7 @@ void f_mapset(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
MapArguments unmap_args = MAP_ARGUMENTS_INIT;
set_maparg_lhs_rhs(lhs, strlen(lhs), "", 0, LUA_NOREF, p_cpo, &unmap_args);
unmap_args.buffer = buffer;
- buf_do_map(MAPTYPE_UNMAP, &unmap_args, mode, is_abbr, curbuf);
+ buf_do_map(MAPTYPE_UNMAP_LHS, &unmap_args, mode, is_abbr, curbuf);
xfree(unmap_args.rhs);
xfree(unmap_args.orig_rhs);
@@ -2649,7 +2657,7 @@ void ex_map(exarg_T *eap)
// If we are in a secure mode we print the mappings for security reasons.
if (secure) {
secure = 2;
- msg_outtrans(eap->cmd, 0);
+ msg_outtrans(eap->cmd, 0, false);
msg_putchar('\n');
}
do_exmap(eap, false);