On Fr, 24 Feb 2017, Vitor Antunes wrote:

> Hi Christian,
> 
> On Thursday, 23 February 2017 21:38:39 UTC, Christian Brabandt  wrote:
> > Would you rather not have the first line indented or abort if the indent 
> > changes the line?
> 
> Well, I would rather have the result in the expected.txt file, but taking
> your question into account I can assume that's not so easy.
> 
> Typically, when doing column insertion every action appears "suspended"
> until insertion mode is exited. Would it be possible to queue the call
> to 'indentexpr' until that time? And maybe then apply it to all
> previously selected lines?
> 
> Aborting is too much. For example, when doing column editing and text goes
> over 'textwidth' a newline is inserted and what was being edited is simply
> lost. This is not ideal behavior, but it doesn't abort. In my opinion,
> coherency should be kept in this case.
> So, if nothing else is possible I would say that it is best not to indent
> at all.

Yeah, it is not that easy. However I might have found a way (but see 
below.

The way block inserting works, is like Vim is figuring out, what text 
has been appended or prepended to a line and applies that change to the 
reset of the line. That does not mean it will reevaluate the indent 
expressions or c indenting or expand abbreviations. It simply copies, 
what the **result** of your editing of the first line was and adds it 
to the rest of the block.

The bug you have found looks therefore to Vim like you have actually 
entered "something();" to the end of the first line since Vim did not 
consider that the line was shifted because of the indenting function.

That means, we cannot make Vim work like you prefer and have all indents 
reapplied as the text is changed per block line.

However here is a first play patch, that at least makes Vim aware that 
indenting could have taken place and tries to adjust to it. Please check 
it out. It seems to work for my test cases so far.

If it works okay, I'll add some test cases.

Best,
Christian
-- 
Demnächst sollen auch die ersten Landesmeisterschaften im
Beamtendreikampf ausgerichtet werden: Knicken, Lochen, Abheften.

-- 
-- 
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 vim_dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
diff --git a/src/misc1.c b/src/misc1.c
index 08963999c..70dd9370d 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 d23b3077f..b1f88b769 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,13 @@ 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 */
+    ind_post = get_whitespace_line_start(curwin->w_cursor.lnum);
+    if (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);

Raspunde prin e-mail lui