On Mo, 20 Feb 2017, micbou wrote:

> The completefunc needs to be called before typing the last `/` so the way to 
> reproduce the issue is:
> ```
> ~$ vim -u NONE -N --cmd ':filetype plugin indent on' --cmd  'call 
> feedkeys("o/*\n\n\<C-X>\<C-U>/\e:wq\n", "t")' foobar.c
> ~$ cat -A foobar.c
> $
> /*$
>  *$
>  * /$
> ```
> Note that the `c_space_errors` option doesn't need to be set to reproduce it.

Yeah, I can reproduce it and I would have been really surprised, if a 
syntax configuration option, would been causing it. I attach a patch, 
that includes a test for this behaviour.

Best,
Christian

-- 
-- 
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 804e7d8849fe7d7468091de97278d5f9231b8e91 Mon Sep 17 00:00:00 2001
From: Christian Brabandt <[email protected]>
Date: Tue, 21 Feb 2017 08:19:10 +0100
Subject: [PATCH] Reset did_ai after failing completion

when you are editing a comment and you are opening a new line by
pressing enter, vim will automatically add the middle comment for a
three part comment and add a space, so that the comment is nicely
formated. You can then easily end the comment by pressing the end
comment leader and Vim will automatically remove the trailing whitespace
and replace it with the end comment leader.

E.g. in a C file you can press 'o/*\nfoobar\n/' and it will be formated like
this:

/*
 * foobar
 */

(note the whitespace between the '*' and 'foobar'. However, once you try
to complete using e.g. <c-x><c-u> Vim won't remove the trailing
whitespace and add the '/' to the '*' with a space separated.

This happens, because in ins_complete() did_ai is unconditionally set to
FALSE, but never reset if completion fails.
So that the following if condition would not be entered in insertchar():
,----
|   #ifdef FEAT_COMMENTS
|       /* Check whether this character should end a comment. */
|       if (did_ai && (int)c == end_comment_pending)
`----
So make sure did_ai is reset to the state before completion was tried
and then adding the end comment leader will automatically remove the
trailing whitespace.

So fix this and also add a test, that the comments option is correctly
applied.
---
 src/edit.c                 |  3 +++
 src/testdir/test_popup.vim | 18 ++++++++++++++++++
 2 files changed, 21 insertions(+)

diff --git a/src/edit.c b/src/edit.c
index bc8652ba4..4d311abf5 100644
--- a/src/edit.c
+++ b/src/edit.c
@@ -5091,6 +5091,7 @@ ins_complete(int c, int enable_pum)
     int		n;
     int		save_w_wrow;
     int		insert_match;
+    int		old_ai = did_ai;
 
     compl_direction = ins_compl_key2dir(c);
     insert_match = ins_compl_use_match(c);
@@ -5374,6 +5375,8 @@ ins_complete(int c, int enable_pum)
 	    {
 		EMSG2(_(e_notset), ctrl_x_mode == CTRL_X_FUNCTION
 					     ? "completefunc" : "omnifunc");
+		/* reset did_ai, so that adding comment leader works */
+		did_ai = old_ai;
 		return FAIL;
 	    }
 
diff --git a/src/testdir/test_popup.vim b/src/testdir/test_popup.vim
index f4ce064d7..f8d482ea3 100644
--- a/src/testdir/test_popup.vim
+++ b/src/testdir/test_popup.vim
@@ -531,4 +531,22 @@ func Test_completion_respect_bs_option()
   bw!
 endfunc
 
+func Test_completion_comment_formatting()
+  new
+  setl formatoptions=tcqro
+  call feedkeys("o/*\<cr>\<cr>/\<esc>", 'tx')
+  call assert_equal(['', '/*', ' *', ' */'], getline(1,4))
+  %d
+  call feedkeys("o/*\<cr>foobar\<cr>/\<esc>", 'tx')
+  call assert_equal(['', '/*', ' * foobar', ' */'], getline(1,4))
+  %d
+  try
+    call feedkeys("o/*\<cr>\<cr>\<c-x>\<c-u>/\<esc>", 'tx')
+    call assert_false(1, 'completefunc not set, should have failed')
+  catch
+    call assert_exception('E764:')
+  endtry
+  call assert_equal(['', '/*', ' *', ' */'], getline(1,4))
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
-- 
2.11.0

Raspunde prin e-mail lui