summaryrefslogtreecommitdiff
path: root/src/map.c
diff options
context:
space:
mode:
authorNicholas Todoroff <nd.todoroff@gmail.com>2023-08-29 00:33:12 -0600
committerRafael Marçalo <raroma09@gmail.com>2023-09-10 23:49:05 +0100
commit1a1a232e4a78d5ab3eb55978606db9a6dc4e78b8 (patch)
treed592e35535884122e5ba6a06e04924778715621f /src/map.c
parentc6ba54c9027dfbcdf868dd5e9e592f8499c4c6eb (diff)
Escape special keys in mappings using backslash
* Interpret a string like "\<C-R>" as representing the literal key sequence '<' 'C' '-' 'R' '>'. * Add a '<Bslash>' special key so that e.g. the string "<Bslash><C-R>" is interpreted as the key sequence '\' followed by CTRL-R.
Diffstat (limited to 'src/map.c')
-rw-r--r--src/map.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/map.c b/src/map.c
index e7129c0..12802d6 100644
--- a/src/map.c
+++ b/src/map.c
@@ -79,6 +79,7 @@ static struct {
char *ch;
int chlen;
} key_labels[] = {
+ {"<Bslash>", 8, "\\", 1},
{"<CR>", 4, "\x0d", 1},
{"<Tab>", 5, "\t", 1},
{"<S-Tab>", 7, CSI_STR "kB", 3},
@@ -435,6 +436,15 @@ static char *convert_keys(const char *in, int inlen, int *len)
*len = 0;
for (p = in; p < &in[inlen]; p++) {
+ /* if we encounter the sequence \< we replace it with just < but act
+ * like it's a non-special character */
+ if (*p == '\\' && p+1 < &in[inlen] && *(p+1) == '<') {
+ g_string_append_len(str, p+1, 1);
+ *len += 1;
+ ++p;
+ continue;
+ }
+
/* if it starts not with < we can add it literally */
if (*p != '<') {
g_string_append_len(str, p, 1);