Mercurial > vim
comparison src/map.c @ 19178:f7081bd2680e v8.2.0148
patch 8.2.0148: mapping related function in wrong source file
Commit: https://github.com/vim/vim/commit/7f51bbe0d19f1f0cb0321326f45a17b4f5155f89
Author: Bram Moolenaar <Bram@vim.org>
Date: Fri Jan 24 20:21:19 2020 +0100
patch 8.2.0148: mapping related function in wrong source file
Problem: Mapping related function in wrong source file.
Solution: Move the function. Add a few more test cases. (Yegappan
Lakshmanan, closes #5528)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Fri, 24 Jan 2020 20:30:04 +0100 |
parents | af1eca322b9e |
children | 658248b68f7c |
comparison
equal
deleted
inserted
replaced
19177:0d7b7b121ca6 | 19178:f7081bd2680e |
---|---|
1053 * Used below when expanding mapping/abbreviation names. | 1053 * Used below when expanding mapping/abbreviation names. |
1054 */ | 1054 */ |
1055 static int expand_mapmodes = 0; | 1055 static int expand_mapmodes = 0; |
1056 static int expand_isabbrev = 0; | 1056 static int expand_isabbrev = 0; |
1057 static int expand_buffer = FALSE; | 1057 static int expand_buffer = FALSE; |
1058 | |
1059 /* | |
1060 * Translate an internal mapping/abbreviation representation into the | |
1061 * corresponding external one recognized by :map/:abbrev commands. | |
1062 * Respects the current B/k/< settings of 'cpoption'. | |
1063 * | |
1064 * This function is called when expanding mappings/abbreviations on the | |
1065 * command-line. | |
1066 * | |
1067 * It uses a growarray to build the translation string since the latter can be | |
1068 * wider than the original description. The caller has to free the string | |
1069 * afterwards. | |
1070 * | |
1071 * Returns NULL when there is a problem. | |
1072 */ | |
1073 static char_u * | |
1074 translate_mapping(char_u *str) | |
1075 { | |
1076 garray_T ga; | |
1077 int c; | |
1078 int modifiers; | |
1079 int cpo_bslash; | |
1080 int cpo_special; | |
1081 | |
1082 ga_init(&ga); | |
1083 ga.ga_itemsize = 1; | |
1084 ga.ga_growsize = 40; | |
1085 | |
1086 cpo_bslash = (vim_strchr(p_cpo, CPO_BSLASH) != NULL); | |
1087 cpo_special = (vim_strchr(p_cpo, CPO_SPECI) != NULL); | |
1088 | |
1089 for (; *str; ++str) | |
1090 { | |
1091 c = *str; | |
1092 if (c == K_SPECIAL && str[1] != NUL && str[2] != NUL) | |
1093 { | |
1094 modifiers = 0; | |
1095 if (str[1] == KS_MODIFIER) | |
1096 { | |
1097 str++; | |
1098 modifiers = *++str; | |
1099 c = *++str; | |
1100 } | |
1101 if (c == K_SPECIAL && str[1] != NUL && str[2] != NUL) | |
1102 { | |
1103 if (cpo_special) | |
1104 { | |
1105 ga_clear(&ga); | |
1106 return NULL; | |
1107 } | |
1108 c = TO_SPECIAL(str[1], str[2]); | |
1109 if (c == K_ZERO) // display <Nul> as ^@ | |
1110 c = NUL; | |
1111 str += 2; | |
1112 } | |
1113 if (IS_SPECIAL(c) || modifiers) // special key | |
1114 { | |
1115 if (cpo_special) | |
1116 { | |
1117 ga_clear(&ga); | |
1118 return NULL; | |
1119 } | |
1120 ga_concat(&ga, get_special_key_name(c, modifiers)); | |
1121 continue; // for (str) | |
1122 } | |
1123 } | |
1124 if (c == ' ' || c == '\t' || c == Ctrl_J || c == Ctrl_V | |
1125 || (c == '<' && !cpo_special) || (c == '\\' && !cpo_bslash)) | |
1126 ga_append(&ga, cpo_bslash ? Ctrl_V : '\\'); | |
1127 if (c) | |
1128 ga_append(&ga, c); | |
1129 } | |
1130 ga_append(&ga, NUL); | |
1131 return (char_u *)(ga.ga_data); | |
1132 } | |
1058 | 1133 |
1059 /* | 1134 /* |
1060 * Work out what to complete when doing command line completion of mapping | 1135 * Work out what to complete when doing command line completion of mapping |
1061 * or abbreviation names. | 1136 * or abbreviation names. |
1062 */ | 1137 */ |