On Mo, 06 Mär 2017, Vitor Antunes wrote:

> Well, at least the original issue would be fixed. When do you think
> you will have your change merged?

I am attaching an updated patch including some tests. Don't know when 
Bram comes to including this.

Best,
Christian
-- 
Es gibt Personen, denen ich wohl will und wünsche, ihnen besser 
wollen zu können.
                -- Goethe, Maximen und Reflektionen, Nr. 381

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.
commit 6f2faf8f8294cba0d83457f4e62bb87d0f8a8f6f
Author: Christian Brabandt <[email protected]>
Date:   Sun Feb 26 21:48:21 2017 +0100

    Fix block-insert when indenting kicks in
    
    This fixes #1269 /
    https://groups.google.com/d/msg/vim_dev/uMsaEfGexoI/j8NlqiHeCgAJ

diff --git a/src/misc1.c b/src/misc1.c
index ec92f0375..f73eebf23 100644
--- a/src/misc1.c
+++ b/src/misc1.c
@@ -27,6 +27,21 @@ static garray_T	ga_users;
 #endif
 
 /*
+ * Return the number of whitespace bytes in front of a given line
+ */
+    int
+get_whitespace_line_start(linenr_T lnum)
+{
+    char_u *l1, *l2;
+
+    l1 = l2 = ml_get(lnum);
+    while (vim_iswhite(*l2))
+	++l2;
+
+    return l2 - l1;
+}
+
+/*
  * Count the size (in window cells) of the indent in the current line.
  */
     int
diff --git a/src/ops.c b/src/ops.c
index 757c11549..1254f0056 100644
--- a/src/ops.c
+++ b/src/ops.c
@@ -2505,6 +2505,7 @@ op_insert(oparg_T *oap, long count1)
 {
     long		ins_len, pre_textlen = 0;
     char_u		*firstline, *ins_text;
+    int                 ind_pre, ind_post;
     struct block_def	bd;
     int			i;
     pos_T		t1;
@@ -2539,7 +2540,10 @@ op_insert(oparg_T *oap, long count1)
 #endif
 	/* Get the info about the block before entering the text */
 	block_prep(oap, &bd, oap->start.lnum, TRUE);
+	/* Get indent information */
+	ind_pre = get_whitespace_line_start(oap->start.lnum);
 	firstline = ml_get(oap->start.lnum) + bd.textcol;
+
 	if (oap->op_type == OP_APPEND)
 	    firstline += bd.textlen;
 	pre_textlen = (long)STRLEN(firstline);
@@ -2591,6 +2595,14 @@ op_insert(oparg_T *oap, long count1)
 	    && lt(curbuf->b_op_start_orig, t1))
 	oap->start = curbuf->b_op_start_orig;
 
+    /* if indent kicked in, the firstline might have changed
+     * but only do that, if the indent actually increased */
+    ind_post = get_whitespace_line_start(curwin->w_cursor.lnum);
+    if (curbuf->b_op_start.col > ind_pre && ind_post > ind_pre)
+    {
+	bd.textcol += ind_post - ind_pre;
+	bd.start_vcol += ind_post - ind_pre;
+    }
     /* If user has moved off this line, we don't know what to do, so do
      * nothing.
      * Also don't repeat the insert when Insert mode ended with CTRL-C. */
diff --git a/src/proto/misc1.pro b/src/proto/misc1.pro
index cac644969..4e299e5f9 100644
--- a/src/proto/misc1.pro
+++ b/src/proto/misc1.pro
@@ -1,4 +1,5 @@
 /* misc1.c */
+int get_whitespace_line_start(linenr_T lnum);
 int get_indent(void);
 int get_indent_lnum(linenr_T lnum);
 int get_indent_buf(buf_T *buf, linenr_T lnum);
diff --git a/src/testdir/test_cindent.vim b/src/testdir/test_cindent.vim
index 5685c2be6..c0fb340b1 100644
--- a/src/testdir/test_cindent.vim
+++ b/src/testdir/test_cindent.vim
@@ -14,3 +14,22 @@ func Test_cino_hash()
   call assert_equal(["#include <iostream>", "#include"], getline(1,2))
   bwipe!
 endfunc
+
+func! Test_cindent_expr()
+  new
+  func! MyIndentFunction()
+    return v:lnum == 1 ? shiftwidth() : 0
+  endfunc
+  setl expandtab sw=8 indentkeys+=; indentexpr=MyIndentFunction()
+  call setline(1, ['var_a = something()', 'b = something()'])
+  call cursor(1, 1)
+  call feedkeys("^\<c-v>j$A;\<esc>", 'tnix')
+  call assert_equal(['        var_a = something();', 'b = something();'], getline(1, '$'))
+
+  %d
+  call setline(1, ['                var_a = something()', '                b = something()'])
+  call cursor(1, 1)
+  call feedkeys("^\<c-v>j$A;\<esc>", 'tnix')
+  call assert_equal(['        var_a = something();', '                b = something()'], getline(1, '$'))
+  bw!
+endfunc

Raspunde prin e-mail lui