On Mo, 13 Feb 2017, David Briscoe wrote:
> I work with lots of scripts that use `#` for comments, so I put `set
> cinoptions+=#1` in my vimrc and have `setlocal cinoptions&` in
> ftplugin/cpp.vim (et al).
>
> When I edit a cpp file, `set cinoptions?` returns `cinoptions=`.
> However, when I edit a cpp file, add a new line after an `#include`,
> and type `#`, it is indented one space.
Yeah, curbuf->b_ind_hash_comment is not correctly reset.
This patch fixes it.
Best,
Christian
--
Es kann nicht jeder um Ablaß gen Rom ziehen.
-- Deutsches Sprichwort
--
--
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 04e5a093f1c86c39d15a3e1366d7511c489051a5 Mon Sep 17 00:00:00 2001
From: Christian Brabandt <[email protected]>
Date: Tue, 14 Feb 2017 08:19:55 +0100
Subject: [PATCH] correctly reset hash_comment when resetting cinoptions
---
src/misc1.c | 3 +++
src/testdir/Make_all.mak | 1 +
src/testdir/test_cino.vim | 16 ++++++++++++++++
3 files changed, 20 insertions(+)
create mode 100644 src/testdir/test_cino.vim
diff --git a/src/misc1.c b/src/misc1.c
index 2a2d9cf64..cc22734d6 100644
--- a/src/misc1.c
+++ b/src/misc1.c
@@ -6969,6 +6969,9 @@ parse_cino(buf_T *buf)
* while(). */
buf->b_ind_if_for_while = 0;
+ /* indentation for # comments */
+ buf->b_ind_hash_comment = 0;
+
for (p = buf->b_p_cino; *p; )
{
l = p++;
diff --git a/src/testdir/Make_all.mak b/src/testdir/Make_all.mak
index 58291ea75..b0066ca23 100644
--- a/src/testdir/Make_all.mak
+++ b/src/testdir/Make_all.mak
@@ -140,6 +140,7 @@ NEW_TESTS = test_arglist.res \
test_cdo.res \
test_channel.res \
test_charsearch.res \
+ test_cino.res \
test_cmdline.res \
test_command_count.res \
test_crypt.res \
diff --git a/src/testdir/test_cino.vim b/src/testdir/test_cino.vim
new file mode 100644
index 000000000..53e6e4a80
--- /dev/null
+++ b/src/testdir/test_cino.vim
@@ -0,0 +1,16 @@
+" Test for cinoptions and cindent
+"
+" TODO: rewrite test3.in into this new style test
+
+function! Test_cino_hash()
+ " Test that curbuf->b_ind_hash_comment is correctly reset
+ new
+ setlocal cindent cinoptions=#1
+ setlocal cinoptions=
+ call setline(1, ["#include <iostream>"])
+ call cursor(1, 1)
+ norm! o#include
+ "call feedkeys("o#include\<esc>", 't')
+ call assert_equal(["#include <iostream>", "#include"], getline(1,2))
+ bw!
+endfu
--
2.11.0