diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2017-07-08 17:33:43 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-07-08 17:33:43 +0200 |
commit | 0fb4d173f8faa7ec4736ceb3b4e89ada6f7d73e5 (patch) | |
tree | 93bb22888e979af1e86dba6c419a441f44e67f42 /src | |
parent | 6720fe253e92b21c7f989389a64e363b5933884f (diff) | |
parent | 829e1f2c43f84caa74c68e8a473d5faf8ec96c48 (diff) | |
download | rneovim-0fb4d173f8faa7ec4736ceb3b4e89ada6f7d73e5.tar.gz rneovim-0fb4d173f8faa7ec4736ceb3b4e89ada6f7d73e5.tar.bz2 rneovim-0fb4d173f8faa7ec4736ceb3b4e89ada6f7d73e5.zip |
Merge #6945 from justinmk/cpoptions
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/api/vim.c | 12 | ||||
-rw-r--r-- | src/nvim/eval.c | 2 | ||||
-rw-r--r-- | src/nvim/ex_docmd.c | 2 | ||||
-rw-r--r-- | src/nvim/getchar.c | 24 | ||||
-rw-r--r-- | src/nvim/keymap.c | 17 | ||||
-rw-r--r-- | src/nvim/keymap.h | 10 | ||||
-rw-r--r-- | src/nvim/menu.c | 5 | ||||
-rw-r--r-- | src/nvim/option.c | 2 | ||||
-rw-r--r-- | src/nvim/option_defs.h | 70 |
9 files changed, 63 insertions, 81 deletions
diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 80efe86ea3..2bc31b2812 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -136,9 +136,13 @@ Integer nvim_input(String keys) return (Integer)input_enqueue(keys); } -/// Replaces terminal codes and key codes (<CR>, <Esc>, ...) in a string with +/// Replaces terminal codes and |keycodes| (<CR>, <Esc>, ...) in a string with /// the internal representation. /// +/// @param str String to be converted. +/// @param from_part Legacy Vim parameter. Usually true. +/// @param do_lt Also translate <lt>. Ignored if `special` is false. +/// @param special Replace |keycodes|, e.g. <CR> becomes a "\n" char. /// @see replace_termcodes /// @see cpoptions String nvim_replace_termcodes(String str, Boolean from_part, Boolean do_lt, @@ -151,12 +155,6 @@ String nvim_replace_termcodes(String str, Boolean from_part, Boolean do_lt, } char *ptr = NULL; - // Set 'cpoptions' the way we want it. - // FLAG_CPO_BSLASH set - backslashes are *not* treated specially - // FLAG_CPO_KEYCODE set - keycodes are *not* reverse-engineered - // FLAG_CPO_SPECI unset - <Key> sequences *are* interpreted - // The third from end parameter of replace_termcodes() is true so that the - // <lt> sequence is recognised - needed for a real backslash. replace_termcodes((char_u *)str.data, str.size, (char_u **)&ptr, from_part, do_lt, special, CPO_TO_CPO_FLAGS); return cstr_as_string(ptr); diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 662270e788..7e9c006f33 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -12111,7 +12111,7 @@ static void get_maparg(typval_T *argvars, typval_T *rettv, int exact) mode = get_map_mode((char_u **)&which, 0); - keys = replace_termcodes(keys, STRLEN(keys), &keys_buf, true, true, false, + keys = replace_termcodes(keys, STRLEN(keys), &keys_buf, true, true, true, CPO_TO_CPO_FLAGS); rhs = check_map(keys, mode, exact, false, abbr, &mp, &buffer_local); xfree(keys_buf); diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index af8845de87..5d7246581c 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -4747,7 +4747,7 @@ static int uc_add_command(char_u *name, size_t name_len, char_u *rep, char_u *rep_buf = NULL; garray_T *gap; - replace_termcodes(rep, STRLEN(rep), &rep_buf, false, false, false, + replace_termcodes(rep, STRLEN(rep), &rep_buf, false, false, true, CPO_TO_CPO_FLAGS); if (rep_buf == NULL) { /* Can't replace termcodes - try using the string as is */ diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index fc1b8ccfcb..a22b716bb6 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -2537,7 +2537,6 @@ do_map ( bool unique = false; bool nowait = false; bool silent = false; - bool special = false; bool expr = false; int noremap; char_u *orig_rhs; @@ -2583,12 +2582,9 @@ do_map ( continue; } - /* - * Check for "<special>": accept special keys in <> - */ + // Ignore obsolete "<special>" modifier. if (STRNCMP(keys, "<special>", 9) == 0) { keys = skipwhite(keys + 9); - special = true; continue; } @@ -2657,7 +2653,7 @@ do_map ( // needs to be freed later (*keys_buf and *arg_buf). // replace_termcodes() also removes CTRL-Vs and sometimes backslashes. if (haskey) { - keys = replace_termcodes(keys, STRLEN(keys), &keys_buf, true, true, special, + keys = replace_termcodes(keys, STRLEN(keys), &keys_buf, true, true, true, CPO_TO_CPO_FLAGS); } orig_rhs = rhs; @@ -2665,7 +2661,7 @@ do_map ( if (STRICMP(rhs, "<nop>") == 0) { // "<Nop>" means nothing rhs = (char_u *)""; } else { - rhs = replace_termcodes(rhs, STRLEN(rhs), &arg_buf, false, true, special, + rhs = replace_termcodes(rhs, STRLEN(rhs), &arg_buf, false, true, true, CPO_TO_CPO_FLAGS); } } @@ -3245,7 +3241,7 @@ bool map_to_exists(const char *const str, const char *const modechars, char_u *buf; char_u *const rhs = replace_termcodes((const char_u *)str, strlen(str), &buf, - false, true, false, + false, true, true, CPO_TO_CPO_FLAGS); #define MAPMODE(mode, modechars, chr, modeflags) \ @@ -4158,8 +4154,7 @@ void add_map(char_u *map, int mode) } // Translate an internal mapping/abbreviation representation into the -// corresponding external one recognized by :map/:abbrev commands; -// respects the current B/k/< settings of 'cpoption'. +// corresponding external one recognized by :map/:abbrev commands. // // This function is called when expanding mappings/abbreviations on the // command-line, and for building the "Ambiguous mapping..." error message. @@ -4179,7 +4174,6 @@ static char_u * translate_mapping ( ga_init(&ga, 1, 40); bool cpo_bslash = !(cpo_flags&FLAG_CPO_BSLASH); - bool cpo_special = !(cpo_flags&FLAG_CPO_SPECI); for (; *str; ++str) { int c = *str; @@ -4192,7 +4186,7 @@ static char_u * translate_mapping ( } if (c == K_SPECIAL && str[1] != NUL && str[2] != NUL) { - if (expmap && cpo_special) { + if (expmap) { ga_clear(&ga); return NULL; } @@ -4203,8 +4197,8 @@ static char_u * translate_mapping ( } str += 2; } - if (IS_SPECIAL(c) || modifiers) { /* special key */ - if (expmap && cpo_special) { + if (IS_SPECIAL(c) || modifiers) { // special key + if (expmap) { ga_clear(&ga); return NULL; } @@ -4214,7 +4208,7 @@ static char_u * translate_mapping ( } if (c == ' ' || c == '\t' || c == Ctrl_J || c == Ctrl_V - || (c == '<' && !cpo_special) || (c == '\\' && !cpo_bslash)) { + || (c == '\\' && !cpo_bslash)) { ga_append(&ga, cpo_bslash ? Ctrl_V : '\\'); } diff --git a/src/nvim/keymap.c b/src/nvim/keymap.c index ee67b4c19d..3d7ebb6382 100644 --- a/src/nvim/keymap.c +++ b/src/nvim/keymap.c @@ -756,9 +756,9 @@ int get_mouse_button(int code, bool *is_click, bool *is_drag) /// Replace any terminal code strings with the equivalent internal /// representation /// -/// This is used for the "from" and "to" part of a mapping, and the "to" part of +/// Used for the "from" and "to" part of a mapping, and the "to" part of /// a menu command. Any strings like "<C-UP>" are also replaced, unless -/// 'cpoptions' contains '<'. K_SPECIAL by itself is replaced by K_SPECIAL +/// `special` is false. K_SPECIAL by itself is replaced by K_SPECIAL /// KS_SPECIAL KE_FILLER. /// /// @param[in] from What characters to replace. @@ -771,7 +771,7 @@ int get_mouse_button(int code, bool *is_click, bool *is_drag) /// When cpo_flags contains #FLAG_CPO_BSLASH, a backslash /// can be used in place of <C-v>. All other <C-v> /// characters are removed. -/// @param[in] special If true, always accept <key> notation. +/// @param[in] special Replace keycodes, e.g. <CR> becomes a "\n" char. /// @param[in] cpo_flags Relevant flags derived from p_cpo, see /// #CPO_TO_CPO_FLAGS. /// @@ -790,11 +790,9 @@ char_u *replace_termcodes(const char_u *from, const size_t from_len, const char_u *src; const char_u *const end = from + from_len - 1; int do_backslash; // backslash is a special character - int do_special; // recognize <> key codes char_u *result; // buffer for resulting string do_backslash = !(cpo_flags&FLAG_CPO_BSLASH); - do_special = !(cpo_flags&FLAG_CPO_SPECI) || special; // Allocate space for the translation. Worst case a single character is // replaced by 6 bytes (shifted special key), plus a NUL at the end. @@ -817,10 +815,9 @@ char_u *replace_termcodes(const char_u *from, const size_t from_len, // Copy each byte from *from to result[dlen] while (src <= end) { - // If 'cpoptions' does not contain '<', check for special key codes, - // like "<C-S-LeftMouse>" - if (do_special && (do_lt || ((end - src) >= 3 - && STRNCMP(src, "<lt>", 4) != 0))) { + // Check for special <> keycodes, like "<C-S-LeftMouse>" + if (special && (do_lt || ((end - src) >= 3 + && STRNCMP(src, "<lt>", 4) != 0))) { // Replace <SID> by K_SNR <script-nr> _. // (room: 5 * 6 = 30 bytes; needed: 3 + <nr> + 1 <= 14) if (end - src >= 4 && STRNICMP(src, "<SID>", 5) == 0) { @@ -846,7 +843,7 @@ char_u *replace_termcodes(const char_u *from, const size_t from_len, } } - if (do_special) { + if (special) { char_u *p, *s, len; // Replace <Leader> by the value of "mapleader". diff --git a/src/nvim/keymap.h b/src/nvim/keymap.h index bb8ba84a6a..b8fed77a90 100644 --- a/src/nvim/keymap.h +++ b/src/nvim/keymap.h @@ -464,13 +464,9 @@ enum key_extra { #define MAX_KEY_CODE_LEN 6 #define FLAG_CPO_BSLASH 0x01 -#define FLAG_CPO_SPECI 0x02 -#define CPO_TO_CPO_FLAGS (((vim_strchr(p_cpo, CPO_BSLASH) == NULL) \ - ? 0 \ - : FLAG_CPO_BSLASH)| \ - (vim_strchr(p_cpo, CPO_SPECI) == NULL \ - ? 0 \ - : FLAG_CPO_SPECI)) +#define CPO_TO_CPO_FLAGS ((vim_strchr(p_cpo, CPO_BSLASH) == NULL) \ + ? 0 \ + : FLAG_CPO_BSLASH) #ifdef INCLUDE_GENERATED_DECLARATIONS # include "keymap.h.generated.h" diff --git a/src/nvim/menu.c b/src/nvim/menu.c index 7e9e9e9e5c..c8e6012e5c 100644 --- a/src/nvim/menu.c +++ b/src/nvim/menu.c @@ -60,7 +60,6 @@ ex_menu ( char_u *map_to; int noremap; bool silent = false; - bool special = false; int unmenu; char_u *map_buf; char_u *arg; @@ -86,7 +85,7 @@ ex_menu ( continue; } if (STRNCMP(arg, "<special>", 9) == 0) { - special = true; + // Ignore obsolete "<special>" modifier. arg = skipwhite(arg + 9); continue; } @@ -222,7 +221,7 @@ ex_menu ( map_buf = NULL; // Menu tips are plain text. } else { map_to = replace_termcodes(map_to, STRLEN(map_to), &map_buf, false, true, - special, CPO_TO_CPO_FLAGS); + true, CPO_TO_CPO_FLAGS); } menuarg.modes = modes; menuarg.noremap[0] = noremap; diff --git a/src/nvim/option.c b/src/nvim/option.c index ed058c420d..37b37e2859 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -3034,7 +3034,7 @@ did_set_string_option ( /* 'pastetoggle': translate key codes like in a mapping */ else if (varp == &p_pt) { if (*p_pt) { - (void)replace_termcodes(p_pt, STRLEN(p_pt), &p, true, true, false, + (void)replace_termcodes(p_pt, STRLEN(p_pt), &p, true, true, true, CPO_TO_CPO_FLAGS); if (p != NULL) { if (new_value_alloced) diff --git a/src/nvim/option_defs.h b/src/nvim/option_defs.h index e68dba734e..a2fe90b3c2 100644 --- a/src/nvim/option_defs.h +++ b/src/nvim/option_defs.h @@ -81,58 +81,56 @@ #define DFLT_FO_VIM "tcqj" #define FO_ALL "tcroq2vlb1mMBn,awj" /* for do_set() */ -/* characters for the p_cpo option: */ -#define CPO_ALTREAD 'a' /* ":read" sets alternate file name */ -#define CPO_ALTWRITE 'A' /* ":write" sets alternate file name */ -#define CPO_BAR 'b' /* "\|" ends a mapping */ -#define CPO_BSLASH 'B' /* backslash in mapping is not special */ +// characters for the p_cpo option: +#define CPO_ALTREAD 'a' // ":read" sets alternate file name +#define CPO_ALTWRITE 'A' // ":write" sets alternate file name +#define CPO_BAR 'b' // "\|" ends a mapping +#define CPO_BSLASH 'B' // backslash in mapping is not special #define CPO_SEARCH 'c' -#define CPO_CONCAT 'C' /* Don't concatenate sourced lines */ -#define CPO_DOTTAG 'd' /* "./tags" in 'tags' is in current dir */ -#define CPO_DIGRAPH 'D' /* No digraph after "r", "f", etc. */ +#define CPO_CONCAT 'C' // Don't concatenate sourced lines +#define CPO_DOTTAG 'd' // "./tags" in 'tags' is in current dir +#define CPO_DIGRAPH 'D' // No digraph after "r", "f", etc. #define CPO_EXECBUF 'e' -#define CPO_EMPTYREGION 'E' /* operating on empty region is an error */ -#define CPO_FNAMER 'f' /* set file name for ":r file" */ -#define CPO_FNAMEW 'F' /* set file name for ":w file" */ -#define CPO_INTMOD 'i' /* interrupt a read makes buffer modified */ -#define CPO_INDENT 'I' /* remove auto-indent more often */ -#define CPO_ENDOFSENT 'J' /* need two spaces to detect end of sentence */ -#define CPO_KEYCODE 'k' /* don't recognize raw key code in mappings */ -#define CPO_KOFFSET 'K' /* don't wait for key code in mappings */ -#define CPO_LITERAL 'l' /* take char after backslash in [] literal */ -#define CPO_LISTWM 'L' /* 'list' changes wrapmargin */ +#define CPO_EMPTYREGION 'E' // operating on empty region is an error +#define CPO_FNAMER 'f' // set file name for ":r file" +#define CPO_FNAMEW 'F' // set file name for ":w file" +#define CPO_INTMOD 'i' // interrupt a read makes buffer modified +#define CPO_INDENT 'I' // remove auto-indent more often +#define CPO_ENDOFSENT 'J' // need two spaces to detect end of sentence +#define CPO_KOFFSET 'K' // don't wait for key code in mappings +#define CPO_LITERAL 'l' // take char after backslash in [] literal +#define CPO_LISTWM 'L' // 'list' changes wrapmargin #define CPO_SHOWMATCH 'm' -#define CPO_MATCHBSL 'M' /* "%" ignores use of backslashes */ -#define CPO_NUMCOL 'n' /* 'number' column also used for text */ +#define CPO_MATCHBSL 'M' // "%" ignores use of backslashes +#define CPO_NUMCOL 'n' // 'number' column also used for text #define CPO_LINEOFF 'o' -#define CPO_OVERNEW 'O' /* silently overwrite new file */ -#define CPO_LISP 'p' /* 'lisp' indenting */ -#define CPO_FNAMEAPP 'P' /* set file name for ":w >>file" */ -#define CPO_JOINCOL 'q' /* with "3J" use column after first join */ +#define CPO_OVERNEW 'O' // silently overwrite new file +#define CPO_LISP 'p' // 'lisp' indenting +#define CPO_FNAMEAPP 'P' // set file name for ":w >>file" +#define CPO_JOINCOL 'q' // with "3J" use column after first join #define CPO_REDO 'r' -#define CPO_REMMARK 'R' /* remove marks when filtering */ +#define CPO_REMMARK 'R' // remove marks when filtering #define CPO_BUFOPT 's' #define CPO_BUFOPTGLOB 'S' #define CPO_TAGPAT 't' -#define CPO_UNDO 'u' /* "u" undoes itself */ -#define CPO_BACKSPACE 'v' /* "v" keep deleted text */ -#define CPO_FWRITE 'W' /* "w!" doesn't overwrite readonly files */ +#define CPO_UNDO 'u' // "u" undoes itself +#define CPO_BACKSPACE 'v' // "v" keep deleted text +#define CPO_FWRITE 'W' // "w!" doesn't overwrite readonly files #define CPO_ESC 'x' -#define CPO_REPLCNT 'X' /* "R" with a count only deletes chars once */ +#define CPO_REPLCNT 'X' // "R" with a count only deletes chars once #define CPO_YANK 'y' -#define CPO_KEEPRO 'Z' /* don't reset 'readonly' on ":w!" */ +#define CPO_KEEPRO 'Z' // don't reset 'readonly' on ":w!" #define CPO_DOLLAR '$' #define CPO_FILTER '!' #define CPO_MATCH '%' -#define CPO_PLUS '+' /* ":write file" resets 'modified' */ -#define CPO_SPECI '<' /* don't recognize <> in mappings */ -#define CPO_REGAPPEND '>' /* insert NL when appending to a register */ -#define CPO_SCOLON ';' /* using "," and ";" will skip over char if - * cursor would not move */ +#define CPO_PLUS '+' // ":write file" resets 'modified' +#define CPO_REGAPPEND '>' // insert NL when appending to a register +#define CPO_SCOLON ';' // using "," and ";" will skip over char if + // cursor would not move #define CPO_CHANGEW '_' // "cw" special-case // default values for Vim and Vi #define CPO_VIM "aABceFs_" -#define CPO_VI "aAbBcCdDeEfFiIJkKlLmMnoOpPqrRsStuvWxXyZ$!%+<>;_" +#define CPO_VI "aAbBcCdDeEfFiIJKlLmMnoOpPqrRsStuvWxXyZ$!%+>;_" /* characters for p_ww option: */ #define WW_ALL "bshl<>[],~" |