diff options
Diffstat (limited to 'src/nvim/normal.c')
-rw-r--r-- | src/nvim/normal.c | 148 |
1 files changed, 75 insertions, 73 deletions
diff --git a/src/nvim/normal.c b/src/nvim/normal.c index 732e5ffc1f..6f1cc494b2 100644 --- a/src/nvim/normal.c +++ b/src/nvim/normal.c @@ -414,14 +414,14 @@ static int find_command(int cmdchar) return -1; } - /* We use the absolute value of the character. Special keys have a - * negative value, but are sorted on their absolute value. */ + // We use the absolute value of the character. Special keys have a + // negative value, but are sorted on their absolute value. if (cmdchar < 0) { cmdchar = -cmdchar; } - /* If the character is in the first part: The character is the index into - * nv_cmd_idx[]. */ + // If the character is in the first part: The character is the index into + // nv_cmd_idx[]. assert(nv_max_linear < (int)NV_CMDS_SIZE); if (cmdchar <= nv_max_linear) { return nv_cmd_idx[cmdchar]; @@ -2167,9 +2167,10 @@ static void op_function(const oparg_T *oap) FUNC_ATTR_NONNULL_ALL { const TriState save_virtual_op = virtual_op; + const bool save_finish_op = finish_op; if (*p_opfunc == NUL) { - EMSG(_("E774: 'operatorfunc' is empty")); + emsg(_("E774: 'operatorfunc' is empty")); } else { // Set '[ and '] marks to text to be operated on. curbuf->b_op_start = oap->start; @@ -2193,9 +2194,13 @@ static void op_function(const oparg_T *oap) // function. virtual_op = kNone; + // Reset finish_op so that mode() returns the right value. + finish_op = false; + (void)call_func_retnr(p_opfunc, 1, argv); virtual_op = save_virtual_op; + finish_op = save_finish_op; } } @@ -3220,9 +3225,9 @@ size_t find_ident_at_pos(win_T *wp, linenr_T lnum, colnr_T startcol, char_u **te if (ptr[col] == NUL || (i == 0 && this_class != 2)) { // Didn't find an identifier or text. if (find_type & FIND_STRING) { - EMSG(_("E348: No string under cursor")); + emsg(_("E348: No string under cursor")); } else { - EMSG(_(e_noident)); + emsg(_(e_noident)); } return 0; } @@ -3892,8 +3897,8 @@ bool find_decl(char_u *ptr, size_t len, bool locally, bool thisblock, int flags_ pat = xmalloc(len + 7); - /* Put "\V" before the pattern to avoid that the special meaning of "." - * and "~" causes trouble. */ + // Put "\V" before the pattern to avoid that the special meaning of "." + // and "~" causes trouble. assert(len <= INT_MAX); sprintf((char *)pat, vim_iswordp(ptr) ? "\\V\\<%.*s\\>" : "\\V%.*s", (int)len, ptr); @@ -4247,9 +4252,9 @@ void scroll_redraw(int up, long count) check_cursor_moved(curwin); curwin->w_valid |= VALID_TOPLINE; - /* If moved back to where we were, at least move the cursor, otherwise - * we get stuck at one position. Don't move the cursor up if the - * first line of the buffer is already on the screen */ + // If moved back to where we were, at least move the cursor, otherwise + // we get stuck at one position. Don't move the cursor up if the + // first line of the buffer is already on the screen while (curwin->w_topline == prev_topline && curwin->w_topfill == prev_topfill) { if (up) { @@ -4333,7 +4338,7 @@ static void nv_zet(cmdarg_T *cap) dozet: // "zf" and "zF" are always an operator, "zd", "zo", "zO", "zc" // and "zC" only in Visual mode. "zj" and "zk" are motion - // commands. */ + // commands. if (cap->nchar != 'f' && cap->nchar != 'F' && !(VIsual_active && vim_strchr((char_u *)"dcCoO", cap->nchar)) && cap->nchar != 'j' && cap->nchar != 'k' @@ -4541,7 +4546,7 @@ dozet: } else if (foldmethodIsMarker(curwin)) { deleteFold(curwin, (linenr_T)1, curbuf->b_ml.ml_line_count, true, false); } else { - EMSG(_("E352: Cannot erase folds with current 'foldmethod'")); + emsg(_("E352: Cannot erase folds with current 'foldmethod'")); } break; @@ -4767,7 +4772,6 @@ dozet: } - /* * "Q" command. */ @@ -4998,15 +5002,15 @@ static void nv_ident(cmdarg_T *cap) return; } - /* Allocate buffer to put the command in. Inserting backslashes can - * double the length of the word. p_kp / curbuf->b_p_kp could be added - * and some numbers. */ + // Allocate buffer to put the command in. Inserting backslashes can + // double the length of the word. p_kp / curbuf->b_p_kp could be added + // and some numbers. char_u *kp = *curbuf->b_p_kp == NUL ? p_kp : curbuf->b_p_kp; // 'keywordprg' assert(*kp != NUL); // option.c:do_set() should default to ":help" if empty. bool kp_ex = (*kp == ':'); // 'keywordprg' is an ex command bool kp_help = (STRCMP(kp, ":he") == 0 || STRCMP(kp, ":help") == 0); if (kp_help && *skipwhite(ptr) == NUL) { - EMSG(_(e_noident)); // found white space only + emsg(_(e_noident)); // found white space only return; } size_t buf_size = n * 2 + 30 + STRLEN(kp); @@ -5041,20 +5045,20 @@ static void nv_ident(cmdarg_T *cap) STRCAT(buf, kp); STRCAT(buf, " "); } else { - /* An external command will probably use an argument starting - * with "-" as an option. To avoid trouble we skip the "-". */ + // An external command will probably use an argument starting + // with "-" as an option. To avoid trouble we skip the "-". while (*ptr == '-' && n > 0) { ++ptr; --n; } if (n == 0) { - EMSG(_(e_noident)); // found dashes only + emsg(_(e_noident)); // found dashes only xfree(buf); return; } - /* When a count is given, turn it into a range. Is this - * really what we want? */ + // When a count is given, turn it into a range. Is this + // really what we want? bool isman = (STRCMP(kp, "man") == 0); bool isman_s = (STRCMP(kp, "man -s") == 0); if (cap->count0 != 0 && !(isman || isman_s)) { @@ -5136,8 +5140,8 @@ static void nv_ident(cmdarg_T *cap) if (vim_strchr(aux_ptr, *ptr) != NULL) { *p++ = '\\'; } - /* When current byte is a part of multibyte character, copy all - * bytes of that character. */ + // When current byte is a part of multibyte character, copy all + // bytes of that character. const size_t len = (size_t)(utfc_ptr2len(ptr) - 1); for (size_t i = 0; i < len && n > 0; i++, n--) { *p++ = *ptr++; @@ -5410,10 +5414,9 @@ static void nv_left(cmdarg_T *cap) cap->oap->inclusive = false; for (n = cap->count1; n > 0; --n) { if (oneleft() == false) { - /* <BS> and <Del> wrap to previous line if 'whichwrap' has 'b'. - * 'h' wraps to previous line if 'whichwrap' has 'h'. - * CURS_LEFT wraps to previous line if 'whichwrap' has '<'. - */ + // <BS> and <Del> wrap to previous line if 'whichwrap' has 'b'. + // 'h' wraps to previous line if 'whichwrap' has 'h'. + // CURS_LEFT wraps to previous line if 'whichwrap' has '<'. if ((((cap->cmdchar == K_BS || cap->cmdchar == Ctrl_H) && vim_strchr(p_ww, 'b') != NULL) || (cap->cmdchar == 'h' && vim_strchr(p_ww, 'h') != NULL) @@ -5565,9 +5568,9 @@ static void nv_dollar(cmdarg_T *cap) { cap->oap->motion_type = kMTCharWise; cap->oap->inclusive = true; - /* In virtual mode when off the edge of a line and an operator - * is pending (whew!) keep the cursor where it is. - * Otherwise, send it to the end of the line. */ + // In virtual mode when off the edge of a line and an operator + // is pending (whew!) keep the cursor where it is. + // Otherwise, send it to the end of the line. if (!virtual_active() || gchar_cursor() != NUL || cap->oap->op_type == OP_NOP) { curwin->w_curswant = MAXCOL; // so we stay at the end @@ -5776,10 +5779,10 @@ static void nv_brackets(cmdarg_T *cap) * "[m" or "]m" search for prev/next start of (Java) method. * "[M" or "]M" search for prev/next end of (Java) method. */ - if ( (cap->cmdchar == '[' - && vim_strchr((char_u *)"{(*/#mM", cap->nchar) != NULL) - || (cap->cmdchar == ']' - && vim_strchr((char_u *)"})*/#mM", cap->nchar) != NULL)) { + if ((cap->cmdchar == '[' + && vim_strchr((char_u *)"{(*/#mM", cap->nchar) != NULL) + || (cap->cmdchar == ']' + && vim_strchr((char_u *)"})*/#mM", cap->nchar) != NULL)) { if (cap->nchar == '*') { cap->nchar = '/'; } @@ -6273,9 +6276,9 @@ static void nv_replace(cmdarg_T *cap) ins_char(cap->ncharC2); } } - --curwin->w_cursor.col; // cursor on the last replaced char - /* if the character on the left of the current cursor is a multi-byte - * character, move two characters left */ + curwin->w_cursor.col--; // cursor on the last replaced char + // if the character on the left of the current cursor is a multi-byte + // character, move two characters left mb_adjust_cursor(); curbuf->b_op_end = curwin->w_cursor; curwin->w_set_curswant = true; @@ -6345,7 +6348,7 @@ static void nv_Replace(cmdarg_T *cap) nv_operator(cap); } else if (!checkclearopq(cap->oap)) { if (!MODIFIABLE(curbuf)) { - EMSG(_(e_modifiable)); + emsg(_(e_modifiable)); } else { if (virtual_active()) { coladvance(getviscol()); @@ -6366,7 +6369,7 @@ static void nv_vreplace(cmdarg_T *cap) nv_replace(cap); // Do same as "r" in Visual mode for now } else if (!checkclearopq(cap->oap)) { if (!MODIFIABLE(curbuf)) { - EMSG(_(e_modifiable)); + emsg(_(e_modifiable)); } else { if (cap->extra_char == Ctrl_V) { // get another character cap->extra_char = get_literal(); @@ -6611,11 +6614,11 @@ static void nv_pcmark(cmdarg_T *cap) nv_cursormark(cap, false, pos); } else if (cap->cmdchar == 'g') { if (curbuf->b_changelistlen == 0) { - EMSG(_("E664: changelist is empty")); + emsg(_("E664: changelist is empty")); } else if (cap->count1 < 0) { - EMSG(_("E662: At start of changelist")); + emsg(_("E662: At start of changelist")); } else { - EMSG(_("E663: At end of changelist")); + emsg(_("E663: At end of changelist")); } } else { clearopbeep(cap->oap); @@ -6797,8 +6800,8 @@ static void n_start_visual_mode(int c) if (p_smd && msg_silent == 0) { redraw_cmdline = true; // show visual mode later } - /* Only need to redraw this line, unless still need to redraw an old - * Visual area (when 'lazyredraw' is set). */ + // Only need to redraw this line, unless still need to redraw an old + // Visual area (when 'lazyredraw' is set). if (curwin->w_redr_type < INVERTED) { curwin->w_old_cursor_lnum = curwin->w_cursor.lnum; curwin->w_old_visual_lnum = curwin->w_cursor.lnum; @@ -7566,8 +7569,8 @@ static void nv_home(cmdarg_T *cap) cap->count0 = 1; nv_pipe(cap); } - ins_at_eol = false; /* Don't move cursor past eol (only necessary in a - one-character line). */ + ins_at_eol = false; // Don't move cursor past eol (only necessary in a + // one-character line). } /* @@ -7584,8 +7587,8 @@ static void nv_pipe(cmdarg_T *cap) } else { curwin->w_curswant = 0; } - /* keep curswant at the column where we wanted to go, not where - * we ended; differs if line is too short */ + // keep curswant at the column where we wanted to go, not where + // we ended; differs if line is too short curwin->w_set_curswant = false; } @@ -7656,8 +7659,8 @@ static void nv_wordcmd(cmdarg_T *cap) n = fwd_word(cap->count1, cap->arg, cap->oap->op_type != OP_NOP); } - /* Don't leave the cursor on the NUL past the end of line. Unless we - * didn't move it forward. */ + // Don't leave the cursor on the NUL past the end of line. Unless we + // didn't move it forward. if (lt(startpos, curwin->w_cursor)) { adjust_cursor(cap->oap); } @@ -7706,8 +7709,8 @@ static void nv_beginline(cmdarg_T *cap) if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP) { foldOpenCursor(); } - ins_at_eol = false; /* Don't move cursor past eol (only necessary in a - one-character line). */ + ins_at_eol = false; // Don't move cursor past eol (only necessary in a + // one-character line). } /* @@ -7845,15 +7848,15 @@ static void nv_esc(cmdarg_T *cap) && !VIsual_active && no_reason) { if (anyBufIsChanged()) { - MSG(_("Type :qa! and press <Enter> to abandon all changes" + msg(_("Type :qa! and press <Enter> to abandon all changes" " and exit Nvim")); } else { - MSG(_("Type :qa and press <Enter> to exit Nvim")); + msg(_("Type :qa and press <Enter> to exit Nvim")); } } - /* Don't reset "restart_edit" when 'insertmode' is set, it won't be - * set again below when halfway through a mapping. */ + // Don't reset "restart_edit" when 'insertmode' is set, it won't be + // set again below when halfway through a mapping. if (!p_im) { restart_edit = 0; } @@ -7880,8 +7883,8 @@ static void nv_esc(cmdarg_T *cap) } clearop(cap->oap); - /* A CTRL-C is often used at the start of a menu. When 'insertmode' is - * set return to Insert mode afterwards. */ + // A CTRL-C is often used at the start of a menu. When 'insertmode' is + // set return to Insert mode afterwards. if (restart_edit == 0 && goto_im() && ex_normal_busy == 0) { restart_edit = 'a'; @@ -7922,7 +7925,7 @@ static void nv_edit(cmdarg_T *cap) nv_object(cap); } else if (!curbuf->b_p_ma && !p_im && !curbuf->terminal) { // Only give this error when 'insertmode' is off. - EMSG(_(e_modifiable)); + emsg(_(e_modifiable)); clearop(cap->oap); } else if (!checkclearopq(cap->oap)) { switch (cap->cmdchar) { @@ -7935,8 +7938,8 @@ static void nv_edit(cmdarg_T *cap) break; case 'a': // "a"ppend is like "i"nsert on the next character. - /* increment coladd when in virtual space, increment the - * column otherwise, also to append after an unprintable char */ + // increment coladd when in virtual space, increment the + // column otherwise, also to append after an unprintable char if (virtual_active() && (curwin->w_cursor.coladd > 0 || *get_cursor_pos_ptr() == NUL @@ -8204,11 +8207,10 @@ static void nv_put_opt(cmdarg_T *cap, bool fix_indent) } if (VIsual_active) { - /* Putting in Visual mode: The put text replaces the selected - * text. First delete the selected text, then put the new text. - * Need to save and restore the registers that the delete - * overwrites if the old contents is being put. - */ + // Putting in Visual mode: The put text replaces the selected + // text. First delete the selected text, then put the new text. + // Need to save and restore the registers that the delete + // overwrites if the old contents is being put. was_visual = true; regname = cap->oap->regname; // '+' and '*' could be the same selection @@ -8281,14 +8283,14 @@ static void nv_put_opt(cmdarg_T *cap, bool fix_indent) } } - /* When all lines were selected and deleted do_put() leaves an empty - * line that needs to be deleted now. */ + // When all lines were selected and deleted do_put() leaves an empty + // line that needs to be deleted now. if (empty && *ml_get(curbuf->b_ml.ml_line_count) == NUL) { ml_delete(curbuf->b_ml.ml_line_count, true); deleted_lines(curbuf->b_ml.ml_line_count + 1, 1); - /* If the cursor was in that line, move it to the end of the last - * line. */ + // If the cursor was in that line, move it to the end of the last + // line. if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) { curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; coladvance(MAXCOL); |