Bram Moolenaar | 5c017b2 | 2019-05-21 23:09:01 +0200 | [diff] [blame] | 1 | *popup.txt* For Vim version 8.1. Last change: 2019 May 21 |
Bram Moolenaar | 957f85d | 2019-05-12 21:43:48 +0200 | [diff] [blame] | 2 | |
| 3 | |
| 4 | VIM REFERENCE MANUAL by Bram Moolenaar |
| 5 | |
| 6 | |
Bram Moolenaar | 5c017b2 | 2019-05-21 23:09:01 +0200 | [diff] [blame] | 7 | Displaying text in floating window. *popup* *popup-window* |
Bram Moolenaar | 957f85d | 2019-05-12 21:43:48 +0200 | [diff] [blame] | 8 | |
| 9 | THIS IS UNDER DESIGN - ANYTHING MAY STILL CHANGE |
| 10 | |
| 11 | 1. Introduction |popup-intro| |
| 12 | 2. Functions |popup-functions| |
| 13 | 3. Examples |popup-examples| |
| 14 | |
| 15 | |
Bram Moolenaar | 5c017b2 | 2019-05-21 23:09:01 +0200 | [diff] [blame] | 16 | {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 |
| 18 | compile time} |
Bram Moolenaar | 957f85d | 2019-05-12 21:43:48 +0200 | [diff] [blame] | 19 | |
| 20 | ============================================================================== |
| 21 | 1. Introduction *popup-intro* |
| 22 | |
Bram Moolenaar | 5c017b2 | 2019-05-21 23:09:01 +0200 | [diff] [blame] | 23 | We are talking about popup windows here, text that goes on top of the regular |
| 24 | windows and is under control of a plugin. You cannot edit the text in the |
| 25 | popup window like with regular windows. |
| 26 | |
| 27 | A 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 Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 30 | - display contextual information while typing |
Bram Moolenaar | 5c017b2 | 2019-05-21 23:09:01 +0200 | [diff] [blame] | 31 | - give extra information for auto-completion |
| 32 | |
| 33 | The text in the popup window can be colored with |text-properties|. It is |
| 34 | also possible to use syntax highlighting. |
| 35 | |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 36 | The 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 Moolenaar | 5c017b2 | 2019-05-21 23:09:01 +0200 | [diff] [blame] | 43 | A popup window has a window-ID like other windows, but behaves differently. |
| 44 | The size can be up to the whole Vim window and it overlaps other windows. |
| 45 | It contains a buffer, and that buffer is always associated with the popup |
| 46 | window. The window cannot be used in Normal, Visual or Insert mode, it does |
| 47 | not get keyboard focus. You can use functions like `setbufline()` to change |
| 48 | the text in the buffer. There are more differences from how this window and |
| 49 | buffer behave compared to regular windows and buffers, see |popup-buffer|. |
| 50 | |
| 51 | If this is not what you are looking for, check out other popup functionality: |
Bram Moolenaar | 957f85d | 2019-05-12 21:43:48 +0200 | [diff] [blame] | 52 | - popup menu, see |popup-menu| |
| 53 | - balloon, see |balloon-eval| |
| 54 | |
Bram Moolenaar | 5c017b2 | 2019-05-21 23:09:01 +0200 | [diff] [blame] | 55 | |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 56 | WINDOW POSITION AND SIZE *popup-position* |
| 57 | |
| 58 | The height of the window is normally equal to the number of lines in the |
| 59 | buffer. It can be limited with the "maxheight" property. You can use empty |
| 60 | lines to increase the height. |
| 61 | |
| 62 | The width of the window is normally equal to the longest line in the buffer. |
| 63 | It can be limited with the "maxwidth" property. You can use spaces to |
| 64 | increase the width. |
| 65 | |
| 66 | By default the 'wrap' option is set, so that no text disappears. However, if |
| 67 | there is not enough space, some text may be invisible. |
| 68 | |
| 69 | |
Bram Moolenaar | 5c017b2 | 2019-05-21 23:09:01 +0200 | [diff] [blame] | 70 | TODO: |
| 71 | |
| 72 | Example how to use syntax highlighting of a code snippet. |
| 73 | |
| 74 | Scrolling: When the screen scrolls up for output of an Ex command, what |
| 75 | happens with popups? |
| 76 | 1. Stay where they are. Problem: listed text may go behind and can't be read. |
| 77 | 2. Scroll with the page. What if they get updated? Either postpone, or take |
| 78 | the scroll offset into account. |
| 79 | Probably 2. is the best choice. |
| 80 | |
Bram Moolenaar | 5c017b2 | 2019-05-21 23:09:01 +0200 | [diff] [blame] | 81 | |
| 82 | IMPLEMENTATION: |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 83 | - 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 Moolenaar | 5c017b2 | 2019-05-21 23:09:01 +0200 | [diff] [blame] | 89 | |
Bram Moolenaar | 957f85d | 2019-05-12 21:43:48 +0200 | [diff] [blame] | 90 | |
| 91 | ============================================================================== |
| 92 | 2. Functions *popup-functions* |
| 93 | |
| 94 | THIS IS UNDER DESIGN - ANYTHING MAY STILL CHANGE |
| 95 | |
| 96 | Proposal and discussion on issue #4063: https://github.com/vim/vim/issues/4063 |
| 97 | |
Bram Moolenaar | 5c017b2 | 2019-05-21 23:09:01 +0200 | [diff] [blame] | 98 | [functions to be moved to eval.txt later, keep list of functions here] |
Bram Moolenaar | 957f85d | 2019-05-12 21:43:48 +0200 | [diff] [blame] | 99 | |
Bram Moolenaar | 5c017b2 | 2019-05-21 23:09:01 +0200 | [diff] [blame] | 100 | popup_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 Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 105 | {not implemented yet} |
Bram Moolenaar | 957f85d | 2019-05-12 21:43:48 +0200 | [diff] [blame] | 106 | {options} is a dictionary with many possible entries. |
Bram Moolenaar | 5c017b2 | 2019-05-21 23:09:01 +0200 | [diff] [blame] | 107 | See |popup_create-usage| for details. |
Bram Moolenaar | 957f85d | 2019-05-12 21:43:48 +0200 | [diff] [blame] | 108 | |
Bram Moolenaar | 5c017b2 | 2019-05-21 23:09:01 +0200 | [diff] [blame] | 109 | 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 Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 115 | < In case of failure zero is returned. |
| 116 | |
| 117 | |
| 118 | popup_close({id}) *popup_close()* |
| 119 | Close popup {id}. The window and the associated buffer will |
| 120 | be deleted. |
Bram Moolenaar | 957f85d | 2019-05-12 21:43:48 +0200 | [diff] [blame] | 121 | |
| 122 | |
Bram Moolenaar | 5c017b2 | 2019-05-21 23:09:01 +0200 | [diff] [blame] | 123 | popup_dialog({text}, {options}) *popup_dialog()* |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 124 | {not implemented yet} |
Bram Moolenaar | 5c017b2 | 2019-05-21 23:09:01 +0200 | [diff] [blame] | 125 | 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 Moolenaar | 957f85d | 2019-05-12 21:43:48 +0200 | [diff] [blame] | 132 | |
| 133 | |
| 134 | popup_notification({text}, {options}) *popup_notification()* |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 135 | {not implemented yet} |
Bram Moolenaar | 5c017b2 | 2019-05-21 23:09:01 +0200 | [diff] [blame] | 136 | Show the {text} for 3 seconds at the top of the Vim window. |
| 137 | This works like: > |
| 138 | call popup_create({text}, { |
Bram Moolenaar | 957f85d | 2019-05-12 21:43:48 +0200 | [diff] [blame] | 139 | \ 'line': 1, |
| 140 | \ 'col': 10, |
| 141 | \ 'time': 3000, |
Bram Moolenaar | 5c017b2 | 2019-05-21 23:09:01 +0200 | [diff] [blame] | 142 | \ 'tab': -1, |
Bram Moolenaar | 957f85d | 2019-05-12 21:43:48 +0200 | [diff] [blame] | 143 | \ 'zindex': 200, |
| 144 | \ 'highlight': 'WarningMsg', |
| 145 | \ 'border: [], |
| 146 | \ }) |
| 147 | < Use {options} to change the properties. |
| 148 | |
Bram Moolenaar | 5c017b2 | 2019-05-21 23:09:01 +0200 | [diff] [blame] | 149 | |
Bram Moolenaar | 957f85d | 2019-05-12 21:43:48 +0200 | [diff] [blame] | 150 | popup_atcursor({text}, {options}) *popup_atcursor()* |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 151 | {not implemented yet} |
Bram Moolenaar | 5c017b2 | 2019-05-21 23:09:01 +0200 | [diff] [blame] | 152 | Show the {text} above the cursor, and close it when the cursor |
| 153 | moves. This works like: > |
| 154 | call popup_create({text}, { |
Bram Moolenaar | 957f85d | 2019-05-12 21:43:48 +0200 | [diff] [blame] | 155 | \ 'line': 'cursor-1', |
| 156 | \ 'col': 'cursor', |
Bram Moolenaar | 957f85d | 2019-05-12 21:43:48 +0200 | [diff] [blame] | 157 | \ 'moved': 'WORD', |
| 158 | \ }) |
| 159 | < Use {options} to change the properties. |
| 160 | |
| 161 | |
Bram Moolenaar | 5c017b2 | 2019-05-21 23:09:01 +0200 | [diff] [blame] | 162 | popup_menu({text}, {options}) *popup_menu()* |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 163 | {not implemented yet} |
Bram Moolenaar | 5c017b2 | 2019-05-21 23:09:01 +0200 | [diff] [blame] | 164 | Show the {text} near the cursor, handle selecting one of the |
Bram Moolenaar | 957f85d | 2019-05-12 21:43:48 +0200 | [diff] [blame] | 165 | items with cursorkeys, and close it an item is selected with |
Bram Moolenaar | 5c017b2 | 2019-05-21 23:09:01 +0200 | [diff] [blame] | 166 | Space or Enter. {text} should have multiple lines to make this |
| 167 | useful. This works like: > |
| 168 | call popup_create({text}, { |
Bram Moolenaar | 957f85d | 2019-05-12 21:43:48 +0200 | [diff] [blame] | 169 | \ '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 Moolenaar | 5c017b2 | 2019-05-21 23:09:01 +0200 | [diff] [blame] | 179 | popup_show({id}) *popup_show()* |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 180 | {not implemented yet} |
Bram Moolenaar | 5c017b2 | 2019-05-21 23:09:01 +0200 | [diff] [blame] | 181 | If {id} is a hidden popup, show it now. |
| 182 | |
| 183 | popup_hide({id}) *popup_hide()* |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 184 | {not implemented yet} |
Bram Moolenaar | 5c017b2 | 2019-05-21 23:09:01 +0200 | [diff] [blame] | 185 | 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 Moolenaar | 957f85d | 2019-05-12 21:43:48 +0200 | [diff] [blame] | 189 | popup_move({id}, {options}) *popup_move()* |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 190 | {not implemented yet} |
Bram Moolenaar | 957f85d | 2019-05-12 21:43:48 +0200 | [diff] [blame] | 191 | Move popup {id} to the position speficied with {options}. |
Bram Moolenaar | 5c017b2 | 2019-05-21 23:09:01 +0200 | [diff] [blame] | 192 | {options} may contain the items from |popup_create()| that |
Bram Moolenaar | 957f85d | 2019-05-12 21:43:48 +0200 | [diff] [blame] | 193 | specify the popup position: "line", "col", "pos", "maxheight", |
| 194 | "minheight", "maxwidth" and "minwidth". |
| 195 | |
| 196 | |
| 197 | popup_filter_menu({id}, {key}) *popup_filter_menu()* |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 198 | {not implemented yet} |
Bram Moolenaar | 957f85d | 2019-05-12 21:43:48 +0200 | [diff] [blame] | 199 | 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 | |
| 206 | popup_filter_yesno({id}, {key}) *popup_filter_yesno()* |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 207 | {not implemented yet} |
Bram Moolenaar | 957f85d | 2019-05-12 21:43:48 +0200 | [diff] [blame] | 208 | 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 Moolenaar | 957f85d | 2019-05-12 21:43:48 +0200 | [diff] [blame] | 215 | popup_setoptions({id}, {options}) *popup_setoptions()* |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 216 | {not implemented yet} |
Bram Moolenaar | 957f85d | 2019-05-12 21:43:48 +0200 | [diff] [blame] | 217 | Override options in popup {id} with entries in {options}. |
| 218 | |
| 219 | |
| 220 | popup_getoptions({id}) *popup_getoptions()* |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 221 | {not implemented yet} |
Bram Moolenaar | 957f85d | 2019-05-12 21:43:48 +0200 | [diff] [blame] | 222 | Return the {options} for popup {id}. |
| 223 | |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 224 | popup_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 Moolenaar | 957f85d | 2019-05-12 21:43:48 +0200 | [diff] [blame] | 232 | |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 233 | win_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 Moolenaar | 957f85d | 2019-05-12 21:43:48 +0200 | [diff] [blame] | 241 | |
Bram Moolenaar | 5c017b2 | 2019-05-21 23:09:01 +0200 | [diff] [blame] | 242 | *:popupclear* *:popupc* |
| 243 | :popupc[lear] Emergency solution to a misbehaving plugin: close all popup |
| 244 | windows. |
Bram Moolenaar | 957f85d | 2019-05-12 21:43:48 +0200 | [diff] [blame] | 245 | |
Bram Moolenaar | 957f85d | 2019-05-12 21:43:48 +0200 | [diff] [blame] | 246 | |
Bram Moolenaar | 5c017b2 | 2019-05-21 23:09:01 +0200 | [diff] [blame] | 247 | POPUP BUFFER AND WINDOW *popup-buffer* |
| 248 | |
| 249 | A new buffer is created to hold the text and text properties of the popup |
| 250 | window. The buffer is always associated with the popup window and |
| 251 | manipulation 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 Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 257 | - 'undolevels' is -1: no undo at all |
Bram Moolenaar | 5c017b2 | 2019-05-21 23:09:01 +0200 | [diff] [blame] | 258 | TODO: more |
| 259 | |
| 260 | The window does have a cursor position, but the cursor is not displayed. |
| 261 | |
| 262 | Options can be set on the window with `setwinvar()`, e.g.: > |
| 263 | call setwinvar(winid, '&wrap', 0) |
| 264 | And options can be set on the buffer with `setbufvar()`, e.g.: > |
| 265 | call setbufvar(winbufnr(winid), '&filetype', 'java') |
| 266 | |
| 267 | |
| 268 | POPUP_CREATE() ARGUMENTS *popup_create-usage* |
| 269 | |
| 270 | The first argument of |popup_create()| specifies the text to be displayed, and |
| 271 | optionally 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 Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 275 | {not implemented yet} |
Bram Moolenaar | 5c017b2 | 2019-05-21 23:09:01 +0200 | [diff] [blame] | 276 | text String with the text to display. |
Bram Moolenaar | 957f85d | 2019-05-12 21:43:48 +0200 | [diff] [blame] | 277 | 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 Moolenaar | 5c017b2 | 2019-05-21 23:09:01 +0200 | [diff] [blame] | 283 | The second argument of |popup_create()| is a dictionary with options: |
Bram Moolenaar | 957f85d | 2019-05-12 21:43:48 +0200 | [diff] [blame] | 284 | 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 Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 288 | {only number is implemented} |
Bram Moolenaar | 957f85d | 2019-05-12 21:43:48 +0200 | [diff] [blame] | 289 | 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 Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 293 | {only number is implemented} |
Bram Moolenaar | 957f85d | 2019-05-12 21:43:48 +0200 | [diff] [blame] | 294 | 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 Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 297 | "center" can be used to position the popup in the |
| 298 | center of the Vim window. |
| 299 | {not implemented yet} |
Bram Moolenaar | 5c017b2 | 2019-05-21 23:09:01 +0200 | [diff] [blame] | 300 | 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 Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 304 | {not implemented yet} |
Bram Moolenaar | 957f85d | 2019-05-12 21:43:48 +0200 | [diff] [blame] | 305 | maxheight maximum height |
| 306 | minheight minimum height |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 307 | {not implemented yet} |
Bram Moolenaar | 957f85d | 2019-05-12 21:43:48 +0200 | [diff] [blame] | 308 | maxwidth maximum width |
| 309 | minwidth minimum width |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 310 | {not implemented yet} |
Bram Moolenaar | 5c017b2 | 2019-05-21 23:09:01 +0200 | [diff] [blame] | 311 | hidden when TRUE the popup exists but is not displayed; use |
| 312 | `popup_show()` to unhide it. |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 313 | {not implemented yet} |
Bram Moolenaar | 5c017b2 | 2019-05-21 23:09:01 +0200 | [diff] [blame] | 314 | 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 Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 318 | {only -1 and 0 are implemented} |
Bram Moolenaar | 957f85d | 2019-05-12 21:43:48 +0200 | [diff] [blame] | 319 | title text to be displayed above the first item in the |
| 320 | popup, on top of any border |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 321 | {not implemented yet} |
Bram Moolenaar | 957f85d | 2019-05-12 21:43:48 +0200 | [diff] [blame] | 322 | wrap TRUE to make the lines wrap (default TRUE) |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 323 | {not implemented yet} |
| 324 | highlight highlight group name to use for the text, stored in |
| 325 | 'wincolor' |
| 326 | {not implemented yet} |
Bram Moolenaar | 957f85d | 2019-05-12 21:43:48 +0200 | [diff] [blame] | 327 | 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 Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 330 | {not implemented yet} |
Bram Moolenaar | 957f85d | 2019-05-12 21:43:48 +0200 | [diff] [blame] | 331 | borderhighlight highlight group name to use for the border |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 332 | {not implemented yet} |
Bram Moolenaar | 957f85d | 2019-05-12 21:43:48 +0200 | [diff] [blame] | 333 | 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 Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 338 | {not implemented yet} |
Bram Moolenaar | 957f85d | 2019-05-12 21:43:48 +0200 | [diff] [blame] | 339 | 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 Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 342 | {not implemented yet} |
Bram Moolenaar | 957f85d | 2019-05-12 21:43:48 +0200 | [diff] [blame] | 343 | 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 Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 348 | {not implemented yet} |
Bram Moolenaar | 957f85d | 2019-05-12 21:43:48 +0200 | [diff] [blame] | 349 | filter a callback that can filter typed characters, see |
| 350 | |popup-filter| |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 351 | {not implemented yet} |
Bram Moolenaar | 957f85d | 2019-05-12 21:43:48 +0200 | [diff] [blame] | 352 | callback a callback to be used when the popup closes, e.g. when |
| 353 | using |popup_filter_menu()|, see |popup-callback|. |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 354 | {not implemented yet} |
Bram Moolenaar | 957f85d | 2019-05-12 21:43:48 +0200 | [diff] [blame] | 355 | |
| 356 | Depending on the "zindex" the popup goes under or above other popups. The |
| 357 | completion menu (|popup-menu|) has zindex 100. For messages that occur for a |
| 358 | short time the suggestion is to use zindex 1000. |
| 359 | |
| 360 | By default text wraps, which causes a line in {lines} to occupy more than one |
| 361 | screen line. When "wrap" is FALSE then the text outside of the popup or |
| 362 | outside of the Vim window will not be displayed, thus truncated. |
| 363 | |
| 364 | |
| 365 | POPUP TEXT PROPERTIES *popup-props* |
| 366 | |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 367 | {not implemented yet} |
Bram Moolenaar | 957f85d | 2019-05-12 21:43:48 +0200 | [diff] [blame] | 368 | These are similar to the third argument of |prop_add()|, but not exactly the |
| 369 | same, 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 | |
| 385 | POPUP FILTER *popup-filter* |
| 386 | |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 387 | {not implemented yet} |
Bram Moolenaar | 5c017b2 | 2019-05-21 23:09:01 +0200 | [diff] [blame] | 388 | A callback that gets any typed keys while a popup is displayed. The filter is |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 389 | not invoked when the popup is hidden. |
Bram Moolenaar | 5c017b2 | 2019-05-21 23:09:01 +0200 | [diff] [blame] | 390 | |
| 391 | The filter can return TRUE to indicate the key has been handled and is to be |
| 392 | discarded, or FALSE to let Vim handle the key as usual in the current state. |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 393 | In case it returns FALSE and there is another popup window visible, that |
| 394 | filter is also called. The filter of the popup window with the highest zindex |
| 395 | is called first. |
Bram Moolenaar | 957f85d | 2019-05-12 21:43:48 +0200 | [diff] [blame] | 396 | |
| 397 | The filter function is called with two arguments: the ID of the popup and the |
| 398 | key. |
| 399 | |
| 400 | Some common key actions: |
| 401 | Esc close the popup |
| 402 | cursor keys select another entry |
| 403 | Tab accept current suggestion |
| 404 | |
Bram Moolenaar | 5c017b2 | 2019-05-21 23:09:01 +0200 | [diff] [blame] | 405 | A mouse click arrives as <LeftMouse>. The coordinates are in |
| 406 | v:mouse_popup_col and v:mouse_popup_row. The top-left screen cell of the |
| 407 | popup is col 1, row 1 (not counting the border). |
| 408 | |
Bram Moolenaar | 957f85d | 2019-05-12 21:43:48 +0200 | [diff] [blame] | 409 | Vim provides standard filters |popup_filter_menu()| and |
| 410 | |popup_filter_yesno()|. |
| 411 | |
| 412 | |
| 413 | POPUP CALLBACK *popup-callback* |
| 414 | |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 415 | {not implemented yet} |
Bram Moolenaar | 957f85d | 2019-05-12 21:43:48 +0200 | [diff] [blame] | 416 | A callback that is invoked when the popup closes. Used by |
| 417 | |popup_filter_menu()|. Invoked with two arguments: the ID of the popup and |
| 418 | the result, which would usually be an index in the popup lines, or whatever |
| 419 | the filter wants to pass. |
| 420 | |
| 421 | ============================================================================== |
| 422 | 3. Examples *popup-examples* |
| 423 | |
| 424 | TODO |
| 425 | |
| 426 | Prompt 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 Moolenaar | 5c017b2 | 2019-05-21 23:09:01 +0200 | [diff] [blame] | 434 | call popup_create(['Continue? y/n'], { |
Bram Moolenaar | 957f85d | 2019-05-12 21:43:48 +0200 | [diff] [blame] | 435 | \ 'filter': 'popup_filter_yesno', |
| 436 | \ 'callback': 'MyDialogHandler', |
| 437 | \ }) |
| 438 | < |
| 439 | |
| 440 | vim:tw=78:ts=8:noet:ft=help:norl: |