blob: cff3b9e523a29e2c947ad36dfbcde5119a94b013 [file] [log] [blame]
Bram Moolenaar30e9b3c2019-09-07 16:24:12 +02001*popup.txt* For Vim version 8.1. Last change: 2019 Sep 04
Bram Moolenaar957f85d2019-05-12 21:43:48 +02002
3
4 VIM REFERENCE MANUAL by Bram Moolenaar
5
6
Bram Moolenaar931a2772019-07-04 16:54:54 +02007Displaying text in a floating window. *popup* *popup-window*
Bram Moolenaar957f85d2019-05-12 21:43:48 +02008
Bram Moolenaar957f85d2019-05-12 21:43:48 +02009
101. Introduction |popup-intro|
Bram Moolenaar931a2772019-07-04 16:54:54 +020011 Window position and size |popup-position|
12 Closing the popup window |popup-close|
13 Popup buffer and window |popup-buffer|
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200142. Functions |popup-functions|
Bram Moolenaar931a2772019-07-04 16:54:54 +020015 Details |popup-function-details|
163. Usage |popup-usage|
17 popup_create() arguments |popup_create-arguments|
18 Popup text properties |popup-props|
Bram Moolenaar12034e22019-08-25 22:25:02 +020019 Position popup with textprop |popup-textprop-pos|
Bram Moolenaar931a2772019-07-04 16:54:54 +020020 Popup filter |popup-filter|
21 Popup callback |popup-callback|
22 Popup scrollbar |popup-scrollbar|
23 Popup mask |popup-mask|
244. Examples |popup-examples|
Bram Moolenaar957f85d2019-05-12 21:43:48 +020025
26
Bram Moolenaar7dd64a32019-05-31 21:41:05 +020027{not available if the |+textprop| feature was disabled at compile time}
Bram Moolenaar957f85d2019-05-12 21:43:48 +020028
29==============================================================================
301. Introduction *popup-intro*
31
Bram Moolenaar5c017b22019-05-21 23:09:01 +020032We are talking about popup windows here, text that goes on top of the regular
33windows and is under control of a plugin. You cannot edit the text in the
34popup window like with regular windows.
35
36A popup window can be used for such things as:
Bram Moolenaar68e65602019-05-26 21:33:31 +020037- briefly show a message without overwriting the command line
Bram Moolenaar5c017b22019-05-21 23:09:01 +020038- prompt the user with a dialog
Bram Moolenaar4d784b22019-05-25 19:51:39 +020039- display contextual information while typing
Bram Moolenaar5c017b22019-05-21 23:09:01 +020040- give extra information for auto-completion
41
42The text in the popup window can be colored with |text-properties|. It is
43also possible to use syntax highlighting.
44
Bram Moolenaar4d784b22019-05-25 19:51:39 +020045The default color used is "Pmenu". If you prefer something else use the
46"highlight" argument or the 'wincolor' option, e.g.: >
47 hi MyPopupColor ctermbg=lightblue guibg=lightblue
48 call setwinvar(winid, '&wincolor', 'MyPopupColor')
49
Bram Moolenaar68d48f42019-06-12 22:42:41 +020050'hlsearch' highlighting is not displayed in a popup window.
Bram Moolenaar4d784b22019-05-25 19:51:39 +020051
Bram Moolenaar5c017b22019-05-21 23:09:01 +020052A popup window has a window-ID like other windows, but behaves differently.
53The size can be up to the whole Vim window and it overlaps other windows.
Bram Moolenaarfc06cbb2019-06-15 14:14:31 +020054Popup windows can also overlap each other. The "zindex" property specifies
55what goes on top of what.
Bram Moolenaar68e65602019-05-26 21:33:31 +020056
57The popup window contains a buffer, and that buffer is always associated with
Bram Moolenaarfc06cbb2019-06-15 14:14:31 +020058the popup window. The window cannot be in Normal, Visual or Insert mode, it
59does not get keyboard focus. You can use functions like `setbufline()` to
Bram Moolenaar68e65602019-05-26 21:33:31 +020060change the text in the buffer. There are more differences from how this
61window and buffer behave compared to regular windows and buffers, see
62|popup-buffer|.
Bram Moolenaar5c017b22019-05-21 23:09:01 +020063
64If this is not what you are looking for, check out other popup functionality:
Bram Moolenaar957f85d2019-05-12 21:43:48 +020065- popup menu, see |popup-menu|
66- balloon, see |balloon-eval|
67
Bram Moolenaar5c017b22019-05-21 23:09:01 +020068
Bram Moolenaar931a2772019-07-04 16:54:54 +020069WINDOW POSITION AND SIZE *popup-position*
Bram Moolenaar4d784b22019-05-25 19:51:39 +020070
Bram Moolenaar68e65602019-05-26 21:33:31 +020071The height of the window is normally equal to the number of, possibly
72wrapping, lines in the buffer. It can be limited with the "maxheight"
Bram Moolenaar7dd64a32019-05-31 21:41:05 +020073property. You can use empty lines to increase the height or the "minheight"
74property.
Bram Moolenaar4d784b22019-05-25 19:51:39 +020075
76The width of the window is normally equal to the longest line in the buffer.
77It can be limited with the "maxwidth" property. You can use spaces to
Bram Moolenaar68d48f42019-06-12 22:42:41 +020078increase the width or use the "minwidth" property.
Bram Moolenaar4d784b22019-05-25 19:51:39 +020079
Bram Moolenaar042fb4b2019-06-02 14:49:56 +020080By default the 'wrap' option is set, so that no text disappears. Otherwise,
81if there is not enough space then the window is shifted left in order to
Bram Moolenaar2e62b562019-06-30 18:07:00 +020082display more text. When right-aligned the window is shifted right to display
83more text. The shifting can be disabled with the "fixed" property.
Bram Moolenaar4d784b22019-05-25 19:51:39 +020084
Bram Moolenaar7dd64a32019-05-31 21:41:05 +020085Vim tries to show the popup in the location you specify. In some cases, e.g.
86when the popup would go outside of the Vim window, it will show it somewhere
Bram Moolenaar2e62b562019-06-30 18:07:00 +020087nearby. E.g. if you use `popup_atcursor()` the popup normally shows just above
Bram Moolenaar7dd64a32019-05-31 21:41:05 +020088the current cursor position, but if the cursor is close to the top of the Vim
89window it will be placed below the cursor position.
90
Bram Moolenaar12ee7ff2019-06-10 22:47:40 +020091When the screen scrolls up for output of an Ex command, popups move too, so
92that they will not cover the output.
Bram Moolenaar4d784b22019-05-25 19:51:39 +020093
Bram Moolenaar68d48f42019-06-12 22:42:41 +020094The current cursor position is displayed even when it is under a popup window.
95That way you can still see where it is, even though you cannot see the text
96that it is in.
Bram Moolenaar868b7b62019-05-29 21:44:40 +020097
Bram Moolenaar5c017b22019-05-21 23:09:01 +020098
Bram Moolenaar931a2772019-07-04 16:54:54 +020099CLOSING THE POPUP WINDOW *popup-close*
Bram Moolenaar2e62b562019-06-30 18:07:00 +0200100
101Normally the plugin that created the popup window is also in charge of closing
102it. If somehow a popup hangs around, you can close all of them with: >
103 call popup_clear()
104Some popups, such as notifications, close after a specified time. This can be
105set with the "time" property on `popup_create()`.
106Otherwise, a popup can be closed by clicking on the X in the top-right corner
107or by clicking anywhere inside the popup. This must be enabled with the
108"close" property. It is set by default for notifications.
109
110
Bram Moolenaar931a2772019-07-04 16:54:54 +0200111POPUP BUFFER AND WINDOW *popup-buffer*
112
113If a popup function is called to create a popup from text, a new buffer is
114created to hold the text and text properties of the popup window. The buffer
115is always associated with the popup window and manipulation is restricted:
116- the buffer has no name
117- 'buftype' is "popup"
118- 'swapfile' is off
119- 'bufhidden' is "hide"
120- 'buflisted' is off
121- 'undolevels' is -1: no undo at all
122- all other buffer-local and window-local options are set to their Vim default
123 value.
124
125It is possible to change the specifically mentioned options, but anything
126might break then, so better leave them alone.
127
Bram Moolenaar06fe74a2019-08-31 16:20:32 +0200128The window does have a cursor position, but the cursor is not displayed. In
129fact, the cursor in the underlying window is displayed, as if it peeks through
130the popup, so you can see where it is.
Bram Moolenaar931a2772019-07-04 16:54:54 +0200131
132To execute a command in the context of the popup window and buffer use
133`win_execute()`. Example: >
134 call win_execute(winid, 'syntax enable')
135
136Options can be set on the window with `setwinvar()`, e.g.: >
137 call setwinvar(winid, '&wrap', 0)
138And options can be set on the buffer with `setbufvar()`, e.g.: >
139 call setbufvar(winbufnr(winid), '&filetype', 'java')
140Note that this does not trigger autocommands. Use `win_execute()` if you do
141need them.
142
143
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200144
145==============================================================================
1462. Functions *popup-functions*
147
Bram Moolenaar68d48f42019-06-12 22:42:41 +0200148Creating a popup window:
149 |popup_create()| centered in the screen
150 |popup_atcursor()| just above the cursor position, closes when
151 the cursor moves away
Bram Moolenaarb3d17a22019-07-07 18:28:14 +0200152 |popup_beval()| at the position indicated by v:beval_
153 variables, closes when the mouse moves away
Bram Moolenaara3fce622019-06-20 02:31:49 +0200154 |popup_notification()| show a notification for three seconds
Bram Moolenaar68d48f42019-06-12 22:42:41 +0200155 |popup_dialog()| centered with padding and border
156 |popup_menu()| prompt for selecting an item from a list
157
158Manipulating a popup window:
159 |popup_hide()| hide a popup temporarily
160 |popup_show()| show a previously hidden popup
161 |popup_move()| change the position and size of a popup
162 |popup_setoptions()| override options of a popup
Bram Moolenaardc2ce582019-06-16 15:32:14 +0200163 |popup_settext()| replace the popup buffer contents
Bram Moolenaar68d48f42019-06-12 22:42:41 +0200164
165Closing popup windows:
166 |popup_close()| close one popup
167 |popup_clear()| close all popups
168
169Filter functions:
170 |popup_filter_menu()| select from a list of items
171 |popup_filter_yesno()| blocks until 'y' or 'n' is pressed
172
173Other:
174 |popup_getoptions()| get current options for a popup
175 |popup_getpos()| get actual position and size of a popup
Bram Moolenaarb4f06282019-07-12 21:07:54 +0200176 |popup_locate()| find popup window at a screen position
Bram Moolenaar68d48f42019-06-12 22:42:41 +0200177
178
Bram Moolenaar931a2772019-07-04 16:54:54 +0200179DETAILS *popup-function-details*
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200180
Bram Moolenaar931a2772019-07-04 16:54:54 +0200181popup_atcursor({what}, {options}) *popup_atcursor()*
Bram Moolenaar5b8cfed2019-06-30 22:16:10 +0200182 Show the {what} above the cursor, and close it when the cursor
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200183 moves. This works like: >
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200184 call popup_create({what}, #{
Bram Moolenaar396e8292019-07-13 23:04:31 +0200185 \ pos: 'botleft',
186 \ line: 'cursor-1',
187 \ col: 'cursor',
188 \ moved: 'WORD',
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200189 \ })
190< Use {options} to change the properties.
191
Bram Moolenaar6a124e62019-09-04 18:15:19 +0200192 Can also be used as a |method|: >
193 GetText()->popup_atcursor({})
194
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200195
Bram Moolenaarb3d17a22019-07-07 18:28:14 +0200196popup_beval({what}, {options}) *popup_beval()*
197 Show the {what} above the position from 'ballooneval' and
198 close it when the mouse moves. This works like: >
199 let pos = screenpos(v:beval_winnr, v:beval_lnum, v:beval_col)
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200200 call popup_create({what}, #{
Bram Moolenaar396e8292019-07-13 23:04:31 +0200201 \ pos: 'botleft',
202 \ line: pos.row - 1,
203 \ col: pos.col,
204 \ mousemoved: 'WORD',
Bram Moolenaarb3d17a22019-07-07 18:28:14 +0200205 \ })
206< Use {options} to change the properties.
207 See |popup_beval_example| for an example use.
208
Bram Moolenaar6a124e62019-09-04 18:15:19 +0200209 Can also be used as a |method|: >
210 GetText()->popup_beval({})
211<
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200212 *popup_clear()*
213popup_clear() Emergency solution to a misbehaving plugin: close all popup
Bram Moolenaara3fce622019-06-20 02:31:49 +0200214 windows for the current tab and global popups.
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200215
216
217popup_close({id} [, {result}]) *popup_close()*
218 Close popup {id}. The window and the associated buffer will
219 be deleted.
220
221 If the popup has a callback it will be called just before the
222 popup window is deleted. If the optional {result} is present
223 it will be passed as the second argument of the callback.
224 Otherwise zero is passed to the callback.
225
Bram Moolenaar6a124e62019-09-04 18:15:19 +0200226 Can also be used as a |method|: >
227 GetPopup()->popup_close()
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200228
Bram Moolenaar5b8cfed2019-06-30 22:16:10 +0200229popup_create({what}, {options}) *popup_create()*
230 Open a popup window showing {what}, which is either:
231 - a buffer number
Bram Moolenaar5c017b22019-05-21 23:09:01 +0200232 - a string
233 - a list of strings
234 - a list of text lines with text properties
Bram Moolenaar5b8cfed2019-06-30 22:16:10 +0200235 When {what} is not a buffer number, a buffer is created with
236 'buftype' set to "popup". That buffer will be wiped out once
237 the popup closes.
Bram Moolenaar7dd64a32019-05-31 21:41:05 +0200238
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200239 {options} is a dictionary with many possible entries.
Bram Moolenaar931a2772019-07-04 16:54:54 +0200240 See |popup_create-arguments| for details.
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200241
Bram Moolenaar5c017b22019-05-21 23:09:01 +0200242 Returns a window-ID, which can be used with other popup
243 functions. Use `winbufnr()` to get the number of the buffer
244 in the window: >
245 let winid = popup_create('hello', {})
246 let bufnr = winbufnr(winid)
247 call setbufline(bufnr, 2, 'second line')
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200248< In case of failure zero is returned.
249
Bram Moolenaar6a124e62019-09-04 18:15:19 +0200250 Can also be used as a |method|: >
251 GetText()->popup_create({})
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200252
Bram Moolenaar5b8cfed2019-06-30 22:16:10 +0200253popup_dialog({what}, {options}) *popup_dialog()*
Bram Moolenaar5c017b22019-05-21 23:09:01 +0200254 Just like |popup_create()| but with these default options: >
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200255 call popup_create({what}, #{
Bram Moolenaar396e8292019-07-13 23:04:31 +0200256 \ pos: 'center',
257 \ zindex: 200,
258 \ drag: 1,
259 \ border: [],
260 \ padding: [],
Bram Moolenaar749fa0a2019-08-03 16:18:07 +0200261 \ mapping: 0,
Bram Moolenaar5c017b22019-05-21 23:09:01 +0200262 \})
Bram Moolenaar68d48f42019-06-12 22:42:41 +0200263< Use {options} to change the properties. E.g. add a 'filter'
Bram Moolenaara42d9452019-06-15 21:46:30 +0200264 option with value 'popup_filter_yesno'. Example: >
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200265 call popup_create('do you want to quit (Yes/no)?', #{
Bram Moolenaar396e8292019-07-13 23:04:31 +0200266 \ filter: 'popup_filter_yesno',
267 \ callback: 'QuitCallback',
Bram Moolenaara42d9452019-06-15 21:46:30 +0200268 \ })
269
270< By default the dialog can be dragged, so that text below it
271 can be read if needed.
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200272
Bram Moolenaar6a124e62019-09-04 18:15:19 +0200273 Can also be used as a |method|: >
274 GetText()->popup_dialog({})
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200275
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200276popup_filter_menu({id}, {key}) *popup_filter_menu()*
Bram Moolenaara730e552019-06-16 19:05:31 +0200277 Filter that can be used for a popup. These keys can be used:
Bram Moolenaara3fce622019-06-20 02:31:49 +0200278 j <Down> select item below
Bram Moolenaara730e552019-06-16 19:05:31 +0200279 k <Up> select item above
280 <Space> <Enter> accept current selection
281 x Esc CTRL-C cancel the menu
282 Other keys are ignored.
283
284 A match is set on that line to highlight it, see
285 |popup_menu()|.
286
287 When the current selection is accepted the "callback" of the
288 popup menu is invoked with the index of the selected line as
289 the second argument. The first entry has index one.
290 Cancelling the menu invokes the callback with -1.
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200291
Bram Moolenaara3fce622019-06-20 02:31:49 +0200292 To add shortcut keys, see the example here:
293 |popup_menu-shortcut-example|
294
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200295
296popup_filter_yesno({id}, {key}) *popup_filter_yesno()*
297 Filter that can be used for a popup. It handles only the keys
298 'y', 'Y' and 'n' or 'N'. Invokes the "callback" of the
299 popup menu with the 1 for 'y' or 'Y' and zero for 'n' or 'N'
Bram Moolenaara42d9452019-06-15 21:46:30 +0200300 as the second argument. Pressing Esc and 'x' works like
301 pressing 'n'. CTRL-C invokes the callback with -1. Other
302 keys are ignored.
Bram Moolenaara3fce622019-06-20 02:31:49 +0200303 See the example here: |popup_dialog-example|
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200304
305
Bram Moolenaarc7c5f102019-08-21 18:31:03 +0200306popup_findinfo() *popup_findinfo()*
307 Get the |window-ID| for the popup info window, as it used by
308 the popup menu. See |complete-popup|. The info popup is
309 hidden when not used, it can be deleted with |popup_clear()|
310 and |popup_close()|.
311 Return zero if there is none.
312
313
314popup_findpreview() *popup_findpreview()*
315 Get the |window-ID| for the popup preview window.
316 Return zero if there is none.
317
318
319
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200320popup_getoptions({id}) *popup_getoptions()*
Bram Moolenaar8c2a6002019-05-30 14:29:45 +0200321 Return the {options} for popup {id} in a Dict.
Bram Moolenaarac1f1bc2019-05-30 21:24:26 +0200322 A zero value means the option was not set. For "zindex" the
323 default value is returned, not zero.
Bram Moolenaar8c2a6002019-05-30 14:29:45 +0200324
Bram Moolenaarb3d17a22019-07-07 18:28:14 +0200325 The "moved" entry is a list with line number, minimum and
326 maximum column, [0, 0, 0] when not set.
327
328 The "mousemoved" entry is a list with screen row, minimum and
329 maximum screen column, [0, 0, 0] when not set.
Bram Moolenaar8c2a6002019-05-30 14:29:45 +0200330
Bram Moolenaar06fe74a2019-08-31 16:20:32 +0200331 "firstline" is the property set on the popup, unlike the
332 "firstline" obtained with |popup_getpos()| which is the actual
333 buffer line at the top of the popup window.
334
Bram Moolenaarae943152019-06-16 22:54:14 +0200335 "border" and "padding" are not included when all values are
336 zero. When all values are one then an empty list is included.
337
338 "borderhighlight" is not included when all values are empty.
Bram Moolenaardf9c6ca2019-07-18 13:46:42 +0200339 "scrollbarhighlight" and "thumbhighlight" are only included
Bram Moolenaarf9c85f52019-06-29 07:41:35 +0200340 when set.
Bram Moolenaarae943152019-06-16 22:54:14 +0200341
Bram Moolenaara3fce622019-06-20 02:31:49 +0200342 "tabpage" will be -1 for a global popup, zero for a popup on
343 the current tabpage and a positive number for a popup on
344 another tabpage.
345
Bram Moolenaar12034e22019-08-25 22:25:02 +0200346 "textprop", "textpropid" and "textpropwin" are only present
347 when "textprop" was set.
348
Bram Moolenaarae943152019-06-16 22:54:14 +0200349 If popup window {id} is not found an empty Dict is returned.
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200350
Bram Moolenaar6a124e62019-09-04 18:15:19 +0200351 Can also be used as a |method|: >
352 GetPopup()->popup_getoptions()
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200353
Bram Moolenaarac1f1bc2019-05-30 21:24:26 +0200354popup_getpos({id}) *popup_getpos()*
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200355 Return the position and size of popup {id}. Returns a Dict
356 with these entries:
Bram Moolenaar8c2a6002019-05-30 14:29:45 +0200357 col screen column of the popup, one-based
358 line screen line of the popup, one-based
Bram Moolenaar2fd8e352019-06-01 20:16:48 +0200359 width width of the whole popup in screen cells
360 height height of the whole popup in screen cells
361 core_col screen column of the text box
362 core_line screen line of the text box
363 core_width width of the text box in screen cells
364 core_height height of the text box in screen cells
Bram Moolenaar68acb412019-06-26 03:40:36 +0200365 firstline line of the buffer at top (1 unless scrolled)
Bram Moolenaar06fe74a2019-08-31 16:20:32 +0200366 (not the value of the "firstline" property)
Bram Moolenaar68acb412019-06-26 03:40:36 +0200367 scrollbar non-zero if a scrollbar is displayed
Bram Moolenaar12ee7ff2019-06-10 22:47:40 +0200368 visible one if the popup is displayed, zero if hidden
Bram Moolenaarbc133542019-05-29 20:26:46 +0200369 Note that these are the actual screen positions. They differ
370 from the values in `popup_getoptions()` for the sizing and
371 positioning mechanism applied.
Bram Moolenaar2fd8e352019-06-01 20:16:48 +0200372
373 The "core_" values exclude the padding and border.
374
Bram Moolenaarbc133542019-05-29 20:26:46 +0200375 If popup window {id} is not found an empty Dict is returned.
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200376
Bram Moolenaar6a124e62019-09-04 18:15:19 +0200377 Can also be used as a |method|: >
378 GetPopup()->popup_getpos()
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200379
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200380popup_hide({id}) *popup_hide()*
381 If {id} is a displayed popup, hide it now. If the popup has a
382 filter it will not be invoked for so long as the popup is
383 hidden.
384 If window {id} does not exist nothing happens. If window {id}
385 exists but is not a popup window an error is given. *E993*
386
Bram Moolenaar6a124e62019-09-04 18:15:19 +0200387 Can also be used as a |method|: >
388 GetPopup()->popup_hide()
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200389
Bram Moolenaarb4f06282019-07-12 21:07:54 +0200390popup_locate({row}, {col}) *popup_locate()*
Bram Moolenaardf9c6ca2019-07-18 13:46:42 +0200391 Return the |window-ID| of the popup at screen position {row}
Bram Moolenaarb4f06282019-07-12 21:07:54 +0200392 and {col}. If there are multiple popups the one with the
393 highest zindex is returned. If there are no popups at this
394 position then zero is returned.
395
396
Bram Moolenaar5b8cfed2019-06-30 22:16:10 +0200397popup_menu({what}, {options}) *popup_menu()*
398 Show the {what} near the cursor, handle selecting one of the
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200399 items with cursorkeys, and close it an item is selected with
Bram Moolenaar5b8cfed2019-06-30 22:16:10 +0200400 Space or Enter. {what} should have multiple lines to make this
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200401 useful. This works like: >
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200402 call popup_create({what}, #{
Bram Moolenaar396e8292019-07-13 23:04:31 +0200403 \ pos: 'center',
404 \ zindex: 200,
405 \ drag: 1,
406 \ wrap: 0,
407 \ border: [],
Bram Moolenaardf9c6ca2019-07-18 13:46:42 +0200408 \ cursorline: 1,
Bram Moolenaar03464132019-07-14 16:28:13 +0200409 \ padding: [0,1,0,1],
Bram Moolenaar396e8292019-07-13 23:04:31 +0200410 \ filter: 'popup_filter_menu',
Bram Moolenaar749fa0a2019-08-03 16:18:07 +0200411 \ mapping: 0,
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200412 \ })
Bram Moolenaara730e552019-06-16 19:05:31 +0200413< The current line is highlighted with a match using
Bram Moolenaar6c1e1572019-06-22 02:13:00 +0200414 "PopupSelected", or "PmenuSel" if that is not defined.
Bram Moolenaara730e552019-06-16 19:05:31 +0200415
416 Use {options} to change the properties. Should at least set
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200417 "callback" to a function that handles the selected item.
Bram Moolenaar749fa0a2019-08-03 16:18:07 +0200418 Example: >
419 func ColorSelected(id, result)
420 " use a:result
421 endfunc
422 call popup_menu(['red', 'green', 'blue'], #{
423 \ callback: 'ColorSelected',
424 \ })
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200425
Bram Moolenaar6a124e62019-09-04 18:15:19 +0200426< Can also be used as a |method|: >
427 GetChoices()->popup_menu({})
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200428
429popup_move({id}, {options}) *popup_move()*
Bram Moolenaarb53fb312019-06-13 23:59:52 +0200430 Move popup {id} to the position specified with {options}.
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200431 {options} may contain the items from |popup_create()| that
Bram Moolenaarae943152019-06-16 22:54:14 +0200432 specify the popup position:
433 line
434 col
435 pos
436 maxheight
437 minheight
438 maxwidth
439 minwidth
440 fixed
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200441 For {id} see `popup_hide()`.
Bram Moolenaarae943152019-06-16 22:54:14 +0200442 For other options see |popup_setoptions()|.
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200443
Bram Moolenaar6a124e62019-09-04 18:15:19 +0200444 Can also be used as a |method|: >
445 GetPopup()->popup_move(options)
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200446
Bram Moolenaar5b8cfed2019-06-30 22:16:10 +0200447popup_notification({what}, {options}) *popup_notification()*
448 Show the {what} for 3 seconds at the top of the Vim window.
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200449 This works like: >
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200450 call popup_create({what}, #{
Bram Moolenaar396e8292019-07-13 23:04:31 +0200451 \ line: 1,
452 \ col: 10,
453 \ minwidth: 20,
454 \ time: 3000,
455 \ tabpage: -1,
456 \ zindex: 300,
457 \ drag: 1,
458 \ highlight: 'WarningMsg',
459 \ border: [],
460 \ close: 'click',
461 \ padding: [0,1,0,1],
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200462 \ })
Bram Moolenaardfa97f22019-06-15 14:31:55 +0200463< The PopupNotification highlight group is used instead of
464 WarningMsg if it is defined.
Bram Moolenaara730e552019-06-16 19:05:31 +0200465
Bram Moolenaar581ba392019-09-03 22:08:33 +0200466 Without the |+timers| feature the popup will not disappear
Bram Moolenaar2e62b562019-06-30 18:07:00 +0200467 automatically, the user has to click in it.
Bram Moolenaar75fb0852019-06-25 05:15:58 +0200468
Bram Moolenaara730e552019-06-16 19:05:31 +0200469 The position will be adjusted to avoid overlap with other
Bram Moolenaar68d48f42019-06-12 22:42:41 +0200470 notifications.
471 Use {options} to change the properties.
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200472
Bram Moolenaar6a124e62019-09-04 18:15:19 +0200473 Can also be used as a |method|: >
474 GetText()->popup_notification({})
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200475
476popup_show({id}) *popup_show()*
477 If {id} is a hidden popup, show it now.
478 For {id} see `popup_hide()`.
479
480
481popup_setoptions({id}, {options}) *popup_setoptions()*
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200482 Override options in popup {id} with entries in {options}.
Bram Moolenaarae943152019-06-16 22:54:14 +0200483 These options can be set:
Bram Moolenaarae943152019-06-16 22:54:14 +0200484 border
Bram Moolenaarae943152019-06-16 22:54:14 +0200485 borderchars
Bram Moolenaar2e62b562019-06-30 18:07:00 +0200486 borderhighlight
487 callback
488 close
Bram Moolenaardf9c6ca2019-07-18 13:46:42 +0200489 cursorline
Bram Moolenaar749fa0a2019-08-03 16:18:07 +0200490 drag
Bram Moolenaar2e62b562019-06-30 18:07:00 +0200491 filter
492 firstline
493 flip
494 highlight
Bram Moolenaar749fa0a2019-08-03 16:18:07 +0200495 mapping
Bram Moolenaar2e62b562019-06-30 18:07:00 +0200496 mask
497 moved
498 padding
Bram Moolenaar749fa0a2019-08-03 16:18:07 +0200499 resize
Bram Moolenaar75fb0852019-06-25 05:15:58 +0200500 scrollbar
Bram Moolenaarf9c85f52019-06-29 07:41:35 +0200501 scrollbarhighlight
502 thumbhighlight
Bram Moolenaarae943152019-06-16 22:54:14 +0200503 time
Bram Moolenaar2e62b562019-06-30 18:07:00 +0200504 title
505 wrap
506 zindex
Bram Moolenaarae943152019-06-16 22:54:14 +0200507 The options from |popup_move()| can also be used.
508 For "hidden" use |popup_hide()| and |popup_show()|.
509 "tabpage" cannot be changed.
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200510
Bram Moolenaar6a124e62019-09-04 18:15:19 +0200511 Can also be used as a |method|: >
512 GetPopup()->popup_setoptions(options)
513
Bram Moolenaardc2ce582019-06-16 15:32:14 +0200514popup_settext({id}, {text}) *popup_settext()*
Bram Moolenaar581ba392019-09-03 22:08:33 +0200515 Set the text of the buffer in popup win {id}. {text} is the
Bram Moolenaar5b8cfed2019-06-30 22:16:10 +0200516 same as supplied to |popup_create()|, except that a buffer
517 number is not allowed.
Bram Moolenaardc2ce582019-06-16 15:32:14 +0200518 Does not change the window size or position, other than caused
519 by the different text.
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200520
Bram Moolenaar6a124e62019-09-04 18:15:19 +0200521 Can also be used as a |method|: >
522 GetPopup()->popup_settext('hello')
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200523
Bram Moolenaar931a2772019-07-04 16:54:54 +0200524==============================================================================
5253. Usage *popup-usage*
Bram Moolenaar5c017b22019-05-21 23:09:01 +0200526
Bram Moolenaar931a2772019-07-04 16:54:54 +0200527POPUP_CREATE() ARGUMENTS *popup_create-arguments*
Bram Moolenaar5c017b22019-05-21 23:09:01 +0200528
Bram Moolenaardc2ce582019-06-16 15:32:14 +0200529The first argument of |popup_create()| (and the second argument to
Bram Moolenaar6c1e1572019-06-22 02:13:00 +0200530|popup_settext()|) specifies the text to be displayed, and optionally text
Bram Moolenaar5b8cfed2019-06-30 22:16:10 +0200531properties. It is in one of four forms:
532- a buffer number
Bram Moolenaar5c017b22019-05-21 23:09:01 +0200533- a string
534- a list of strings
535- a list of dictionaries, where each dictionary has these entries:
536 text String with the text to display.
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200537 props A list of text properties. Optional.
538 Each entry is a dictionary, like the third argument of
539 |prop_add()|, but specifying the column in the
540 dictionary with a "col" entry, see below:
541 |popup-props|.
542
Bram Moolenaar5c017b22019-05-21 23:09:01 +0200543The second argument of |popup_create()| is a dictionary with options:
Bram Moolenaar042fb4b2019-06-02 14:49:56 +0200544 line Screen line where to position the popup. Can use a
Bram Moolenaarac1f1bc2019-05-30 21:24:26 +0200545 number or "cursor", "cursor+1" or "cursor-1" to use
546 the line of the cursor and add or subtract a number of
Bram Moolenaar042fb4b2019-06-02 14:49:56 +0200547 lines. If omitted the popup is vertically centered.
548 The first line is 1.
Bram Moolenaar12034e22019-08-25 22:25:02 +0200549 When using "textprop" the number is relative to the
550 text property and can be negative.
Bram Moolenaar042fb4b2019-06-02 14:49:56 +0200551 col Screen column where to position the popup. Can use a
Bram Moolenaarac1f1bc2019-05-30 21:24:26 +0200552 number or "cursor" to use the column of the cursor,
Bram Moolenaar042fb4b2019-06-02 14:49:56 +0200553 "cursor+9" or "cursor-9" to add or subtract a number
554 of columns. If omitted the popup is horizontally
555 centered. The first column is 1.
Bram Moolenaar12034e22019-08-25 22:25:02 +0200556 When using "textprop" the number is relative to the
557 text property and can be negative.
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200558 pos "topleft", "topright", "botleft" or "botright":
559 defines what corner of the popup "line" and "col" are
Bram Moolenaar8c2a6002019-05-30 14:29:45 +0200560 used for. When not set "topleft" is used.
561 Alternatively "center" can be used to position the
Bram Moolenaarac1f1bc2019-05-30 21:24:26 +0200562 popup in the center of the Vim window, in which case
563 "line" and "col" are ignored.
Bram Moolenaar12034e22019-08-25 22:25:02 +0200564 textprop When present the popup is positioned next to a text
565 property with this name and will move when the text
566 property moves. Use an empty string to remove. See
567 |popup-textprop-pos|.
568 textpropwin What window to search for the text property. When
569 omitted or invalid the current window is used.
570 textpropid Used to identify the text property when "textprop" is
571 present. Use zero to reset.
Bram Moolenaar042fb4b2019-06-02 14:49:56 +0200572 fixed When FALSE (the default), and:
573 - "pos" is "botleft" or "topleft", and
574 - "wrap" is off, and
575 - the popup would be truncated at the right edge of
576 the screen, then
577 the popup is moved to the left so as to fit the
578 contents on the screen. Set to TRUE to disable this.
579 flip When TRUE (the default) and the position is relative
Bram Moolenaar5c017b22019-05-21 23:09:01 +0200580 to the cursor, flip to below or above the cursor to
581 avoid overlap with the |popupmenu-completion| or
Bram Moolenaardc2ce582019-06-16 15:32:14 +0200582 another popup with a higher "zindex". When there is
583 no space above/below the cursor then show the popup to
584 the side of the popup or popup menu.
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200585 {not implemented yet}
Bram Moolenaar042fb4b2019-06-02 14:49:56 +0200586 maxheight Maximum height of the contents, excluding border and
587 padding.
588 minheight Minimum height of the contents, excluding border and
589 padding.
Bram Moolenaar54775062019-07-31 21:07:14 +0200590 maxwidth Maximum width of the contents, excluding border,
591 padding and scrollbar.
592 minwidth Minimum width of the contents, excluding border,
593 padding and scrollbar.
Bram Moolenaar8d241042019-06-12 23:40:01 +0200594 firstline First buffer line to display. When larger than one it
595 looks like the text scrolled up. When out of range
596 the last buffer line will at the top of the window.
Bram Moolenaar06fe74a2019-08-31 16:20:32 +0200597 Set to zero to leave the position as set by commands.
Bram Moolenaar75fb0852019-06-25 05:15:58 +0200598 Also see "scrollbar".
Bram Moolenaar042fb4b2019-06-02 14:49:56 +0200599 hidden When TRUE the popup exists but is not displayed; use
Bram Moolenaar5c017b22019-05-21 23:09:01 +0200600 `popup_show()` to unhide it.
Bram Moolenaar6c1e1572019-06-22 02:13:00 +0200601 tabpage When -1: display the popup on all tab pages.
Bram Moolenaar042fb4b2019-06-02 14:49:56 +0200602 When 0 (the default): display the popup on the current
Bram Moolenaarfc06cbb2019-06-15 14:14:31 +0200603 tab page.
Bram Moolenaar042fb4b2019-06-02 14:49:56 +0200604 Otherwise the number of the tab page the popup is
Bram Moolenaara3fce622019-06-20 02:31:49 +0200605 displayed on; when invalid the popup is not created
Bram Moolenaarb2cda0d2019-06-24 05:06:36 +0200606 and an error is given. *E997*
Bram Moolenaar042fb4b2019-06-02 14:49:56 +0200607 title Text to be displayed above the first item in the
608 popup, on top of any border. If there is no top
Bram Moolenaarb53fb312019-06-13 23:59:52 +0200609 border one line of padding is added to put the title
Bram Moolenaareb2310d2019-06-16 20:09:10 +0200610 on. You might want to add one or more spaces at the
611 start and end as padding.
Bram Moolenaar042fb4b2019-06-02 14:49:56 +0200612 wrap TRUE to make the lines wrap (default TRUE).
Bram Moolenaarb53fb312019-06-13 23:59:52 +0200613 drag TRUE to allow the popup to be dragged with the mouse
Bram Moolenaar581ba392019-09-03 22:08:33 +0200614 by grabbing at the border. Has no effect if the
Bram Moolenaardc2ce582019-06-16 15:32:14 +0200615 popup does not have a border. As soon as dragging
616 starts and "pos" is "center" it is changed to
617 "topleft".
Bram Moolenaar9bcb70c2019-08-01 21:11:05 +0200618 resize TRUE to allow the popup to be resized with the mouse
Bram Moolenaar581ba392019-09-03 22:08:33 +0200619 by grabbing at the bottom right corner. Has no effect
620 if the popup does not have a border.
Bram Moolenaar2e62b562019-06-30 18:07:00 +0200621 close When "button" an X is displayed in the top-right, on
622 top of any border, padding or text. When clicked on
623 the X the popup will close. Any callback is invoked
624 with the value -2.
625 When "click" any mouse click in the popup will close
626 it.
627 When "none" (the default) mouse clicks do not close
628 the popup window.
Bram Moolenaar042fb4b2019-06-02 14:49:56 +0200629 highlight Highlight group name to use for the text, stored in
630 the 'wincolor' option.
631 padding List with numbers, defining the padding
632 above/right/below/left of the popup (similar to CSS).
633 An empty list uses a padding of 1 all around. The
634 padding goes around the text, inside any border.
635 Padding uses the 'wincolor' highlight.
636 Example: [1, 2, 1, 3] has 1 line of padding above, 2
637 columns on the right, 1 line below and 3 columns on
638 the left.
639 border List with numbers, defining the border thickness
640 above/right/below/left of the popup (similar to CSS).
641 Only values of zero and non-zero are recognized.
642 An empty list uses a border all around.
643 borderhighlight List of highlight group names to use for the border.
644 When one entry it is used for all borders, otherwise
645 the highlight for the top/right/bottom/left border.
646 Example: ['TopColor', 'RightColor', 'BottomColor,
647 'LeftColor']
648 borderchars List with characters, defining the character to use
649 for the top/right/bottom/left border. Optionally
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200650 followed by the character to use for the
Bram Moolenaar042fb4b2019-06-02 14:49:56 +0200651 topleft/topright/botright/botleft corner.
652 Example: ['-', '|', '-', '|', '┌', '┐', '┘', '└']
653 When the list has one character it is used for all.
654 When the list has two characters the first is used for
655 the border lines, the second for the corners.
656 By default a double line is used all around when
Bram Moolenaar6c1e1572019-06-22 02:13:00 +0200657 'encoding' is "utf-8" and 'ambiwidth' is "single",
Bram Moolenaara3fce622019-06-20 02:31:49 +0200658 otherwise ASCII characters are used.
Bram Moolenaar75fb0852019-06-25 05:15:58 +0200659 scrollbar non-zero: show a scrollbar when the text doesn't fit.
660 zero: do not show a scrollbar. Default is non-zero.
Bram Moolenaarf9c85f52019-06-29 07:41:35 +0200661 Also see |popup-scrollbar|.
662 scrollbarhighlight Highlight group name for the scrollbar. The
663 background color is what matters. When not given then
664 PmenuSbar is used.
665 thumbhighlight Highlight group name for the scrollbar thumb. The
666 background color is what matters. When not given then
667 PmenuThumb is used.
Bram Moolenaarb53fb312019-06-13 23:59:52 +0200668 zindex Priority for the popup, default 50. Minimum value is
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200669 1, maximum value is 32000.
Bram Moolenaarc662ec92019-06-23 00:15:57 +0200670 mask A list of lists with coordinates, defining parts of
671 the popup that are transparent. See |popup-mask|.
Bram Moolenaar042fb4b2019-06-02 14:49:56 +0200672 time Time in milliseconds after which the popup will close.
673 When omitted |popup_close()| must be used.
Bram Moolenaar3397f742019-06-02 18:40:06 +0200674 moved Specifies to close the popup if the cursor moved:
675 - "any": if the cursor moved at all
676 - "word": if the cursor moved outside |<cword>|
677 - "WORD": if the cursor moved outside |<cWORD>|
Bram Moolenaarb3d17a22019-07-07 18:28:14 +0200678 - "expr": if the cursor moved outside |<cexpr>|
Bram Moolenaar3397f742019-06-02 18:40:06 +0200679 - [{start}, {end}]: if the cursor moved before column
680 {start} or after {end}
681 The popup also closes if the cursor moves to another
682 line or to another window.
Bram Moolenaardf9c6ca2019-07-18 13:46:42 +0200683 cursorline non-zero: Highlight the cursor line. Also scrolls the
684 text to show this line (only works properly
685 when 'wrap' is off).
686 zero: Do not highlight the cursor line.
687 Default is zero, except for |popup_menu()|.
Bram Moolenaar12ee7ff2019-06-10 22:47:40 +0200688 filter A callback that can filter typed characters, see
Bram Moolenaar042fb4b2019-06-02 14:49:56 +0200689 |popup-filter|.
Bram Moolenaar749fa0a2019-08-03 16:18:07 +0200690 mapping Allow for key mapping. When FALSE and the popup is
691 visible and has a filter callback key mapping is
692 disabled. Default value is TRUE.
Bram Moolenaar581ba392019-09-03 22:08:33 +0200693 filtermode In which modes the filter is used (same flags as with
694 |hasmapto()| plus "a"):
695 n Normal mode
696 v Visual and Select mode
697 x Visual mode
698 s Select mode
699 o Operator-pending mode
700 i Insert mode
701 l Language-Argument ("r", "f", "t", etc.)
702 c Command-line mode
703 a all modes
704 The default value is "a".
Bram Moolenaar042fb4b2019-06-02 14:49:56 +0200705 callback A callback that is called when the popup closes, e.g.
706 when using |popup_filter_menu()|, see |popup-callback|.
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200707
708Depending on the "zindex" the popup goes under or above other popups. The
709completion menu (|popup-menu|) has zindex 100. For messages that occur for a
710short time the suggestion is to use zindex 1000.
711
712By default text wraps, which causes a line in {lines} to occupy more than one
713screen line. When "wrap" is FALSE then the text outside of the popup or
714outside of the Vim window will not be displayed, thus truncated.
715
716
717POPUP TEXT PROPERTIES *popup-props*
718
Bram Moolenaar7a8d0272019-05-26 23:32:06 +0200719These are similar to the third argument of |prop_add()| except:
720- "lnum" is always the current line in the list
721- "bufnr" is always the buffer of the popup
722- "col" is in the Dict instead of a separate argument
Bram Moolenaar7a8d0272019-05-26 23:32:06 +0200723So we get:
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200724 col starting column, counted in bytes, use one for the
725 first column.
726 length length of text in bytes; can be zero
Bram Moolenaar7a8d0272019-05-26 23:32:06 +0200727 end_lnum line number for the end of the text
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200728 end_col column just after the text; not used when "length" is
729 present; when {col} and "end_col" are equal, this is a
730 zero-width text property
731 id user defined ID for the property; when omitted zero is
732 used
733 type name of the text property type, as added with
734 |prop_type_add()|
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200735
736
Bram Moolenaar12034e22019-08-25 22:25:02 +0200737POSITION POPUP WITH TEXTPROP *popup-textprop-pos*
738
739Positioning a popup next to a text property causes the popup to move when text
740is inserted or deleted. The popup functions like a tooltip.
741
742These steps are needed to make this work:
743
744- Define a text property type, it defines the name. >
745 call prop_type_add('popupMarker', {})
746
747- Place a text property at the desired text: >
748 let lnum = {line of the text}
749 let col = {start column of the text}
750 let len = {length of the text}
751 let propId = {arbitrary but unique number}
752 call prop_add(lnum, col, #{
753 \ length: len,
754 \ type: 'popupMarker',
755 \ id: propId,
756 \ })
757
758- Create a popup: >
759 let winid = popup_create('the text', #{
760 \ pos: 'botleft',
761 \ textprop: 'popupMarker',
762 \ textpropid: propId,
763 \ border: [],
764 \ padding: [0,1,0,1],
765 \ close: 'click',
766 \ })
767
768By default the popup is positioned at the corner of the text, opposite of the
769"pos" specified for the popup. Thus when the popup uses "botleft", the
770bottom-left corner of the popup is positioned next to the top-right corner of
771the text property:
772 +----------+
773 | the text |
774 +----------+
775 just some PROPERTY as an example
776
777Here the text property is on "PROPERTY". Move the popup to the left by
778passing a negative "col" value to popup_create(). With "col: -5" you get:
779
780 +----------+
781 | the text |
782 +----------+
783 just some PROPERTY as an example
784
785If the text property moves out of view then the popup will be hidden.
786If the window for which the popup was defined is closed, the popup is closed.
787
788If the popup cannot fit in the desired position, it may show at a nearby
789position.
790
791Some hints:
792- To avoid collision with other plugins the text property type name has to be
793 unique. You can also use the "bufnr" item to make it local to a buffer.
794- You can leave out the text property ID if there is only ever one text
795 property visible.
796- The popup may be in the way of what the user is doing, making it close with
797 a click, as in the example above, helps for that.
798- If the text property is removed the popup is closed. Use something like
799 this: >
800 call prop_remove(#{type: 'popupMarker', id: propId})
801
802
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200803POPUP FILTER *popup-filter*
804
Bram Moolenaar5c017b22019-05-21 23:09:01 +0200805A callback that gets any typed keys while a popup is displayed. The filter is
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200806not invoked when the popup is hidden.
Bram Moolenaar5c017b22019-05-21 23:09:01 +0200807
808The filter can return TRUE to indicate the key has been handled and is to be
809discarded, or FALSE to let Vim handle the key as usual in the current state.
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200810In case it returns FALSE and there is another popup window visible, that
811filter is also called. The filter of the popup window with the highest zindex
812is called first.
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200813
814The filter function is called with two arguments: the ID of the popup and the
Bram Moolenaara42d9452019-06-15 21:46:30 +0200815key as a string, e.g.: >
Bram Moolenaarbf0eff02019-06-01 17:13:36 +0200816 func MyFilter(winid, key)
817 if a:key == "\<F2>"
818 " do something
819 return 1
820 endif
821 if a:key == 'x'
822 call popup_close(a:winid)
823 return 1
824 endif
825 return 0
Bram Moolenaar12ee7ff2019-06-10 22:47:40 +0200826 endfunc
Bram Moolenaar581ba392019-09-03 22:08:33 +0200827< *popup-filter-mode*
828The "filtermode" property can be used to specify in what mode the filter is
829invoked. The default is "a": all modes. When using "nvi" Command-line mode
830is not included, so that any command typed on the command line is not
831filtered. However, to get to Command-line mode the filter must not consume
832":". Just like it must not consume "v" to allow for entering Visual mode.
833
834 *popup-mapping*
Bram Moolenaar749fa0a2019-08-03 16:18:07 +0200835Normally the key is what results after any mapping, since the keys pass on as
836normal input if the filter does not use it. If the filter consumes all the
837keys, set the "mapping" property to zero so that mappings do not get in the
838way. This is default for |popup_menu()| and |popup_dialog()|.
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200839
Bram Moolenaar581ba392019-09-03 22:08:33 +0200840Some recommended key actions:
Bram Moolenaarbf0eff02019-06-01 17:13:36 +0200841 x close the popup (see note below)
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200842 cursor keys select another entry
843 Tab accept current suggestion
844
Bram Moolenaar5c017b22019-05-21 23:09:01 +0200845A mouse click arrives as <LeftMouse>. The coordinates are in
846v:mouse_popup_col and v:mouse_popup_row. The top-left screen cell of the
847popup is col 1, row 1 (not counting the border).
848
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200849Vim provides standard filters |popup_filter_menu()| and
850|popup_filter_yesno()|.
851
Bram Moolenaarbf0eff02019-06-01 17:13:36 +0200852Note that "x" is the normal way to close a popup. You may want to use Esc,
853but since many keys start with an Esc character, there may be a delay before
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200854Vim recognizes the Esc key. If you do use Esc, it is recommended to set the
Bram Moolenaarbf0eff02019-06-01 17:13:36 +0200855'ttimeoutlen' option to 100 and set 'timeout' and/or 'ttimeout'.
856
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200857
858POPUP CALLBACK *popup-callback*
859
Bram Moolenaara42d9452019-06-15 21:46:30 +0200860A callback that is invoked when the popup closes.
Bram Moolenaar9eaac892019-06-01 22:49:29 +0200861
862The callback is invoked with two arguments: the ID of the popup window and the
863result, which could be an index in the popup lines, or whatever was passed as
864the second argument of `popup_close()`.
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200865
Bram Moolenaara42d9452019-06-15 21:46:30 +0200866If the popup is force-closed, e.g. because the cursor moved or CTRL-C was
867pressed, the number -1 is passed to the callback.
Bram Moolenaar3397f742019-06-02 18:40:06 +0200868
Bram Moolenaar749fa0a2019-08-03 16:18:07 +0200869Example: >
870 func SelectedColor(id, result)
871 echo 'choice made: ' .. a:result
872 endfunc
873
Bram Moolenaarc662ec92019-06-23 00:15:57 +0200874
Bram Moolenaarf9c85f52019-06-29 07:41:35 +0200875POPUP SCROLLBAR *popup-scrollbar*
876
877If the text does not fit in the popup a scrollbar is displayed on the right of
878the window. This can be disabled by setting the "scrollbar" option to zero.
879When the scrollbar is displayed mouse scroll events, while the mouse pointer
880is on the popup, will cause the text to scroll up or down as you would expect.
Bram Moolenaar85850f32019-07-19 22:05:51 +0200881A click in the upper half of the scrollbar will scroll the text down one line.
882A click in the lower half will scroll the text up one line. However, this is
883limited so that the popup does not get smaller.
Bram Moolenaarf9c85f52019-06-29 07:41:35 +0200884
885
Bram Moolenaarc662ec92019-06-23 00:15:57 +0200886POPUP MASK *popup-mask*
887
888To minimize the text that the popup covers, parts of it can be made
889transparent. This is defined by a "mask" which is a list of lists, where each
890list has four numbers:
891 col start column, positive for counting from the left, 1 for
892 leftmost, negative for counting from the right, -1 for
893 rightmost
894 endcol last column, like "col"
Bram Moolenaardf9c6ca2019-07-18 13:46:42 +0200895 line start line, positive for counting from the top, 1 for top,
Bram Moolenaarc662ec92019-06-23 00:15:57 +0200896 negative for counting from the bottom, -1 for bottom
897 endline end line, like "line"
898
899For example, to make the last 10 columns of the last line transparent:
900 [[-10, -1, -1, -1]]
901
902To make the four corners transparent:
903 [[1, 1, 1, 1], [-1, -1, 1, 1], [1, 1, -1, -1], [-1, -1, -1, -1]]
904
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200905==============================================================================
Bram Moolenaar931a2772019-07-04 16:54:54 +02009064. Examples *popup-examples*
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200907
Bram Moolenaar931a2772019-07-04 16:54:54 +0200908TODO: more interesting examples
Bram Moolenaara3fce622019-06-20 02:31:49 +0200909 *popup_dialog-example*
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200910Prompt the user to press y/Y or n/N: >
911
912 func MyDialogHandler(id, result)
913 if a:result
914 " ... 'y' or 'Y' was pressed
915 endif
916 endfunc
917
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200918 call popup_dialog('Continue? y/n', #{
Bram Moolenaar396e8292019-07-13 23:04:31 +0200919 \ filter: 'popup_filter_yesno',
920 \ callback: 'MyDialogHandler',
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200921 \ })
922<
Bram Moolenaara3fce622019-06-20 02:31:49 +0200923 *popup_menu-shortcut-example*
924Extend popup_filter_menu() with shortcut keys: >
925
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200926 call popup_menu(['Save', 'Cancel', 'Discard'], #{
Bram Moolenaar396e8292019-07-13 23:04:31 +0200927 \ filter: 'MyMenuFilter',
928 \ callback: 'MyMenuHandler',
Bram Moolenaara3fce622019-06-20 02:31:49 +0200929 \ })
930
931 func MyMenuFilter(id, key)
932 " Handle shortcuts
933 if a:key == 'S'
934 call popup_close(a:id, 1)
935 return 1
936 endif
937 if a:key == 'C'
938 call popup_close(a:id, 2)
939 return 1
940 endif
941 if a:key == 'D'
942 call popup_close(a:id, 3)
943 return 1
944 endif
945
946 " No shortcut, pass to generic filter
947 return popup_filter_menu(a:id, a:key)
948 endfunc
949<
Bram Moolenaarb3d17a22019-07-07 18:28:14 +0200950 *popup_beval_example*
951Example for using a popup window for 'ballooneval': >
952
953 set ballooneval balloonevalterm
954 set balloonexpr=BalloonExpr()
955 let s:winid = 0
Bram Moolenaarb05caa72019-07-10 21:55:54 +0200956 let s:last_text = ''
Bram Moolenaarb3d17a22019-07-07 18:28:14 +0200957
958 func BalloonExpr()
Bram Moolenaarb05caa72019-07-10 21:55:54 +0200959 if s:winid && popup_getpos(s:winid) != {}
960 " previous popup window still shows
961 if v:beval_text == s:last_text
962 " Still the same text, keep the existing popup
963 return ''
964 endif
Bram Moolenaarb3d17a22019-07-07 18:28:14 +0200965 call popup_close(s:winid)
Bram Moolenaarb3d17a22019-07-07 18:28:14 +0200966 endif
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200967 let s:winid = popup_beval(v:beval_text, #{mousemoved: 'word'})
Bram Moolenaarb05caa72019-07-10 21:55:54 +0200968 let s:last_text = v:beval_text
Bram Moolenaarb3d17a22019-07-07 18:28:14 +0200969 return ''
970 endfunc
971<
972If the text has to be obtained asynchronously return an empty string from the
973expression function and call popup_beval() once the text is available. In
Bram Moolenaarb05caa72019-07-10 21:55:54 +0200974this example simulated with a timer callback: >
Bram Moolenaarb3d17a22019-07-07 18:28:14 +0200975
976 set ballooneval balloonevalterm
977 set balloonexpr=BalloonExpr()
978 let s:winid = 0
Bram Moolenaarb05caa72019-07-10 21:55:54 +0200979 let s:balloonText = ''
Bram Moolenaarb3d17a22019-07-07 18:28:14 +0200980
981 func BalloonExpr()
Bram Moolenaarb05caa72019-07-10 21:55:54 +0200982 if s:winid && popup_getpos(s:winid) != {}
983 " previous popup window still shows
984 if v:beval_text == s:balloonText
985 " Still the same text, keep the existing popup
986 return ''
987 endif
Bram Moolenaarb3d17a22019-07-07 18:28:14 +0200988 call popup_close(s:winid)
989 let s:winid = 0
990 endif
Bram Moolenaar581ba392019-09-03 22:08:33 +0200991 " simulate an asynchronous lookup for the text to display
Bram Moolenaarb05caa72019-07-10 21:55:54 +0200992 let s:balloonText = v:beval_text
Bram Moolenaarb3d17a22019-07-07 18:28:14 +0200993 call timer_start(100, 'ShowPopup')
994 return ''
995 endfunc
996
997 func ShowPopup(id)
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200998 let s:winid = popup_beval(s:balloonText, #{mousemoved: 'word'})
Bram Moolenaarb3d17a22019-07-07 18:28:14 +0200999 endfunc
1000<
Bram Moolenaar957f85d2019-05-12 21:43:48 +02001001
1002 vim:tw=78:ts=8:noet:ft=help:norl: