diff options
Diffstat (limited to 'src/nvim/normal.c')
-rw-r--r-- | src/nvim/normal.c | 126 |
1 files changed, 68 insertions, 58 deletions
diff --git a/src/nvim/normal.c b/src/nvim/normal.c index 1f789dc153..8ff47097fa 100644 --- a/src/nvim/normal.c +++ b/src/nvim/normal.c @@ -17,6 +17,7 @@ #include "nvim/api/private/helpers.h" #include "nvim/ascii_defs.h" #include "nvim/autocmd.h" +#include "nvim/autocmd_defs.h" #include "nvim/buffer.h" #include "nvim/buffer_defs.h" #include "nvim/change.h" @@ -34,19 +35,21 @@ #include "nvim/ex_getln.h" #include "nvim/fileio.h" #include "nvim/fold.h" -#include "nvim/func_attr.h" #include "nvim/getchar.h" -#include "nvim/gettext.h" +#include "nvim/gettext_defs.h" #include "nvim/globals.h" #include "nvim/grid.h" #include "nvim/help.h" #include "nvim/highlight.h" +#include "nvim/highlight_defs.h" #include "nvim/keycodes.h" #include "nvim/macros_defs.h" #include "nvim/mapping.h" #include "nvim/mark.h" +#include "nvim/mark_defs.h" #include "nvim/mbyte.h" #include "nvim/memline.h" +#include "nvim/memline_defs.h" #include "nvim/memory.h" #include "nvim/message.h" #include "nvim/mouse.h" @@ -62,21 +65,25 @@ #include "nvim/quickfix.h" #include "nvim/search.h" #include "nvim/spell.h" +#include "nvim/spell_defs.h" #include "nvim/spellfile.h" #include "nvim/spellsuggest.h" #include "nvim/state.h" +#include "nvim/state_defs.h" #include "nvim/statusline.h" #include "nvim/strings.h" #include "nvim/syntax.h" #include "nvim/tag.h" #include "nvim/textformat.h" #include "nvim/textobject.h" +#include "nvim/types_defs.h" #include "nvim/ui.h" +#include "nvim/ui_defs.h" #include "nvim/undo.h" #include "nvim/vim_defs.h" #include "nvim/window.h" -typedef struct normal_state { +typedef struct { VimState state; bool command_finished; bool ctrl_w; @@ -368,7 +375,7 @@ static int nv_compare(const void *s1, const void *s2) if (c2 < 0) { c2 = -c2; } - return c1 - c2; + return c1 == c2 ? 0 : c1 > c2 ? 1 : -1; } /// Initialize the nv_cmd_idx[] table. @@ -703,7 +710,7 @@ static void normal_get_additional_char(NormalState *s) int *cp; bool repl = false; // get character for replace mode bool lit = false; // get extra character literally - int lang; // getting a text character + bool lang; // getting a text character no_mapping++; allow_keys++; // no mapping for nchar, but allow key codes @@ -838,10 +845,10 @@ static void normal_get_additional_char(NormalState *s) no_mapping++; // Vim may be in a different mode when the user types the next key, // but when replaying a recording the next key is already in the - // typeahead buffer, so record a <Nop> before that to prevent the - // vpeekc() above from applying wrong mappings when replaying. + // typeahead buffer, so record an <Ignore> before that to prevent + // the vpeekc() above from applying wrong mappings when replaying. no_u_sync++; - gotchars_nop(); + gotchars_ignore(); no_u_sync--; } } @@ -1028,7 +1035,7 @@ normal_end: restart_VIsual_select = 0; } if (restart_edit != 0 && !VIsual_active && s->old_mapped_len == 0) { - (void)edit(restart_edit, false, 1); + edit(restart_edit, false, 1); } } @@ -1257,7 +1264,7 @@ static void normal_check_interrupt(NormalState *s) } else if (!global_busy || !exmode_active) { if (!quit_more) { // flush all buffers - (void)vgetc(); + vgetc(); } got_int = false; } @@ -1340,10 +1347,6 @@ static void normal_redraw(NormalState *s) show_cursor_info_later(false); - if (VIsual_active) { - redraw_curbuf_later(UPD_INVERTED); // update inverted part - } - if (must_redraw) { update_screen(); } else { @@ -1448,9 +1451,7 @@ static int normal_check(VimState *state) // has been done, close any file for startup messages. if (time_fd != NULL) { TIME_MSG("first screen update"); - TIME_MSG("--- NVIM STARTED ---"); - fclose(time_fd); - time_fd = NULL; + time_finish(); } // After the first screen update may start triggering WinScrolled // autocmd events. Store all the scroll positions and sizes now. @@ -1848,7 +1849,7 @@ void clear_showcmd(void) } if (VIsual_active && !char_avail()) { - int cursor_bot = lt(VIsual, curwin->w_cursor); + bool cursor_bot = lt(VIsual, curwin->w_cursor); int lines; colnr_T leftcol, rightcol; linenr_T top, bot; @@ -1862,8 +1863,8 @@ void clear_showcmd(void) bot = VIsual.lnum; } // Include closed folds as a whole. - (void)hasFolding(top, &top, NULL); - (void)hasFolding(bot, NULL, &bot); + hasFolding(top, &top, NULL); + hasFolding(bot, NULL, &bot); lines = bot - top + 1; if (VIsual_mode == Ctrl_V) { @@ -2186,7 +2187,7 @@ void check_scrollbind(linenr_T topline_diff, int leftcol_diff) // do the horizontal scroll if (want_hor) { - (void)set_leftcol(tgt_leftcol); + set_leftcol(tgt_leftcol); } } @@ -2257,7 +2258,7 @@ static void nv_page(cmdarg_T *cap) goto_tabpage(cap->count0); } } else { - (void)onepage(cap->arg, cap->count1); + onepage(cap->arg, cap->count1); } } @@ -2607,7 +2608,7 @@ void nv_scroll_line(cmdarg_T *cap) } /// Scroll "count" lines up or down, and redraw. -void scroll_redraw(int up, linenr_T count) +void scroll_redraw(bool up, linenr_T count) { linenr_T prev_topline = curwin->w_topline; int prev_skipcol = curwin->w_skipcol; @@ -2678,7 +2679,7 @@ static bool nv_z_get_count(cmdarg_T *cap, int *nchar_arg) LANGMAP_ADJUST(nchar, true); no_mapping--; allow_keys--; - (void)add_to_showcmd(nchar); + add_to_showcmd(nchar); if (nchar == K_DEL || nchar == K_KDEL) { n /= 10; @@ -2723,7 +2724,7 @@ static int nv_zg_zw(cmdarg_T *cap, int nchar) LANGMAP_ADJUST(nchar, true); no_mapping--; allow_keys--; - (void)add_to_showcmd(nchar); + add_to_showcmd(nchar); if (vim_strchr("gGwW", nchar) == NULL) { clearopbeep(cap->oap); @@ -2873,8 +2874,8 @@ static void nv_zet(cmdarg_T *cap) case 'h': case K_LEFT: if (!curwin->w_p_wrap) { - (void)set_leftcol((colnr_T)cap->count1 > curwin->w_leftcol - ? 0 : curwin->w_leftcol - (colnr_T)cap->count1); + set_leftcol((colnr_T)cap->count1 > curwin->w_leftcol + ? 0 : curwin->w_leftcol - (colnr_T)cap->count1); } break; @@ -2887,7 +2888,7 @@ static void nv_zet(cmdarg_T *cap) case 'l': case K_RIGHT: if (!curwin->w_p_wrap) { - (void)set_leftcol(curwin->w_leftcol + (colnr_T)cap->count1); + set_leftcol(curwin->w_leftcol + (colnr_T)cap->count1); } break; @@ -3289,8 +3290,8 @@ static void nv_ctrlo(cmdarg_T *cap) static void nv_hat(cmdarg_T *cap) { if (!checkclearopq(cap->oap)) { - (void)buflist_getfile(cap->count0, 0, - GETF_SETMARK|GETF_ALT, false); + buflist_getfile(cap->count0, 0, + GETF_SETMARK|GETF_ALT, false); } } @@ -3555,7 +3556,7 @@ static void nv_ident(cmdarg_T *cap) init_history(); add_to_history(HIST_SEARCH, buf, true, NUL); - (void)normal_search(cap, cmdchar == '*' ? '/' : '?', buf, 0, NULL); + normal_search(cap, cmdchar == '*' ? '/' : '?', buf, 0, NULL); } else { g_tag_at_cursor = true; do_cmdline_cmd(buf); @@ -3639,8 +3640,8 @@ static void nv_scroll(cmdarg_T *cap) // Count a fold for one screen line. for (n = cap->count1 - 1; n > 0 && curwin->w_cursor.lnum > curwin->w_topline; n--) { - (void)hasFolding(curwin->w_cursor.lnum, - &curwin->w_cursor.lnum, NULL); + hasFolding(curwin->w_cursor.lnum, + &curwin->w_cursor.lnum, NULL); if (curwin->w_cursor.lnum > curwin->w_topline) { curwin->w_cursor.lnum--; } @@ -3681,7 +3682,7 @@ static void nv_scroll(cmdarg_T *cap) // Count a fold for one screen line. lnum = curwin->w_topline; while (n-- > 0 && lnum < curwin->w_botline - 1) { - (void)hasFolding(lnum, NULL, &lnum); + hasFolding(lnum, NULL, &lnum); lnum++; } n = lnum - curwin->w_topline; @@ -3901,7 +3902,7 @@ static void nv_gotofile(cmdarg_T *cap) if (ptr != NULL) { // do autowrite if necessary if (curbufIsChanged() && curbuf->b_nwindows <= 1 && !buf_hide(curbuf)) { - (void)autowrite(curbuf, false); + autowrite(curbuf, false); } setpcmark(); if (do_ecmd(0, ptr, NULL, NULL, ECMD_LAST, @@ -3972,9 +3973,9 @@ static void nv_search(cmdarg_T *cap) return; } - (void)normal_search(cap, cap->cmdchar, cap->searchbuf, - (cap->arg || !equalpos(save_cursor, curwin->w_cursor)) - ? 0 : SEARCH_MARK, NULL); + normal_search(cap, cap->cmdchar, cap->searchbuf, + (cap->arg || !equalpos(save_cursor, curwin->w_cursor)) + ? 0 : SEARCH_MARK, NULL); } /// Handle "N" and "n" commands. @@ -3990,7 +3991,7 @@ static void nv_next(cmdarg_T *cap) // an offset is given and the cursor is on the last char in the buffer: // Repeat with count + 1. cap->count1 += 1; - (void)normal_search(cap, 0, NULL, SEARCH_MARK | cap->arg, NULL); + normal_search(cap, 0, NULL, SEARCH_MARK | cap->arg, NULL); cap->count1 -= 1; } } @@ -4124,7 +4125,7 @@ static void nv_bracket_block(cmdarg_T *cap, const pos_T *old_pos) if (cap->nchar == 'm' || cap->nchar == 'M') { int c; // norm is true for "]M" and "[m" - int norm = ((findc == '{') == (cap->nchar == 'm')); + bool norm = ((findc == '{') == (cap->nchar == 'm')); n = cap->count1; // found a match: we were inside a method @@ -4290,9 +4291,9 @@ static void nv_brackets(cmdarg_T *cap) } else if (cap->nchar >= K_RIGHTRELEASE && cap->nchar <= K_LEFTMOUSE) { // [ or ] followed by a middle mouse click: put selected text with // indent adjustment. Any other button just does as usual. - (void)do_mouse(cap->oap, cap->nchar, - (cap->cmdchar == ']') ? FORWARD : BACKWARD, - cap->count1, PUT_FIXINDENT); + do_mouse(cap->oap, cap->nchar, + (cap->cmdchar == ']') ? FORWARD : BACKWARD, + cap->count1, PUT_FIXINDENT); } else if (cap->nchar == 'z') { // "[z" and "]z": move to start or end of open fold. if (foldMoveTo(false, cap->cmdchar == ']' ? FORWARD : BACKWARD, @@ -4557,7 +4558,7 @@ static void nv_replace(cmdarg_T *cap) // Insert the newline with an insert command, takes care of // autoindent. The insert command depends on being on the last // character of a line or not. - (void)del_chars(cap->count1, false); // delete the characters + del_chars(cap->count1, false); // delete the characters stuffcharReadbuff('\r'); stuffcharReadbuff(ESC); @@ -4722,7 +4723,7 @@ static void nv_vreplace(cmdarg_T *cap) /// Swap case for "~" command, when it does not work like an operator. static void n_swapchar(cmdarg_T *cap) { - int did_change = 0; + bool did_change = false; if (checkclearopq(cap->oap)) { return; @@ -5122,6 +5123,7 @@ static void n_start_visual_mode(int c) curwin->w_old_cursor_lnum = curwin->w_cursor.lnum; curwin->w_old_visual_lnum = curwin->w_cursor.lnum; } + redraw_curbuf_later(UPD_VALID); } /// CTRL-W: Window commands @@ -5313,7 +5315,7 @@ static void nv_g_dollar_cmd(cmdarg_T *cap) } else { if (cap->count1 > 1) { // if it fails, let the cursor still move to the last char - (void)cursor_down(cap->count1 - 1, false); + cursor_down(cap->count1 - 1, false); } i = curwin->w_leftcol + curwin->w_width_inner - col_off - 1; coladvance((colnr_T)i); @@ -5627,7 +5629,7 @@ static void nv_g_cmd(cmdarg_T *cap) case K_X2DRAG: case K_X2RELEASE: mod_mask = MOD_MASK_CTRL; - (void)do_mouse(oap, cap->nchar, BACKWARD, cap->count1, 0); + do_mouse(oap, cap->nchar, BACKWARD, cap->count1, 0); break; case K_IGNORE: @@ -5700,12 +5702,12 @@ static void n_opencmd(cmdarg_T *cap) if (cap->cmdchar == 'O') { // Open above the first line of a folded sequence of lines - (void)hasFolding(curwin->w_cursor.lnum, - &curwin->w_cursor.lnum, NULL); + hasFolding(curwin->w_cursor.lnum, + &curwin->w_cursor.lnum, NULL); } else { // Open below the last line of a folded sequence of lines - (void)hasFolding(curwin->w_cursor.lnum, - NULL, &curwin->w_cursor.lnum); + hasFolding(curwin->w_cursor.lnum, + NULL, &curwin->w_cursor.lnum); } // trigger TextChangedI for the 'o/O' command curbuf->b_last_changedtick_i = buf_get_changedtick(curbuf); @@ -6109,10 +6111,10 @@ static void nv_normal(cmdarg_T *cap) /// Don't even beep if we are canceling a command. static void nv_esc(cmdarg_T *cap) { - int no_reason = (cap->oap->op_type == OP_NOP - && cap->opcount == 0 - && cap->count0 == 0 - && cap->oap->regname == 0); + bool no_reason = (cap->oap->op_type == OP_NOP + && cap->opcount == 0 + && cap->count0 == 0 + && cap->oap->regname == 0); if (cap->arg) { // true for CTRL-C if (restart_edit == 0 && cmdwin_type == 0 && !VIsual_active && no_reason) { @@ -6444,6 +6446,7 @@ static void nv_put_opt(cmdarg_T *cap, bool fix_indent) bool was_visual = false; int dir; int flags = 0; + const int save_fen = curwin->w_p_fen; if (cap->oap->op_type != OP_NOP) { // "dp" is ":diffput" @@ -6494,6 +6497,10 @@ static void nv_put_opt(cmdarg_T *cap, bool fix_indent) savereg = copy_register(regname); } + // Temporarily disable folding, as deleting a fold marker may cause + // the cursor to be included in a fold. + curwin->w_p_fen = false; + // To place the cursor correctly after a blockwise put, and to leave the // text in the correct position when putting over a selection with // 'virtualedit' and past the end of the line, we use the 'c' operator in @@ -6544,9 +6551,12 @@ static void nv_put_opt(cmdarg_T *cap, bool fix_indent) xfree(savereg); } - // What to reselect with "gv"? Selecting the just put text seems to - // be the most useful, since the original text was removed. if (was_visual) { + if (save_fen) { + curwin->w_p_fen = true; + } + // What to reselect with "gv"? Selecting the just put text seems to + // be the most useful, since the original text was removed. curbuf->b_visual.vi_start = curbuf->b_op_start; curbuf->b_visual.vi_end = curbuf->b_op_end; // need to adjust cursor position @@ -6619,6 +6629,6 @@ void normal_cmd(oparg_T *oap, bool toplevel) s.toplevel = toplevel; s.oa = *oap; normal_prepare(&s); - (void)normal_execute(&s.state, safe_vgetc()); + normal_execute(&s.state, safe_vgetc()); *oap = s.oa; } |