Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure a minimum width for the completion popup menu #2314

Closed
languitar opened this issue Nov 10, 2017 · 11 comments
Closed

Ensure a minimum width for the completion popup menu #2314

languitar opened this issue Nov 10, 2017 · 11 comments
Labels

Comments

@languitar
Copy link

Following the discussions in neovim/neovim#5649, I open this issue here as the upstream project. This is my original text from the neovim issue:

In case the completion is triggered close to the right border of the terminal, it might look something like this:
2017-11-08t11 04 16 01 00
In some situations this makes the entries indistinguishable and completion pretty useless.

It would be nice if there was an option to specify a minimum width of the completion popup and in case the width cannot be held, the origin of the popup could be shifted to the left, away from the cursor position. As there is always only one of these popups, I don't see a strong reason why it always has to appear at the cursor location.

This has also been requested at the Debian bug tracker: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=450481 and @jamessan has indicated that an unfinished patch exists in the neovim issue.

@brammool
Copy link
Contributor

brammool commented Nov 11, 2017 via email

@chrisbra
Copy link
Member

chrisbra commented Nov 13, 2017

You mean like this?

From 6e624279cda8f8dcad17253a54b03f06dca19dd8 Mon Sep 17 00:00:00 2001
From: Christian Brabandt <cb@256bit.org>
Date: Mon, 13 Nov 2017 17:08:46 +0100
Subject: [PATCH] add 'pumwidth' option

fixes #2314
allows to define the max width for the popup menu.

Most of this has been done by @jamessan
---
 runtime/doc/options.txt | 10 +++++++++
 src/option.c            |  7 +++++++
 src/option.h            |  1 +
 src/popupmnu.c          | 55 ++++++++++++++++++++++++++++++++++++++++++-------
 src/proto/popupmnu.pro  |  1 +
 5 files changed, 66 insertions(+), 8 deletions(-)

diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt
index 1af19606d..61397f3ca 100644
--- a/runtime/doc/options.txt
+++ b/runtime/doc/options.txt
@@ -6010,6 +6010,16 @@ A jump table for the options with a short description can be found at |Q_op|.
 			{not in Vi}
 	Determines the maximum number of items to show in the popup menu for
 	Insert mode completion.  When zero as much space as available is used.
+	|ins-completion-menu|.
+
+						*'pumwidth'* *'pw'*
+'pumwidth' 'pw'	        number	(default 0)
+			global
+			{not available when compiled without the
+			|+insert_expand| feature}
+			{not in Vi}
+	Determines the maximum width to show in the popup menu for
+	Insert mode completion.  When zero as much space as available is used.
 	|ins-completion-menu|.
 
 						*'pythondll'*
diff --git a/src/option.c b/src/option.c
index 4f25c1ff4..b84036fba 100644
--- a/src/option.c
+++ b/src/option.c
@@ -2228,6 +2228,13 @@ static struct vimoption options[] =
 			    (char_u *)&p_ph, PV_NONE,
 #else
 			    (char_u *)NULL, PV_NONE,
+#endif
+			    {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
+    {"pumwidth",    "pw",   P_NUM|P_VI_DEF,
+#ifdef FEAT_INS_EXPAND
+			    (char_u *)&p_pw, PV_NONE,
+#else
+			    (char_u *)NULL, PV_NONE,
 #endif
 			    {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
     {"pythonthreedll",  NULL,   P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
diff --git a/src/option.h b/src/option.h
index f9972f21a..30712b494 100644
--- a/src/option.h
+++ b/src/option.h
@@ -419,6 +419,7 @@ EXTERN int	p_cp;		/* 'compatible' */
 #ifdef FEAT_INS_EXPAND
 EXTERN char_u	*p_cot;		/* 'completeopt' */
 EXTERN long	p_ph;		/* 'pumheight' */
+EXTERN long	p_pw;		/* 'pumwidth' */
 #endif
 EXTERN char_u	*p_cpo;		/* 'cpoptions' */
 #ifdef FEAT_CSCOPE
diff --git a/src/popupmnu.c b/src/popupmnu.c
index ec75281e7..f74a51b7d 100644
--- a/src/popupmnu.c
+++ b/src/popupmnu.c
@@ -66,7 +66,7 @@ pum_display(
 
     do
     {
-	def_width = PUM_DEF_WIDTH;
+	def_width = pum_get_height();
 	max_width = 0;
 	kind_width = 0;
 	extra_width = 0;
@@ -209,10 +209,10 @@ pum_display(
 	if (def_width < max_width)
 	    def_width = max_width;
 
-	if (((col < Columns - PUM_DEF_WIDTH || col < Columns - max_width)
+	if (((col < Columns - pum_get_width() || col < Columns - max_width)
 #ifdef FEAT_RIGHTLEFT
 		    && !curwin->w_p_rl)
-		|| (curwin->w_p_rl && (col > PUM_DEF_WIDTH || col > max_width)
+		|| (curwin->w_p_rl && (col > pum_get_width() || col > max_width)
 #endif
 	   ))
 	{
@@ -227,12 +227,44 @@ pum_display(
 		pum_width = Columns - pum_col - pum_scrollbar;
 
 	    if (pum_width > max_width + kind_width + extra_width + 1
-						     && pum_width > PUM_DEF_WIDTH)
+						     && pum_width > pum_get_width())
 	    {
 		pum_width = max_width + kind_width + extra_width + 1;
-		if (pum_width < PUM_DEF_WIDTH)
-		    pum_width = PUM_DEF_WIDTH;
+		if (pum_width < pum_get_width())
+		    pum_width = pum_get_width();
 	    }
+	    else if (((col > pum_get_width() || col > max_width)
+#ifdef FEAT_RIGHTLEFT
+		&& !curwin->w_p_rl)
+		|| (curwin->w_p_rl && (col < Columns - pum_get_width()
+			|| col < Columns - max_width)
+#endif
+	    ))
+	    {
+	    /* align right pum edge with "col" */
+#ifdef FEAT_RIGHTLEFT
+		if (curwin->w_p_rl)
+		    pum_col = col + max_width + pum_scrollbar + 1;
+		else
+#endif
+		    pum_col = col - max_width - pum_scrollbar;
+
+#ifdef FEAT_RIGHTLEFT
+		if (curwin->w_p_rl)
+		    pum_width = W_ENDCOL(curwin) - pum_col - pum_scrollbar + 1;
+		else
+#endif
+		    pum_width = pum_col - pum_scrollbar;
+
+		if (pum_width > max_width + kind_width + extra_width + 1
+			    && pum_width > pum_get_width())
+		{
+		    pum_width = max_width + kind_width + extra_width + 1;
+		    if (pum_width < pum_get_width())
+			pum_width = pum_get_width();
+		}
+	    }
+
 	}
 	else if (Columns < def_width)
 	{
@@ -247,8 +279,8 @@ pum_display(
 	}
 	else
 	{
-	    if (max_width > PUM_DEF_WIDTH)
-		max_width = PUM_DEF_WIDTH;	/* truncate */
+	    if (max_width > pum_get_width())
+		max_width = pum_get_width();	/* truncate */
 #ifdef FEAT_RIGHTLEFT
 	    if (curwin->w_p_rl)
 		pum_col = max_width - 1;
@@ -756,4 +788,11 @@ pum_get_height(void)
     return pum_height;
 }
 
+/* Return the minimum width of the popup menu */
+    int
+pum_get_width(void)
+{
+    return p_pw ? p_pw : PUM_DEF_WIDTH;
+}
+
 #endif
diff --git a/src/proto/popupmnu.pro b/src/proto/popupmnu.pro
index 423076c3e..c0531f48d 100644
--- a/src/proto/popupmnu.pro
+++ b/src/proto/popupmnu.pro
@@ -5,4 +5,5 @@ void pum_undisplay(void);
 void pum_clear(void);
 int pum_visible(void);
 int pum_get_height(void);
+int pum_get_width(void);
 /* vim: set ft=c : */
-- 
2.14.1

@vim-ml
Copy link

vim-ml commented Nov 13, 2017 via email

@k-takata k-takata added the patch label Nov 13, 2017
chrisbra added a commit to chrisbra/vim that referenced this issue Nov 14, 2017
fixes vim#2314
allows to define the max width for the popup menu.

Most of this has been done by @jamessan
@brammool
Copy link
Contributor

brammool commented Nov 14, 2017 via email

@chrisbra
Copy link
Member

ah yeah, I messed that up. I'll post a proper patch later

chrisbra added a commit to chrisbra/vim that referenced this issue Nov 15, 2017
fixes vim#2314
allows to define the max width for the popup menu.

Most of this has been done by @jamessan
@languitar
Copy link
Author

What's the state here? Any chance to get this going again?

@chrisbra
Copy link
Member

It is still on my list to do. Unfortunately my fucked up private life come into play so had no chance to fix it. I don't expect this to be any better in the foreseeable future. And then I also have to take care of my profession, which also needs much more time then expected. So sorry, no progress here.

chrisbra added a commit to chrisbra/vim that referenced this issue Jan 3, 2018
fixes vim#2314
allows to define the max width for the popup menu.

Most of this has been done by @jamessan
@chrisbra
Copy link
Member

chrisbra commented Jan 3, 2018

updated patch

chrisbra added a commit to chrisbra/vim that referenced this issue Jan 6, 2018
fixes vim#2314
allows to define the max width for the popup menu.

Most of this has been done by @jamessan
chrisbra added a commit to chrisbra/vim that referenced this issue Jan 27, 2018
fixes vim#2314
allows to define the max width for the popup menu.

Most of this has been done by @jamessan
chrisbra added a commit to chrisbra/vim that referenced this issue Jan 28, 2018
fixes vim#2314
allows to define the max width for the popup menu.

Most of this has been done by @jamessan
chrisbra added a commit to chrisbra/vim that referenced this issue Jan 29, 2018
fixes vim#2314
allows to define the max width for the popup menu.

Most of this has been done by @jamessan
@brammool
Copy link
Contributor

I am including the patch, but had to fix several problems. The popup test crashed.
Looks like a few more improvements are needed, the code is a bit messy and lacks comments about what the intention of the various if-else blocks are. It should be possible to improve and simplify the logic.

@chrisbra
Copy link
Member

chrisbra commented Feb 10, 2018 via email

@micbou
Copy link

micbou commented Feb 15, 2018

I think this patch should be reverted. See issue #2640.

I don't see a strong reason why it always has to appear at the cursor location.

There is a good reason why users expect the completion menu to be at the cursor position: it's where they are looking at.

adizero pushed a commit to adizero/vim that referenced this issue May 19, 2018
Problem:    The minimum width of the popup menu is hard coded.
Solution:   Add the 'pumwidth' option. (Christian Brabandt, James McCoy,
            closes vim#2314)
janlazo added a commit to janlazo/neovim that referenced this issue Sep 10, 2019
Problem:    The minimum width of the popup menu is hard coded.
Solution:   Add the 'pumwidth' option. (Christian Brabandt, James McCoy,
            closes vim/vim#2314)
vim/vim@a8f04aa
janlazo added a commit to janlazo/neovim that referenced this issue Sep 10, 2019
Problem:    The minimum width of the popup menu is hard coded.
Solution:   Add the 'pumwidth' option. (Christian Brabandt, James McCoy,
            closes vim/vim#2314)
vim/vim@a8f04aa
janlazo added a commit to janlazo/neovim that referenced this issue Dec 26, 2019
Problem:    The minimum width of the popup menu is hard coded.
Solution:   Add the 'pumwidth' option. (Christian Brabandt, James McCoy,
            closes vim/vim#2314)
vim/vim@a8f04aa
janlazo added a commit to janlazo/neovim that referenced this issue Dec 26, 2019
Problem:    The minimum width of the popup menu is hard coded.
Solution:   Add the 'pumwidth' option. (Christian Brabandt, James McCoy,
            closes vim/vim#2314)
vim/vim@a8f04aa
janlazo added a commit to janlazo/neovim that referenced this issue Dec 28, 2019
Problem:    The minimum width of the popup menu is hard coded.
Solution:   Add the 'pumwidth' option. (Christian Brabandt, James McCoy,
            closes vim/vim#2314)
vim/vim@a8f04aa
janlazo added a commit to janlazo/neovim that referenced this issue Dec 29, 2019
Problem:    The minimum width of the popup menu is hard coded.
Solution:   Add the 'pumwidth' option. (Christian Brabandt, James McCoy,
            closes vim/vim#2314)
vim/vim@a8f04aa
janlazo added a commit to janlazo/neovim that referenced this issue Dec 29, 2019
Problem:    The minimum width of the popup menu is hard coded.
Solution:   Add the 'pumwidth' option. (Christian Brabandt, James McCoy,
            closes vim/vim#2314)
vim/vim@a8f04aa
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants