blob: 9f1fae4fb02f8292b55e42c5b3ce3548ced9a10b [file] [log] [blame]
Bram Moolenaar4b779472005-10-04 09:12:31 +00001/* vi:set ts=8 sts=4 sw=4:
2 *
3 * VIM - Vi IMproved by Bram Moolenaar
4 *
5 * Do ":help uganda" in Vim to read copying and usage conditions.
6 * Do ":help credits" in Vim to see a list of people who contributed.
7 * See README.txt for an overview of the Vim source code.
8 */
9
10/*
Bram Moolenaar76b92b22006-03-24 22:46:53 +000011 * popupmnu.c: Popup menu (PUM)
Bram Moolenaar4b779472005-10-04 09:12:31 +000012 */
13#include "vim.h"
14
15#if defined(FEAT_INS_EXPAND) || defined(PROTO)
16
Bram Moolenaar8b6144b2006-02-08 09:20:24 +000017static pumitem_T *pum_array = NULL; /* items of displayed pum */
Bram Moolenaar4b779472005-10-04 09:12:31 +000018static int pum_size; /* nr of items in "pum_array" */
19static int pum_selected; /* index of selected item or -1 */
20static int pum_first = 0; /* index of top item */
21
22static int pum_height; /* nr of displayed pum items */
23static int pum_width; /* width of displayed pum items */
Bram Moolenaar8b6144b2006-02-08 09:20:24 +000024static int pum_base_width; /* width of pum items base */
Bram Moolenaar96d2c5b2006-03-11 21:27:59 +000025static int pum_kind_width; /* width of pum items kind column */
Bram Moolenaar4b779472005-10-04 09:12:31 +000026static int pum_scrollbar; /* TRUE when scrollbar present */
27
28static int pum_row; /* top row of pum */
29static int pum_col; /* left column of pum */
30
Bram Moolenaar96d2c5b2006-03-11 21:27:59 +000031static int pum_do_redraw = FALSE; /* do redraw anyway */
32
33static int pum_set_selected __ARGS((int n));
34
Bram Moolenaar4b779472005-10-04 09:12:31 +000035#define PUM_DEF_HEIGHT 10
36#define PUM_DEF_WIDTH 15
37
38/*
39 * Show the popup menu with items "array[size]".
40 * "array" must remain valid until pum_undisplay() is called!
41 * When possible the leftmost character is aligned with screen column "col".
42 * The menu appears above the screen line "row" or at "row" + "height" - 1.
43 */
44 void
Bram Moolenaar96d2c5b2006-03-11 21:27:59 +000045pum_display(array, size, selected)
Bram Moolenaar8b6144b2006-02-08 09:20:24 +000046 pumitem_T *array;
Bram Moolenaar4b779472005-10-04 09:12:31 +000047 int size;
Bram Moolenaar1f35bf92006-03-07 22:38:47 +000048 int selected; /* index of initially selected item, none if
49 out of range */
Bram Moolenaar96d2c5b2006-03-11 21:27:59 +000050{
51 int w;
52 int def_width;
53 int max_width;
54 int kind_width;
55 int extra_width;
56 int i;
57 int top_clear;
Bram Moolenaar4b779472005-10-04 09:12:31 +000058 int row;
59 int height;
60 int col;
Bram Moolenaarefd2bf12006-03-16 21:41:35 +000061 int above_row = cmdline_row;
Bram Moolenaar96d2c5b2006-03-11 21:27:59 +000062
63redo:
64 def_width = PUM_DEF_WIDTH;
65 max_width = 0;
66 kind_width = 0;
67 extra_width = 0;
68
Bram Moolenaar1e607892006-03-13 22:15:53 +000069 /* Pretend the pum is already there to avoid that must_redraw is set when
70 * 'cuc' is on. */
71 pum_array = (pumitem_T *)1;
Bram Moolenaar96d2c5b2006-03-11 21:27:59 +000072 validate_cursor_col();
Bram Moolenaar1e607892006-03-13 22:15:53 +000073 pum_array = NULL;
74
Bram Moolenaar96d2c5b2006-03-11 21:27:59 +000075 row = curwin->w_cline_row + W_WINROW(curwin);
76 height = curwin->w_cline_height;
77 col = curwin->w_wcol + W_WINCOL(curwin) - curwin->w_leftcol;
78
79 if (firstwin->w_p_pvw)
80 top_clear = firstwin->w_height;
81 else
82 top_clear = 0;
Bram Moolenaar4b779472005-10-04 09:12:31 +000083
Bram Moolenaarefd2bf12006-03-16 21:41:35 +000084 /* When the preview window is at the bottom stop just above it. Also
85 * avoid drawing over the status line so that it's clear there is a window
86 * boundary. */
87 if (lastwin->w_p_pvw)
88 above_row -= lastwin->w_height + lastwin->w_status_height + 1;
89
Bram Moolenaar4b779472005-10-04 09:12:31 +000090 /*
91 * Figure out the size and position of the pum.
92 */
93 if (size < PUM_DEF_HEIGHT)
94 pum_height = size;
95 else
96 pum_height = PUM_DEF_HEIGHT;
Bram Moolenaar7d47b6e2006-03-15 22:59:18 +000097 if (p_ph > 0 && pum_height > p_ph)
98 pum_height = p_ph;
Bram Moolenaar4b779472005-10-04 09:12:31 +000099
100 /* Put the pum below "row" if possible. If there are few lines decide on
101 * where there is more room. */
Bram Moolenaarefd2bf12006-03-16 21:41:35 +0000102 if (row >= above_row - pum_height
103 && row > (above_row - top_clear - height) / 2)
Bram Moolenaar4b779472005-10-04 09:12:31 +0000104 {
105 /* pum above "row" */
106 if (row >= size)
107 {
108 pum_row = row - size;
109 pum_height = size;
110 }
111 else
112 {
113 pum_row = 0;
114 pum_height = row;
115 }
Bram Moolenaar7d47b6e2006-03-15 22:59:18 +0000116 if (p_ph > 0 && pum_height > p_ph)
117 {
118 pum_row += pum_height - p_ph;
119 pum_height = p_ph;
120 }
Bram Moolenaar4b779472005-10-04 09:12:31 +0000121 }
122 else
123 {
124 /* pum below "row" */
125 pum_row = row + height;
Bram Moolenaarefd2bf12006-03-16 21:41:35 +0000126 if (size > above_row - pum_row)
127 pum_height = above_row - pum_row;
Bram Moolenaar4b779472005-10-04 09:12:31 +0000128 else
129 pum_height = size;
Bram Moolenaar7d47b6e2006-03-15 22:59:18 +0000130 if (p_ph > 0 && pum_height > p_ph)
131 pum_height = p_ph;
Bram Moolenaar4b779472005-10-04 09:12:31 +0000132 }
133
134 /* don't display when we only have room for one line */
Bram Moolenaara6557602006-02-04 22:43:20 +0000135 if (pum_height < 1 || (pum_height == 1 && size > 1))
Bram Moolenaar4b779472005-10-04 09:12:31 +0000136 return;
137
Bram Moolenaar96d2c5b2006-03-11 21:27:59 +0000138 /* If there is a preview window at the top avoid drawing over it. */
139 if (firstwin->w_p_pvw
140 && pum_row < firstwin->w_height
141 && pum_height > firstwin->w_height + 4)
142 {
143 pum_row += firstwin->w_height;
144 pum_height -= firstwin->w_height;
145 }
146
Bram Moolenaar8b6144b2006-02-08 09:20:24 +0000147 /* Compute the width of the widest match and the widest extra. */
Bram Moolenaar4b779472005-10-04 09:12:31 +0000148 for (i = 0; i < size; ++i)
149 {
Bram Moolenaar8b6144b2006-02-08 09:20:24 +0000150 w = vim_strsize(array[i].pum_text);
Bram Moolenaar4b779472005-10-04 09:12:31 +0000151 if (max_width < w)
152 max_width = w;
Bram Moolenaar96d2c5b2006-03-11 21:27:59 +0000153 if (array[i].pum_kind != NULL)
154 {
155 w = vim_strsize(array[i].pum_kind) + 1;
156 if (kind_width < w)
157 kind_width = w;
158 }
Bram Moolenaar8b6144b2006-02-08 09:20:24 +0000159 if (array[i].pum_extra != NULL)
160 {
Bram Moolenaar1e607892006-03-13 22:15:53 +0000161 w = vim_strsize(array[i].pum_extra) + 1;
Bram Moolenaar8b6144b2006-02-08 09:20:24 +0000162 if (extra_width < w)
163 extra_width = w;
164 }
Bram Moolenaar4b779472005-10-04 09:12:31 +0000165 }
Bram Moolenaar8b6144b2006-02-08 09:20:24 +0000166 pum_base_width = max_width;
Bram Moolenaar96d2c5b2006-03-11 21:27:59 +0000167 pum_kind_width = kind_width;
Bram Moolenaar4b779472005-10-04 09:12:31 +0000168
169 /* if there are more items than room we need a scrollbar */
170 if (pum_height < size)
171 {
172 pum_scrollbar = 1;
173 ++max_width;
174 }
175 else
176 pum_scrollbar = 0;
177
178 if (def_width < max_width)
179 def_width = max_width;
180
181 if (col < Columns - PUM_DEF_WIDTH || col < Columns - max_width)
182 {
183 /* align pum column with "col" */
184 pum_col = col;
185 pum_width = Columns - pum_col - pum_scrollbar;
Bram Moolenaar96d2c5b2006-03-11 21:27:59 +0000186 if (pum_width > max_width + kind_width + extra_width + 1
Bram Moolenaar8b6144b2006-02-08 09:20:24 +0000187 && pum_width > PUM_DEF_WIDTH)
188 {
Bram Moolenaar96d2c5b2006-03-11 21:27:59 +0000189 pum_width = max_width + kind_width + extra_width + 1;
Bram Moolenaar8b6144b2006-02-08 09:20:24 +0000190 if (pum_width < PUM_DEF_WIDTH)
191 pum_width = PUM_DEF_WIDTH;
192 }
Bram Moolenaar4b779472005-10-04 09:12:31 +0000193 }
194 else if (Columns < def_width)
195 {
196 /* not enough room, will use what we have */
197 pum_col = 0;
198 pum_width = Columns - 1;
199 }
200 else
201 {
202 if (max_width > PUM_DEF_WIDTH)
203 max_width = PUM_DEF_WIDTH; /* truncate */
204 pum_col = Columns - max_width;
205 pum_width = max_width - pum_scrollbar;
206 }
207
208 pum_array = array;
209 pum_size = size;
210
Bram Moolenaar96d2c5b2006-03-11 21:27:59 +0000211 /* Set selected item and redraw. If the window size changed need to redo
212 * the positioning. */
213 if (pum_set_selected(selected))
214 goto redo;
Bram Moolenaar4b779472005-10-04 09:12:31 +0000215}
216
217/*
218 * Redraw the popup menu, using "pum_first" and "pum_selected".
219 */
220 void
221pum_redraw()
222{
223 int row = pum_row;
224 int col;
225 int attr_norm = highlight_attr[HLF_PNI];
226 int attr_select = highlight_attr[HLF_PSI];
227 int attr_scroll = highlight_attr[HLF_PSB];
228 int attr_thumb = highlight_attr[HLF_PST];
229 int attr;
230 int i;
231 int idx;
232 char_u *s;
Bram Moolenaar7d47b6e2006-03-15 22:59:18 +0000233 char_u *p = NULL;
Bram Moolenaar8b6144b2006-02-08 09:20:24 +0000234 int totwidth, width, w;
Bram Moolenaar4b779472005-10-04 09:12:31 +0000235 int thumb_pos = 0;
236 int thumb_heigth = 1;
Bram Moolenaar8b6144b2006-02-08 09:20:24 +0000237 int round;
Bram Moolenaar96d2c5b2006-03-11 21:27:59 +0000238 int n;
Bram Moolenaar4b779472005-10-04 09:12:31 +0000239
240 if (pum_scrollbar)
241 {
242 thumb_heigth = pum_height * pum_height / pum_size;
243 if (thumb_heigth == 0)
244 thumb_heigth = 1;
245 thumb_pos = (pum_first * (pum_height - thumb_heigth)
246 + (pum_size - pum_height) / 2)
247 / (pum_size - pum_height);
248 }
249
250 for (i = 0; i < pum_height; ++i)
251 {
252 idx = i + pum_first;
253 attr = (idx == pum_selected) ? attr_select : attr_norm;
254
255 /* prepend a space if there is room */
256 if (pum_col > 0)
257 screen_putchar(' ', row, pum_col - 1, attr);
258
Bram Moolenaar8b6144b2006-02-08 09:20:24 +0000259 /* Display each entry, use two spaces for a Tab.
Bram Moolenaar96d2c5b2006-03-11 21:27:59 +0000260 * Do this 3 times: For the main text, kind and extra info */
Bram Moolenaar4b779472005-10-04 09:12:31 +0000261 col = pum_col;
Bram Moolenaar8b6144b2006-02-08 09:20:24 +0000262 totwidth = 0;
Bram Moolenaar96d2c5b2006-03-11 21:27:59 +0000263 for (round = 1; round <= 3; ++round)
Bram Moolenaar4b779472005-10-04 09:12:31 +0000264 {
Bram Moolenaar8b6144b2006-02-08 09:20:24 +0000265 width = 0;
266 s = NULL;
Bram Moolenaar96d2c5b2006-03-11 21:27:59 +0000267 switch (round)
Bram Moolenaar4b779472005-10-04 09:12:31 +0000268 {
Bram Moolenaar96d2c5b2006-03-11 21:27:59 +0000269 case 1: p = pum_array[idx].pum_text; break;
270 case 2: p = pum_array[idx].pum_kind; break;
271 case 3: p = pum_array[idx].pum_extra; break;
Bram Moolenaar4b779472005-10-04 09:12:31 +0000272 }
Bram Moolenaar96d2c5b2006-03-11 21:27:59 +0000273 if (p != NULL)
274 for ( ; ; mb_ptr_adv(p))
275 {
276 if (s == NULL)
277 s = p;
278 w = ptr2cells(p);
279 if (*p == NUL || *p == TAB || totwidth + w > pum_width)
280 {
281 /* Display the text that fits or comes before a Tab. */
282 screen_puts_len(s, p - s, row, col, attr);
283 col += width;
284
285 if (*p != TAB)
286 break;
287
288 /* Display two spaces for a Tab. */
289 screen_puts_len((char_u *)" ", 2, row, col, attr);
290 col += 2;
291 totwidth += 2;
292 s = NULL; /* start text at next char */
293 width = 0;
294 }
295 else
296 width += w;
297 }
298
299 if (round > 1)
300 n = pum_kind_width + 1;
301 else
302 n = 1;
303
304 /* Stop when there is nothing more to display. */
305 if (round == 3
306 || (round == 2 && pum_array[idx].pum_extra == NULL)
307 || (round == 1 && pum_array[idx].pum_kind == NULL
308 && pum_array[idx].pum_extra == NULL)
309 || pum_base_width + n >= pum_width)
Bram Moolenaar8b6144b2006-02-08 09:20:24 +0000310 break;
Bram Moolenaar96d2c5b2006-03-11 21:27:59 +0000311 screen_fill(row, row + 1, col, pum_col + pum_base_width + n,
Bram Moolenaar8b6144b2006-02-08 09:20:24 +0000312 ' ', ' ', attr);
Bram Moolenaar96d2c5b2006-03-11 21:27:59 +0000313 col = pum_col + pum_base_width + n;
314 totwidth = pum_base_width + n;
Bram Moolenaar4b779472005-10-04 09:12:31 +0000315 }
316
317 screen_fill(row, row + 1, col, pum_col + pum_width, ' ', ' ', attr);
318 if (pum_scrollbar > 0)
319 screen_putchar(' ', row, pum_col + pum_width,
320 i >= thumb_pos && i < thumb_pos + thumb_heigth
321 ? attr_thumb : attr_scroll);
322
323 ++row;
324 }
325}
326
327#if 0 /* not used yet */
328/*
329 * Return the index of the currently selected item.
330 */
331 int
332pum_get_selected()
333{
334 return pum_selected;
335}
336#endif
337
338/*
339 * Set the index of the currently selected item. The menu will scroll when
Bram Moolenaar1f35bf92006-03-07 22:38:47 +0000340 * necessary. When "n" is out of range don't scroll.
Bram Moolenaar96d2c5b2006-03-11 21:27:59 +0000341 * Returns TRUE when the window was resized and the location of the popup menu
342 * must be recomputed.
Bram Moolenaar4b779472005-10-04 09:12:31 +0000343 */
Bram Moolenaar96d2c5b2006-03-11 21:27:59 +0000344 static int
Bram Moolenaar4b779472005-10-04 09:12:31 +0000345pum_set_selected(n)
346 int n;
347{
Bram Moolenaar96d2c5b2006-03-11 21:27:59 +0000348 int resized = FALSE;
Bram Moolenaar7d47b6e2006-03-15 22:59:18 +0000349 int context = pum_height / 2;
Bram Moolenaar96d2c5b2006-03-11 21:27:59 +0000350
Bram Moolenaar4b779472005-10-04 09:12:31 +0000351 pum_selected = n;
352
Bram Moolenaar1f35bf92006-03-07 22:38:47 +0000353 if (pum_selected >= 0 && pum_selected < pum_size)
Bram Moolenaar4b779472005-10-04 09:12:31 +0000354 {
Bram Moolenaare3226be2005-12-18 22:10:00 +0000355 if (pum_first > pum_selected - 4)
356 {
357 /* scroll down; when we did a jump it's probably a PageUp then
Bram Moolenaar7df351e2006-01-23 22:30:28 +0000358 * scroll a whole page */
Bram Moolenaare3226be2005-12-18 22:10:00 +0000359 if (pum_first > pum_selected - 2)
360 {
Bram Moolenaar7df351e2006-01-23 22:30:28 +0000361 pum_first -= pum_height - 2;
Bram Moolenaare3226be2005-12-18 22:10:00 +0000362 if (pum_first < 0)
363 pum_first = 0;
Bram Moolenaar7df351e2006-01-23 22:30:28 +0000364 else if (pum_first > pum_selected)
365 pum_first = pum_selected;
Bram Moolenaare3226be2005-12-18 22:10:00 +0000366 }
367 else
368 pum_first = pum_selected;
369 }
370 else if (pum_first < pum_selected - pum_height + 5)
371 {
372 /* scroll up; when we did a jump it's probably a PageDown then
Bram Moolenaar7df351e2006-01-23 22:30:28 +0000373 * scroll a whole page */
Bram Moolenaare3226be2005-12-18 22:10:00 +0000374 if (pum_first < pum_selected - pum_height + 1 + 2)
Bram Moolenaar7df351e2006-01-23 22:30:28 +0000375 {
376 pum_first += pum_height - 2;
377 if (pum_first < pum_selected - pum_height + 1)
378 pum_first = pum_selected - pum_height + 1;
379 }
Bram Moolenaare3226be2005-12-18 22:10:00 +0000380 else
381 pum_first = pum_selected - pum_height + 1;
382 }
Bram Moolenaar4b779472005-10-04 09:12:31 +0000383
Bram Moolenaar7d47b6e2006-03-15 22:59:18 +0000384 /* Give a few lines of context when possible. */
385 if (context > 3)
386 context = 3;
387 if (pum_height > 2)
Bram Moolenaar4b779472005-10-04 09:12:31 +0000388 {
Bram Moolenaar7d47b6e2006-03-15 22:59:18 +0000389 if (pum_first > pum_selected - context)
Bram Moolenaar4b779472005-10-04 09:12:31 +0000390 {
391 /* scroll down */
Bram Moolenaar7d47b6e2006-03-15 22:59:18 +0000392 pum_first = pum_selected - context;
Bram Moolenaar4b779472005-10-04 09:12:31 +0000393 if (pum_first < 0)
394 pum_first = 0;
395 }
Bram Moolenaar7d47b6e2006-03-15 22:59:18 +0000396 else if (pum_first < pum_selected + context - pum_height + 1)
Bram Moolenaar4b779472005-10-04 09:12:31 +0000397 {
398 /* scroll up */
Bram Moolenaar7d47b6e2006-03-15 22:59:18 +0000399 pum_first = pum_selected + context - pum_height + 1;
Bram Moolenaar4b779472005-10-04 09:12:31 +0000400 }
401 }
Bram Moolenaar96d2c5b2006-03-11 21:27:59 +0000402
403#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
Bram Moolenaard2cec5b2006-03-28 21:08:56 +0000404 /*
405 * Show extra info in the preview window if there is something and
406 * 'completeopt' contains "preview".
407 * NOTE: Be very careful not to sync undo!
408 */
Bram Moolenaar96d2c5b2006-03-11 21:27:59 +0000409 if (pum_array[pum_selected].pum_info != NULL
410 && vim_strchr(p_cot, 'p') != NULL)
411 {
412 win_T *curwin_save = curwin;
413 int res = OK;
414
415 /* Open a preview window. 3 lines by default. */
416 g_do_tagpreview = 3;
Bram Moolenaard2cec5b2006-03-28 21:08:56 +0000417 resized = prepare_tagpreview(FALSE);
Bram Moolenaar96d2c5b2006-03-11 21:27:59 +0000418 g_do_tagpreview = 0;
419
420 if (curwin->w_p_pvw)
421 {
422 if (curbuf->b_fname == NULL
423 && curbuf->b_p_bt[0] == 'n' && curbuf->b_p_bt[2] == 'f'
424 && curbuf->b_p_bh[0] == 'w')
425 {
426 /* Already a "wipeout" buffer, make it empty. */
427 while (!bufempty())
428 ml_delete((linenr_T)1, FALSE);
429 }
430 else if ((res = do_ecmd(0, NULL, NULL, NULL, ECMD_ONE, 0))
431 == OK)
432 {
433 /* Edit a new, empty buffer. Set options for a "wipeout"
434 * buffer. */
435 set_option_value((char_u *)"swf", 0L, NULL, OPT_LOCAL);
436 set_option_value((char_u *)"bt", 0L, (char_u *)"nofile",
437 OPT_LOCAL);
438 set_option_value((char_u *)"bh", 0L, (char_u *)"wipe",
439 OPT_LOCAL);
440 set_option_value((char_u *)"diff", 0L, (char_u *)"",
441 OPT_LOCAL);
442 }
443 if (res == OK)
444 {
445 char_u *p, *e;
446 linenr_T lnum = 0;
447
448 for (p = pum_array[pum_selected].pum_info; *p != NUL; )
449 {
450 e = vim_strchr(p, '\n');
451 if (e == NULL)
452 {
453 ml_append(lnum++, p, 0, FALSE);
454 break;
455 }
456 else
457 {
458 *e = NUL;
459 ml_append(lnum++, p, e - p + 1, FALSE);
460 *e = '\n';
461 p = e + 1;
462 }
463 }
464
465 /* Increase the height of the preview window to show the
466 * text, but no more than 'previewheight' lines. */
467 if (lnum > p_pvh)
468 lnum = p_pvh;
469 if (curwin->w_height < lnum)
470 {
471 win_setheight((int)lnum);
472 resized = TRUE;
473 }
474
475 curbuf->b_changed = 0;
476 curbuf->b_p_ma = FALSE;
477 curwin->w_cursor.lnum = 0;
478 curwin->w_cursor.col = 0;
479
480 if (curwin != curwin_save && win_valid(curwin_save))
481 {
482 /* Return cursor to where we were */
483 validate_cursor();
Bram Moolenaar600dddc2006-03-12 22:05:10 +0000484 redraw_later(SOME_VALID);
Bram Moolenaar96d2c5b2006-03-11 21:27:59 +0000485
486 /* When the preview window was resized we need to
487 * update the view on the buffer. Only go back to
488 * the window when needed, otherwise it will always be
489 * redraw. */
490 if (resized)
491 {
492 win_enter(curwin_save, TRUE);
493 update_topline();
494 }
495
496 /* Update the screen before drawing the popup menu.
497 * Enable updating the status lines. */
498 pum_do_redraw = TRUE;
499 update_screen(0);
500 pum_do_redraw = FALSE;
501
Bram Moolenaard2cec5b2006-03-28 21:08:56 +0000502 if (!resized && win_valid(curwin_save))
Bram Moolenaar96d2c5b2006-03-11 21:27:59 +0000503 win_enter(curwin_save, TRUE);
Bram Moolenaar7d47b6e2006-03-15 22:59:18 +0000504
505 /* May need to update the screen again when there are
506 * autocommands involved. */
507 pum_do_redraw = TRUE;
508 update_screen(0);
509 pum_do_redraw = FALSE;
Bram Moolenaar96d2c5b2006-03-11 21:27:59 +0000510 }
511 }
512 }
513 }
514#endif
Bram Moolenaar4b779472005-10-04 09:12:31 +0000515 }
516
517 /* Never display more than we have */
518 if (pum_first > pum_size - pum_height)
519 pum_first = pum_size - pum_height;
520
Bram Moolenaar96d2c5b2006-03-11 21:27:59 +0000521 if (!resized)
522 pum_redraw();
523
524 return resized;
Bram Moolenaar4b779472005-10-04 09:12:31 +0000525}
526
527/*
528 * Undisplay the popup menu (later).
529 */
530 void
531pum_undisplay()
532{
533 pum_array = NULL;
Bram Moolenaar600dddc2006-03-12 22:05:10 +0000534 redraw_all_later(SOME_VALID);
Bram Moolenaar1f4d4de2006-03-14 23:00:46 +0000535 status_redraw_all();
Bram Moolenaar4b779472005-10-04 09:12:31 +0000536}
537
538/*
539 * Clear the popup menu. Currently only resets the offset to the first
540 * displayed item.
541 */
542 void
543pum_clear()
544{
545 pum_first = 0;
546}
547
548/*
549 * Return TRUE if the popup menu is displayed.
Bram Moolenaar96d2c5b2006-03-11 21:27:59 +0000550 * Overruled when "pum_do_redraw" is set, used to redraw the status lines.
Bram Moolenaar4b779472005-10-04 09:12:31 +0000551 */
552 int
553pum_visible()
554{
Bram Moolenaar96d2c5b2006-03-11 21:27:59 +0000555 return !pum_do_redraw && pum_array != NULL;
Bram Moolenaar4b779472005-10-04 09:12:31 +0000556}
557
Bram Moolenaare3226be2005-12-18 22:10:00 +0000558/*
559 * Return the height of the popup menu, the number of entries visible.
560 * Only valid when pum_visible() returns TRUE!
561 */
562 int
563pum_get_height()
564{
565 return pum_height;
566}
567
Bram Moolenaar4b779472005-10-04 09:12:31 +0000568#endif