Bram Moolenaar | 4b77947 | 2005-10-04 09:12:31 +0000 | [diff] [blame] | 1 | /* 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 Moolenaar | 76b92b2 | 2006-03-24 22:46:53 +0000 | [diff] [blame] | 11 | * popupmnu.c: Popup menu (PUM) |
Bram Moolenaar | 4b77947 | 2005-10-04 09:12:31 +0000 | [diff] [blame] | 12 | */ |
| 13 | #include "vim.h" |
| 14 | |
| 15 | #if defined(FEAT_INS_EXPAND) || defined(PROTO) |
| 16 | |
Bram Moolenaar | 8b6144b | 2006-02-08 09:20:24 +0000 | [diff] [blame] | 17 | static pumitem_T *pum_array = NULL; /* items of displayed pum */ |
Bram Moolenaar | 4b77947 | 2005-10-04 09:12:31 +0000 | [diff] [blame] | 18 | static int pum_size; /* nr of items in "pum_array" */ |
| 19 | static int pum_selected; /* index of selected item or -1 */ |
| 20 | static int pum_first = 0; /* index of top item */ |
| 21 | |
| 22 | static int pum_height; /* nr of displayed pum items */ |
| 23 | static int pum_width; /* width of displayed pum items */ |
Bram Moolenaar | 8b6144b | 2006-02-08 09:20:24 +0000 | [diff] [blame] | 24 | static int pum_base_width; /* width of pum items base */ |
Bram Moolenaar | 96d2c5b | 2006-03-11 21:27:59 +0000 | [diff] [blame] | 25 | static int pum_kind_width; /* width of pum items kind column */ |
Bram Moolenaar | 4b77947 | 2005-10-04 09:12:31 +0000 | [diff] [blame] | 26 | static int pum_scrollbar; /* TRUE when scrollbar present */ |
| 27 | |
| 28 | static int pum_row; /* top row of pum */ |
| 29 | static int pum_col; /* left column of pum */ |
| 30 | |
Bram Moolenaar | 96d2c5b | 2006-03-11 21:27:59 +0000 | [diff] [blame] | 31 | static int pum_do_redraw = FALSE; /* do redraw anyway */ |
| 32 | |
Bram Moolenaar | fc1421e | 2006-04-20 22:17:20 +0000 | [diff] [blame] | 33 | static int pum_set_selected __ARGS((int n, int repeat)); |
Bram Moolenaar | 96d2c5b | 2006-03-11 21:27:59 +0000 | [diff] [blame] | 34 | |
Bram Moolenaar | 4b77947 | 2005-10-04 09:12:31 +0000 | [diff] [blame] | 35 | #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 Moolenaar | 96d2c5b | 2006-03-11 21:27:59 +0000 | [diff] [blame] | 45 | pum_display(array, size, selected) |
Bram Moolenaar | 8b6144b | 2006-02-08 09:20:24 +0000 | [diff] [blame] | 46 | pumitem_T *array; |
Bram Moolenaar | 4b77947 | 2005-10-04 09:12:31 +0000 | [diff] [blame] | 47 | int size; |
Bram Moolenaar | 1f35bf9 | 2006-03-07 22:38:47 +0000 | [diff] [blame] | 48 | int selected; /* index of initially selected item, none if |
| 49 | out of range */ |
Bram Moolenaar | 96d2c5b | 2006-03-11 21:27:59 +0000 | [diff] [blame] | 50 | { |
| 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 Moolenaar | 4b77947 | 2005-10-04 09:12:31 +0000 | [diff] [blame] | 58 | int row; |
Bram Moolenaar | c1a11ed | 2008-06-24 22:09:24 +0000 | [diff] [blame] | 59 | int context_lines; |
Bram Moolenaar | 4b77947 | 2005-10-04 09:12:31 +0000 | [diff] [blame] | 60 | int col; |
Bram Moolenaar | efd2bf1 | 2006-03-16 21:41:35 +0000 | [diff] [blame] | 61 | int above_row = cmdline_row; |
Bram Moolenaar | fc1421e | 2006-04-20 22:17:20 +0000 | [diff] [blame] | 62 | int redo_count = 0; |
Bram Moolenaar | 96d2c5b | 2006-03-11 21:27:59 +0000 | [diff] [blame] | 63 | |
| 64 | redo: |
| 65 | def_width = PUM_DEF_WIDTH; |
| 66 | max_width = 0; |
| 67 | kind_width = 0; |
| 68 | extra_width = 0; |
| 69 | |
Bram Moolenaar | 1e60789 | 2006-03-13 22:15:53 +0000 | [diff] [blame] | 70 | /* Pretend the pum is already there to avoid that must_redraw is set when |
| 71 | * 'cuc' is on. */ |
| 72 | pum_array = (pumitem_T *)1; |
Bram Moolenaar | 96d2c5b | 2006-03-11 21:27:59 +0000 | [diff] [blame] | 73 | validate_cursor_col(); |
Bram Moolenaar | 1e60789 | 2006-03-13 22:15:53 +0000 | [diff] [blame] | 74 | pum_array = NULL; |
| 75 | |
Bram Moolenaar | c1a11ed | 2008-06-24 22:09:24 +0000 | [diff] [blame] | 76 | row = curwin->w_wrow + W_WINROW(curwin); |
Bram Moolenaar | 96d2c5b | 2006-03-11 21:27:59 +0000 | [diff] [blame] | 77 | |
| 78 | if (firstwin->w_p_pvw) |
| 79 | top_clear = firstwin->w_height; |
| 80 | else |
| 81 | top_clear = 0; |
Bram Moolenaar | 4b77947 | 2005-10-04 09:12:31 +0000 | [diff] [blame] | 82 | |
Bram Moolenaar | efd2bf1 | 2006-03-16 21:41:35 +0000 | [diff] [blame] | 83 | /* When the preview window is at the bottom stop just above it. Also |
| 84 | * avoid drawing over the status line so that it's clear there is a window |
| 85 | * boundary. */ |
| 86 | if (lastwin->w_p_pvw) |
| 87 | above_row -= lastwin->w_height + lastwin->w_status_height + 1; |
| 88 | |
Bram Moolenaar | 4b77947 | 2005-10-04 09:12:31 +0000 | [diff] [blame] | 89 | /* |
| 90 | * Figure out the size and position of the pum. |
| 91 | */ |
| 92 | if (size < PUM_DEF_HEIGHT) |
| 93 | pum_height = size; |
| 94 | else |
| 95 | pum_height = PUM_DEF_HEIGHT; |
Bram Moolenaar | 7d47b6e | 2006-03-15 22:59:18 +0000 | [diff] [blame] | 96 | if (p_ph > 0 && pum_height > p_ph) |
| 97 | pum_height = p_ph; |
Bram Moolenaar | 4b77947 | 2005-10-04 09:12:31 +0000 | [diff] [blame] | 98 | |
| 99 | /* Put the pum below "row" if possible. If there are few lines decide on |
| 100 | * where there is more room. */ |
Bram Moolenaar | c1a11ed | 2008-06-24 22:09:24 +0000 | [diff] [blame] | 101 | if (row + 2 >= above_row - pum_height |
| 102 | && row > (above_row - top_clear) / 2) |
Bram Moolenaar | 4b77947 | 2005-10-04 09:12:31 +0000 | [diff] [blame] | 103 | { |
| 104 | /* pum above "row" */ |
Bram Moolenaar | c1a11ed | 2008-06-24 22:09:24 +0000 | [diff] [blame] | 105 | |
| 106 | /* Leave two lines of context if possible */ |
| 107 | if (curwin->w_wrow - curwin->w_cline_row >= 2) |
| 108 | context_lines = 2; |
| 109 | else |
| 110 | context_lines = curwin->w_wrow - curwin->w_cline_row; |
| 111 | |
| 112 | if (row >= size + context_lines) |
Bram Moolenaar | 4b77947 | 2005-10-04 09:12:31 +0000 | [diff] [blame] | 113 | { |
Bram Moolenaar | c1a11ed | 2008-06-24 22:09:24 +0000 | [diff] [blame] | 114 | pum_row = row - size - context_lines; |
Bram Moolenaar | 4b77947 | 2005-10-04 09:12:31 +0000 | [diff] [blame] | 115 | pum_height = size; |
| 116 | } |
| 117 | else |
| 118 | { |
| 119 | pum_row = 0; |
Bram Moolenaar | c1a11ed | 2008-06-24 22:09:24 +0000 | [diff] [blame] | 120 | pum_height = row - context_lines; |
Bram Moolenaar | 4b77947 | 2005-10-04 09:12:31 +0000 | [diff] [blame] | 121 | } |
Bram Moolenaar | 7d47b6e | 2006-03-15 22:59:18 +0000 | [diff] [blame] | 122 | if (p_ph > 0 && pum_height > p_ph) |
| 123 | { |
| 124 | pum_row += pum_height - p_ph; |
| 125 | pum_height = p_ph; |
| 126 | } |
Bram Moolenaar | 4b77947 | 2005-10-04 09:12:31 +0000 | [diff] [blame] | 127 | } |
| 128 | else |
| 129 | { |
| 130 | /* pum below "row" */ |
Bram Moolenaar | c1a11ed | 2008-06-24 22:09:24 +0000 | [diff] [blame] | 131 | |
| 132 | /* Leave two lines of context if possible */ |
| 133 | if (curwin->w_cline_row + curwin->w_cline_height - curwin->w_wrow >= 3) |
| 134 | context_lines = 3; |
| 135 | else |
| 136 | context_lines = curwin->w_cline_row |
| 137 | + curwin->w_cline_height - curwin->w_wrow; |
| 138 | |
| 139 | pum_row = row + context_lines; |
Bram Moolenaar | efd2bf1 | 2006-03-16 21:41:35 +0000 | [diff] [blame] | 140 | if (size > above_row - pum_row) |
| 141 | pum_height = above_row - pum_row; |
Bram Moolenaar | 4b77947 | 2005-10-04 09:12:31 +0000 | [diff] [blame] | 142 | else |
| 143 | pum_height = size; |
Bram Moolenaar | 7d47b6e | 2006-03-15 22:59:18 +0000 | [diff] [blame] | 144 | if (p_ph > 0 && pum_height > p_ph) |
| 145 | pum_height = p_ph; |
Bram Moolenaar | 4b77947 | 2005-10-04 09:12:31 +0000 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | /* don't display when we only have room for one line */ |
Bram Moolenaar | a655760 | 2006-02-04 22:43:20 +0000 | [diff] [blame] | 149 | if (pum_height < 1 || (pum_height == 1 && size > 1)) |
Bram Moolenaar | 4b77947 | 2005-10-04 09:12:31 +0000 | [diff] [blame] | 150 | return; |
| 151 | |
Bram Moolenaar | 96d2c5b | 2006-03-11 21:27:59 +0000 | [diff] [blame] | 152 | /* If there is a preview window at the top avoid drawing over it. */ |
| 153 | if (firstwin->w_p_pvw |
| 154 | && pum_row < firstwin->w_height |
| 155 | && pum_height > firstwin->w_height + 4) |
| 156 | { |
| 157 | pum_row += firstwin->w_height; |
| 158 | pum_height -= firstwin->w_height; |
| 159 | } |
| 160 | |
Bram Moolenaar | 8b6144b | 2006-02-08 09:20:24 +0000 | [diff] [blame] | 161 | /* Compute the width of the widest match and the widest extra. */ |
Bram Moolenaar | 4b77947 | 2005-10-04 09:12:31 +0000 | [diff] [blame] | 162 | for (i = 0; i < size; ++i) |
| 163 | { |
Bram Moolenaar | 8b6144b | 2006-02-08 09:20:24 +0000 | [diff] [blame] | 164 | w = vim_strsize(array[i].pum_text); |
Bram Moolenaar | 4b77947 | 2005-10-04 09:12:31 +0000 | [diff] [blame] | 165 | if (max_width < w) |
| 166 | max_width = w; |
Bram Moolenaar | 96d2c5b | 2006-03-11 21:27:59 +0000 | [diff] [blame] | 167 | if (array[i].pum_kind != NULL) |
| 168 | { |
| 169 | w = vim_strsize(array[i].pum_kind) + 1; |
| 170 | if (kind_width < w) |
| 171 | kind_width = w; |
| 172 | } |
Bram Moolenaar | 8b6144b | 2006-02-08 09:20:24 +0000 | [diff] [blame] | 173 | if (array[i].pum_extra != NULL) |
| 174 | { |
Bram Moolenaar | 1e60789 | 2006-03-13 22:15:53 +0000 | [diff] [blame] | 175 | w = vim_strsize(array[i].pum_extra) + 1; |
Bram Moolenaar | 8b6144b | 2006-02-08 09:20:24 +0000 | [diff] [blame] | 176 | if (extra_width < w) |
| 177 | extra_width = w; |
| 178 | } |
Bram Moolenaar | 4b77947 | 2005-10-04 09:12:31 +0000 | [diff] [blame] | 179 | } |
Bram Moolenaar | 8b6144b | 2006-02-08 09:20:24 +0000 | [diff] [blame] | 180 | pum_base_width = max_width; |
Bram Moolenaar | 96d2c5b | 2006-03-11 21:27:59 +0000 | [diff] [blame] | 181 | pum_kind_width = kind_width; |
Bram Moolenaar | 4b77947 | 2005-10-04 09:12:31 +0000 | [diff] [blame] | 182 | |
Bram Moolenaar | abc9773 | 2007-08-08 20:49:37 +0000 | [diff] [blame] | 183 | /* Calculate column */ |
| 184 | #ifdef FEAT_RIGHTLEFT |
| 185 | if (curwin->w_p_rl) |
| 186 | col = W_WINCOL(curwin) + W_WIDTH(curwin) - curwin->w_wcol - |
| 187 | curwin->w_leftcol - 1; |
| 188 | else |
| 189 | #endif |
| 190 | col = W_WINCOL(curwin) + curwin->w_wcol - curwin->w_leftcol; |
| 191 | |
Bram Moolenaar | 4b77947 | 2005-10-04 09:12:31 +0000 | [diff] [blame] | 192 | /* if there are more items than room we need a scrollbar */ |
| 193 | if (pum_height < size) |
| 194 | { |
| 195 | pum_scrollbar = 1; |
| 196 | ++max_width; |
| 197 | } |
| 198 | else |
| 199 | pum_scrollbar = 0; |
| 200 | |
| 201 | if (def_width < max_width) |
| 202 | def_width = max_width; |
| 203 | |
Bram Moolenaar | abc9773 | 2007-08-08 20:49:37 +0000 | [diff] [blame] | 204 | if (((col < Columns - PUM_DEF_WIDTH || col < Columns - max_width) |
| 205 | #ifdef FEAT_RIGHTLEFT |
| 206 | && !curwin->w_p_rl) |
| 207 | || (curwin->w_p_rl && (col > PUM_DEF_WIDTH || col > max_width) |
| 208 | #endif |
| 209 | )) |
Bram Moolenaar | 4b77947 | 2005-10-04 09:12:31 +0000 | [diff] [blame] | 210 | { |
| 211 | /* align pum column with "col" */ |
| 212 | pum_col = col; |
Bram Moolenaar | abc9773 | 2007-08-08 20:49:37 +0000 | [diff] [blame] | 213 | |
| 214 | #ifdef FEAT_RIGHTLEFT |
| 215 | if (curwin->w_p_rl) |
| 216 | pum_width = pum_col - pum_scrollbar + 1; |
| 217 | else |
| 218 | #endif |
| 219 | pum_width = Columns - pum_col - pum_scrollbar; |
| 220 | |
Bram Moolenaar | 96d2c5b | 2006-03-11 21:27:59 +0000 | [diff] [blame] | 221 | if (pum_width > max_width + kind_width + extra_width + 1 |
Bram Moolenaar | 8b6144b | 2006-02-08 09:20:24 +0000 | [diff] [blame] | 222 | && pum_width > PUM_DEF_WIDTH) |
| 223 | { |
Bram Moolenaar | 96d2c5b | 2006-03-11 21:27:59 +0000 | [diff] [blame] | 224 | pum_width = max_width + kind_width + extra_width + 1; |
Bram Moolenaar | 8b6144b | 2006-02-08 09:20:24 +0000 | [diff] [blame] | 225 | if (pum_width < PUM_DEF_WIDTH) |
| 226 | pum_width = PUM_DEF_WIDTH; |
| 227 | } |
Bram Moolenaar | 4b77947 | 2005-10-04 09:12:31 +0000 | [diff] [blame] | 228 | } |
| 229 | else if (Columns < def_width) |
| 230 | { |
| 231 | /* not enough room, will use what we have */ |
Bram Moolenaar | abc9773 | 2007-08-08 20:49:37 +0000 | [diff] [blame] | 232 | #ifdef FEAT_RIGHTLEFT |
| 233 | if (curwin->w_p_rl) |
| 234 | pum_col = Columns - 1; |
| 235 | else |
| 236 | #endif |
| 237 | pum_col = 0; |
Bram Moolenaar | 4b77947 | 2005-10-04 09:12:31 +0000 | [diff] [blame] | 238 | pum_width = Columns - 1; |
| 239 | } |
| 240 | else |
| 241 | { |
| 242 | if (max_width > PUM_DEF_WIDTH) |
| 243 | max_width = PUM_DEF_WIDTH; /* truncate */ |
Bram Moolenaar | abc9773 | 2007-08-08 20:49:37 +0000 | [diff] [blame] | 244 | #ifdef FEAT_RIGHTLEFT |
| 245 | if (curwin->w_p_rl) |
| 246 | pum_col = max_width - 1; |
| 247 | else |
| 248 | #endif |
| 249 | pum_col = Columns - max_width; |
Bram Moolenaar | 4b77947 | 2005-10-04 09:12:31 +0000 | [diff] [blame] | 250 | pum_width = max_width - pum_scrollbar; |
| 251 | } |
| 252 | |
| 253 | pum_array = array; |
| 254 | pum_size = size; |
| 255 | |
Bram Moolenaar | 96d2c5b | 2006-03-11 21:27:59 +0000 | [diff] [blame] | 256 | /* Set selected item and redraw. If the window size changed need to redo |
Bram Moolenaar | fc1421e | 2006-04-20 22:17:20 +0000 | [diff] [blame] | 257 | * the positioning. Limit this to two times, when there is not much |
| 258 | * room the window size will keep changing. */ |
| 259 | if (pum_set_selected(selected, redo_count) && ++redo_count <= 2) |
Bram Moolenaar | 96d2c5b | 2006-03-11 21:27:59 +0000 | [diff] [blame] | 260 | goto redo; |
Bram Moolenaar | 4b77947 | 2005-10-04 09:12:31 +0000 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | /* |
| 264 | * Redraw the popup menu, using "pum_first" and "pum_selected". |
| 265 | */ |
| 266 | void |
| 267 | pum_redraw() |
| 268 | { |
| 269 | int row = pum_row; |
| 270 | int col; |
| 271 | int attr_norm = highlight_attr[HLF_PNI]; |
| 272 | int attr_select = highlight_attr[HLF_PSI]; |
| 273 | int attr_scroll = highlight_attr[HLF_PSB]; |
| 274 | int attr_thumb = highlight_attr[HLF_PST]; |
| 275 | int attr; |
| 276 | int i; |
| 277 | int idx; |
| 278 | char_u *s; |
Bram Moolenaar | 7d47b6e | 2006-03-15 22:59:18 +0000 | [diff] [blame] | 279 | char_u *p = NULL; |
Bram Moolenaar | 8b6144b | 2006-02-08 09:20:24 +0000 | [diff] [blame] | 280 | int totwidth, width, w; |
Bram Moolenaar | 4b77947 | 2005-10-04 09:12:31 +0000 | [diff] [blame] | 281 | int thumb_pos = 0; |
| 282 | int thumb_heigth = 1; |
Bram Moolenaar | 8b6144b | 2006-02-08 09:20:24 +0000 | [diff] [blame] | 283 | int round; |
Bram Moolenaar | 96d2c5b | 2006-03-11 21:27:59 +0000 | [diff] [blame] | 284 | int n; |
Bram Moolenaar | 4b77947 | 2005-10-04 09:12:31 +0000 | [diff] [blame] | 285 | |
| 286 | if (pum_scrollbar) |
| 287 | { |
| 288 | thumb_heigth = pum_height * pum_height / pum_size; |
| 289 | if (thumb_heigth == 0) |
| 290 | thumb_heigth = 1; |
| 291 | thumb_pos = (pum_first * (pum_height - thumb_heigth) |
| 292 | + (pum_size - pum_height) / 2) |
| 293 | / (pum_size - pum_height); |
| 294 | } |
| 295 | |
| 296 | for (i = 0; i < pum_height; ++i) |
| 297 | { |
| 298 | idx = i + pum_first; |
| 299 | attr = (idx == pum_selected) ? attr_select : attr_norm; |
| 300 | |
| 301 | /* prepend a space if there is room */ |
Bram Moolenaar | abc9773 | 2007-08-08 20:49:37 +0000 | [diff] [blame] | 302 | #ifdef FEAT_RIGHTLEFT |
| 303 | if (curwin->w_p_rl) |
| 304 | { |
| 305 | if (pum_col < W_WINCOL(curwin) + W_WIDTH(curwin) - 1) |
| 306 | screen_putchar(' ', row, pum_col + 1, attr); |
| 307 | } |
| 308 | else |
| 309 | #endif |
| 310 | if (pum_col > 0) |
| 311 | screen_putchar(' ', row, pum_col - 1, attr); |
Bram Moolenaar | 4b77947 | 2005-10-04 09:12:31 +0000 | [diff] [blame] | 312 | |
Bram Moolenaar | 8b6144b | 2006-02-08 09:20:24 +0000 | [diff] [blame] | 313 | /* Display each entry, use two spaces for a Tab. |
Bram Moolenaar | 96d2c5b | 2006-03-11 21:27:59 +0000 | [diff] [blame] | 314 | * Do this 3 times: For the main text, kind and extra info */ |
Bram Moolenaar | 4b77947 | 2005-10-04 09:12:31 +0000 | [diff] [blame] | 315 | col = pum_col; |
Bram Moolenaar | 8b6144b | 2006-02-08 09:20:24 +0000 | [diff] [blame] | 316 | totwidth = 0; |
Bram Moolenaar | 96d2c5b | 2006-03-11 21:27:59 +0000 | [diff] [blame] | 317 | for (round = 1; round <= 3; ++round) |
Bram Moolenaar | 4b77947 | 2005-10-04 09:12:31 +0000 | [diff] [blame] | 318 | { |
Bram Moolenaar | 8b6144b | 2006-02-08 09:20:24 +0000 | [diff] [blame] | 319 | width = 0; |
| 320 | s = NULL; |
Bram Moolenaar | 96d2c5b | 2006-03-11 21:27:59 +0000 | [diff] [blame] | 321 | switch (round) |
Bram Moolenaar | 4b77947 | 2005-10-04 09:12:31 +0000 | [diff] [blame] | 322 | { |
Bram Moolenaar | 96d2c5b | 2006-03-11 21:27:59 +0000 | [diff] [blame] | 323 | case 1: p = pum_array[idx].pum_text; break; |
| 324 | case 2: p = pum_array[idx].pum_kind; break; |
| 325 | case 3: p = pum_array[idx].pum_extra; break; |
Bram Moolenaar | 4b77947 | 2005-10-04 09:12:31 +0000 | [diff] [blame] | 326 | } |
Bram Moolenaar | 96d2c5b | 2006-03-11 21:27:59 +0000 | [diff] [blame] | 327 | if (p != NULL) |
| 328 | for ( ; ; mb_ptr_adv(p)) |
| 329 | { |
| 330 | if (s == NULL) |
| 331 | s = p; |
| 332 | w = ptr2cells(p); |
| 333 | if (*p == NUL || *p == TAB || totwidth + w > pum_width) |
| 334 | { |
Bram Moolenaar | 7cc36e9 | 2007-03-27 10:42:05 +0000 | [diff] [blame] | 335 | /* Display the text that fits or comes before a Tab. |
| 336 | * First convert it to printable characters. */ |
Bram Moolenaar | abc9773 | 2007-08-08 20:49:37 +0000 | [diff] [blame] | 337 | char_u *st; |
| 338 | int saved = *p; |
Bram Moolenaar | 7cc36e9 | 2007-03-27 10:42:05 +0000 | [diff] [blame] | 339 | |
| 340 | *p = NUL; |
| 341 | st = transstr(s); |
| 342 | *p = saved; |
Bram Moolenaar | abc9773 | 2007-08-08 20:49:37 +0000 | [diff] [blame] | 343 | #ifdef FEAT_RIGHTLEFT |
| 344 | if (curwin->w_p_rl) |
Bram Moolenaar | 7cc36e9 | 2007-03-27 10:42:05 +0000 | [diff] [blame] | 345 | { |
Bram Moolenaar | abc9773 | 2007-08-08 20:49:37 +0000 | [diff] [blame] | 346 | if (st != NULL) |
| 347 | { |
| 348 | char_u *rt = reverse_text(st); |
| 349 | char_u *rt_saved = rt; |
| 350 | int len, j; |
| 351 | |
| 352 | if (rt != NULL) |
| 353 | { |
Bram Moolenaar | cb4cef2 | 2008-03-16 15:04:34 +0000 | [diff] [blame] | 354 | len = (int)STRLEN(rt); |
Bram Moolenaar | abc9773 | 2007-08-08 20:49:37 +0000 | [diff] [blame] | 355 | if (len > pum_width) |
| 356 | { |
| 357 | for (j = pum_width; j < len; ++j) |
| 358 | mb_ptr_adv(rt); |
| 359 | len = pum_width; |
| 360 | } |
| 361 | screen_puts_len(rt, len, row, |
| 362 | col - len + 1, attr); |
| 363 | vim_free(rt_saved); |
| 364 | } |
| 365 | vim_free(st); |
| 366 | } |
| 367 | col -= width; |
Bram Moolenaar | 7cc36e9 | 2007-03-27 10:42:05 +0000 | [diff] [blame] | 368 | } |
Bram Moolenaar | abc9773 | 2007-08-08 20:49:37 +0000 | [diff] [blame] | 369 | else |
| 370 | #endif |
| 371 | { |
| 372 | if (st != NULL) |
| 373 | { |
| 374 | screen_puts_len(st, (int)STRLEN(st), row, col, |
| 375 | attr); |
| 376 | vim_free(st); |
| 377 | } |
| 378 | col += width; |
| 379 | } |
Bram Moolenaar | 96d2c5b | 2006-03-11 21:27:59 +0000 | [diff] [blame] | 380 | |
| 381 | if (*p != TAB) |
| 382 | break; |
| 383 | |
| 384 | /* Display two spaces for a Tab. */ |
Bram Moolenaar | abc9773 | 2007-08-08 20:49:37 +0000 | [diff] [blame] | 385 | #ifdef FEAT_RIGHTLEFT |
| 386 | if (curwin->w_p_rl) |
| 387 | { |
| 388 | screen_puts_len((char_u *)" ", 2, row, col - 1, |
| 389 | attr); |
| 390 | col -= 2; |
| 391 | } |
| 392 | else |
| 393 | #endif |
| 394 | { |
| 395 | screen_puts_len((char_u *)" ", 2, row, col, attr); |
| 396 | col += 2; |
| 397 | } |
Bram Moolenaar | 96d2c5b | 2006-03-11 21:27:59 +0000 | [diff] [blame] | 398 | totwidth += 2; |
| 399 | s = NULL; /* start text at next char */ |
| 400 | width = 0; |
| 401 | } |
| 402 | else |
| 403 | width += w; |
| 404 | } |
| 405 | |
| 406 | if (round > 1) |
| 407 | n = pum_kind_width + 1; |
| 408 | else |
| 409 | n = 1; |
| 410 | |
| 411 | /* Stop when there is nothing more to display. */ |
| 412 | if (round == 3 |
| 413 | || (round == 2 && pum_array[idx].pum_extra == NULL) |
| 414 | || (round == 1 && pum_array[idx].pum_kind == NULL |
| 415 | && pum_array[idx].pum_extra == NULL) |
| 416 | || pum_base_width + n >= pum_width) |
Bram Moolenaar | 8b6144b | 2006-02-08 09:20:24 +0000 | [diff] [blame] | 417 | break; |
Bram Moolenaar | abc9773 | 2007-08-08 20:49:37 +0000 | [diff] [blame] | 418 | #ifdef FEAT_RIGHTLEFT |
| 419 | if (curwin->w_p_rl) |
| 420 | { |
| 421 | screen_fill(row, row + 1, pum_col - pum_base_width - n + 1, |
| 422 | col + 1, ' ', ' ', attr); |
| 423 | col = pum_col - pum_base_width - n + 1; |
| 424 | } |
| 425 | else |
| 426 | #endif |
| 427 | { |
| 428 | screen_fill(row, row + 1, col, pum_col + pum_base_width + n, |
Bram Moolenaar | 8b6144b | 2006-02-08 09:20:24 +0000 | [diff] [blame] | 429 | ' ', ' ', attr); |
Bram Moolenaar | abc9773 | 2007-08-08 20:49:37 +0000 | [diff] [blame] | 430 | col = pum_col + pum_base_width + n; |
| 431 | } |
Bram Moolenaar | 96d2c5b | 2006-03-11 21:27:59 +0000 | [diff] [blame] | 432 | totwidth = pum_base_width + n; |
Bram Moolenaar | 4b77947 | 2005-10-04 09:12:31 +0000 | [diff] [blame] | 433 | } |
| 434 | |
Bram Moolenaar | abc9773 | 2007-08-08 20:49:37 +0000 | [diff] [blame] | 435 | #ifdef FEAT_RIGHTLEFT |
| 436 | if (curwin->w_p_rl) |
| 437 | screen_fill(row, row + 1, pum_col - pum_width + 1, col + 1, ' ', |
| 438 | ' ', attr); |
| 439 | else |
| 440 | #endif |
| 441 | screen_fill(row, row + 1, col, pum_col + pum_width, ' ', ' ', |
| 442 | attr); |
Bram Moolenaar | 4b77947 | 2005-10-04 09:12:31 +0000 | [diff] [blame] | 443 | if (pum_scrollbar > 0) |
Bram Moolenaar | abc9773 | 2007-08-08 20:49:37 +0000 | [diff] [blame] | 444 | { |
| 445 | #ifdef FEAT_RIGHTLEFT |
| 446 | if (curwin->w_p_rl) |
| 447 | screen_putchar(' ', row, pum_col - pum_width, |
| 448 | i >= thumb_pos && i < thumb_pos + thumb_heigth |
Bram Moolenaar | 4b77947 | 2005-10-04 09:12:31 +0000 | [diff] [blame] | 449 | ? attr_thumb : attr_scroll); |
Bram Moolenaar | abc9773 | 2007-08-08 20:49:37 +0000 | [diff] [blame] | 450 | else |
| 451 | #endif |
| 452 | screen_putchar(' ', row, pum_col + pum_width, |
| 453 | i >= thumb_pos && i < thumb_pos + thumb_heigth |
| 454 | ? attr_thumb : attr_scroll); |
| 455 | } |
Bram Moolenaar | 4b77947 | 2005-10-04 09:12:31 +0000 | [diff] [blame] | 456 | |
| 457 | ++row; |
| 458 | } |
| 459 | } |
| 460 | |
| 461 | #if 0 /* not used yet */ |
| 462 | /* |
| 463 | * Return the index of the currently selected item. |
| 464 | */ |
| 465 | int |
| 466 | pum_get_selected() |
| 467 | { |
| 468 | return pum_selected; |
| 469 | } |
| 470 | #endif |
| 471 | |
| 472 | /* |
| 473 | * Set the index of the currently selected item. The menu will scroll when |
Bram Moolenaar | 1f35bf9 | 2006-03-07 22:38:47 +0000 | [diff] [blame] | 474 | * necessary. When "n" is out of range don't scroll. |
Bram Moolenaar | fc1421e | 2006-04-20 22:17:20 +0000 | [diff] [blame] | 475 | * This may be repeated when the preview window is used: |
| 476 | * "repeat" == 0: open preview window normally |
| 477 | * "repeat" == 1: open preview window but don't set the size |
| 478 | * "repeat" == 2: don't open preview window |
Bram Moolenaar | 96d2c5b | 2006-03-11 21:27:59 +0000 | [diff] [blame] | 479 | * Returns TRUE when the window was resized and the location of the popup menu |
| 480 | * must be recomputed. |
Bram Moolenaar | 4b77947 | 2005-10-04 09:12:31 +0000 | [diff] [blame] | 481 | */ |
Bram Moolenaar | 96d2c5b | 2006-03-11 21:27:59 +0000 | [diff] [blame] | 482 | static int |
Bram Moolenaar | fc1421e | 2006-04-20 22:17:20 +0000 | [diff] [blame] | 483 | pum_set_selected(n, repeat) |
Bram Moolenaar | 4b77947 | 2005-10-04 09:12:31 +0000 | [diff] [blame] | 484 | int n; |
Bram Moolenaar | fc1421e | 2006-04-20 22:17:20 +0000 | [diff] [blame] | 485 | int repeat; |
Bram Moolenaar | 4b77947 | 2005-10-04 09:12:31 +0000 | [diff] [blame] | 486 | { |
Bram Moolenaar | 96d2c5b | 2006-03-11 21:27:59 +0000 | [diff] [blame] | 487 | int resized = FALSE; |
Bram Moolenaar | 7d47b6e | 2006-03-15 22:59:18 +0000 | [diff] [blame] | 488 | int context = pum_height / 2; |
Bram Moolenaar | 96d2c5b | 2006-03-11 21:27:59 +0000 | [diff] [blame] | 489 | |
Bram Moolenaar | 4b77947 | 2005-10-04 09:12:31 +0000 | [diff] [blame] | 490 | pum_selected = n; |
| 491 | |
Bram Moolenaar | 1f35bf9 | 2006-03-07 22:38:47 +0000 | [diff] [blame] | 492 | if (pum_selected >= 0 && pum_selected < pum_size) |
Bram Moolenaar | 4b77947 | 2005-10-04 09:12:31 +0000 | [diff] [blame] | 493 | { |
Bram Moolenaar | e3226be | 2005-12-18 22:10:00 +0000 | [diff] [blame] | 494 | if (pum_first > pum_selected - 4) |
| 495 | { |
| 496 | /* scroll down; when we did a jump it's probably a PageUp then |
Bram Moolenaar | 7df351e | 2006-01-23 22:30:28 +0000 | [diff] [blame] | 497 | * scroll a whole page */ |
Bram Moolenaar | e3226be | 2005-12-18 22:10:00 +0000 | [diff] [blame] | 498 | if (pum_first > pum_selected - 2) |
| 499 | { |
Bram Moolenaar | 7df351e | 2006-01-23 22:30:28 +0000 | [diff] [blame] | 500 | pum_first -= pum_height - 2; |
Bram Moolenaar | e3226be | 2005-12-18 22:10:00 +0000 | [diff] [blame] | 501 | if (pum_first < 0) |
| 502 | pum_first = 0; |
Bram Moolenaar | 7df351e | 2006-01-23 22:30:28 +0000 | [diff] [blame] | 503 | else if (pum_first > pum_selected) |
| 504 | pum_first = pum_selected; |
Bram Moolenaar | e3226be | 2005-12-18 22:10:00 +0000 | [diff] [blame] | 505 | } |
| 506 | else |
| 507 | pum_first = pum_selected; |
| 508 | } |
| 509 | else if (pum_first < pum_selected - pum_height + 5) |
| 510 | { |
| 511 | /* scroll up; when we did a jump it's probably a PageDown then |
Bram Moolenaar | 7df351e | 2006-01-23 22:30:28 +0000 | [diff] [blame] | 512 | * scroll a whole page */ |
Bram Moolenaar | e3226be | 2005-12-18 22:10:00 +0000 | [diff] [blame] | 513 | if (pum_first < pum_selected - pum_height + 1 + 2) |
Bram Moolenaar | 7df351e | 2006-01-23 22:30:28 +0000 | [diff] [blame] | 514 | { |
| 515 | pum_first += pum_height - 2; |
| 516 | if (pum_first < pum_selected - pum_height + 1) |
| 517 | pum_first = pum_selected - pum_height + 1; |
| 518 | } |
Bram Moolenaar | e3226be | 2005-12-18 22:10:00 +0000 | [diff] [blame] | 519 | else |
| 520 | pum_first = pum_selected - pum_height + 1; |
| 521 | } |
Bram Moolenaar | 4b77947 | 2005-10-04 09:12:31 +0000 | [diff] [blame] | 522 | |
Bram Moolenaar | 7d47b6e | 2006-03-15 22:59:18 +0000 | [diff] [blame] | 523 | /* Give a few lines of context when possible. */ |
| 524 | if (context > 3) |
| 525 | context = 3; |
| 526 | if (pum_height > 2) |
Bram Moolenaar | 4b77947 | 2005-10-04 09:12:31 +0000 | [diff] [blame] | 527 | { |
Bram Moolenaar | 7d47b6e | 2006-03-15 22:59:18 +0000 | [diff] [blame] | 528 | if (pum_first > pum_selected - context) |
Bram Moolenaar | 4b77947 | 2005-10-04 09:12:31 +0000 | [diff] [blame] | 529 | { |
| 530 | /* scroll down */ |
Bram Moolenaar | 7d47b6e | 2006-03-15 22:59:18 +0000 | [diff] [blame] | 531 | pum_first = pum_selected - context; |
Bram Moolenaar | 4b77947 | 2005-10-04 09:12:31 +0000 | [diff] [blame] | 532 | if (pum_first < 0) |
| 533 | pum_first = 0; |
| 534 | } |
Bram Moolenaar | 7d47b6e | 2006-03-15 22:59:18 +0000 | [diff] [blame] | 535 | else if (pum_first < pum_selected + context - pum_height + 1) |
Bram Moolenaar | 4b77947 | 2005-10-04 09:12:31 +0000 | [diff] [blame] | 536 | { |
| 537 | /* scroll up */ |
Bram Moolenaar | 7d47b6e | 2006-03-15 22:59:18 +0000 | [diff] [blame] | 538 | pum_first = pum_selected + context - pum_height + 1; |
Bram Moolenaar | 4b77947 | 2005-10-04 09:12:31 +0000 | [diff] [blame] | 539 | } |
| 540 | } |
Bram Moolenaar | 96d2c5b | 2006-03-11 21:27:59 +0000 | [diff] [blame] | 541 | |
| 542 | #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX) |
Bram Moolenaar | d2cec5b | 2006-03-28 21:08:56 +0000 | [diff] [blame] | 543 | /* |
| 544 | * Show extra info in the preview window if there is something and |
| 545 | * 'completeopt' contains "preview". |
Bram Moolenaar | fc1421e | 2006-04-20 22:17:20 +0000 | [diff] [blame] | 546 | * Skip this when tried twice already. |
| 547 | * Skip this also when there is not much room. |
Bram Moolenaar | d2cec5b | 2006-03-28 21:08:56 +0000 | [diff] [blame] | 548 | * NOTE: Be very careful not to sync undo! |
| 549 | */ |
Bram Moolenaar | 96d2c5b | 2006-03-11 21:27:59 +0000 | [diff] [blame] | 550 | if (pum_array[pum_selected].pum_info != NULL |
Bram Moolenaar | fc1421e | 2006-04-20 22:17:20 +0000 | [diff] [blame] | 551 | && Rows > 10 |
| 552 | && repeat <= 1 |
| 553 | && vim_strchr(p_cot, 'p') != NULL) |
Bram Moolenaar | 96d2c5b | 2006-03-11 21:27:59 +0000 | [diff] [blame] | 554 | { |
| 555 | win_T *curwin_save = curwin; |
| 556 | int res = OK; |
| 557 | |
| 558 | /* Open a preview window. 3 lines by default. */ |
| 559 | g_do_tagpreview = 3; |
Bram Moolenaar | d2cec5b | 2006-03-28 21:08:56 +0000 | [diff] [blame] | 560 | resized = prepare_tagpreview(FALSE); |
Bram Moolenaar | 96d2c5b | 2006-03-11 21:27:59 +0000 | [diff] [blame] | 561 | g_do_tagpreview = 0; |
| 562 | |
| 563 | if (curwin->w_p_pvw) |
| 564 | { |
| 565 | if (curbuf->b_fname == NULL |
| 566 | && curbuf->b_p_bt[0] == 'n' && curbuf->b_p_bt[2] == 'f' |
| 567 | && curbuf->b_p_bh[0] == 'w') |
| 568 | { |
| 569 | /* Already a "wipeout" buffer, make it empty. */ |
| 570 | while (!bufempty()) |
| 571 | ml_delete((linenr_T)1, FALSE); |
| 572 | } |
Bram Moolenaar | 779b74b | 2006-04-10 14:55:34 +0000 | [diff] [blame] | 573 | else |
Bram Moolenaar | 96d2c5b | 2006-03-11 21:27:59 +0000 | [diff] [blame] | 574 | { |
Bram Moolenaar | 779b74b | 2006-04-10 14:55:34 +0000 | [diff] [blame] | 575 | /* Don't want to sync undo in the current buffer. */ |
| 576 | ++no_u_sync; |
| 577 | res = do_ecmd(0, NULL, NULL, NULL, ECMD_ONE, 0); |
| 578 | --no_u_sync; |
| 579 | if (res == OK) |
| 580 | { |
| 581 | /* Edit a new, empty buffer. Set options for a "wipeout" |
| 582 | * buffer. */ |
| 583 | set_option_value((char_u *)"swf", 0L, NULL, OPT_LOCAL); |
| 584 | set_option_value((char_u *)"bt", 0L, |
| 585 | (char_u *)"nofile", OPT_LOCAL); |
| 586 | set_option_value((char_u *)"bh", 0L, |
| 587 | (char_u *)"wipe", OPT_LOCAL); |
| 588 | set_option_value((char_u *)"diff", 0L, |
Bram Moolenaar | 7f51474 | 2007-06-28 19:33:43 +0000 | [diff] [blame] | 589 | NULL, OPT_LOCAL); |
Bram Moolenaar | 779b74b | 2006-04-10 14:55:34 +0000 | [diff] [blame] | 590 | } |
Bram Moolenaar | 96d2c5b | 2006-03-11 21:27:59 +0000 | [diff] [blame] | 591 | } |
| 592 | if (res == OK) |
| 593 | { |
| 594 | char_u *p, *e; |
| 595 | linenr_T lnum = 0; |
| 596 | |
| 597 | for (p = pum_array[pum_selected].pum_info; *p != NUL; ) |
| 598 | { |
| 599 | e = vim_strchr(p, '\n'); |
| 600 | if (e == NULL) |
| 601 | { |
| 602 | ml_append(lnum++, p, 0, FALSE); |
| 603 | break; |
| 604 | } |
| 605 | else |
| 606 | { |
| 607 | *e = NUL; |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 608 | ml_append(lnum++, p, (int)(e - p + 1), FALSE); |
Bram Moolenaar | 96d2c5b | 2006-03-11 21:27:59 +0000 | [diff] [blame] | 609 | *e = '\n'; |
| 610 | p = e + 1; |
| 611 | } |
| 612 | } |
| 613 | |
| 614 | /* Increase the height of the preview window to show the |
| 615 | * text, but no more than 'previewheight' lines. */ |
Bram Moolenaar | fc1421e | 2006-04-20 22:17:20 +0000 | [diff] [blame] | 616 | if (repeat == 0) |
Bram Moolenaar | 96d2c5b | 2006-03-11 21:27:59 +0000 | [diff] [blame] | 617 | { |
Bram Moolenaar | fc1421e | 2006-04-20 22:17:20 +0000 | [diff] [blame] | 618 | if (lnum > p_pvh) |
| 619 | lnum = p_pvh; |
| 620 | if (curwin->w_height < lnum) |
| 621 | { |
| 622 | win_setheight((int)lnum); |
| 623 | resized = TRUE; |
| 624 | } |
Bram Moolenaar | 96d2c5b | 2006-03-11 21:27:59 +0000 | [diff] [blame] | 625 | } |
| 626 | |
| 627 | curbuf->b_changed = 0; |
| 628 | curbuf->b_p_ma = FALSE; |
| 629 | curwin->w_cursor.lnum = 0; |
| 630 | curwin->w_cursor.col = 0; |
| 631 | |
| 632 | if (curwin != curwin_save && win_valid(curwin_save)) |
| 633 | { |
| 634 | /* Return cursor to where we were */ |
| 635 | validate_cursor(); |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 636 | redraw_later(SOME_VALID); |
Bram Moolenaar | 96d2c5b | 2006-03-11 21:27:59 +0000 | [diff] [blame] | 637 | |
| 638 | /* When the preview window was resized we need to |
| 639 | * update the view on the buffer. Only go back to |
| 640 | * the window when needed, otherwise it will always be |
| 641 | * redraw. */ |
| 642 | if (resized) |
| 643 | { |
| 644 | win_enter(curwin_save, TRUE); |
| 645 | update_topline(); |
| 646 | } |
| 647 | |
| 648 | /* Update the screen before drawing the popup menu. |
| 649 | * Enable updating the status lines. */ |
| 650 | pum_do_redraw = TRUE; |
| 651 | update_screen(0); |
| 652 | pum_do_redraw = FALSE; |
| 653 | |
Bram Moolenaar | d2cec5b | 2006-03-28 21:08:56 +0000 | [diff] [blame] | 654 | if (!resized && win_valid(curwin_save)) |
Bram Moolenaar | 96d2c5b | 2006-03-11 21:27:59 +0000 | [diff] [blame] | 655 | win_enter(curwin_save, TRUE); |
Bram Moolenaar | 7d47b6e | 2006-03-15 22:59:18 +0000 | [diff] [blame] | 656 | |
| 657 | /* May need to update the screen again when there are |
| 658 | * autocommands involved. */ |
| 659 | pum_do_redraw = TRUE; |
| 660 | update_screen(0); |
| 661 | pum_do_redraw = FALSE; |
Bram Moolenaar | 96d2c5b | 2006-03-11 21:27:59 +0000 | [diff] [blame] | 662 | } |
| 663 | } |
| 664 | } |
| 665 | } |
| 666 | #endif |
Bram Moolenaar | 4b77947 | 2005-10-04 09:12:31 +0000 | [diff] [blame] | 667 | } |
| 668 | |
| 669 | /* Never display more than we have */ |
| 670 | if (pum_first > pum_size - pum_height) |
| 671 | pum_first = pum_size - pum_height; |
| 672 | |
Bram Moolenaar | 96d2c5b | 2006-03-11 21:27:59 +0000 | [diff] [blame] | 673 | if (!resized) |
| 674 | pum_redraw(); |
| 675 | |
| 676 | return resized; |
Bram Moolenaar | 4b77947 | 2005-10-04 09:12:31 +0000 | [diff] [blame] | 677 | } |
| 678 | |
| 679 | /* |
| 680 | * Undisplay the popup menu (later). |
| 681 | */ |
| 682 | void |
| 683 | pum_undisplay() |
| 684 | { |
| 685 | pum_array = NULL; |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 686 | redraw_all_later(SOME_VALID); |
Bram Moolenaar | 2d69460 | 2006-08-22 19:48:48 +0000 | [diff] [blame] | 687 | #ifdef FEAT_WINDOWS |
| 688 | redraw_tabline = TRUE; |
| 689 | #endif |
Bram Moolenaar | 1f4d4de | 2006-03-14 23:00:46 +0000 | [diff] [blame] | 690 | status_redraw_all(); |
Bram Moolenaar | 4b77947 | 2005-10-04 09:12:31 +0000 | [diff] [blame] | 691 | } |
| 692 | |
| 693 | /* |
| 694 | * Clear the popup menu. Currently only resets the offset to the first |
| 695 | * displayed item. |
| 696 | */ |
| 697 | void |
| 698 | pum_clear() |
| 699 | { |
| 700 | pum_first = 0; |
| 701 | } |
| 702 | |
| 703 | /* |
| 704 | * Return TRUE if the popup menu is displayed. |
Bram Moolenaar | 96d2c5b | 2006-03-11 21:27:59 +0000 | [diff] [blame] | 705 | * Overruled when "pum_do_redraw" is set, used to redraw the status lines. |
Bram Moolenaar | 4b77947 | 2005-10-04 09:12:31 +0000 | [diff] [blame] | 706 | */ |
| 707 | int |
| 708 | pum_visible() |
| 709 | { |
Bram Moolenaar | 96d2c5b | 2006-03-11 21:27:59 +0000 | [diff] [blame] | 710 | return !pum_do_redraw && pum_array != NULL; |
Bram Moolenaar | 4b77947 | 2005-10-04 09:12:31 +0000 | [diff] [blame] | 711 | } |
| 712 | |
Bram Moolenaar | e3226be | 2005-12-18 22:10:00 +0000 | [diff] [blame] | 713 | /* |
| 714 | * Return the height of the popup menu, the number of entries visible. |
| 715 | * Only valid when pum_visible() returns TRUE! |
| 716 | */ |
| 717 | int |
| 718 | pum_get_height() |
| 719 | { |
| 720 | return pum_height; |
| 721 | } |
| 722 | |
Bram Moolenaar | 4b77947 | 2005-10-04 09:12:31 +0000 | [diff] [blame] | 723 | #endif |