diff options
author | Josh Rahm <joshuarahm@gmail.com> | 2023-01-25 17:57:01 +0000 |
---|---|---|
committer | Josh Rahm <joshuarahm@gmail.com> | 2023-01-25 17:57:01 +0000 |
commit | 9837de570c5972f98e74848edc97c297a13136ea (patch) | |
tree | cc948611912d116a3f98a744e690d3d7b6e2f59a /src/nvim/digraph.c | |
parent | c367400b73d207833d51e09d663f969ffab37531 (diff) | |
parent | 3c48d3c83fc21dbc0841f9210f04bdb073d73cd1 (diff) | |
download | rneovim-9837de570c5972f98e74848edc97c297a13136ea.tar.gz rneovim-9837de570c5972f98e74848edc97c297a13136ea.tar.bz2 rneovim-9837de570c5972f98e74848edc97c297a13136ea.zip |
Merge remote-tracking branch 'upstream/master' into colorcolchar
Diffstat (limited to 'src/nvim/digraph.c')
-rw-r--r-- | src/nvim/digraph.c | 170 |
1 files changed, 91 insertions, 79 deletions
diff --git a/src/nvim/digraph.c b/src/nvim/digraph.c index 1267d49ad1..a057978a5e 100644 --- a/src/nvim/digraph.c +++ b/src/nvim/digraph.c @@ -8,24 +8,34 @@ #include <assert.h> #include <inttypes.h> #include <stdbool.h> +#include <string.h> #include "nvim/ascii.h" +#include "nvim/buffer_defs.h" #include "nvim/charset.h" #include "nvim/digraph.h" #include "nvim/drawscreen.h" #include "nvim/eval/typval.h" +#include "nvim/eval/typval_defs.h" +#include "nvim/ex_cmds_defs.h" #include "nvim/ex_docmd.h" #include "nvim/ex_getln.h" #include "nvim/garray.h" #include "nvim/getchar.h" +#include "nvim/gettext.h" +#include "nvim/globals.h" +#include "nvim/highlight_defs.h" +#include "nvim/keycodes.h" #include "nvim/mapping.h" #include "nvim/mbyte.h" #include "nvim/memory.h" #include "nvim/message.h" #include "nvim/normal.h" +#include "nvim/option_defs.h" #include "nvim/os/input.h" #include "nvim/runtime.h" #include "nvim/strings.h" +#include "nvim/types.h" #include "nvim/vim.h" typedef int result_T; @@ -52,7 +62,6 @@ static garray_T user_digraphs = { 0, 0, (int)sizeof(digr_T), 10, NULL }; /// Note: Characters marked with XX are not included literally, because some /// compilers cannot handle them (Amiga SAS/C is the most picky one). static digr_T digraphdefault[] = - // digraphs for Unicode from RFC1345 // (also work for ISO-8859-1 aka latin1) { @@ -1480,7 +1489,7 @@ int do_digraph(int c) /// Find a digraph for "val". If found return the string to display it. /// If not found return NULL. -char_u *get_digraph_for_char(int val_arg) +char *get_digraph_for_char(int val_arg) { const int val = val_arg; const digr_T *dp; @@ -1497,7 +1506,7 @@ char_u *get_digraph_for_char(int val_arg) r[0] = dp->char1; r[1] = dp->char2; r[2] = NUL; - return r; + return (char *)r; } dp++; } @@ -1519,30 +1528,31 @@ int get_digraph(bool cmdline) no_mapping--; allow_keys--; - if (c != ESC) { - // ESC cancels CTRL-K - if (IS_SPECIAL(c)) { - // insert special key code - return c; - } + if (c == ESC) { // ESC cancels CTRL-K + return NUL; + } - if (cmdline) { - if ((char2cells(c) == 1) && c < 128 && (cmdline_star == 0)) { - putcmdline((char)c, true); - } - } else { - add_to_showcmd(c); - } - no_mapping++; - allow_keys++; - int cc = plain_vgetc(); - no_mapping--; - allow_keys--; - - if (cc != ESC) { - // ESC cancels CTRL-K - return digraph_get(c, cc, true); + if (IS_SPECIAL(c)) { + // insert special key code + return c; + } + + if (cmdline) { + if ((char2cells(c) == 1) && c < 128 && (cmdline_star == 0)) { + putcmdline((char)c, true); } + } else { + add_to_showcmd(c); + } + no_mapping++; + allow_keys++; + int cc = plain_vgetc(); + no_mapping--; + allow_keys--; + + if (cc != ESC) { + // ESC cancels CTRL-K + return digraph_get(c, cc, true); } return NUL; } @@ -1646,8 +1656,8 @@ static void registerdigraph(int char1, int char2, int n) bool check_digraph_chars_valid(int char1, int char2) { if (char2 == 0) { - char_u msg[MB_MAXBYTES + 1]; - msg[utf_char2bytes(char1, (char *)msg)] = NUL; + char msg[MB_MAXBYTES + 1]; + msg[utf_char2bytes(char1, msg)] = NUL; semsg(_(e_digraph_must_be_just_two_characters_str), msg); return false; } @@ -1739,16 +1749,16 @@ static void digraph_getlist_appendpair(const digr_T *dp, list_T *l) list_T *l2 = tv_list_alloc(2); tv_list_append_list(l, l2); - char_u buf[30]; - buf[0] = dp->char1; - buf[1] = dp->char2; + char buf[30]; + buf[0] = (char)dp->char1; + buf[1] = (char)dp->char2; buf[2] = NUL; - tv_list_append_string(l2, (char *)buf, -1); + tv_list_append_string(l2, buf, -1); - char_u *p = buf; - p += utf_char2bytes(dp->result, (char *)p); + char *p = buf; + p += utf_char2bytes(dp->result, p); *p = NUL; - tv_list_append_string(l2, (char *)buf, -1); + tv_list_append_string(l2, buf, -1); } void digraph_getlist_common(bool list_all, typval_T *rettv) @@ -1814,57 +1824,59 @@ struct dg_header_entry { static void printdigraph(const digr_T *dp, result_T *previous) FUNC_ATTR_NONNULL_ARG(1) { - char_u buf[30]; + char buf[30]; int list_width = 13; - if (dp->result != 0) { - if (previous != NULL) { - for (int i = 0; header_table[i].dg_header != NULL; i++) { - if (*previous < header_table[i].dg_start - && dp->result >= header_table[i].dg_start - && dp->result < header_table[i + 1].dg_start) { - digraph_header(_(header_table[i].dg_header)); - break; - } + if (dp->result == 0) { + return; + } + + if (previous != NULL) { + for (int i = 0; header_table[i].dg_header != NULL; i++) { + if (*previous < header_table[i].dg_start + && dp->result >= header_table[i].dg_start + && dp->result < header_table[i + 1].dg_start) { + digraph_header(_(header_table[i].dg_header)); + break; } - *previous = dp->result; - } - if (msg_col > Columns - list_width) { - msg_putchar('\n'); } + *previous = dp->result; + } + if (msg_col > Columns - list_width) { + msg_putchar('\n'); + } - // Make msg_col a multiple of list_width by using spaces. - if (msg_col % list_width != 0) { - int spaces = (msg_col / list_width + 1) * list_width - msg_col; - while (spaces--) { - msg_putchar(' '); - } + // Make msg_col a multiple of list_width by using spaces. + if (msg_col % list_width != 0) { + int spaces = (msg_col / list_width + 1) * list_width - msg_col; + while (spaces--) { + msg_putchar(' '); } + } - char_u *p = &buf[0]; - *p++ = dp->char1; - *p++ = dp->char2; - *p++ = ' '; - *p = NUL; - msg_outtrans((char *)buf); - p = buf; + char *p = &buf[0]; + *p++ = (char)dp->char1; + *p++ = (char)dp->char2; + *p++ = ' '; + *p = NUL; + msg_outtrans(buf); + p = buf; - // add a space to draw a composing char on - if (utf_iscomposing(dp->result)) { - *p++ = ' '; - } - p += utf_char2bytes(dp->result, (char *)p); + // add a space to draw a composing char on + if (utf_iscomposing(dp->result)) { + *p++ = ' '; + } + p += utf_char2bytes(dp->result, p); - *p = NUL; - msg_outtrans_attr((char *)buf, HL_ATTR(HLF_8)); - p = buf; - if (char2cells(dp->result) == 1) { - *p++ = ' '; - } - assert(p >= buf); - vim_snprintf((char *)p, sizeof(buf) - (size_t)(p - buf), " %3d", dp->result); - msg_outtrans((char *)buf); + *p = NUL; + msg_outtrans_attr(buf, HL_ATTR(HLF_8)); + p = buf; + if (char2cells(dp->result) == 1) { + *p++ = ' '; } + assert(p >= buf); + vim_snprintf(p, sizeof(buf) - (size_t)(p - buf), " %3d", dp->result); + msg_outtrans(buf); } /// Get the two digraph characters from a typval. @@ -1873,7 +1885,7 @@ static int get_digraph_chars(const typval_T *arg, int *char1, int *char2) { char buf_chars[NUMBUFLEN]; const char *chars = tv_get_string_buf_chk(arg, buf_chars); - const char_u *p = (const char_u *)chars; + const char *p = chars; if (p != NULL) { if (*p != NUL) { @@ -1905,7 +1917,7 @@ static bool digraph_set_common(const typval_T *argchars, const typval_T *argdigr if (digraph == NULL) { return false; } - const char_u *p = (const char_u *)digraph; + const char *p = digraph; int n = mb_cptr2char_adv(&p); if (*p != NUL) { semsg(_(e_digraph_argument_must_be_one_character_str), digraph); @@ -2121,7 +2133,7 @@ void ex_loadkeymap(exarg_T *eap) vim_snprintf(buf, sizeof(buf), "<buffer> %s %s", ((kmap_T *)curbuf->b_kmap_ga.ga_data)[i].from, ((kmap_T *)curbuf->b_kmap_ga.ga_data)[i].to); - (void)do_map(MAPTYPE_MAP, (char_u *)buf, MODE_LANGMAP, false); + (void)do_map(MAPTYPE_MAP, buf, MODE_LANGMAP, false); } p_cpo = save_cpo; @@ -2158,7 +2170,7 @@ static void keymap_unload(void) for (int i = 0; i < curbuf->b_kmap_ga.ga_len; i++) { vim_snprintf(buf, sizeof(buf), "<buffer> %s", kp[i].from); - (void)do_map(MAPTYPE_UNMAP, (char_u *)buf, MODE_LANGMAP, false); + (void)do_map(MAPTYPE_UNMAP, buf, MODE_LANGMAP, false); } keymap_ga_clear(&curbuf->b_kmap_ga); |