On Mo, 25 Sep 2017, Gary Johnson wrote:
> I've noticed this problem, too, since recently updating from 8.0.691
> to 8.0.1127. Here is a demonstration.
>
> $ vim -N -u NONE -i NONE -c 'so $VIMRUNTIME/indent/sh.vim'
>
> Enter the following text, letting Vim do all the indenting.
>
> if [ $this ]; then
> that
> fi
>
> Note that "fi" is not unindented. As another example, enter this
> text.
>
> if [ $this ]
> then
> that
> fi
>
> Note here that not only is "fi" not unindented, but that "then" is
> indented, which it should not be.
It was a bit tricky, but finally found the problem. Patch 8.0.1041 had
one small typo, which forgot to obtain the line pointer in insert mode
again once the indentkeys 0=word kicked in.
I initially searched the error in the block editing mode, which
obviously was not involved here, so that confused me a bit.
Attached patch fixes the problem and contains a test.
Christian
--
Begriff ist Summe, Idee Resultat der Erfahrung; jene zu ziehen,
wird Verstand, dieses zu erfassen, Vernunft erfordert.
-- Goethe, Maximen und Reflektionen, Nr. 1061
--
--
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.
From 2939f48d9305292bffba7d39568ac53123890aeb Mon Sep 17 00:00:00 2001
From: Christian Brabandt <[email protected]>
Date: Mon, 25 Sep 2017 22:16:01 +0200
Subject: [PATCH] Fix indenting in edit mode
patch 8.0.1041 changed the way indenting in insert mode worked slightly.
Initially in the case of indentkeys:0=word when typing word Vim would
get a pointer to the current line and calculate the indent on it.
However when applying patch 8.0.1041, the line pointer was not refreshed,
so it used the old pointer (which usually pointed to the empty string) and
therefore the indentexpr() was not reapplied.
Fix that, by making sure to get the cursorline again and verify the behaviour
using a test.
fixes #2151 #2114
---
src/edit.c | 2 +-
src/testdir/test_edit.vim | 27 +++++++++++++++++++++++++++
2 files changed, 28 insertions(+), 1 deletion(-)
diff --git a/src/edit.c b/src/edit.c
index 14201a2ec..5f513068a 100644
--- a/src/edit.c
+++ b/src/edit.c
@@ -8202,7 +8202,7 @@ in_cinkeys(
{
/* "0=word": Check if there are only blanks before the
* word. */
- if (getwhitecols(line) !=
+ if (getwhitecols_curline() !=
(int)(curwin->w_cursor.col - (p - look)))
match = FALSE;
}
diff --git a/src/testdir/test_edit.vim b/src/testdir/test_edit.vim
index 0986bf9b1..cc9540c77 100644
--- a/src/testdir/test_edit.vim
+++ b/src/testdir/test_edit.vim
@@ -314,6 +314,33 @@ func! Test_edit_11()
bw!
endfunc
+func! Test_edit_11_indentexpr()
+ " Test that indenting kicks in
+ new
+ " Use indentexpr instead of cindenting
+ func! Do_Indent()
+ let pline=prevnonblank(v:lnum)
+ if empty(getline(v:lnum))
+ if getline(pline) =~ 'if\|then'
+ return shiftwidth()
+ else
+ return 0
+ endif
+ else
+ return 0
+ endif
+ endfunc
+ setl indentexpr=Do_Indent() indentkeys+=0=then,0=fi
+ call setline(1, ['if [ $this ]'])
+ call cursor(1, 1)
+ call feedkeys("othen\<cr>that\<cr>fi", 'tnix')
+ call assert_equal(['if [ $this ]', "then", "\<tab>that", "fi"], getline(1, '$'))
+ set cinkeys&vim indentkeys&vim
+ set nocindent indentexpr=
+ delfu Do_Indent
+ bw!
+endfunc
+
func! Test_edit_12()
" Test changing indent in replace mode
new
--
2.14.1