Skip to content
Permalink
Browse files

patch 8.1.1880: cannot show extra info for completion in a popup window

Problem:    Cannot show extra info for completion in a popup window.
Solution:   Add the "popup" entry in 'completeopt'.
  • Loading branch information...
brammool committed Aug 18, 2019
1 parent 93cf85f commit 576a4a6ff14da876d7c4418e5f27e926fcfa8d2a
@@ -1,4 +1,4 @@
*options.txt* For Vim version 8.1. Last change: 2019 Jul 31
*options.txt* For Vim version 8.1. Last change: 2019 Aug 17


VIM REFERENCE MANUAL by Bram Moolenaar
@@ -1915,6 +1915,11 @@ A jump table for the options with a short description can be found at |Q_op|.
completion in the preview window. Only works in
combination with "menu" or "menuone".

popup Show extra information about the currently selected
completion in a popup window. Only works in combination
with "menu" or "menuone". Overrides "preview".
{only works when compiled with the +textprop feature}

noinsert Do not insert any text for a match until the user selects
a match from the menu. Only works in combination with
"menu" or "menuone". No effect if "longest" is present.
@@ -5650,6 +5655,8 @@ A jump table for the options with a short description can be found at |Q_op|.
|+textprop| or |+quickfix| feature}
When not empty a popup window is used for commands that would open a
preview window. See |preview-popup|.
Not used for the insert completion info, add "popup" to
'completeopt' for that.

*'previewwindow'* *'nopreviewwindow'*
*'pvw'* *'nopvw'* *E590*
@@ -5131,7 +5131,9 @@ free_old_sub(void)
*/
int
prepare_tagpreview(
int undo_sync) /* sync undo when leaving the window */
int undo_sync, // sync undo when leaving the window
int use_previewpopup, // use popup if 'previewpopup' set
int use_popup) // use other popup window
{
win_T *wp;

@@ -5145,11 +5147,16 @@ prepare_tagpreview(
if (!curwin->w_p_pvw)
{
# ifdef FEAT_TEXT_PROP
if (*p_pvp != NUL)
if (use_previewpopup && *p_pvp != NUL)
{
wp = popup_find_preview_window();
if (wp != NULL)
popup_set_wantpos(wp, wp->w_minwidth);
popup_set_wantpos_cursor(wp, wp->w_minwidth);
}
else if (use_popup)
{
wp = popup_find_info_window();
// TODO: set position
}
else
# endif
@@ -5166,8 +5173,8 @@ prepare_tagpreview(
* There is no preview window open yet. Create one.
*/
# ifdef FEAT_TEXT_PROP
if (*p_pvp != NUL)
return popup_create_preview_window();
if ((use_previewpopup && *p_pvp != NUL) || use_popup)
return popup_create_preview_window(use_popup);
# endif
if (win_split(g_do_tagpreview > 0 ? g_do_tagpreview : 0, 0) == FAIL)
return FALSE;
@@ -5825,7 +5825,7 @@ ex_pclose(exarg_T *eap)
}
# ifdef FEAT_TEXT_PROP
// Also when 'previewpopup' is empty, it might have been cleared.
popup_close_preview();
popup_close_preview(FALSE);
# endif
}
#endif
@@ -8614,7 +8614,7 @@ ex_pedit(exarg_T *eap)

// Open the preview window or popup and make it the current window.
g_do_tagpreview = p_pvh;
prepare_tagpreview(TRUE);
prepare_tagpreview(TRUE, TRUE, FALSE);

// Edit the file.
do_exedit(eap, NULL);
@@ -3247,7 +3247,7 @@ static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
static char *(p_fcl_values[]) = {"all", NULL};
#endif
#ifdef FEAT_INS_EXPAND
static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", "noinsert", "noselect", NULL};
static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", "popup", "noinsert", "noselect", NULL};
# ifdef BACKSLASH_IN_FILENAME
static char *(p_csl_values[]) = {"slash", "backslash", NULL};
# endif
@@ -638,6 +638,9 @@ pum_set_selected(int n, int repeat)
{
int resized = FALSE;
int context = pum_height / 2;
#ifdef FEAT_TEXT_PROP
int has_info = FALSE;
#endif

pum_selected = n;

@@ -690,11 +693,14 @@ pum_set_selected(int n, int repeat)
pum_first = pum_selected + context - pum_height + 1;
}
}
// adjust for the number of lines displayed
if (pum_first > pum_size - pum_height)
pum_first = pum_size - pum_height;

#if defined(FEAT_QUICKFIX)
/*
* Show extra info in the preview window if there is something and
* 'completeopt' contains "preview".
* 'completeopt' contains "preview" or "popup".
* Skip this when tried twice already.
* Skip this also when there is not much room.
* NOTE: Be very careful not to sync undo!
@@ -707,43 +713,71 @@ pum_set_selected(int n, int repeat)
win_T *curwin_save = curwin;
tabpage_T *curtab_save = curtab;
int res = OK;
# ifdef FEAT_TEXT_PROP
int use_popup = strstr((char *)p_cot, "popup") != NULL;
# else
# define use_popup 0
# endif
has_info = TRUE;

/* Open a preview window. 3 lines by default. Prefer
* 'previewheight' if set and smaller. */
// Open a preview window. 3 lines by default. Prefer
// 'previewheight' if set and smaller.
g_do_tagpreview = 3;
if (p_pvh > 0 && p_pvh < g_do_tagpreview)
g_do_tagpreview = p_pvh;
++RedrawingDisabled;
/* Prevent undo sync here, if an autocommand syncs undo weird
* things can happen to the undo tree. */
// Prevent undo sync here, if an autocommand syncs undo weird
// things can happen to the undo tree.
++no_u_sync;
resized = prepare_tagpreview(FALSE);
resized = prepare_tagpreview(FALSE, FALSE, use_popup);
--no_u_sync;
--RedrawingDisabled;
g_do_tagpreview = 0;

if (curwin->w_p_pvw)
if (curwin->w_p_pvw
# ifdef FEAT_TEXT_PROP
|| (curwin->w_popup_flags & POPF_INFO)
# endif
)
{
# ifdef FEAT_TEXT_PROP
if (use_popup)
{
int col = pum_col + pum_width + 1;

if (Columns - col < 20 && Columns - col < pum_col)
{
col = pum_col - 1;
curwin->w_popup_pos = POPPOS_TOPRIGHT;
curwin->w_maxwidth = pum_col - 1;
}
else
curwin->w_maxwidth = Columns - col + 1;
curwin->w_maxwidth -= popup_extra_width(curwin);
popup_set_wantpos_rowcol(curwin,
pum_row + pum_selected - pum_first, col);
}
# endif
if (!resized
&& curbuf->b_nwindows == 1
&& curbuf->b_fname == NULL
&& bt_nofile(curbuf)
&& curbuf->b_p_bh[0] == 'w')
{
/* Already a "wipeout" buffer, make it empty. */
// Already a "wipeout" buffer, make it empty.
while (!BUFEMPTY())
ml_delete((linenr_T)1, FALSE);
}
else
{
/* Don't want to sync undo in the current buffer. */
// Don't want to sync undo in the current buffer.
++no_u_sync;
res = do_ecmd(0, NULL, NULL, NULL, ECMD_ONE, 0, NULL);
--no_u_sync;
if (res == OK)
{
/* Edit a new, empty buffer. Set options for a "wipeout"
* buffer. */
// Edit a new, empty buffer. Set options for a "wipeout"
// buffer.
set_option_value((char_u *)"swf", 0L, NULL, OPT_LOCAL);
set_option_value((char_u *)"bt", 0L,
(char_u *)"nofile", OPT_LOCAL);
@@ -774,10 +808,12 @@ pum_set_selected(int n, int repeat)
p = e + 1;
}
}
// delete the empty last line
ml_delete(curbuf->b_ml.ml_line_count, FALSE);

/* Increase the height of the preview window to show the
* text, but no more than 'previewheight' lines. */
if (repeat == 0)
if (repeat == 0 && !use_popup)
{
if (lnum > p_pvh)
lnum = p_pvh;
@@ -792,6 +828,8 @@ pum_set_selected(int n, int repeat)
curbuf->b_p_ma = FALSE;
curwin->w_cursor.lnum = 1;
curwin->w_cursor.col = 0;
if (use_popup && win_valid(curwin_save))
redraw_win_later(curwin_save, SOME_VALID);

if ((curwin != curwin_save && win_valid(curwin_save))
|| (curtab != curtab_save
@@ -852,6 +890,11 @@ pum_set_selected(int n, int repeat)
}
#endif
}
# ifdef FEAT_TEXT_PROP
if (!has_info)
// close any popup info window
popup_close_preview(TRUE);
# endif

if (!resized)
pum_redraw();
@@ -869,6 +912,10 @@ pum_undisplay(void)
redraw_all_later(NOT_VALID);
redraw_tabline = TRUE;
status_redraw_all();
#ifdef FEAT_TEXT_PROP
// close any popup info window
popup_close_preview(TRUE);
#endif
}

/*

0 comments on commit 576a4a6

Please sign in to comment.
You can’t perform that action at this time.