diff options
author | zeertzjq <zeertzjq@outlook.com> | 2022-07-05 15:39:50 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-05 15:39:50 +0800 |
commit | eb814bdca0bad2a68e111d59fae62f79b8dbeef1 (patch) | |
tree | 769e0b5b6911e953e012b9d368cec5436a3ec134 /src/nvim/ops.c | |
parent | 6e2d23ac435aa187c88a4174b8f9bb3e01e8d622 (diff) | |
parent | d9e5737fdceebe17da52d5c9b41db21259449c19 (diff) | |
download | rneovim-eb814bdca0bad2a68e111d59fae62f79b8dbeef1.tar.gz rneovim-eb814bdca0bad2a68e111d59fae62f79b8dbeef1.tar.bz2 rneovim-eb814bdca0bad2a68e111d59fae62f79b8dbeef1.zip |
Merge pull request #19231 from zeertzjq/vim-8.2.3615
vim-patch:8.2.{3615,3754,5122}: indent fixes
Diffstat (limited to 'src/nvim/ops.c')
-rw-r--r-- | src/nvim/ops.c | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/src/nvim/ops.c b/src/nvim/ops.c index a8198cfce9..f2859bf707 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -4421,6 +4421,7 @@ void format_lines(linenr_T line_count, int avoid_fex) int smd_save; long count; bool need_set_indent = true; // set indent of next paragraph + linenr_T first_line = curwin->w_cursor.lnum; bool force_format = false; const int old_State = State; @@ -4547,9 +4548,24 @@ void format_lines(linenr_T line_count, int avoid_fex) */ if (is_end_par || force_format) { if (need_set_indent) { - // replace indent in first line with minimal number of - // tabs and spaces, according to current options - (void)set_indent(get_indent(), SIN_CHANGED); + int indent = 0; // amount of indent needed + + // Replace indent in first line of a paragraph with minimal + // number of tabs and spaces, according to current options. + // For the very first formatted line keep the current + // indent. + if (curwin->w_cursor.lnum == first_line) { + indent = get_indent(); + } else if (curbuf->b_p_lisp) { + indent = get_lisp_indent(); + } else { + if (cindent_on()) { + indent = *curbuf->b_p_inde != NUL ? get_expr_indent() : get_c_indent(); + } else { + indent = get_indent(); + } + } + (void)set_indent(indent, SIN_CHANGED); } // put cursor on last non-space |