diff options
Diffstat (limited to 'src/nvim/change.c')
-rw-r--r-- | src/nvim/change.c | 80 |
1 files changed, 45 insertions, 35 deletions
diff --git a/src/nvim/change.c b/src/nvim/change.c index c9e57ab88f..06696610b0 100644 --- a/src/nvim/change.c +++ b/src/nvim/change.c @@ -3,8 +3,16 @@ /// change.c: functions related to changing text +#include <assert.h> +#include <stdbool.h> +#include <stdint.h> +#include <string.h> + +#include "nvim/ascii.h" #include "nvim/assert.h" +#include "nvim/autocmd.h" #include "nvim/buffer.h" +#include "nvim/buffer_defs.h" #include "nvim/buffer_updates.h" #include "nvim/change.h" #include "nvim/charset.h" @@ -13,22 +21,35 @@ #include "nvim/drawscreen.h" #include "nvim/edit.h" #include "nvim/eval.h" +#include "nvim/ex_cmds_defs.h" #include "nvim/extmark.h" -#include "nvim/fileio.h" #include "nvim/fold.h" +#include "nvim/gettext.h" +#include "nvim/globals.h" +#include "nvim/grid_defs.h" +#include "nvim/highlight_defs.h" #include "nvim/indent.h" #include "nvim/indent_c.h" #include "nvim/insexpand.h" +#include "nvim/macros.h" #include "nvim/mark.h" +#include "nvim/mbyte.h" #include "nvim/memline.h" +#include "nvim/memory.h" +#include "nvim/message.h" #include "nvim/move.h" #include "nvim/option.h" +#include "nvim/os/time.h" #include "nvim/plines.h" +#include "nvim/pos.h" +#include "nvim/screen.h" #include "nvim/search.h" #include "nvim/state.h" +#include "nvim/strings.h" #include "nvim/textformat.h" #include "nvim/ui.h" #include "nvim/undo.h" +#include "nvim/vim.h" #ifdef INCLUDE_GENERATED_DECLARATIONS # include "change.c.generated.h" @@ -107,7 +128,7 @@ void changed(void) // Wait two seconds, to make sure the user reads this unexpected // message. Since we could be anywhere, call wait_return() now, // and don't let the emsg() set msg_scroll. - if (need_wait_return && emsg_silent == 0) { + if (need_wait_return && emsg_silent == 0 && !in_assert_fails) { ui_flush(); os_delay(2002L, true); wait_return(true); @@ -397,14 +418,7 @@ void appended_lines(linenr_T lnum, linenr_T count) /// Like appended_lines(), but adjust marks first. void appended_lines_mark(linenr_T lnum, long count) { - // Skip mark_adjust when adding a line after the last one, there can't - // be marks there. But it's still needed in diff mode. - if (lnum + count < curbuf->b_ml.ml_line_count || curwin->w_p_diff) { - mark_adjust(lnum + 1, (linenr_T)MAXLNUM, (linenr_T)count, 0L, kExtmarkUndo); - } else { - extmark_adjust(curbuf, lnum + 1, (linenr_T)MAXLNUM, (linenr_T)count, 0L, - kExtmarkUndo); - } + mark_adjust(lnum + 1, (linenr_T)MAXLNUM, (linenr_T)count, 0L, kExtmarkUndo); changed_lines(lnum + 1, 0, lnum + 1, (linenr_T)count, true); } @@ -539,6 +553,7 @@ void unchanged(buf_T *buf, int ff, bool always_inc_changedtick) void save_file_ff(buf_T *buf) { buf->b_start_ffc = (unsigned char)(*buf->b_p_ff); + buf->b_start_eof = buf->b_p_eof; buf->b_start_eol = buf->b_p_eol; buf->b_start_bomb = buf->b_p_bomb; @@ -573,7 +588,8 @@ bool file_ff_differs(buf_T *buf, bool ignore_empty) if (buf->b_start_ffc != *buf->b_p_ff) { return true; } - if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol) { + if ((buf->b_p_bin || !buf->b_p_fixeol) + && (buf->b_start_eof != buf->b_p_eof || buf->b_start_eol != buf->b_p_eol)) { return true; } if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb) { @@ -854,7 +870,7 @@ int del_bytes(colnr_T count, bool fixpos_arg, bool use_delcombine) bool was_alloced = ml_line_alloced(); // check if oldp was allocated char *newp; if (was_alloced) { - ml_add_deleted_len((char *)curbuf->b_ml.ml_line_ptr, oldlen); + ml_add_deleted_len(curbuf->b_ml.ml_line_ptr, oldlen); newp = oldp; // use same allocated memory } else { // need to allocate a new line newp = xmalloc((size_t)(oldlen + 1 - count)); @@ -1319,7 +1335,7 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) // the comment leader. if (dir == FORWARD) { for (p = saved_line + lead_len; *p; p++) { - if (STRNCMP(p, lead_end, n) == 0) { + if (strncmp(p, lead_end, n) == 0) { comment_end = p; lead_len = 0; break; @@ -1410,7 +1426,7 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) leader = xmalloc((size_t)bytes); allocated = leader; // remember to free it later - STRLCPY(leader, saved_line, lead_len + 1); + xstrlcpy(leader, saved_line, (size_t)lead_len + 1); // TODO(vim): handle multi-byte and double width chars for (int li = 0; li < comment_start; li++) { @@ -1671,13 +1687,7 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) } // Postpone calling changed_lines(), because it would mess up folding // with markers. - // Skip mark_adjust when adding a line after the last one, there can't - // be marks there. But still needed in diff mode. - if (curwin->w_cursor.lnum + 1 < curbuf->b_ml.ml_line_count - || curwin->w_p_diff) { - mark_adjust(curwin->w_cursor.lnum + 1, (linenr_T)MAXLNUM, 1L, 0L, - kExtmarkNOOP); - } + mark_adjust(curwin->w_cursor.lnum + 1, (linenr_T)MAXLNUM, 1L, 0L, kExtmarkNOOP); did_append = true; } else { // In MODE_VREPLACE state we are starting to replace the next line. @@ -1814,19 +1824,19 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) vreplace_mode = 0; } - // May do lisp indenting. - if (!p_paste - && leader == NULL - && curbuf->b_p_lisp - && curbuf->b_p_ai) { - fixthisline(get_lisp_indent); - ai_col = (colnr_T)getwhitecols_curline(); - } - - // May do indenting after opening a new line. - if (do_cindent) { - do_c_expr_indent(); - ai_col = (colnr_T)getwhitecols_curline(); + if (!p_paste) { + if (leader == NULL + && !use_indentexpr_for_lisp() + && curbuf->b_p_lisp + && curbuf->b_p_ai) { + // do lisp indenting + fixthisline(get_lisp_indent); + ai_col = (colnr_T)getwhitecols_curline(); + } else if (do_cindent || (curbuf->b_p_ai && use_indentexpr_for_lisp())) { + // do 'cindent' or 'indentexpr' indenting + do_c_expr_indent(); + ai_col = (colnr_T)getwhitecols_curline(); + } } if (vreplace_mode != 0) { @@ -2194,7 +2204,7 @@ int get_last_leader_offset(char *line, char **flags) // beginning the com_leader. for (off = (len2 > i ? i : len2); off > 0 && off + len1 > len2;) { off--; - if (!STRNCMP(string + off, com_leader, len2 - off)) { + if (!strncmp(string + off, com_leader, (size_t)(len2 - off))) { if (i - off < lower_check_bound) { lower_check_bound = i - off; } |