diff options
Diffstat (limited to 'src/nvim/edit.c')
-rw-r--r-- | src/nvim/edit.c | 268 |
1 files changed, 114 insertions, 154 deletions
diff --git a/src/nvim/edit.c b/src/nvim/edit.c index 5002ef2710..d7e82729a9 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -29,7 +29,7 @@ #include "nvim/highlight_group.h" #include "nvim/indent.h" #include "nvim/indent_c.h" -#include "nvim/keymap.h" +#include "nvim/keycodes.h" #include "nvim/main.h" #include "nvim/mark.h" #include "nvim/mbyte.h" @@ -290,7 +290,7 @@ static void insert_enter(InsertState *s) { s->did_backspace = true; s->old_topfill = -1; - s->replaceState = REPLACE; + s->replaceState = MODE_REPLACE; s->cmdchar_todo = s->cmdchar; // Remember whether editing was restarted after CTRL-O did_restart_edit = restart_edit; @@ -335,7 +335,7 @@ static void insert_enter(InsertState *s) int save_state = State; curwin->w_cursor = save_cursor; - State = INSERT; + State = MODE_INSERT; check_cursor_col(); State = save_state; } @@ -377,14 +377,14 @@ static void insert_enter(InsertState *s) } if (s->cmdchar == 'R') { - State = REPLACE; + State = MODE_REPLACE; } else if (s->cmdchar == 'V' || s->cmdchar == 'v') { - State = VREPLACE; - s->replaceState = VREPLACE; + State = MODE_VREPLACE; + s->replaceState = MODE_VREPLACE; orig_line_count = curbuf->b_ml.ml_line_count; vr_lines_changed = 1; } else { - State = INSERT; + State = MODE_INSERT; } may_trigger_modechanged(); @@ -400,13 +400,13 @@ static void insert_enter(InsertState *s) // 'iminsert' value may not reflect what is actually used. It is updated // when hitting <Esc>. if (curbuf->b_p_iminsert == B_IMODE_LMAP) { - State |= LANGMAP; + State |= MODE_LANGMAP; } setmouse(); clear_showcmd(); // there is no reverse replace mode - revins_on = (State == INSERT && p_ri); + revins_on = (State == MODE_INSERT && p_ri); if (revins_on) { undisplay_dollar(); } @@ -1325,21 +1325,21 @@ normalchar: if (!p_paste) { // Trigger InsertCharPre. - char_u *str = do_insert_char_pre(s->c); - char_u *p; + char *str = (char *)do_insert_char_pre(s->c); + char *p; if (str != NULL) { if (*str != NUL && stop_arrow() != FAIL) { // Insert the new value of v:char literally. for (p = str; *p != NUL; MB_PTR_ADV(p)) { - s->c = utf_ptr2char((char *)p); + s->c = utf_ptr2char(p); if (s->c == CAR || s->c == K_KENTER || s->c == NL) { ins_eol(s->c); } else { ins_char(s->c); } } - AppendToRedobuffLit((char *)str, -1); + AppendToRedobuffLit(str, -1); } xfree(str); s->c = NUL; @@ -1396,7 +1396,7 @@ static void insert_do_complete(InsertState *s) compl_cont_status = 0; } compl_busy = false; - can_si = true; // allow smartindenting + can_si = may_do_si(); // allow smartindenting } static void insert_do_cindent(InsertState *s) @@ -1632,7 +1632,7 @@ void edit_putchar(int c, bool highlight) pc_col = 0; pc_status = PC_STATUS_UNSET; if (curwin->w_p_rl) { - pc_col += curwin->w_grid.Columns - 1 - curwin->w_wcol; + pc_col += curwin->w_grid.cols - 1 - curwin->w_wcol; const int fix_col = grid_fix_col(&curwin->w_grid, pc_col, pc_row); if (fix_col != pc_col) { @@ -1759,7 +1759,7 @@ void display_dollar(colnr_T col) char_u *p = get_cursor_line_ptr(); curwin->w_cursor.col -= utf_head_off(p, p + col); curs_columns(curwin, false); // Recompute w_wrow and w_wcol - if (curwin->w_wcol < curwin->w_grid.Columns) { + if (curwin->w_wcol < curwin->w_grid.cols) { edit_putchar('$', false); dollar_vcol = curwin->w_virtcol; } @@ -1800,7 +1800,7 @@ void change_indent(int type, int amount, int round, int replaced, int call_chang colnr_T orig_col = 0; // init for GCC char_u *new_line, *orig_line = NULL; // init for GCC - // VREPLACE mode needs to know what the line was like before changing + // MODE_VREPLACE state needs to know what the line was like before changing if (State & VREPLACE_FLAG) { orig_line = vim_strsave(get_cursor_line_ptr()); // Deal with NULL below orig_col = curwin->w_cursor.col; @@ -1848,7 +1848,7 @@ void change_indent(int type, int amount, int round, int replaced, int call_chang // Avoid being called recursively. if (State & VREPLACE_FLAG) { - State = INSERT; + State = MODE_INSERT; } shift_line(type == INDENT_DEC, round, 1, call_changed_bytes); State = save_State; @@ -1873,7 +1873,7 @@ void change_indent(int type, int amount, int round, int replaced, int call_chang insstart_less = MAXCOL; } new_cursor_col += curwin->w_cursor.col; - } else if (!(State & INSERT)) { + } else if (!(State & MODE_INSERT)) { new_cursor_col = curwin->w_cursor.col; } else { /* @@ -1933,7 +1933,7 @@ void change_indent(int type, int amount, int round, int replaced, int call_chang /* * May have to adjust the start of the insert. */ - if (State & INSERT) { + if (State & MODE_INSERT) { if (curwin->w_cursor.lnum == Insstart.lnum && Insstart.col != 0) { if ((int)Insstart.col <= insstart_less) { Insstart.col = 0; @@ -1948,13 +1948,11 @@ void change_indent(int type, int amount, int round, int replaced, int call_chang } } - /* - * For REPLACE mode, may have to fix the replace stack, if it's possible. - * If the number of characters before the cursor decreased, need to pop a - * few characters from the replace stack. - * If the number of characters before the cursor increased, need to push a - * few NULs onto the replace stack. - */ + // For MODE_REPLACE state, may have to fix the replace stack, if it's + // possible. If the number of characters before the cursor decreased, need + // to pop a few characters from the replace stack. + // If the number of characters before the cursor increased, need to push a + // few NULs onto the replace stack. if (REPLACE_NORMAL(State) && start_col >= 0) { while (start_col > (int)curwin->w_cursor.col) { replace_join(0); // remove a NUL from the replace stack @@ -1970,11 +1968,9 @@ void change_indent(int type, int amount, int round, int replaced, int call_chang } } - /* - * For VREPLACE mode, we also have to fix the replace stack. In this case - * it is always possible because we backspace over the whole line and then - * put it back again the way we wanted it. - */ + // For MODE_VREPLACE state, we also have to fix the replace stack. In this + // case it is always possible because we backspace over the whole line and + // then put it back again the way we wanted it. if (State & VREPLACE_FLAG) { // Save new line new_line = vim_strsave(get_cursor_line_ptr()); @@ -2009,11 +2005,9 @@ void change_indent(int type, int amount, int round, int replaced, int call_chang } } -/* - * Truncate the space at the end of a line. This is to be used only in an - * insert mode. It handles fixing the replace stack for REPLACE and VREPLACE - * modes. - */ +/// Truncate the space at the end of a line. This is to be used only in an +/// insert mode. It handles fixing the replace stack for MODE_REPLACE and +/// MODE_VREPLACE modes. void truncate_spaces(char_u *line) { int i; @@ -2027,12 +2021,10 @@ void truncate_spaces(char_u *line) line[i + 1] = NUL; } -/* - * Backspace the cursor until the given column. Handles REPLACE and VREPLACE - * modes correctly. May also be used when not in insert mode at all. - * Will attempt not to go before "col" even when there is a composing - * character. - */ +/// Backspace the cursor until the given column. Handles MODE_REPLACE and +/// MODE_VREPLACE modes correctly. May also be used when not in insert mode at +/// all. Will attempt not to go before "col" even when there is a composing +/// character. void backspace_until_column(int col) { while ((int)curwin->w_cursor.col > col) { @@ -2743,7 +2735,7 @@ static bool pum_wanted(void) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT { // "completeopt" must contain "menu" or "menuone" - return vim_strchr(p_cot, 'm') != NULL; + return vim_strchr((char *)p_cot, 'm') != NULL; } /// Check that there are two or more matches to be shown in the popup menu. @@ -2991,11 +2983,11 @@ static void ins_compl_dictionaries(char_u *dict_start, char_u *pat, int flags, i size_t len = STRLEN(pat_esc) + 10; ptr = xmalloc(len); vim_snprintf((char *)ptr, len, "^\\s*\\zs\\V%s", pat_esc); - regmatch.regprog = vim_regcomp(ptr, RE_MAGIC); + regmatch.regprog = vim_regcomp((char *)ptr, RE_MAGIC); xfree(pat_esc); xfree(ptr); } else { - regmatch.regprog = vim_regcomp(pat, p_magic ? RE_MAGIC : 0); + regmatch.regprog = vim_regcomp((char *)pat, p_magic ? RE_MAGIC : 0); if (regmatch.regprog == NULL) { goto theend; } @@ -3015,7 +3007,7 @@ static void ins_compl_dictionaries(char_u *dict_start, char_u *pat, int flags, i copy_option_part(&dict, buf, LSIZE, ","); if (!thesaurus && STRCMP(buf, "spell") == 0) { count = -1; - } else if (vim_strchr(buf, '`') != NULL + } else if (vim_strchr((char *)buf, '`') != NULL || expand_wildcards(1, &buf, &count, &files, EW_FILE|EW_SILENT) != OK) { count = 0; @@ -3513,11 +3505,11 @@ static void ins_compl_addleader(int c) return; } if ((cc = utf_char2len(c)) > 1) { - char_u buf[MB_MAXBYTES + 1]; + char buf[MB_MAXBYTES + 1]; utf_char2bytes(c, (char *)buf); buf[cc] = NUL; - ins_char_bytes(buf, (size_t)cc); + ins_char_bytes((char_u *)buf, (size_t)cc); } else { ins_char(c); } @@ -4260,9 +4252,8 @@ static int ins_compl_get_exp(pos_T *ini) // Remember the first match so that the loop stops when we // wrap and come back there a second time. set_match_pos = true; - } else if (vim_strchr((char_u *)"buwU", *e_cpt) != NULL - && (ins_buf = - ins_compl_next_buf(ins_buf, *e_cpt)) != curbuf) { + } else if (vim_strchr("buwU", *e_cpt) != NULL + && (ins_buf = ins_compl_next_buf(ins_buf, *e_cpt)) != curbuf) { // Scan a buffer, but not the current one. if (ins_buf->b_ml.ml_mfp != NULL) { // loaded buffer compl_started = true; @@ -4276,7 +4267,7 @@ static int ins_compl_get_exp(pos_T *ini) continue; } type = CTRL_X_DICTIONARY; - dict = ins_buf->b_fname; + dict = (char_u *)ins_buf->b_fname; dict_f = DICT_EXACT; } msg_hist_off = true; // reset in msg_trunc_attr() @@ -4284,7 +4275,7 @@ static int ins_compl_get_exp(pos_T *ini) ins_buf->b_fname == NULL ? buf_spname(ins_buf) : ins_buf->b_sfname == NULL - ? ins_buf->b_fname + ? (char_u *)ins_buf->b_fname : ins_buf->b_sfname); (void)msg_trunc_attr((char *)IObuff, true, HL_ATTR(HLF_R)); } else if (*e_cpt == NUL) { @@ -5641,7 +5632,7 @@ int get_literal(bool no_simplify) // character for i_CTRL-V_digit. break; } - if (!(State & CMDLINE) && MB_BYTE2LEN_CHECK(nc) == 1) { + if ((State & MODE_CMDLINE) == 0 && MB_BYTE2LEN_CHECK(nc) == 1) { add_to_showcmd(nc); } if (nc == 'x' || nc == 'X') { @@ -5784,21 +5775,19 @@ void insertchar(int c, int flags, int second_indent) const int textwidth = comp_textwidth(force_format); const bool fo_ins_blank = has_format_option(FO_INS_BLANK); - /* - * Try to break the line in two or more pieces when: - * - Always do this if we have been called to do formatting only. - * - Always do this when 'formatoptions' has the 'a' flag and the line - * ends in white space. - * - Otherwise: - * - Don't do this if inserting a blank - * - Don't do this if an existing character is being replaced, unless - * we're in VREPLACE mode. - * - Do this if the cursor is not on the line where insert started - * or - 'formatoptions' doesn't have 'l' or the line was not too long - * before the insert. - * - 'formatoptions' doesn't have 'b' or a blank was inserted at or - * before 'textwidth' - */ + // Try to break the line in two or more pieces when: + // - Always do this if we have been called to do formatting only. + // - Always do this when 'formatoptions' has the 'a' flag and the line + // ends in white space. + // - Otherwise: + // - Don't do this if inserting a blank + // - Don't do this if an existing character is being replaced, unless + // we're in MODE_VREPLACE state. + // - Do this if the cursor is not on the line where insert started + // or - 'formatoptions' doesn't have 'l' or the line was not too long + // before the insert. + // - 'formatoptions' doesn't have 'b' or a blank was inserted at or + // before 'textwidth' if (textwidth > 0 && (force_format || (!ascii_iswhite(c) @@ -5843,7 +5832,7 @@ void insertchar(int c, int flags, int second_indent) * comment leader. First, check what comment leader we can find. */ i = get_leader_len(line = get_cursor_line_ptr(), &p, false, true); - if (i > 0 && vim_strchr(p, COM_MIDDLE) != NULL) { // Just checking + if (i > 0 && vim_strchr((char *)p, COM_MIDDLE) != NULL) { // Just checking // Skip middle-comment string while (*p && p[-1] != ':') { // find end of middle flags p++; @@ -5949,11 +5938,11 @@ void insertchar(int c, int flags, int second_indent) int cc; if ((cc = utf_char2len(c)) > 1) { - char_u buf[MB_MAXBYTES + 1]; + char buf[MB_MAXBYTES + 1]; utf_char2bytes(c, (char *)buf); buf[cc] = NUL; - ins_char_bytes(buf, (size_t)cc); + ins_char_bytes((char_u *)buf, (size_t)cc); AppendCharToRedobuff(c); } else { ins_char(c); @@ -6248,11 +6237,9 @@ static void internal_format(int textwidth, int second_indent, int flags, int for // Going to break the line, remove any "$" now. undisplay_dollar(); - /* - * Offset between cursor position and line break is used by replace - * stack functions. VREPLACE does not use this, and backspaces - * over the text instead. - */ + // Offset between cursor position and line break is used by replace + // stack functions. MODE_VREPLACE does not use this, and backspaces + // over the text instead. if (State & VREPLACE_FLAG) { orig_col = startcol; // Will start backspacing from here } else { @@ -6274,10 +6261,8 @@ static void internal_format(int textwidth, int second_indent, int flags, int for } if (State & VREPLACE_FLAG) { - /* - * In VREPLACE mode, we will backspace over the text to be - * wrapped, so save a copy now to put on the next line. - */ + // In MODE_VREPLACE state, we will backspace over the text to be + // wrapped, so save a copy now to put on the next line. saved_text = vim_strsave(get_cursor_pos_ptr()); curwin->w_cursor.col = orig_col; saved_text[startcol] = NUL; @@ -6349,10 +6334,8 @@ static void internal_format(int textwidth, int second_indent, int flags, int for } if (State & VREPLACE_FLAG) { - /* - * In VREPLACE mode we have backspaced over the text to be - * moved, now we re-insert it into the new line. - */ + // In MODE_VREPLACE state we have backspaced over the text to be + // moved, now we re-insert it into the new line. ins_bytes(saved_text); xfree(saved_text); } else { @@ -6787,13 +6770,8 @@ static void stop_insert(pos_T *end_insert_pos, int esc, int nomove) // <C-S-Right> may have started Visual mode, adjust the position for // deleted characters. - if (VIsual_active && VIsual.lnum == curwin->w_cursor.lnum) { - int len = (int)STRLEN(get_cursor_line_ptr()); - - if (VIsual.col > len) { - VIsual.col = len; - VIsual.coladd = 0; - } + if (VIsual_active) { + check_visual_pos(); } } } @@ -6856,7 +6834,7 @@ char_u *add_char2buf(int c, char_u *s) char_u temp[MB_MAXBYTES + 1]; const int len = utf_char2bytes(c, (char *)temp); for (int i = 0; i < len; i++) { - c = temp[i]; + c = (uint8_t)temp[i]; // Need to escape K_SPECIAL like in the typeahead buffer. if (c == K_SPECIAL) { *s++ = K_SPECIAL; @@ -7021,7 +6999,7 @@ int cursor_up(long n, int upd_topline) // If we entered a fold, move to the beginning, unless in // Insert mode or when 'foldopen' contains "all": it will open // in a moment. - if (n > 0 || !((State & INSERT) || (fdo_flags & FDO_ALL))) { + if (n > 0 || !((State & MODE_INSERT) || (fdo_flags & FDO_ALL))) { (void)hasFolding(lnum, &lnum, NULL); } } @@ -7293,16 +7271,14 @@ static void replace_join(int off) } } -/* - * Pop bytes from the replace stack until a NUL is found, and insert them - * before the cursor. Can only be used in REPLACE or VREPLACE mode. - */ +/// Pop bytes from the replace stack until a NUL is found, and insert them +/// before the cursor. Can only be used in MODE_REPLACE or MODE_VREPLACE state. static void replace_pop_ins(void) { int cc; int oldState = State; - State = NORMAL; // don't want REPLACE here + State = MODE_NORMAL; // don't want MODE_REPLACE here while ((cc = replace_pop()) > 0) { mb_replace_pop_ins(cc); dec_cursor(); @@ -7598,7 +7574,7 @@ bool in_cinkeys(int keytyped, int when, bool line_is_empty) // make up some named keys <o>, <O>, <e>, <0>, <>>, <<>, <*>, // <:> and <!> so that people can re-indent on o, O, e, 0, <, // >, *, : and ! keys if they really really want to. - if (vim_strchr((char_u *)"<>!*oOe0:", look[1]) != NULL + if (vim_strchr("<>!*oOe0:", look[1]) != NULL && keytyped == look[1]) { return true; } @@ -7625,7 +7601,7 @@ bool in_cinkeys(int keytyped, int when, bool line_is_empty) } else { icase = false; } - p = vim_strchr(look, ','); + p = (char_u *)vim_strchr((char *)look, ','); if (p == NULL) { p = look + STRLEN(look); } @@ -7950,14 +7926,14 @@ static void ins_ctrl_g(void) */ static void ins_ctrl_hat(void) { - if (map_to_exists_mode("", LANGMAP, false)) { + if (map_to_exists_mode("", MODE_LANGMAP, false)) { // ":lmap" mappings exists, Toggle use of ":lmap" mappings. - if (State & LANGMAP) { + if (State & MODE_LANGMAP) { curbuf->b_p_iminsert = B_IMODE_NONE; - State &= ~LANGMAP; + State &= ~MODE_LANGMAP; } else { curbuf->b_p_iminsert = B_IMODE_LMAP; - State |= LANGMAP; + State |= MODE_LANGMAP; } } set_iminsert_global(); @@ -8064,7 +8040,7 @@ static bool ins_esc(long *count, int cmdchar, bool nomove) } - State = NORMAL; + State = MODE_NORMAL; may_trigger_modechanged(); // need to position cursor again when on a TAB if (gchar_cursor() == TAB) { @@ -8097,7 +8073,7 @@ static void ins_ctrl_(void) } } p_ri = !p_ri; - revins_on = (State == INSERT && p_ri); + revins_on = (State == MODE_INSERT && p_ri); if (revins_on) { revins_scol = curwin->w_cursor.col; revins_legal++; @@ -8161,13 +8137,13 @@ static bool ins_start_select(int c) static void ins_insert(int replaceState) { set_vim_var_string(VV_INSERTMODE, ((State & REPLACE_FLAG) ? "i" : - replaceState == VREPLACE ? "v" : + replaceState == MODE_VREPLACE ? "v" : "r"), 1); ins_apply_autocmds(EVENT_INSERTCHANGE); if (State & REPLACE_FLAG) { - State = INSERT | (State & LANGMAP); + State = MODE_INSERT | (State & MODE_LANGMAP); } else { - State = replaceState | (State & LANGMAP); + State = replaceState | (State & MODE_LANGMAP); } may_trigger_modechanged(); AppendCharToRedobuff(K_INS); @@ -8405,23 +8381,17 @@ static bool ins_bs(int c, int mode, int *inserted_space_p) dec_cursor(); } - /* - * In REPLACE mode we have to put back the text that was replaced - * by the NL. On the replace stack is first a NUL-terminated - * sequence of characters that were deleted and then the - * characters that NL replaced. - */ + // In MODE_REPLACE mode we have to put back the text that was + // replaced by the NL. On the replace stack is first a + // NUL-terminated sequence of characters that were deleted and then + // the characters that NL replaced. if (State & REPLACE_FLAG) { - /* - * Do the next ins_char() in NORMAL state, to - * prevent ins_char() from replacing characters and - * avoiding showmatch(). - */ + // Do the next ins_char() in MODE_NORMAL state, to + // prevent ins_char() from replacing characters and + // avoiding showmatch(). oldState = State; - State = NORMAL; - /* - * restore characters (blanks) deleted after cursor - */ + State = MODE_NORMAL; + // restore characters (blanks) deleted after cursor while (cc > 0) { save_col = curwin->w_cursor.col; mb_replace_pop_ins(cc); @@ -8721,7 +8691,7 @@ static void ins_left(void) revins_legal++; } revins_chars++; - } else if (vim_strchr(p_ww, '[') != NULL && curwin->w_cursor.lnum > 1) { + } else if (vim_strchr((char *)p_ww, '[') != NULL && curwin->w_cursor.lnum > 1) { // if 'whichwrap' set for cursor in insert mode may go to previous line. // always break undo when moving upwards/downwards, else undo may break start_arrow(&tpos); @@ -8814,7 +8784,7 @@ static void ins_right(void) if (revins_chars) { revins_chars--; } - } else if (vim_strchr(p_ww, ']') != NULL + } else if (vim_strchr((char *)p_ww, ']') != NULL && curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count) { // if 'whichwrap' set for cursor in insert mode, may move the // cursor to the next line @@ -9008,11 +8978,9 @@ static bool ins_tab(void) curbuf->b_p_vts_array); } - /* - * Insert the first space with ins_char(). It will delete one char in - * replace mode. Insert the rest with ins_str(); it will not delete any - * chars. For VREPLACE mode, we use ins_char() for all characters. - */ + // Insert the first space with ins_char(). It will delete one char in + // replace mode. Insert the rest with ins_str(); it will not delete any + // chars. For MODE_VREPLACE state, we use ins_char() for all characters. ins_char(' '); while (--temp > 0) { if (State & VREPLACE_FLAG) { @@ -9040,10 +9008,8 @@ static bool ins_tab(void) int change_col = -1; int save_list = curwin->w_p_list; - /* - * Get the current line. For VREPLACE mode, don't make real changes - * yet, just work on a copy of the line. - */ + // Get the current line. For MODE_VREPLACE state, don't make real + // changes yet, just work on a copy of the line. if (State & VREPLACE_FLAG) { pos = curwin->w_cursor; cursor = &pos; @@ -9136,11 +9102,9 @@ static bool ins_tab(void) } cursor->col -= i; - /* - * In VREPLACE mode, we haven't changed anything yet. Do it now by - * backspacing over the changed spacing and then inserting the new - * spacing. - */ + // In MODE_VREPLACE state, we haven't changed anything yet. Do it + // now by backspacing over the changed spacing and then inserting + // the new spacing. if (State & VREPLACE_FLAG) { // Backspace from real cursor to change_col backspace_until_column(change_col); @@ -9183,12 +9147,10 @@ static bool ins_eol(int c) replace_push(NUL); } - /* - * In VREPLACE mode, a NL replaces the rest of the line, and starts - * replacing the next line, so we push all of the characters left on the - * line onto the replace stack. This is not done here though, it is done - * in open_line(). - */ + // In MODE_VREPLACE state, a NL replaces the rest of the line, and starts + // replacing the next line, so we push all of the characters left on the + // line onto the replace stack. This is not done here though, it is done + // in open_line(). // Put cursor on NUL if on the last char and coladd is 1 (happens after // CTRL-O). @@ -9376,10 +9338,8 @@ static void ins_try_si(int c) /* * do some very smart indenting when entering '{' or '}' */ - if (((did_si || can_si_back) && c == '{') || (can_si && c == '}')) { - /* - * for '}' set indent equal to indent of line containing matching '{' - */ + if (((did_si || can_si_back) && c == '{') || (can_si && c == '}' && inindent(0))) { + // for '}' set indent equal to indent of line containing matching '{' if (c == '}' && (pos = findmatch(NULL, '{')) != NULL) { old_pos = curwin->w_cursor; /* @@ -9435,7 +9395,7 @@ static void ins_try_si(int c) /* * set indent of '#' always to 0 */ - if (curwin->w_cursor.col > 0 && can_si && c == '#') { + if (curwin->w_cursor.col > 0 && can_si && c == '#' && inindent(0)) { // remember current indent for next line old_indent = get_indent(); (void)set_indent(0, SIN_CHANGED); @@ -9492,7 +9452,7 @@ static char_u *do_insert_char_pre(int c) // character. Only use it when changed, otherwise continue with the // original character to avoid breaking autoindent. if (STRCMP(buf, get_vim_var_str(VV_CHAR)) != 0) { - res = vim_strsave(get_vim_var_str(VV_CHAR)); + res = vim_strsave((char_u *)get_vim_var_str(VV_CHAR)); } } |