blob: 8d3619acf7ce40a3386dfd15c4c735ed63582aff [file] [log] [blame]
Bram Moolenaar5c017b22019-05-21 23:09:01 +02001*popup.txt* For Vim version 8.1. Last change: 2019 May 21
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 Moolenaar5c017b22019-05-21 23:09:01 +020016{not available if the |+eval| feature was disabled at compile time}
17{not able to use text properties if the |+textprop| feature was disabled at
18compile time}
Bram Moolenaar957f85d2019-05-12 21:43:48 +020019
20==============================================================================
211. Introduction *popup-intro*
22
Bram Moolenaar5c017b22019-05-21 23:09:01 +020023We are talking about popup windows here, text that goes on top of the regular
24windows and is under control of a plugin. You cannot edit the text in the
25popup window like with regular windows.
26
27A popup window can be used for such things as:
28- briefly show a message without changing the command line
29- prompt the user with a dialog
Bram Moolenaar4d784b22019-05-25 19:51:39 +020030- display contextual information while typing
Bram Moolenaar5c017b22019-05-21 23:09:01 +020031- give extra information for auto-completion
32
33The text in the popup window can be colored with |text-properties|. It is
34also possible to use syntax highlighting.
35
Bram Moolenaar4d784b22019-05-25 19:51:39 +020036The default color used is "Pmenu". If you prefer something else use the
37"highlight" argument or the 'wincolor' option, e.g.: >
38 hi MyPopupColor ctermbg=lightblue guibg=lightblue
39 call setwinvar(winid, '&wincolor', 'MyPopupColor')
40
41'hlsearch' and match highlighting are not displayed in a popup window.
42
Bram Moolenaar5c017b22019-05-21 23:09:01 +020043A popup window has a window-ID like other windows, but behaves differently.
44The size can be up to the whole Vim window and it overlaps other windows.
45It contains a buffer, and that buffer is always associated with the popup
46window. The window cannot be used in Normal, Visual or Insert mode, it does
47not get keyboard focus. You can use functions like `setbufline()` to change
48the text in the buffer. There are more differences from how this window and
49buffer behave compared to regular windows and buffers, see |popup-buffer|.
50
51If this is not what you are looking for, check out other popup functionality:
Bram Moolenaar957f85d2019-05-12 21:43:48 +020052- popup menu, see |popup-menu|
53- balloon, see |balloon-eval|
54
Bram Moolenaar5c017b22019-05-21 23:09:01 +020055
Bram Moolenaar4d784b22019-05-25 19:51:39 +020056WINDOW POSITION AND SIZE *popup-position*
57
58The height of the window is normally equal to the number of lines in the
59buffer. It can be limited with the "maxheight" property. You can use empty
60lines to increase the height.
61
62The width of the window is normally equal to the longest line in the buffer.
63It can be limited with the "maxwidth" property. You can use spaces to
64increase the width.
65
66By default the 'wrap' option is set, so that no text disappears. However, if
67there is not enough space, some text may be invisible.
68
69
Bram Moolenaar5c017b22019-05-21 23:09:01 +020070TODO:
71
72Example how to use syntax highlighting of a code snippet.
73
74Scrolling: When the screen scrolls up for output of an Ex command, what
75happens with popups?
761. Stay where they are. Problem: listed text may go behind and can't be read.
772. Scroll with the page. What if they get updated? Either postpone, or take
78 the scroll offset into account.
79Probably 2. is the best choice.
80
Bram Moolenaar5c017b22019-05-21 23:09:01 +020081
82IMPLEMENTATION:
Bram Moolenaar4d784b22019-05-25 19:51:39 +020083- Code is in popupwin.c
84- handle screen resize in screenalloc().
85- Support tab-local popup windows, use tp_first_popupwin and
86 first_tab_popupwin. Swap like with firstwin/curwin.
87- Make redrawing more efficient and avoid flicker.
88- implement all the unimplemented features.
Bram Moolenaar5c017b22019-05-21 23:09:01 +020089
Bram Moolenaar957f85d2019-05-12 21:43:48 +020090
91==============================================================================
922. Functions *popup-functions*
93
94THIS IS UNDER DESIGN - ANYTHING MAY STILL CHANGE
95
96Proposal and discussion on issue #4063: https://github.com/vim/vim/issues/4063
97
Bram Moolenaar5c017b22019-05-21 23:09:01 +020098[functions to be moved to eval.txt later, keep list of functions here]
Bram Moolenaar957f85d2019-05-12 21:43:48 +020099
Bram Moolenaar5c017b22019-05-21 23:09:01 +0200100popup_create({text}, {options}) *popup_create()*
101 Open a popup window showing {text}, which is either:
102 - a string
103 - a list of strings
104 - a list of text lines with text properties
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200105 {not implemented yet}
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200106 {options} is a dictionary with many possible entries.
Bram Moolenaar5c017b22019-05-21 23:09:01 +0200107 See |popup_create-usage| for details.
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200108
Bram Moolenaar5c017b22019-05-21 23:09:01 +0200109 Returns a window-ID, which can be used with other popup
110 functions. Use `winbufnr()` to get the number of the buffer
111 in the window: >
112 let winid = popup_create('hello', {})
113 let bufnr = winbufnr(winid)
114 call setbufline(bufnr, 2, 'second line')
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200115< In case of failure zero is returned.
116
117
118popup_close({id}) *popup_close()*
119 Close popup {id}. The window and the associated buffer will
120 be deleted.
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200121
122
Bram Moolenaar5c017b22019-05-21 23:09:01 +0200123popup_dialog({text}, {options}) *popup_dialog()*
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200124 {not implemented yet}
Bram Moolenaar5c017b22019-05-21 23:09:01 +0200125 Just like |popup_create()| but with these default options: >
126 call popup_create({text}, {
127 \ 'pos': 'center',
128 \ 'zindex': 200,
129 \ 'border': [],
130 \})
131< Use {options} to change the properties.
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200132
133
134popup_notification({text}, {options}) *popup_notification()*
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200135 {not implemented yet}
Bram Moolenaar5c017b22019-05-21 23:09:01 +0200136 Show the {text} for 3 seconds at the top of the Vim window.
137 This works like: >
138 call popup_create({text}, {
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200139 \ 'line': 1,
140 \ 'col': 10,
141 \ 'time': 3000,
Bram Moolenaar5c017b22019-05-21 23:09:01 +0200142 \ 'tab': -1,
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200143 \ 'zindex': 200,
144 \ 'highlight': 'WarningMsg',
145 \ 'border: [],
146 \ })
147< Use {options} to change the properties.
148
Bram Moolenaar5c017b22019-05-21 23:09:01 +0200149
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200150popup_atcursor({text}, {options}) *popup_atcursor()*
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200151 {not implemented yet}
Bram Moolenaar5c017b22019-05-21 23:09:01 +0200152 Show the {text} above the cursor, and close it when the cursor
153 moves. This works like: >
154 call popup_create({text}, {
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200155 \ 'line': 'cursor-1',
156 \ 'col': 'cursor',
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200157 \ 'moved': 'WORD',
158 \ })
159< Use {options} to change the properties.
160
161
Bram Moolenaar5c017b22019-05-21 23:09:01 +0200162popup_menu({text}, {options}) *popup_menu()*
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200163 {not implemented yet}
Bram Moolenaar5c017b22019-05-21 23:09:01 +0200164 Show the {text} near the cursor, handle selecting one of the
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200165 items with cursorkeys, and close it an item is selected with
Bram Moolenaar5c017b22019-05-21 23:09:01 +0200166 Space or Enter. {text} should have multiple lines to make this
167 useful. This works like: >
168 call popup_create({text}, {
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200169 \ 'pos': 'center',
170 \ 'zindex': 200,
171 \ 'wrap': 0,
172 \ 'border': [],
173 \ 'filter': 'popup_filter_menu',
174 \ })
175< Use {options} to change the properties. Should at least set
176 "callback" to a function that handles the selected item.
177
178
Bram Moolenaar5c017b22019-05-21 23:09:01 +0200179popup_show({id}) *popup_show()*
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200180 {not implemented yet}
Bram Moolenaar5c017b22019-05-21 23:09:01 +0200181 If {id} is a hidden popup, show it now.
182
183popup_hide({id}) *popup_hide()*
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200184 {not implemented yet}
Bram Moolenaar5c017b22019-05-21 23:09:01 +0200185 If {id} is a displayed popup, hide it now. If the popup has a
186 filter it will not be invoked for so long as the popup is
187 hidden.
188
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200189popup_move({id}, {options}) *popup_move()*
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200190 {not implemented yet}
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200191 Move popup {id} to the position speficied with {options}.
Bram Moolenaar5c017b22019-05-21 23:09:01 +0200192 {options} may contain the items from |popup_create()| that
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200193 specify the popup position: "line", "col", "pos", "maxheight",
194 "minheight", "maxwidth" and "minwidth".
195
196
197popup_filter_menu({id}, {key}) *popup_filter_menu()*
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200198 {not implemented yet}
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200199 Filter that can be used for a popup. It handles the cursor
200 keys to move the selected index in the popup. Space and Enter
201 can be used to select an item. Invokes the "callback" of the
202 popup menu with the index of the selected line as the second
203 argument.
204
205
206popup_filter_yesno({id}, {key}) *popup_filter_yesno()*
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200207 {not implemented yet}
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200208 Filter that can be used for a popup. It handles only the keys
209 'y', 'Y' and 'n' or 'N'. Invokes the "callback" of the
210 popup menu with the 1 for 'y' or 'Y' and zero for 'n' or 'N'
211 as the second argument. Pressing Esc and CTRL-C works like
212 pressing 'n'.
213
214
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200215popup_setoptions({id}, {options}) *popup_setoptions()*
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200216 {not implemented yet}
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200217 Override options in popup {id} with entries in {options}.
218
219
220popup_getoptions({id}) *popup_getoptions()*
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200221 {not implemented yet}
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200222 Return the {options} for popup {id}.
223
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200224popup_getposition({id}) *popup_getposition()*
225 {not implemented yet}
226 Return the position and size of popup {id}. Returns a Dict
227 with these entries:
228 col screen column of the popup, one-based
229 line screen line of the popup, one-based
230 width width of the popup in screen cells
231 height height of the popup in screen cells
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200232
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200233win_execute({id}, {command})
234 {not implemented yet}
235 Like `execute()` but in the context of window {id}.
236 The window will temporarily be made the current window,
237 without triggering autocommands.
238 Example: >
239 call win_execute(winid, 'syntax enable')
240<
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200241
Bram Moolenaar5c017b22019-05-21 23:09:01 +0200242 *:popupclear* *:popupc*
243:popupc[lear] Emergency solution to a misbehaving plugin: close all popup
244 windows.
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200245
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200246
Bram Moolenaar5c017b22019-05-21 23:09:01 +0200247POPUP BUFFER AND WINDOW *popup-buffer*
248
249A new buffer is created to hold the text and text properties of the popup
250window. The buffer is always associated with the popup window and
251manipulation is restricted:
252- the buffer has no name
253- 'buftype' is "popup"
254- 'swapfile' is off
255- 'bufhidden' is "hide"
256- 'buflisted' is off
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200257- 'undolevels' is -1: no undo at all
Bram Moolenaar5c017b22019-05-21 23:09:01 +0200258TODO: more
259
260The window does have a cursor position, but the cursor is not displayed.
261
262Options can be set on the window with `setwinvar()`, e.g.: >
263 call setwinvar(winid, '&wrap', 0)
264And options can be set on the buffer with `setbufvar()`, e.g.: >
265 call setbufvar(winbufnr(winid), '&filetype', 'java')
266
267
268POPUP_CREATE() ARGUMENTS *popup_create-usage*
269
270The first argument of |popup_create()| specifies the text to be displayed, and
271optionally text properties. It is in one of three forms:
272- a string
273- a list of strings
274- a list of dictionaries, where each dictionary has these entries:
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200275 {not implemented yet}
Bram Moolenaar5c017b22019-05-21 23:09:01 +0200276 text String with the text to display.
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200277 props A list of text properties. Optional.
278 Each entry is a dictionary, like the third argument of
279 |prop_add()|, but specifying the column in the
280 dictionary with a "col" entry, see below:
281 |popup-props|.
282
Bram Moolenaar5c017b22019-05-21 23:09:01 +0200283The second argument of |popup_create()| is a dictionary with options:
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200284 line screen line where to position the popup; can use
285 "cursor", "cursor+1" or "cursor-1" to use the line of
286 the cursor and add or subtract a number of lines;
287 default is "cursor-1".
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200288 {only number is implemented}
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200289 col screen column where to position the popup; can use
290 "cursor" to use the column of the cursor, "cursor+99"
291 and "cursor-99" to add or subtract a number of
292 columns; default is "cursor"
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200293 {only number is implemented}
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200294 pos "topleft", "topright", "botleft" or "botright":
295 defines what corner of the popup "line" and "col" are
296 used for. Default is "botleft". Alternatively
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200297 "center" can be used to position the popup in the
298 center of the Vim window.
299 {not implemented yet}
Bram Moolenaar5c017b22019-05-21 23:09:01 +0200300 flip when TRUE (the default) and the position is relative
301 to the cursor, flip to below or above the cursor to
302 avoid overlap with the |popupmenu-completion| or
303 another popup with a higher "zindex"
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200304 {not implemented yet}
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200305 maxheight maximum height
306 minheight minimum height
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200307 {not implemented yet}
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200308 maxwidth maximum width
309 minwidth minimum width
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200310 {not implemented yet}
Bram Moolenaar5c017b22019-05-21 23:09:01 +0200311 hidden when TRUE the popup exists but is not displayed; use
312 `popup_show()` to unhide it.
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200313 {not implemented yet}
Bram Moolenaar5c017b22019-05-21 23:09:01 +0200314 tab when -1: display the popup on all tabs; when 0 (the
315 default): display the popup on the current tab;
316 otherwise the number of the tab page the popup is
317 displayed on; when invalid the current tab is used
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200318 {only -1 and 0 are implemented}
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200319 title text to be displayed above the first item in the
320 popup, on top of any border
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200321 {not implemented yet}
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200322 wrap TRUE to make the lines wrap (default TRUE)
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200323 {not implemented yet}
324 highlight highlight group name to use for the text, stored in
325 'wincolor'
326 {not implemented yet}
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200327 border list with numbers, defining the border thickness
328 above/right/below/left of the popup; an empty list
329 uses a border of 1 all around
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200330 {not implemented yet}
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200331 borderhighlight highlight group name to use for the border
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200332 {not implemented yet}
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200333 borderchars list with characters, defining the character to use
334 for the top/right/bottom/left border; optionally
335 followed by the character to use for the
336 topright/botright/botleft/topleft corner; an empty
337 list can be used to show a double line all around
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200338 {not implemented yet}
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200339 zindex priority for the popup, default 50
340 time time in milliseconds after which the popup will close;
341 when omitted |popup_close()| must be used.
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200342 {not implemented yet}
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200343 moved "cell": close the popup if the cursor moved at least
344 one screen cell; "word" allows for moving within
345 |<cword>|, "WORD" allows for moving within |<cWORD>|,
346 a list with two numbers specifies the start and end
347 column
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200348 {not implemented yet}
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200349 filter a callback that can filter typed characters, see
350 |popup-filter|
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200351 {not implemented yet}
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200352 callback a callback to be used when the popup closes, e.g. when
353 using |popup_filter_menu()|, see |popup-callback|.
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200354 {not implemented yet}
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200355
356Depending on the "zindex" the popup goes under or above other popups. The
357completion menu (|popup-menu|) has zindex 100. For messages that occur for a
358short time the suggestion is to use zindex 1000.
359
360By default text wraps, which causes a line in {lines} to occupy more than one
361screen line. When "wrap" is FALSE then the text outside of the popup or
362outside of the Vim window will not be displayed, thus truncated.
363
364
365POPUP TEXT PROPERTIES *popup-props*
366
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200367{not implemented yet}
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200368These are similar to the third argument of |prop_add()|, but not exactly the
369same, since they only apply to one line.
370 col starting column, counted in bytes, use one for the
371 first column.
372 length length of text in bytes; can be zero
373 end_col column just after the text; not used when "length" is
374 present; when {col} and "end_col" are equal, this is a
375 zero-width text property
376 id user defined ID for the property; when omitted zero is
377 used
378 type name of the text property type, as added with
379 |prop_type_add()|
380 transparent do not show these characters, show the text under it;
381 if there is an border character to the right or below
382 it will be made transparent as well
383
384
385POPUP FILTER *popup-filter*
386
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200387{not implemented yet}
Bram Moolenaar5c017b22019-05-21 23:09:01 +0200388A callback that gets any typed keys while a popup is displayed. The filter is
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200389not invoked when the popup is hidden.
Bram Moolenaar5c017b22019-05-21 23:09:01 +0200390
391The filter can return TRUE to indicate the key has been handled and is to be
392discarded, or FALSE to let Vim handle the key as usual in the current state.
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200393In case it returns FALSE and there is another popup window visible, that
394filter is also called. The filter of the popup window with the highest zindex
395is called first.
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200396
397The filter function is called with two arguments: the ID of the popup and the
398key.
399
400Some common key actions:
401 Esc close the popup
402 cursor keys select another entry
403 Tab accept current suggestion
404
Bram Moolenaar5c017b22019-05-21 23:09:01 +0200405A mouse click arrives as <LeftMouse>. The coordinates are in
406v:mouse_popup_col and v:mouse_popup_row. The top-left screen cell of the
407popup is col 1, row 1 (not counting the border).
408
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200409Vim provides standard filters |popup_filter_menu()| and
410|popup_filter_yesno()|.
411
412
413POPUP CALLBACK *popup-callback*
414
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200415{not implemented yet}
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200416A callback that is invoked when the popup closes. Used by
417|popup_filter_menu()|. Invoked with two arguments: the ID of the popup and
418the result, which would usually be an index in the popup lines, or whatever
419the filter wants to pass.
420
421==============================================================================
4223. Examples *popup-examples*
423
424TODO
425
426Prompt the user to press y/Y or n/N: >
427
428 func MyDialogHandler(id, result)
429 if a:result
430 " ... 'y' or 'Y' was pressed
431 endif
432 endfunc
433
Bram Moolenaar5c017b22019-05-21 23:09:01 +0200434 call popup_create(['Continue? y/n'], {
Bram Moolenaar957f85d2019-05-12 21:43:48 +0200435 \ 'filter': 'popup_filter_yesno',
436 \ 'callback': 'MyDialogHandler',
437 \ })
438<
439
440 vim:tw=78:ts=8:noet:ft=help:norl: