aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/ops.c
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2022-07-05 14:58:59 +0800
committerzeertzjq <zeertzjq@outlook.com>2022-07-05 15:04:37 +0800
commit42863634dd83d70710436bb599b13571d734c662 (patch)
tree2468a5b93ab897f105ea303669c7fffdbcb238d3 /src/nvim/ops.c
parent6e2d23ac435aa187c88a4174b8f9bb3e01e8d622 (diff)
downloadrneovim-42863634dd83d70710436bb599b13571d734c662.tar.gz
rneovim-42863634dd83d70710436bb599b13571d734c662.tar.bz2
rneovim-42863634dd83d70710436bb599b13571d734c662.zip
vim-patch:8.2.3615: wrong indent in first line if re-formatting with indent expr
Problem: When re-formatting with an indent expression the first line of a paragraph may get the wrong indent. (Martin F. Krafft) Solution: Apply the correct indenting function for the first line. (Christian Brabandt, closes vim/vim#9150, closes vim/vim#9056) https://github.com/vim/vim/commit/818ff25cd1aabf60b9cd239da2f1328a959954f7
Diffstat (limited to 'src/nvim/ops.c')
-rw-r--r--src/nvim/ops.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/nvim/ops.c b/src/nvim/ops.c
index a8198cfce9..cd7ae25a20 100644
--- a/src/nvim/ops.c
+++ b/src/nvim/ops.c
@@ -4547,9 +4547,20 @@ void format_lines(linenr_T line_count, int avoid_fex)
*/
if (is_end_par || force_format) {
if (need_set_indent) {
+ int indent = 0; // amount of indent needed
+
// replace indent in first line with minimal number of
// tabs and spaces, according to current options
- (void)set_indent(get_indent(), SIN_CHANGED);
+ 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