Re: test popupmenu question

2016-09-22 Fir de Conversatie Bram Moolenaar

Hirohito Higashi wrote:

> Hi ChrisBra, Bram and list,
> 
> 2016-9-23(Fri) 0:34:35 UTC+9 Christian Brabandt:
> > Hi,
> > 
> > On Mi, 21 Sep 2016, h_east wrote:
> > >  func! Test_popup_complete2()
> > > -  " Insert match immediately, if there is only one match
> > > -  "   Should select a character from the line below
> > > -  " TODO: test disabled because the code change has been reverted.
> > > -  throw "Skipped: Bug with  and popupmenu not fixed yet"
> > > +  " 'the popup menu is not visible' is not equivalent to  'the 
> > > completion mode
> > > +  " is not active'.
> > > +  " After the type , Vim still stay in the first state of the 
> > > completion
> > > +  " mode.  It is not related to the visible of popup.
> > > +  " So that, the first  behavior is `complete_CTRL-E`, and the 
> > > second and
> > > +  " more  is `i_CTRL_E`
> > 
> > 
> > How about this:
> > Although the popupmenu is not visible, this does not mean completion 
> > mode has ended. After pressing  to complete the currently typed 
> > char, Vim still stays in the first state of the completion
> > (:h ins-completion-menu), although the popupmenu wasn't shown  will 
> > remove the inserted completed text (:h complete_CTRL-E), while the 
> > following  will behave like expected (:h i_CTRL-E)
> 
> Nicely. I like this. Thanks𐟑 .
> 
> > 
> > > -  call assert_equal(["December2015", "", "December2015"], getline(1,3))
> > > +  call assert_equal(["Dece", "", "December2015"], getline(1,3))
> > 
> > Looks good to me.
> 
> Thanks for the check.
> I update a patch.
> 
> Bram>
> Please include this patch.

I will, thanks.

-- 
You were lucky to have a LAKE! There were a hundred and sixty of
us living in a small shoebox in the middle of the road.

 /// Bram Moolenaar -- b...@moolenaar.net -- http://www.Moolenaar.net   \\\
///sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org///
 \\\help me help AIDS victims -- http://ICCF-Holland.org///

-- 
-- 
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.


Re: test popupmenu question

2016-09-22 Fir de Conversatie h_east
Hi ChrisBra, Bram and list,

2016-9-23(Fri) 0:34:35 UTC+9 Christian Brabandt:
> Hi,
> 
> On Mi, 21 Sep 2016, h_east wrote:
> >  func! Test_popup_complete2()
> > -  " Insert match immediately, if there is only one match
> > -  "   Should select a character from the line below
> > -  " TODO: test disabled because the code change has been reverted.
> > -  throw "Skipped: Bug with  and popupmenu not fixed yet"
> > +  " 'the popup menu is not visible' is not equivalent to  'the completion 
> > mode
> > +  " is not active'.
> > +  " After the type , Vim still stay in the first state of the 
> > completion
> > +  " mode.  It is not related to the visible of popup.
> > +  " So that, the first  behavior is `complete_CTRL-E`, and the second 
> > and
> > +  " more  is `i_CTRL_E`
> 
> 
> How about this:
> Although the popupmenu is not visible, this does not mean completion 
> mode has ended. After pressing  to complete the currently typed 
> char, Vim still stays in the first state of the completion
> (:h ins-completion-menu), although the popupmenu wasn't shown  will 
> remove the inserted completed text (:h complete_CTRL-E), while the 
> following  will behave like expected (:h i_CTRL-E)

Nicely. I like this. Thanks👍.

> 
> > -  call assert_equal(["December2015", "", "December2015"], getline(1,3))
> > +  call assert_equal(["Dece", "", "December2015"], getline(1,3))
> 
> Looks good to me.

Thanks for the check.
I update a patch.

Bram>
Please include this patch.

--
Best regards,
Hirohito Higashi (a.k.a. h_east)

-- 
-- 
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/testdir/test_popup.vim b/src/testdir/test_popup.vim
index 6e07393..10eaf3a 100644
--- a/src/testdir/test_popup.vim
+++ b/src/testdir/test_popup.vim
@@ -17,16 +17,18 @@ func! ListMonths()
 endfunc
 
 func! Test_popup_complete2()
-  " Insert match immediately, if there is only one match
-  "   Should select a character from the line below
-  " TODO: test disabled because the code change has been reverted.
-  throw "Skipped: Bug with  and popupmenu not fixed yet"
+  " Although the popupmenu is not visible, this does not mean completion mode
+  " has ended. After pressing  to complete the currently typed char, Vim
+  " still stays in the first state of the completion (:h ins-completion-menu),
+  " although the popupmenu wasn't shown  will remove the inserted
+  " completed text (:h complete_CTRL-E), while the following  will behave
+  " like expected (:h i_CTRL-E)
   new
   inoremap  =ListMonths()
   call append(1, ["December2015"])
   :1
   call feedkeys("aD\\\", 'tx')
-  call assert_equal(["December2015", "", "December2015"], getline(1,3))
+  call assert_equal(["Dece", "", "December2015"], getline(1,3))
   %d
   bw!
 endfu


Re: test popupmenu question

2016-09-22 Fir de Conversatie Christian Brabandt
Hi,

On Mi, 21 Sep 2016, h_east wrote:
>  func! Test_popup_complete2()
> -  " Insert match immediately, if there is only one match
> -  "   Should select a character from the line below
> -  " TODO: test disabled because the code change has been reverted.
> -  throw "Skipped: Bug with  and popupmenu not fixed yet"
> +  " 'the popup menu is not visible' is not equivalent to  'the completion 
> mode
> +  " is not active'.
> +  " After the type , Vim still stay in the first state of the completion
> +  " mode.  It is not related to the visible of popup.
> +  " So that, the first  behavior is `complete_CTRL-E`, and the second 
> and
> +  " more  is `i_CTRL_E`


How about this:
Although the popupmenu is not visible, this does not mean completion 
mode has ended. After pressing  to complete the currently typed 
char, Vim still stays in the first state of the completion
(:h ins-completion-menu), although the popupmenu wasn't shown  will 
remove the inserted completed text (:h complete_CTRL-E), while the 
following  will behave like expected (:h i_CTRL-E)

> -  call assert_equal(["December2015", "", "December2015"], getline(1,3))
> +  call assert_equal(["Dece", "", "December2015"], getline(1,3))

Looks good to me.


Best,
Christian
-- 
Autokraten lieben meist kleine Kinder. Sie schränken ihre Macht nicht
ein, dafür sind sie ihnen dankbar.
-- Ludwig Marcuse (Argumente und Rezepte)

-- 
-- 
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.


Re: test popupmenu question

2016-09-21 Fir de Conversatie h_east
Hi ChrisBra, Bram and list!

2016-9-12(Mon) 2:56:04 UTC+9 Christian Brabandt:
> On So, 11 Sep 2016, h_east wrote:
> 
> > Hi ChrisBra, Bram and list,
> > 2016-7-24(Sun) 0:36:14 UTC+9 Christian Brabandt:
> > > On Sa, 23 Jul 2016, Bram Moolenaar wrote:
> > > > Christian Brabandt wrote:
> > > I think I also found a bug, and this makes the test currently fail.
> > > Take this example from the test:
> > > 
> > > (The popupmenu is the one from the help for all months)
> > > The initial state of the buffer is this:
> > > ,
> > > | D
> > > | December2015
> > > `
> > 
> > I have investigated this behavior.
> > 
> > Related vim_dev threads:
> > - Patch 7.4.2146
> >   https://groups.google.com/d/msg/vim_dev/75ZXlRlBzl4/DDnqvSn9BgAJ
> > - [vim/vim] VIM 7.4: Possible regression via patch 2146? (#972)
> >   https://groups.google.com/d/msg/vim_dev/mQ2YacpOKvo/vOsgkU-2AQAJ
> > - Patch 7.4.2188
> >   https://groups.google.com/d/msg/vim_dev/e2Rr8Px3qkQ/1XWiAQ0LAgAJ
> > 
> > I think the series of  behavior is correct.
> 
> okay.
> 
> > > ,
> > > | Dece
> > > | 
> > > | December2015
> > > `
> > > (because after inserting the match  is still in popupmenu mode and
> > > "ends completion and goes back to what was there before selecting a 
> > > match")
> > > 
> > > However, a total mystery is to me, when the test is run, it will 
> > > complete to 
> > > 
> > > ,
> > > | December2015
> > > | December2015
> > > | December2015
> > > `
> > 
> > Hmm?, I got the following result. (make test_popup in 7.4.2358)
> > 
> > 1 FAILED:
> > Found errors in Test_popup_complete2():
> > function RunTheTest[9]..Test_popup_complete2 line 10: Expected 
> > ['December2015', '', 'December2015'] but got ['Dece', '', 'December2015']
> > 
> > I think `['Dece', '', 'December2015']` is right.
> 
> Okay then we can enable the test again and need to change the test 
> assert.

I changed test_popup.vim
I was wondering if you can check an attached patch?
I would like you to check the mainly English sentence 👍

Thank you
--
Best regards,
Hirohito Higashi (a.k.a. h_east)

-- 
-- 
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/testdir/test_popup.vim b/src/testdir/test_popup.vim
index 6e07393..eae8bc3 100644
--- a/src/testdir/test_popup.vim
+++ b/src/testdir/test_popup.vim
@@ -17,16 +17,18 @@ func! ListMonths()
 endfunc
 
 func! Test_popup_complete2()
-  " Insert match immediately, if there is only one match
-  "   Should select a character from the line below
-  " TODO: test disabled because the code change has been reverted.
-  throw "Skipped: Bug with  and popupmenu not fixed yet"
+  " 'the popup menu is not visible' is not equivalent to  'the completion mode
+  " is not active'.
+  " After the type , Vim still stay in the first state of the completion
+  " mode.  It is not related to the visible of popup.
+  " So that, the first  behavior is `complete_CTRL-E`, and the second and
+  " more  is `i_CTRL_E`
   new
   inoremap  =ListMonths()
   call append(1, ["December2015"])
   :1
   call feedkeys("aD\\\", 'tx')
-  call assert_equal(["December2015", "", "December2015"], getline(1,3))
+  call assert_equal(["Dece", "", "December2015"], getline(1,3))
   %d
   bw!
 endfu


Re: test popupmenu question

2016-09-11 Fir de Conversatie Christian Brabandt
On So, 11 Sep 2016, h_east wrote:

> Hi ChrisBra, Bram and list,
> 2016-7-24(Sun) 0:36:14 UTC+9 Christian Brabandt:
> > On Sa, 23 Jul 2016, Bram Moolenaar wrote:
> > > Christian Brabandt wrote:
> > I think I also found a bug, and this makes the test currently fail.
> > Take this example from the test:
> > 
> > (The popupmenu is the one from the help for all months)
> > The initial state of the buffer is this:
> > ,
> > | D
> > | December2015
> > `
> 
> I have investigated this behavior.
> 
> Related vim_dev threads:
> - Patch 7.4.2146
>   https://groups.google.com/d/msg/vim_dev/75ZXlRlBzl4/DDnqvSn9BgAJ
> - [vim/vim] VIM 7.4: Possible regression via patch 2146? (#972)
>   https://groups.google.com/d/msg/vim_dev/mQ2YacpOKvo/vOsgkU-2AQAJ
> - Patch 7.4.2188
>   https://groups.google.com/d/msg/vim_dev/e2Rr8Px3qkQ/1XWiAQ0LAgAJ
> 
> I think the series of  behavior is correct.

okay.

> > ,
> > | Dece
> > | 
> > | December2015
> > `
> > (because after inserting the match  is still in popupmenu mode and
> > "ends completion and goes back to what was there before selecting a 
> > match")
> > 
> > However, a total mystery is to me, when the test is run, it will 
> > complete to 
> > 
> > ,
> > | December2015
> > | December2015
> > | December2015
> > `
> 
> Hmm?, I got the following result. (make test_popup in 7.4.2358)
> 
> 1 FAILED:
> Found errors in Test_popup_complete2():
> function RunTheTest[9]..Test_popup_complete2 line 10: Expected 
> ['December2015', '', 'December2015'] but got ['Dece', '', 'December2015']
> 
> I think `['Dece', '', 'December2015']` is right.

Okay then we can enable the test again and need to change the test 
assert.

Best,
Christian
-- 
Alles was man will, kostet etwas mehr als es wert ist.
  (Das zweite Gesetz der Thermodynamik)

-- 
-- 
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.


Re: test popupmenu question

2016-09-11 Fir de Conversatie h_east
Hi ChrisBra, Bram and list,

2016-7-24(Sun) 0:36:14 UTC+9 Christian Brabandt:
> Hi Bram!
> 
> On Sa, 23 Jul 2016, Bram Moolenaar wrote:
> 
> > 
> > Christian Brabandt wrote:
> > 
> > > Bram,
> > > I am writing a test for the popupmenu and the different keys, that can 
> > > be used there (:h popupmenu-keys)
> > 
> > Thanks, that is useful.
> > 
> > > And I have some questions.
> > > 1)
> > > 
> > > ,
> > > | In the first state these keys have a special meaning:
> > > |  and CTRL-H   Delete one character, find the matches for the word 
> > > before
> > > |   the cursor.  This reduces the list of matches, often 
> > > to one
> > > |   entry, and switches to the second state.
> > > `
> > > 
> > > I fail to understand what this does, especially in difference to the 
> > > second state:
> > 
> > For example, if you type "compl" then you get a list of matches,
> > and the first one is used for the text.  That could be "completion".
> > Still the matches for "compl" are shown.
> > Then typing BS changes it to "completio" and only matches for that are
> > shown.
> 
> Hm, that works when using , but not when using, e.g.
> calling the completion menu like this:
> 
> inoremap  =ListMonths()
> 
> Then  will always end the completion menu and remove the last 
> letter.
> 
> I did not think, that there is a difference depending on how the 
> completion menu is called. This might be a bug.
> 
> > > ,
> > > | In the second and third state these keys have a special meaning:
> > > |  and CTRL-H   Delete one character, find the matches for the 
> > > shorter word
> > > |   before the cursor.  This may find more matches.
> > > `
> > > 
> > > And whatever I do, using  will always end the completion menu and 
> > > remove one character. Either from the last typed char or from the 
> > > inserted char. I can't seem to figure out, how to use  to adjust the 
> > > number of entries in the completion menu.
> > 
> > The main difference is that in the second state the highlighted item
> > differs from what the current text is.
> 
> Oh yes. Emphasis on "Cursor Key". Basically, that happens only then. Now 
> I understand.
> 
> > 
> > > 2) The behaviour of the enter key
> > > 
> > > ,
> > > | The behavior of the  key depends on the state you are in:
> > > | first state:  Use the text as it is and insert a line break.
> > > | second state: Insert the currently selected match.
> > > | third state:  Use the text as it is and insert a line break.
> > > `
> > > 
> > > For me the  Key will always insert a line break.
> > 
> > Not for me.  Probably depends on 'completeopt'.  My value is
> > menu,preview
> 
> Yeah, once i figured, that I need to use the cursor keys to select the 
> match, it works as expected.
> 
> > It's possible that the help is not correct for all possible ways
> > completion works.  The code is very complicated and there are many
> > corner cases.
> 
> Well, here is an updated patch for the popupmenu.
> 
> I think I also found a bug, and this makes the test currently fail.
> Take this example from the test:
> 
> (The popupmenu is the one from the help for all months)
> The initial state of the buffer is this:
> ,
> | D
> | December2015
> `

I have investigated this behavior.

Related vim_dev threads:
- Patch 7.4.2146
  https://groups.google.com/d/msg/vim_dev/75ZXlRlBzl4/DDnqvSn9BgAJ
- [vim/vim] VIM 7.4: Possible regression via patch 2146? (#972)
  https://groups.google.com/d/msg/vim_dev/mQ2YacpOKvo/vOsgkU-2AQAJ
- Patch 7.4.2188
  https://groups.google.com/d/msg/vim_dev/e2Rr8Px3qkQ/1XWiAQ0LAgAJ

I think the series of  behavior is correct.

> 
> (cursor at D, press )
> 
> Now if you want to complete the letter D this should only complete to 
> December, since all other values do not match it and therefore it should 
> be completed immediately to December and no menu shown. Therefore, 
> pressing  afterwards should select the letter from below the 
> cursors line, so it should complete to "December2015" if you press  
> 4 times, then there should be a new line because of the enter and then 
> the "December2015" should be shown. So in the end, the buffer should 
> look like this:
> 
> ,
> | December2015
> | 
> | December2015
> `

"the popup menu is not visible" is not equivalent to  "the completion mode is 
not active".
After the type , Vim still stay in the first state of the completion mode.
It is not related to the visible of popup menu.
Check on the gdb.

(gdb) p compl_started
$4 = 1
(gdb) p pum_visible()
$5 = 0

So that, the first  behavior `complete_CTRL-E` is correct.
Of course, the second and more  is `i_CTRL_E`.

> 
> For whatever reason, doing it interactively, this results in:
> 
> ,
> | Dece
> | 
> | December2015
> `
> (because after inserting the match  is still in popupmenu mode and
> "ends completion and goes back to what was there before selecting a 
> match")
> 
> However, a total mystery is to me, wh

Re: test popupmenu question

2016-08-02 Fir de Conversatie Bram Moolenaar

Christian Brabandt wrote:

> On Sa, 23 Jul 2016, Christian Brabandt wrote:
> 
> > Hm, that works when using , but not when using, e.g.
> > calling the completion menu like this:
> > 
> > inoremap  =ListMonths()
> > 
> > Then  will always end the completion menu and remove the last 
> > letter.
> > 
> > I did not think, that there is a difference depending on how the 
> > completion menu is called. This might be a bug.
> 
> I am still not sure how to handle this. 
> 
> > I think I also found a bug, and this makes the test currently fail.
> > Take this example from the test:
> > 
> > (The popupmenu is the one from the help for all months)
> > The initial state of the buffer is this:
> > ,
> > | D
> > | December2015
> > `
> > 
> > (cursor at D, press )
> > 
> > Now if you want to complete the letter D this should only complete to 
> > December, since all other values do not match it and therefore it should 
> > be completed immediately to December and no menu shown. Therefore, 
> > pressing  afterwards should select the letter from below the 
> > cursors line, so it should complete to "December2015" if you press  
> > 4 times, then there should be a new line because of the enter and then 
> > the "December2015" should be shown. So in the end, the buffer should 
> > look like this:
> > 
> > ,
> > | December2015
> > | 
> > | December2015
> > `
> > 
> > For whatever reason, doing it interactively, this results in:
> > 
> > ,
> > | Dece
> > | 
> > | December2015
> > `
> 
> Attached patch fixes this. Not sure, this is the best way. I basically 
> test, when the current key is  that the popupmen is still visible 
> and if not, handle it like a normal  character. This fixes at least 
> the test.

Thanks.  Not sure about the best either.  The insert mode completion is
a bit of a mess...

-- 
It might look like I'm doing nothing, but at the cellular level
I'm really quite busy.

 /// Bram Moolenaar -- b...@moolenaar.net -- http://www.Moolenaar.net   \\\
///sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org///
 \\\help me help AIDS victims -- http://ICCF-Holland.org///

-- 
-- 
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.


Re: test popupmenu question

2016-07-30 Fir de Conversatie Christian Brabandt
On Sa, 23 Jul 2016, Christian Brabandt wrote:

> Hm, that works when using , but not when using, e.g.
> calling the completion menu like this:
> 
> inoremap  =ListMonths()
> 
> Then  will always end the completion menu and remove the last 
> letter.
> 
> I did not think, that there is a difference depending on how the 
> completion menu is called. This might be a bug.

I am still not sure how to handle this. 

> I think I also found a bug, and this makes the test currently fail.
> Take this example from the test:
> 
> (The popupmenu is the one from the help for all months)
> The initial state of the buffer is this:
> ,
> | D
> | December2015
> `
> 
> (cursor at D, press )
> 
> Now if you want to complete the letter D this should only complete to 
> December, since all other values do not match it and therefore it should 
> be completed immediately to December and no menu shown. Therefore, 
> pressing  afterwards should select the letter from below the 
> cursors line, so it should complete to "December2015" if you press  
> 4 times, then there should be a new line because of the enter and then 
> the "December2015" should be shown. So in the end, the buffer should 
> look like this:
> 
> ,
> | December2015
> | 
> | December2015
> `
> 
> For whatever reason, doing it interactively, this results in:
> 
> ,
> | Dece
> | 
> | December2015
> `

Attached patch fixes this. Not sure, this is the best way. I basically 
test, when the current key is  that the popupmen is still visible 
and if not, handle it like a normal  character. This fixes at least 
the test.

Best,
Christian
-- 
Die Fähigkeit, seine Muße klug auszufüllen, ist die letzte Stufe der
persönlichen Kultur.
-- Bertrand A. W. Russell

-- 
-- 
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.
From 03545d3331a8d07e4e1846ab205284f0640d9a2a Mon Sep 17 00:00:00 2001
From: Christian Brabandt 
Date: Sat, 23 Jul 2016 17:38:41 +0200
Subject: [PATCH] better test for the popupmenu

Also fix a bug, that when using  and the popupmenu
was closed again, that  works as expected.
---
 src/edit.c |   5 +-
 src/testdir/test_popup.vim | 207 -
 2 files changed, 207 insertions(+), 5 deletions(-)

diff --git a/src/edit.c b/src/edit.c
index d24aba9..af9d4a1 100644
--- a/src/edit.c
+++ b/src/edit.c
@@ -3891,8 +3891,9 @@ ins_compl_prep(int c)
 		&& pum_visible())
 		retval = TRUE;
 
-	/* CTRL-E means completion is Ended, go back to the typed text. */
-	if (c == Ctrl_E)
+	/* CTRL-E means completion is Ended, go back to the typed text.
+	 * but only do this, if the Popup is still visible */
+	if (c == Ctrl_E && pum_visible())
 	{
 		ins_compl_delete();
 		if (compl_leader != NULL)
diff --git a/src/testdir/test_popup.vim b/src/testdir/test_popup.vim
index ea489f9..3e32454 100644
--- a/src/testdir/test_popup.vim
+++ b/src/testdir/test_popup.vim
@@ -3,14 +3,209 @@
 let g:months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
 let g:setting = ''
 
-func ListMonths()
+func! ListMonths()
 if g:setting != ''
-	exe ":set" g:setting
+  exe ":set" g:setting
 endif
-call complete(col('.'), g:months) 
+let mth=copy(g:months)
+let entered = strcharpart(getline('.'),0,col('.'))
+if !empty(entered)
+  let mth=filter(mth, 'v:val=~"^".entered')
+endif
+call complete(1, mth) 
 return ''
 endfunc
 
+func! Test_popup_complete()
+  new
+  inoremap  =ListMonths()
+
+  "  - select original typed text before the completion started
+  call feedkeys("aJu", 'tx')
+  call assert_equal(["Ju"], getline(1,2))
+  %d
+
+  "  - accept current match
+  call feedkeys("a\". repeat("\",7). "\\", 'tx')
+  call assert_equal(["August"], getline(1,2))
+  %d
+
+  "  - Delete one character from the inserted text (state: 1)
+  " TODO: This should not end the completion, but it does.
+  " This should according to the documentation:
+  " January
+  " but instead, this does
+  " Januar
+  " (idea is, C-L inserts the match from the popup menu
+  " but if the menu is closed, it will insert the character 
+  call feedkeys("aJ", 'tx')
+  call assert_equal(["Januar"], getline(1,2))
+  %d
+
+  " any-non special character: Stop completion without changing the match
+  " and insert the typed character
+  call feedkeys("a\20", 'tx')
+  call assert_equal(["January20"], getline(1,2))
+  %d
+
+  " any-non printable, non-white character: Add this character and
+  " reduce number 

Re: test popupmenu question

2016-07-23 Fir de Conversatie Christian Brabandt
Hi Bram!

On Sa, 23 Jul 2016, Bram Moolenaar wrote:

> 
> Christian Brabandt wrote:
> 
> > Bram,
> > I am writing a test for the popupmenu and the different keys, that can 
> > be used there (:h popupmenu-keys)
> 
> Thanks, that is useful.
> 
> > And I have some questions.
> > 1)
> > 
> > ,
> > | In the first state these keys have a special meaning:
> > |  and CTRL-H   Delete one character, find the matches for the word 
> > before
> > | the cursor.  This reduces the list of matches, often to one
> > | entry, and switches to the second state.
> > `
> > 
> > I fail to understand what this does, especially in difference to the 
> > second state:
> 
> For example, if you type "compl" then you get a list of matches,
> and the first one is used for the text.  That could be "completion".
> Still the matches for "compl" are shown.
> Then typing BS changes it to "completio" and only matches for that are
> shown.

Hm, that works when using , but not when using, e.g.
calling the completion menu like this:

inoremap  =ListMonths()

Then  will always end the completion menu and remove the last 
letter.

I did not think, that there is a difference depending on how the 
completion menu is called. This might be a bug.

> > ,
> > | In the second and third state these keys have a special meaning:
> > |  and CTRL-H   Delete one character, find the matches for the shorter 
> > word
> > | before the cursor.  This may find more matches.
> > `
> > 
> > And whatever I do, using  will always end the completion menu and 
> > remove one character. Either from the last typed char or from the 
> > inserted char. I can't seem to figure out, how to use  to adjust the 
> > number of entries in the completion menu.
> 
> The main difference is that in the second state the highlighted item
> differs from what the current text is.

Oh yes. Emphasis on "Cursor Key". Basically, that happens only then. Now 
I understand.

> 
> > 2) The behaviour of the enter key
> > 
> > ,
> > | The behavior of the  key depends on the state you are in:
> > | first state:Use the text as it is and insert a line break.
> > | second state:   Insert the currently selected match.
> > | third state:Use the text as it is and insert a line break.
> > `
> > 
> > For me the  Key will always insert a line break.
> 
> Not for me.  Probably depends on 'completeopt'.  My value is
>   menu,preview

Yeah, once i figured, that I need to use the cursor keys to select the 
match, it works as expected.

> It's possible that the help is not correct for all possible ways
> completion works.  The code is very complicated and there are many
> corner cases.

Well, here is an updated patch for the popupmenu.

I think I also found a bug, and this makes the test currently fail.
Take this example from the test:

(The popupmenu is the one from the help for all months)
The initial state of the buffer is this:
,
| D
| December2015
`

(cursor at D, press )

Now if you want to complete the letter D this should only complete to 
December, since all other values do not match it and therefore it should 
be completed immediately to December and no menu shown. Therefore, 
pressing  afterwards should select the letter from below the 
cursors line, so it should complete to "December2015" if you press  
4 times, then there should be a new line because of the enter and then 
the "December2015" should be shown. So in the end, the buffer should 
look like this:

,
| December2015
| 
| December2015
`

For whatever reason, doing it interactively, this results in:

,
| Dece
| 
| December2015
`
(because after inserting the match  is still in popupmenu mode and
"ends completion and goes back to what was there before selecting a 
match")

However, a total mystery is to me, when the test is run, it will 
complete to 

,
| December2015
| December2015
| December2015
`

I have left this documented in the test. I am pretty sure, this is a 
bug, and therefore, the test fails currently.

On a related note, since the "noinsert/noselect" property only seem to 
change, what is inserted when the completion menu is entered initially, 

It is hard to correctly test for that, therefore, I basically tested, 
whether enter will insert a line break or not (difference in the states 
as you explained above) and by that we know, if there was something 
selected.

Mit freundlichen Grüßen
Christian
-- 
Die ersten vierzig Jahre unseres Lebens liefern den Text, die
folgenden dreißig den Kommentar dazu.
-- Arthur Schopenhauer

-- 
-- 
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+unsub

Re: test popupmenu question

2016-07-23 Fir de Conversatie Bram Moolenaar

Christian Brabandt wrote:

> Bram,
> I am writing a test for the popupmenu and the different keys, that can 
> be used there (:h popupmenu-keys)

Thanks, that is useful.

> And I have some questions.
> 1)
> 
> ,
> | In the first state these keys have a special meaning:
> |  and CTRL-H   Delete one character, find the matches for the word before
> |   the cursor.  This reduces the list of matches, often to one
> |   entry, and switches to the second state.
> `
> 
> I fail to understand what this does, especially in difference to the 
> second state:

For example, if you type "compl" then you get a list of matches,
and the first one is used for the text.  That could be "completion".
Still the matches for "compl" are shown.
Then typing BS changes it to "completio" and only matches for that are
shown.

> ,
> | In the second and third state these keys have a special meaning:
> |  and CTRL-H   Delete one character, find the matches for the shorter 
> word
> |   before the cursor.  This may find more matches.
> `
> 
> And whatever I do, using  will always end the completion menu and 
> remove one character. Either from the last typed char or from the 
> inserted char. I can't seem to figure out, how to use  to adjust the 
> number of entries in the completion menu.

The main difference is that in the second state the highlighted item
differs from what the current text is.

> 2) The behaviour of the enter key
> 
> ,
> | The behavior of the  key depends on the state you are in:
> | first state:  Use the text as it is and insert a line break.
> | second state: Insert the currently selected match.
> | third state:  Use the text as it is and insert a line break.
> `
> 
> For me the  Key will always insert a line break.

Not for me.  Probably depends on 'completeopt'.  My value is
menu,preview

> Any clarification would be appreciated.

It's possible that the help is not correct for all possible ways
completion works.  The code is very complicated and there are many
corner cases.

-- 
ARTHUR: Listen, old crone!  Unless you tell us where we can buy a shrubbery,
my friend and I will ... we will say "Ni!"
CRONE:  Do your worst!
 "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

 /// Bram Moolenaar -- b...@moolenaar.net -- http://www.Moolenaar.net   \\\
///sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org///
 \\\help me help AIDS victims -- http://ICCF-Holland.org///

-- 
-- 
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.