From cdc839353f68ca43db6446e1b727fc7ba657b738 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 12 Sep 2022 13:38:41 +0100 Subject: patch 9.0.0449: there is no easy way to translate a key code into a string 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) --- src/message.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'src/message.c') diff --git a/src/message.c b/src/message.c index b68c08974..57197c1a8 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 "". + // used for the lhs of mapping and keytrans(). + int replace_lt) // TRUE to replace "<" with "". { 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 "". + // used for the lhs of mapping and keytrans(). + int replace_lt) // TRUE to replace "<" with "". { 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 . - // Use 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); } -- cgit v1.2.1