comparison src/term.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 847cc7932c42
children 2ef19eed524a
comparison
equal deleted inserted replaced
19177:0d7b7b121ca6 19178:f7081bd2680e
5934 --no_mapping; 5934 --no_mapping;
5935 --allow_keys; 5935 --allow_keys;
5936 } 5936 }
5937 #endif 5937 #endif
5938 5938
5939 /*
5940 * Translate an internal mapping/abbreviation representation into the
5941 * corresponding external one recognized by :map/:abbrev commands.
5942 * Respects the current B/k/< settings of 'cpoption'.
5943 *
5944 * This function is called when expanding mappings/abbreviations on the
5945 * command-line.
5946 *
5947 * It uses a growarray to build the translation string since the latter can be
5948 * wider than the original description. The caller has to free the string
5949 * afterwards.
5950 *
5951 * Returns NULL when there is a problem.
5952 */
5953 char_u *
5954 translate_mapping(char_u *str)
5955 {
5956 garray_T ga;
5957 int c;
5958 int modifiers;
5959 int cpo_bslash;
5960 int cpo_special;
5961
5962 ga_init(&ga);
5963 ga.ga_itemsize = 1;
5964 ga.ga_growsize = 40;
5965
5966 cpo_bslash = (vim_strchr(p_cpo, CPO_BSLASH) != NULL);
5967 cpo_special = (vim_strchr(p_cpo, CPO_SPECI) != NULL);
5968
5969 for (; *str; ++str)
5970 {
5971 c = *str;
5972 if (c == K_SPECIAL && str[1] != NUL && str[2] != NUL)
5973 {
5974 modifiers = 0;
5975 if (str[1] == KS_MODIFIER)
5976 {
5977 str++;
5978 modifiers = *++str;
5979 c = *++str;
5980 }
5981 if (c == K_SPECIAL && str[1] != NUL && str[2] != NUL)
5982 {
5983 if (cpo_special)
5984 {
5985 ga_clear(&ga);
5986 return NULL;
5987 }
5988 c = TO_SPECIAL(str[1], str[2]);
5989 if (c == K_ZERO) // display <Nul> as ^@
5990 c = NUL;
5991 str += 2;
5992 }
5993 if (IS_SPECIAL(c) || modifiers) // special key
5994 {
5995 if (cpo_special)
5996 {
5997 ga_clear(&ga);
5998 return NULL;
5999 }
6000 ga_concat(&ga, get_special_key_name(c, modifiers));
6001 continue; // for (str)
6002 }
6003 }
6004 if (c == ' ' || c == '\t' || c == Ctrl_J || c == Ctrl_V
6005 || (c == '<' && !cpo_special) || (c == '\\' && !cpo_bslash))
6006 ga_append(&ga, cpo_bslash ? Ctrl_V : '\\');
6007 if (c)
6008 ga_append(&ga, c);
6009 }
6010 ga_append(&ga, NUL);
6011 return (char_u *)(ga.ga_data);
6012 }
6013
6014 #if (defined(MSWIN) && (!defined(FEAT_GUI) || defined(VIMDLL))) || defined(PROTO) 5939 #if (defined(MSWIN) && (!defined(FEAT_GUI) || defined(VIMDLL))) || defined(PROTO)
6015 static char ksme_str[20]; 5940 static char ksme_str[20];
6016 static char ksmr_str[20]; 5941 static char ksmr_str[20];
6017 static char ksmd_str[20]; 5942 static char ksmd_str[20];
6018 5943