blob: 7fa172c88b06569f33f34d5a62fd98fe06b64d21 [file] [log] [blame]
Bram Moolenaarbf0eff02019-06-01 17:13:36 +02001*popup.txt* For Vim version 8.1. Last change: 2019 Jun 01
Bram Moolenaar957f85d2019-05-12 21:43:48 +02002
3
4 VIM REFERENCE MANUAL by Bram Moolenaar
5
6
Bram Moolenaar5c017b22019-05-21 23:09:01 +02007Displaying text in floating window. *popup* *popup-window*
Bram Moolenaar957f85d2019-05-12 21:43:48 +02008
9THIS IS UNDER DESIGN - ANYTHING MAY STILL CHANGE
10
111. Introduction |popup-intro|
122. Functions |popup-functions|
133. Examples |popup-examples|
14
15
Bram Moolenaar7dd64a32019-05-31 21:41:05 +020016{not available if the |+textprop| feature was disabled at compile time}
Bram Moolenaar957f85d2019-05-12 21:43:48 +020017
18==============================================================================
191. Introduction *popup-intro*
20
Bram Moolenaar5c017b22019-05-21 23:09:01 +020021We are talking about popup windows here, text that goes on top of the regular
22windows and is under control of a plugin. You cannot edit the text in the
23popup window like with regular windows.
24
25A popup window can be used for such things as:
Bram Moolenaar68e65602019-05-26 21:33:31 +020026- briefly show a message without overwriting the command line
Bram Moolenaar5c017b22019-05-21 23:09:01 +020027- prompt the user with a dialog
Bram Moolenaar4d784b22019-05-25 19:51:39 +020028- display contextual information while typing
Bram Moolenaar5c017b22019-05-21 23:09:01 +020029- give extra information for auto-completion
30
31The text in the popup window can be colored with |text-properties|. It is
32also possible to use syntax highlighting.
33
Bram Moolenaar4d784b22019-05-25 19:51:39 +020034The default color used is "Pmenu". If you prefer something else use the
35"highlight" argument or the 'wincolor' option, e.g.: >
36 hi MyPopupColor ctermbg=lightblue guibg=lightblue
37 call setwinvar(winid, '&wincolor', 'MyPopupColor')
38
39'hlsearch' and match highlighting are not displayed in a popup window.
40
Bram Moolenaar5c017b22019-05-21 23:09:01 +020041A popup window has a window-ID like other windows, but behaves differently.
42The size can be up to the whole Vim window and it overlaps other windows.
Bram Moolenaar68e65602019-05-26 21:33:31 +020043Popup windows can also overlap each other.
44
45The popup window contains a buffer, and that buffer is always associated with
46the popup window. The window cannot be used in Normal, Visual or Insert mode,
47it does not get keyboard focus. You can use functions like `setbufline()` to
48change the text in the buffer. There are more differences from how this
49window and buffer behave compared to regular windows and buffers, see
50|popup-buffer|.
Bram Moolenaar5c017b22019-05-21 23:09:01 +020051
52If this is not what you are looking for, check out other popup functionality:
Bram Moolenaar957f85d2019-05-12 21:43:48 +020053- popup menu, see |popup-menu|
54- balloon, see |balloon-eval|
55
Bram Moolenaar5c017b22019-05-21 23:09:01 +020056
Bram Moolenaar4d784b22019-05-25 19:51:39 +020057WINDOW POSITION AND SIZE *popup-position*
58
Bram Moolenaar68e65602019-05-26 21:33:31 +020059The height of the window is normally equal to the number of, possibly
60wrapping, lines in the buffer. It can be limited with the "maxheight"
Bram Moolenaar7dd64a32019-05-31 21:41:05 +020061property. You can use empty lines to increase the height or the "minheight"
62property.
Bram Moolenaar4d784b22019-05-25 19:51:39 +020063
64The width of the window is normally equal to the longest line in the buffer.
65It can be limited with the "maxwidth" property. You can use spaces to
Bram Moolenaar7dd64a32019-05-31 21:41:05 +020066increase the width or the "minwidth" property.
Bram Moolenaar4d784b22019-05-25 19:51:39 +020067
Bram Moolenaar042fb4b2019-06-02 14:49:56 +020068By default the 'wrap' option is set, so that no text disappears. Otherwise,
69if there is not enough space then the window is shifted left in order to
70display more text. This can be disabled with the "fixed" property. Also
71disabled when right-aligned.
Bram Moolenaar4d784b22019-05-25 19:51:39 +020072
Bram Moolenaar7dd64a32019-05-31 21:41:05 +020073Vim tries to show the popup in the location you specify. In some cases, e.g.
74when the popup would go outside of the Vim window, it will show it somewhere
75else. E.g. if you use `popup_atcursor()` the popup normally shows just above
76the current cursor position, but if the cursor is close to the top of the Vim
77window it will be placed below the cursor position.
78
Bram Moolenaar4d784b22019-05-25 19:51:39 +020079
Bram Moolenaar868b7b62019-05-29 21:44:40 +020080
Bram Moolenaar5c017b22019-05-21 23:09:01 +020081TODO:
82
Bram Moolenaar5c017b22019-05-21 23:09:01 +020083Scrolling: When the screen scrolls up for output of an Ex command, what
84happens with popups?
851. Stay where they are. Problem: listed text may go behind and can't be read.
862. Scroll with the page. What if they get updated? Either postpone, or take
87 the scroll offset into account.
88Probably 2. is the best choice.
89
Bram Moolenaar5c017b22019-05-21 23:09:01 +020090
91IMPLEMENTATION:
Bram Moolenaar4d784b22019-05-25 19:51:39 +020092- Code is in popupwin.c
Bram Moolenaarbf0eff02019-06-01 17:13:36 +020093- Why does 'nrformats' leak from the popup window buffer???
Bram Moolenaar4d784b22019-05-25 19:51:39 +020094- Make redrawing more efficient and avoid flicker.
Bram Moolenaar042fb4b2019-06-02 14:49:56 +020095 First draw popups, creating a mask, use the mask in screen_line() when
96 drawing other windows and stuff. Mask contains zindex of popups.
97 Keep mask until next update_screen(), use when drawing status lines.
98 Remove update_popup() calls after draw_tabline()/updating statusline
Bram Moolenaarbc133542019-05-29 20:26:46 +020099 Fix redrawing problem with completion.
100 Fix redrawing problem when scrolling non-current window
Bram Moolenaarbf0eff02019-06-01 17:13:36 +0200101- Disable commands, feedkeys(), CTRL-W, etc. in a popup window.
Bram Moolenaar2fd8e352019-06-01 20:16:48 +0200102 Use NOT_IN_POPUP_WINDOW for more commands.
103- Invoke filter with character before mapping?
Bram Moolenaar8c2a6002019-05-30 14:29:45 +0200104- Figure out the size and position better.
105 if wrapping splits a double-wide character
Bram Moolenaarcc31ad92019-05-30 19:25:06 +0200106 if wrapping inserts indent
Bram Moolenaarbc133542019-05-29 20:26:46 +0200107- Can the buffer be re-used, to avoid using up lots of buffer numbers?
Bram Moolenaar68e65602019-05-26 21:33:31 +0200108- Implement all the unimplemented options and features.
Bram Moolenaar5c017b22019-05-21 23:09:01 +0200109
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200110
111==============================================================================
1122. Functions *popup-functions*
113
114THIS IS UNDER DESIGN - ANYTHING MAY STILL CHANGE
115
Bram Moolenaar68e65602019-05-26 21:33:31 +0200116[functions to be moved to eval.txt later, keep overview of functions here]
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200117
Bram Moolenaar5c017b22019-05-21 23:09:01 +0200118popup_create({text}, {options}) *popup_create()*
119 Open a popup window showing {text}, which is either:
120 - a string
121 - a list of strings
122 - a list of text lines with text properties
Bram Moolenaar7dd64a32019-05-31 21:41:05 +0200123
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200124 {options} is a dictionary with many possible entries.
Bram Moolenaar5c017b22019-05-21 23:09:01 +0200125 See |popup_create-usage| for details.
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200126
Bram Moolenaar5c017b22019-05-21 23:09:01 +0200127 Returns a window-ID, which can be used with other popup
128 functions. Use `winbufnr()` to get the number of the buffer
129 in the window: >
130 let winid = popup_create('hello', {})
131 let bufnr = winbufnr(winid)
132 call setbufline(bufnr, 2, 'second line')
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200133< In case of failure zero is returned.
134
135
Bram Moolenaar9eaac892019-06-01 22:49:29 +0200136popup_close({id} [, {result}]) *popup_close()*
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200137 Close popup {id}. The window and the associated buffer will
138 be deleted.
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200139
Bram Moolenaar9eaac892019-06-01 22:49:29 +0200140 If the popup has a callback it will be called just before the
141 popup window is deleted. If the optional {result} is present
142 it will be passed as the second argument of the callback.
143 Otherwise zero is passed to the callback.
144
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200145
Bram Moolenaar5c017b22019-05-21 23:09:01 +0200146popup_dialog({text}, {options}) *popup_dialog()*
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200147 {not implemented yet}
Bram Moolenaar5c017b22019-05-21 23:09:01 +0200148 Just like |popup_create()| but with these default options: >
149 call popup_create({text}, {
150 \ 'pos': 'center',
151 \ 'zindex': 200,
152 \ 'border': [],
Bram Moolenaar9eaac892019-06-01 22:49:29 +0200153 \ 'padding': [],
Bram Moolenaar5c017b22019-05-21 23:09:01 +0200154 \})
155< Use {options} to change the properties.
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200156
157
158popup_notification({text}, {options}) *popup_notification()*
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200159 {not implemented yet}
Bram Moolenaar5c017b22019-05-21 23:09:01 +0200160 Show the {text} for 3 seconds at the top of the Vim window.
161 This works like: >
162 call popup_create({text}, {
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200163 \ 'line': 1,
164 \ 'col': 10,
165 \ 'time': 3000,
Bram Moolenaar5c017b22019-05-21 23:09:01 +0200166 \ 'tab': -1,
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200167 \ 'zindex': 200,
168 \ 'highlight': 'WarningMsg',
Bram Moolenaar51fe3b12019-05-26 20:10:06 +0200169 \ 'border': [],
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200170 \ })
171< Use {options} to change the properties.
172
Bram Moolenaar5c017b22019-05-21 23:09:01 +0200173
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200174popup_atcursor({text}, {options}) *popup_atcursor()*
Bram Moolenaar9eaac892019-06-01 22:49:29 +0200175 {not implemented yet: close when cursor moves}
Bram Moolenaar5c017b22019-05-21 23:09:01 +0200176 Show the {text} above the cursor, and close it when the cursor
177 moves. This works like: >
178 call popup_create({text}, {
Bram Moolenaarcc31ad92019-05-30 19:25:06 +0200179 \ 'pos': 'botleft',
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200180 \ 'line': 'cursor-1',
181 \ 'col': 'cursor',
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200182 \ 'moved': 'WORD',
183 \ })
184< Use {options} to change the properties.
185
186
Bram Moolenaar5c017b22019-05-21 23:09:01 +0200187popup_menu({text}, {options}) *popup_menu()*
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200188 {not implemented yet}
Bram Moolenaar5c017b22019-05-21 23:09:01 +0200189 Show the {text} near the cursor, handle selecting one of the
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200190 items with cursorkeys, and close it an item is selected with
Bram Moolenaar5c017b22019-05-21 23:09:01 +0200191 Space or Enter. {text} should have multiple lines to make this
192 useful. This works like: >
193 call popup_create({text}, {
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200194 \ 'pos': 'center',
195 \ 'zindex': 200,
196 \ 'wrap': 0,
197 \ 'border': [],
198 \ 'filter': 'popup_filter_menu',
199 \ })
200< Use {options} to change the properties. Should at least set
201 "callback" to a function that handles the selected item.
202
203
Bram Moolenaar5c017b22019-05-21 23:09:01 +0200204popup_hide({id}) *popup_hide()*
205 If {id} is a displayed popup, hide it now. If the popup has a
206 filter it will not be invoked for so long as the popup is
207 hidden.
Bram Moolenaar2cd0dce2019-05-26 22:17:52 +0200208 If window {id} does not exist nothing happens. If window {id}
209 exists but is not a popup window an error is given. *E993*
210
211popup_show({id}) *popup_show()*
212 If {id} is a hidden popup, show it now.
213 For {id} see `popup_hide()`.
Bram Moolenaar5c017b22019-05-21 23:09:01 +0200214
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200215popup_move({id}, {options}) *popup_move()*
216 Move popup {id} to the position speficied with {options}.
Bram Moolenaar5c017b22019-05-21 23:09:01 +0200217 {options} may contain the items from |popup_create()| that
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200218 specify the popup position: "line", "col", "pos", "maxheight",
219 "minheight", "maxwidth" and "minwidth".
Bram Moolenaar2cd0dce2019-05-26 22:17:52 +0200220 For {id} see `popup_hide()`.
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200221
222
223popup_filter_menu({id}, {key}) *popup_filter_menu()*
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200224 {not implemented yet}
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200225 Filter that can be used for a popup. It handles the cursor
226 keys to move the selected index in the popup. Space and Enter
227 can be used to select an item. Invokes the "callback" of the
228 popup menu with the index of the selected line as the second
229 argument.
230
231
232popup_filter_yesno({id}, {key}) *popup_filter_yesno()*
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200233 {not implemented yet}
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200234 Filter that can be used for a popup. It handles only the keys
235 'y', 'Y' and 'n' or 'N'. Invokes the "callback" of the
236 popup menu with the 1 for 'y' or 'Y' and zero for 'n' or 'N'
237 as the second argument. Pressing Esc and CTRL-C works like
238 pressing 'n'.
239
240
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200241popup_setoptions({id}, {options}) *popup_setoptions()*
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200242 {not implemented yet}
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200243 Override options in popup {id} with entries in {options}.
244
245
246popup_getoptions({id}) *popup_getoptions()*
Bram Moolenaar8c2a6002019-05-30 14:29:45 +0200247 Return the {options} for popup {id} in a Dict.
Bram Moolenaarac1f1bc2019-05-30 21:24:26 +0200248 A zero value means the option was not set. For "zindex" the
249 default value is returned, not zero.
Bram Moolenaar8c2a6002019-05-30 14:29:45 +0200250
251 The "highlight" entry is omitted, use the 'wincolor' option
252 for that: >
253 let hl = getwinvar(winid, '&wincolor')
254
255< If popup window {id} is not found an empty Dict is returned.
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200256
Bram Moolenaarac1f1bc2019-05-30 21:24:26 +0200257popup_getpos({id}) *popup_getpos()*
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200258 Return the position and size of popup {id}. Returns a Dict
259 with these entries:
Bram Moolenaar8c2a6002019-05-30 14:29:45 +0200260 col screen column of the popup, one-based
261 line screen line of the popup, one-based
Bram Moolenaar2fd8e352019-06-01 20:16:48 +0200262 width width of the whole popup in screen cells
263 height height of the whole popup in screen cells
264 core_col screen column of the text box
265 core_line screen line of the text box
266 core_width width of the text box in screen cells
267 core_height height of the text box in screen cells
Bram Moolenaar8c2a6002019-05-30 14:29:45 +0200268 visible one if the popup is displayed, zero if hidden
Bram Moolenaarbc133542019-05-29 20:26:46 +0200269 Note that these are the actual screen positions. They differ
270 from the values in `popup_getoptions()` for the sizing and
271 positioning mechanism applied.
Bram Moolenaar2fd8e352019-06-01 20:16:48 +0200272
273 The "core_" values exclude the padding and border.
274
Bram Moolenaarbc133542019-05-29 20:26:46 +0200275 If popup window {id} is not found an empty Dict is returned.
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200276
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200277
Bram Moolenaar5c017b22019-05-21 23:09:01 +0200278 *:popupclear* *:popupc*
279:popupc[lear] Emergency solution to a misbehaving plugin: close all popup
280 windows.
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200281
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200282
Bram Moolenaar5c017b22019-05-21 23:09:01 +0200283POPUP BUFFER AND WINDOW *popup-buffer*
284
285A new buffer is created to hold the text and text properties of the popup
286window. The buffer is always associated with the popup window and
287manipulation is restricted:
288- the buffer has no name
289- 'buftype' is "popup"
290- 'swapfile' is off
291- 'bufhidden' is "hide"
292- 'buflisted' is off
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200293- 'undolevels' is -1: no undo at all
Bram Moolenaarcc31ad92019-05-30 19:25:06 +0200294- all other buffer-local and window_local options are set to their Vim default
295 value.
Bram Moolenaar5c017b22019-05-21 23:09:01 +0200296
Bram Moolenaarcc31ad92019-05-30 19:25:06 +0200297It is possible to change the specifically mentioned options, but anything
298might break then, so better leave them alone.
Bram Moolenaar68e65602019-05-26 21:33:31 +0200299
Bram Moolenaar5c017b22019-05-21 23:09:01 +0200300The window does have a cursor position, but the cursor is not displayed.
301
Bram Moolenaar868b7b62019-05-29 21:44:40 +0200302To execute a command in the context of the popup window and buffer use
303`win_execute()`. Example: >
304 call win_execute(winid, 'syntax enable')
305
Bram Moolenaar5c017b22019-05-21 23:09:01 +0200306Options can be set on the window with `setwinvar()`, e.g.: >
307 call setwinvar(winid, '&wrap', 0)
308And options can be set on the buffer with `setbufvar()`, e.g.: >
309 call setbufvar(winbufnr(winid), '&filetype', 'java')
Bram Moolenaarc6896e22019-05-30 22:32:34 +0200310Note that this does not trigger autocommands. Use `win_execute()` if you do
311need them.
Bram Moolenaar5c017b22019-05-21 23:09:01 +0200312
313
314POPUP_CREATE() ARGUMENTS *popup_create-usage*
315
316The first argument of |popup_create()| specifies the text to be displayed, and
317optionally text properties. It is in one of three forms:
318- a string
319- a list of strings
320- a list of dictionaries, where each dictionary has these entries:
321 text String with the text to display.
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200322 props A list of text properties. Optional.
323 Each entry is a dictionary, like the third argument of
324 |prop_add()|, but specifying the column in the
325 dictionary with a "col" entry, see below:
326 |popup-props|.
327
Bram Moolenaar5c017b22019-05-21 23:09:01 +0200328The second argument of |popup_create()| is a dictionary with options:
Bram Moolenaar042fb4b2019-06-02 14:49:56 +0200329 line Screen line where to position the popup. Can use a
Bram Moolenaarac1f1bc2019-05-30 21:24:26 +0200330 number or "cursor", "cursor+1" or "cursor-1" to use
331 the line of the cursor and add or subtract a number of
Bram Moolenaar042fb4b2019-06-02 14:49:56 +0200332 lines. If omitted the popup is vertically centered.
333 The first line is 1.
334 col Screen column where to position the popup. Can use a
Bram Moolenaarac1f1bc2019-05-30 21:24:26 +0200335 number or "cursor" to use the column of the cursor,
Bram Moolenaar042fb4b2019-06-02 14:49:56 +0200336 "cursor+9" or "cursor-9" to add or subtract a number
337 of columns. If omitted the popup is horizontally
338 centered. The first column is 1.
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200339 pos "topleft", "topright", "botleft" or "botright":
340 defines what corner of the popup "line" and "col" are
Bram Moolenaar8c2a6002019-05-30 14:29:45 +0200341 used for. When not set "topleft" is used.
342 Alternatively "center" can be used to position the
Bram Moolenaarac1f1bc2019-05-30 21:24:26 +0200343 popup in the center of the Vim window, in which case
344 "line" and "col" are ignored.
Bram Moolenaar042fb4b2019-06-02 14:49:56 +0200345 fixed When FALSE (the default), and:
346 - "pos" is "botleft" or "topleft", and
347 - "wrap" is off, and
348 - the popup would be truncated at the right edge of
349 the screen, then
350 the popup is moved to the left so as to fit the
351 contents on the screen. Set to TRUE to disable this.
352 flip When TRUE (the default) and the position is relative
Bram Moolenaar5c017b22019-05-21 23:09:01 +0200353 to the cursor, flip to below or above the cursor to
354 avoid overlap with the |popupmenu-completion| or
Bram Moolenaar042fb4b2019-06-02 14:49:56 +0200355 another popup with a higher "zindex".
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200356 {not implemented yet}
Bram Moolenaar042fb4b2019-06-02 14:49:56 +0200357 maxheight Maximum height of the contents, excluding border and
358 padding.
359 minheight Minimum height of the contents, excluding border and
360 padding.
361 maxwidth Maximum width of the contents, excluding border and
362 padding.
363 minwidth Minimum width of the contents, excluding border and
364 padding.
365 hidden When TRUE the popup exists but is not displayed; use
Bram Moolenaar5c017b22019-05-21 23:09:01 +0200366 `popup_show()` to unhide it.
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200367 {not implemented yet}
Bram Moolenaar042fb4b2019-06-02 14:49:56 +0200368 tab When -1: display the popup on all tabs.
369 When 0 (the default): display the popup on the current
370 tab.
371 Otherwise the number of the tab page the popup is
372 displayed on; when invalid the current tab is used.
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200373 {only -1 and 0 are implemented}
Bram Moolenaar042fb4b2019-06-02 14:49:56 +0200374 title Text to be displayed above the first item in the
375 popup, on top of any border. If there is no top
376 border on line of padding is added to put the title on.
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200377 {not implemented yet}
Bram Moolenaar042fb4b2019-06-02 14:49:56 +0200378 wrap TRUE to make the lines wrap (default TRUE).
379 highlight Highlight group name to use for the text, stored in
380 the 'wincolor' option.
381 padding List with numbers, defining the padding
382 above/right/below/left of the popup (similar to CSS).
383 An empty list uses a padding of 1 all around. The
384 padding goes around the text, inside any border.
385 Padding uses the 'wincolor' highlight.
386 Example: [1, 2, 1, 3] has 1 line of padding above, 2
387 columns on the right, 1 line below and 3 columns on
388 the left.
389 border List with numbers, defining the border thickness
390 above/right/below/left of the popup (similar to CSS).
391 Only values of zero and non-zero are recognized.
392 An empty list uses a border all around.
393 borderhighlight List of highlight group names to use for the border.
394 When one entry it is used for all borders, otherwise
395 the highlight for the top/right/bottom/left border.
396 Example: ['TopColor', 'RightColor', 'BottomColor,
397 'LeftColor']
398 borderchars List with characters, defining the character to use
399 for the top/right/bottom/left border. Optionally
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200400 followed by the character to use for the
Bram Moolenaar042fb4b2019-06-02 14:49:56 +0200401 topleft/topright/botright/botleft corner.
402 Example: ['-', '|', '-', '|', '┌', '┐', '┘', '└']
403 When the list has one character it is used for all.
404 When the list has two characters the first is used for
405 the border lines, the second for the corners.
406 By default a double line is used all around when
407 'encoding' is "utf-8", otherwise ASCII characters are
408 used.
409 zindex Priority for the popup, default 50.
410 time Time in milliseconds after which the popup will close.
411 When omitted |popup_close()| must be used.
Bram Moolenaar3397f742019-06-02 18:40:06 +0200412 moved Specifies to close the popup if the cursor moved:
413 - "any": if the cursor moved at all
414 - "word": if the cursor moved outside |<cword>|
415 - "WORD": if the cursor moved outside |<cWORD>|
416 - [{start}, {end}]: if the cursor moved before column
417 {start} or after {end}
418 The popup also closes if the cursor moves to another
419 line or to another window.
Bram Moolenaar042fb4b2019-06-02 14:49:56 +0200420 filter A callback that can filter typed characters, see
421 |popup-filter|.
422 callback A callback that is called when the popup closes, e.g.
423 when using |popup_filter_menu()|, see |popup-callback|.
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200424
425Depending on the "zindex" the popup goes under or above other popups. The
426completion menu (|popup-menu|) has zindex 100. For messages that occur for a
427short time the suggestion is to use zindex 1000.
428
429By default text wraps, which causes a line in {lines} to occupy more than one
430screen line. When "wrap" is FALSE then the text outside of the popup or
431outside of the Vim window will not be displayed, thus truncated.
432
433
434POPUP TEXT PROPERTIES *popup-props*
435
Bram Moolenaar7a8d0272019-05-26 23:32:06 +0200436These are similar to the third argument of |prop_add()| except:
437- "lnum" is always the current line in the list
438- "bufnr" is always the buffer of the popup
439- "col" is in the Dict instead of a separate argument
440- "transparent" is extra
441So we get:
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200442 col starting column, counted in bytes, use one for the
443 first column.
444 length length of text in bytes; can be zero
Bram Moolenaar7a8d0272019-05-26 23:32:06 +0200445 end_lnum line number for the end of the text
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200446 end_col column just after the text; not used when "length" is
447 present; when {col} and "end_col" are equal, this is a
448 zero-width text property
449 id user defined ID for the property; when omitted zero is
450 used
451 type name of the text property type, as added with
452 |prop_type_add()|
453 transparent do not show these characters, show the text under it;
Bram Moolenaar7dd64a32019-05-31 21:41:05 +0200454 if there is a border character to the right or below
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200455 it will be made transparent as well
Bram Moolenaar7a8d0272019-05-26 23:32:06 +0200456 {not implemented yet}
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200457
458
459POPUP FILTER *popup-filter*
460
Bram Moolenaar5c017b22019-05-21 23:09:01 +0200461A callback that gets any typed keys while a popup is displayed. The filter is
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200462not invoked when the popup is hidden.
Bram Moolenaar5c017b22019-05-21 23:09:01 +0200463
464The filter can return TRUE to indicate the key has been handled and is to be
465discarded, or FALSE to let Vim handle the key as usual in the current state.
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200466In case it returns FALSE and there is another popup window visible, that
467filter is also called. The filter of the popup window with the highest zindex
468is called first.
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200469
470The filter function is called with two arguments: the ID of the popup and the
Bram Moolenaarbf0eff02019-06-01 17:13:36 +0200471key, e.g.: >
472 func MyFilter(winid, key)
473 if a:key == "\<F2>"
474 " do something
475 return 1
476 endif
477 if a:key == 'x'
478 call popup_close(a:winid)
479 return 1
480 endif
481 return 0
482 endfunc
483
484Currently the key is what results after any mapping. This may change...
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200485
486Some common key actions:
Bram Moolenaarbf0eff02019-06-01 17:13:36 +0200487 x close the popup (see note below)
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200488 cursor keys select another entry
489 Tab accept current suggestion
490
Bram Moolenaar5c017b22019-05-21 23:09:01 +0200491A mouse click arrives as <LeftMouse>. The coordinates are in
492v:mouse_popup_col and v:mouse_popup_row. The top-left screen cell of the
493popup is col 1, row 1 (not counting the border).
494
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200495Vim provides standard filters |popup_filter_menu()| and
496|popup_filter_yesno()|.
497
Bram Moolenaarbf0eff02019-06-01 17:13:36 +0200498Note that "x" is the normal way to close a popup. You may want to use Esc,
499but since many keys start with an Esc character, there may be a delay before
500Vim recognizes the Esc key. If you do use Esc, it is reecommended to set the
501'ttimeoutlen' option to 100 and set 'timeout' and/or 'ttimeout'.
502
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200503
504POPUP CALLBACK *popup-callback*
505
506A callback that is invoked when the popup closes. Used by
Bram Moolenaar9eaac892019-06-01 22:49:29 +0200507|popup_filter_menu()|.
508
509The callback is invoked with two arguments: the ID of the popup window and the
510result, which could be an index in the popup lines, or whatever was passed as
511the second argument of `popup_close()`.
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200512
Bram Moolenaar3397f742019-06-02 18:40:06 +0200513If the popup is closed because the cursor moved, the number -1 is passed to
514the callback.
515
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200516==============================================================================
5173. Examples *popup-examples*
518
519TODO
520
521Prompt the user to press y/Y or n/N: >
522
523 func MyDialogHandler(id, result)
524 if a:result
525 " ... 'y' or 'Y' was pressed
526 endif
527 endfunc
528
Bram Moolenaar5c017b22019-05-21 23:09:01 +0200529 call popup_create(['Continue? y/n'], {
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200530 \ 'filter': 'popup_filter_yesno',
531 \ 'callback': 'MyDialogHandler',
532 \ })
533<
534
535 vim:tw=78:ts=8:noet:ft=help:norl: