diff options
author | zeertzjq <zeertzjq@outlook.com> | 2022-09-12 13:38:41 +0100 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2022-09-12 13:38:41 +0100 |
commit | cdc839353f68ca43db6446e1b727fc7ba657b738 (patch) | |
tree | 0729860faa774e594b183ce0823ae23776b92701 /src/message.c | |
parent | 5a4eb55122e45444d3a6c56ce108ce29bc8e52ab (diff) |
patch 9.0.0449: there is no easy way to translate a key code into a stringv9.0.0449
Problem: There is no easy way to translate a string with a key code into a
readable string.
Solution: Add the keytrans() function. (closes #11114)
Diffstat (limited to 'src/message.c')
-rw-r--r-- | src/message.c | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/src/message.c b/src/message.c index b68c089747..57197c1a83 100644 --- a/src/message.c +++ b/src/message.c @@ -1759,7 +1759,7 @@ msg_outtrans_special( ++str; } else - text = (char *)str2special(&str, from); + text = (char *)str2special(&str, from, FALSE); if (text[0] != NUL && text[1] == NUL) // single-byte character or illegal byte text = (char *)transchar_byte((char_u)text[0]); @@ -1782,14 +1782,16 @@ msg_outtrans_special( char_u * str2special_save( char_u *str, - int is_lhs) // TRUE for lhs, FALSE for rhs + int replace_spaces, // TRUE to replace " " with "<Space>". + // used for the lhs of mapping and keytrans(). + int replace_lt) // TRUE to replace "<" with "<lt>". { garray_T ga; char_u *p = str; ga_init2(&ga, 1, 40); while (*p != NUL) - ga_concat(&ga, str2special(&p, is_lhs)); + ga_concat(&ga, str2special(&p, replace_spaces, replace_lt)); ga_append(&ga, NUL); return (char_u *)ga.ga_data; } @@ -1804,7 +1806,9 @@ str2special_save( char_u * str2special( char_u **sp, - int from) // TRUE for lhs of mapping + int replace_spaces, // TRUE to replace " " with "<Space>". + // used for the lhs of mapping and keytrans(). + int replace_lt) // TRUE to replace "<" with "<lt>". { int c; static char_u buf[7]; @@ -1861,8 +1865,10 @@ str2special( *sp = str + (*str == NUL ? 0 : 1); // Make special keys and C0 control characters in <> form, also <M-Space>. - // Use <Space> only for lhs of a mapping. - if (special || c < ' ' || (from && c == ' ')) + if (special + || c < ' ' + || (replace_spaces && c == ' ') + || (replace_lt && c == '<')) return get_special_key_name(c, modifiers); buf[0] = c; buf[1] = NUL; @@ -1880,7 +1886,7 @@ str2specialbuf(char_u *sp, char_u *buf, int len) *buf = NUL; while (*sp) { - s = str2special(&sp, FALSE); + s = str2special(&sp, FALSE, FALSE); if ((int)(STRLEN(s) + STRLEN(buf)) < len) STRCAT(buf, s); } |