blob: b62619368f2dae494b9dfee54232f3c0e855c6ee [file] [log] [blame]
Bram Moolenaar98aefe72018-12-13 22:20:09 +01001/* vi:set ts=8 sts=4 sw=4 noet:
2 *
3 * VIM - Vi IMproved by Bram Moolenaar
4 *
5 * Do ":help uganda" in Vim to read copying and usage conditions.
6 * Do ":help credits" in Vim to see a list of people who contributed.
7 * See README.txt for an overview of the Vim source code.
8 */
9
10/*
Bram Moolenaar45dd07f2019-05-15 22:45:37 +020011 * Text properties implementation. See ":help text-properties".
Bram Moolenaar98aefe72018-12-13 22:20:09 +010012 *
13 * TODO:
Bram Moolenaarb9c67a52019-01-01 19:49:20 +010014 * - Adjust text property column and length when text is inserted/deleted.
Bram Moolenaar4164bb22019-01-04 23:09:49 +010015 * -> a :substitute with a multi-line match
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010016 * -> search for changed_bytes() from misc1.c
Bram Moolenaar80e737c2019-05-17 19:56:34 +020017 * -> search for mark_col_adjust()
Bram Moolenaarb9c67a52019-01-01 19:49:20 +010018 * - Perhaps we only need TP_FLAG_CONT_NEXT and can drop TP_FLAG_CONT_PREV?
Bram Moolenaar32aa1022019-11-02 22:54:41 +010019 * - Add an array for global_proptypes, to quickly lookup a prop type by ID
20 * - Add an array for b_proptypes, to quickly lookup a prop type by ID
Bram Moolenaarb56ac042018-12-28 23:22:40 +010021 * - Checking the text length to detect text properties is slow. Use a flag in
22 * the index, like DB_MARKED?
Bram Moolenaarb413d2e2018-12-25 23:15:46 +010023 * - Also test line2byte() with many lines, so that ml_updatechunk() is taken
24 * into account.
Bram Moolenaarc6663882019-02-22 19:14:54 +010025 * - Perhaps have a window-local option to disable highlighting from text
26 * properties?
Bram Moolenaar98aefe72018-12-13 22:20:09 +010027 */
28
29#include "vim.h"
30
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +010031#if defined(FEAT_PROP_POPUP) || defined(PROTO)
Bram Moolenaar98aefe72018-12-13 22:20:09 +010032
33/*
34 * In a hashtable item "hi_key" points to "pt_name" in a proptype_T.
35 * This avoids adding a pointer to the hashtable item.
36 * PT2HIKEY() converts a proptype pointer to a hashitem key pointer.
37 * HIKEY2PT() converts a hashitem key pointer to a proptype pointer.
38 * HI2PT() converts a hashitem pointer to a proptype pointer.
39 */
40#define PT2HIKEY(p) ((p)->pt_name)
41#define HIKEY2PT(p) ((proptype_T *)((p) - offsetof(proptype_T, pt_name)))
42#define HI2PT(hi) HIKEY2PT((hi)->hi_key)
43
44// The global text property types.
45static hashtab_T *global_proptypes = NULL;
46
47// The last used text property type ID.
48static int proptype_id = 0;
49
50static char_u e_type_not_exist[] = N_("E971: Property type %s does not exist");
51static char_u e_invalid_col[] = N_("E964: Invalid column number: %ld");
Bram Moolenaare3d31b02018-12-24 23:07:04 +010052static char_u e_invalid_lnum[] = N_("E966: Invalid line number: %ld");
Bram Moolenaar98aefe72018-12-13 22:20:09 +010053
54/*
55 * Find a property type by name, return the hashitem.
56 * Returns NULL if the item can't be found.
57 */
58 static hashitem_T *
59find_prop_hi(char_u *name, buf_T *buf)
60{
61 hashtab_T *ht;
62 hashitem_T *hi;
63
64 if (*name == NUL)
65 return NULL;
66 if (buf == NULL)
67 ht = global_proptypes;
68 else
69 ht = buf->b_proptypes;
70
71 if (ht == NULL)
72 return NULL;
73 hi = hash_find(ht, name);
74 if (HASHITEM_EMPTY(hi))
75 return NULL;
76 return hi;
77}
78
79/*
80 * Like find_prop_hi() but return the property type.
81 */
82 static proptype_T *
83find_prop(char_u *name, buf_T *buf)
84{
85 hashitem_T *hi = find_prop_hi(name, buf);
86
87 if (hi == NULL)
88 return NULL;
89 return HI2PT(hi);
90}
91
92/*
Bram Moolenaar12034e22019-08-25 22:25:02 +020093 * Get the prop type ID of "name".
94 * When not found return zero.
95 */
96 int
97find_prop_type_id(char_u *name, buf_T *buf)
98{
99 proptype_T *pt = find_prop(name, buf);
100
101 if (pt == NULL)
102 return 0;
103 return pt->pt_id;
104}
105
106/*
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100107 * Lookup a property type by name. First in "buf" and when not found in the
108 * global types.
109 * When not found gives an error message and returns NULL.
110 */
111 static proptype_T *
112lookup_prop_type(char_u *name, buf_T *buf)
113{
114 proptype_T *type = find_prop(name, buf);
115
116 if (type == NULL)
117 type = find_prop(name, NULL);
118 if (type == NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +0100119 semsg(_(e_type_not_exist), name);
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100120 return type;
121}
122
123/*
124 * Get an optional "bufnr" item from the dict in "arg".
125 * When the argument is not used or "bufnr" is not present then "buf" is
126 * unchanged.
127 * If "bufnr" is valid or not present return OK.
Bram Moolenaar32aa1022019-11-02 22:54:41 +0100128 * When "arg" is not a dict or "bufnr" is invalid return FAIL.
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100129 */
130 static int
131get_bufnr_from_arg(typval_T *arg, buf_T **buf)
132{
133 dictitem_T *di;
134
135 if (arg->v_type != VAR_DICT)
136 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +0100137 emsg(_(e_dictreq));
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100138 return FAIL;
139 }
140 if (arg->vval.v_dict == NULL)
141 return OK; // NULL dict is like an empty dict
142 di = dict_find(arg->vval.v_dict, (char_u *)"bufnr", -1);
143 if (di != NULL)
144 {
Bram Moolenaarf0884c52019-05-24 21:22:29 +0200145 *buf = get_buf_arg(&di->di_tv);
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100146 if (*buf == NULL)
147 return FAIL;
148 }
149 return OK;
150}
151
152/*
153 * prop_add({lnum}, {col}, {props})
154 */
155 void
156f_prop_add(typval_T *argvars, typval_T *rettv UNUSED)
157{
Bram Moolenaare3d31b02018-12-24 23:07:04 +0100158 linenr_T start_lnum;
Bram Moolenaare3d31b02018-12-24 23:07:04 +0100159 colnr_T start_col;
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100160
Bram Moolenaare3d31b02018-12-24 23:07:04 +0100161 start_lnum = tv_get_number(&argvars[0]);
162 start_col = tv_get_number(&argvars[1]);
163 if (start_col < 1)
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100164 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +0100165 semsg(_(e_invalid_col), (long)start_col);
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100166 return;
167 }
168 if (argvars[2].v_type != VAR_DICT)
169 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +0100170 emsg(_(e_dictreq));
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100171 return;
172 }
Bram Moolenaar7a8d0272019-05-26 23:32:06 +0200173
174 prop_add_common(start_lnum, start_col, argvars[2].vval.v_dict,
175 curbuf, &argvars[2]);
176}
177
178/*
179 * Shared between prop_add() and popup_create().
180 * "dict_arg" is the function argument of a dict containing "bufnr".
181 * it is NULL for popup_create().
182 */
183 void
184prop_add_common(
185 linenr_T start_lnum,
186 colnr_T start_col,
187 dict_T *dict,
188 buf_T *default_buf,
189 typval_T *dict_arg)
190{
191 linenr_T lnum;
192 linenr_T end_lnum;
193 colnr_T end_col;
194 char_u *type_name;
195 proptype_T *type;
196 buf_T *buf = default_buf;
197 int id = 0;
198 char_u *newtext;
199 int proplen;
200 size_t textlen;
201 char_u *props = NULL;
202 char_u *newprops;
203 textprop_T tmp_prop;
204 int i;
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100205
206 if (dict == NULL || dict_find(dict, (char_u *)"type", -1) == NULL)
207 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +0100208 emsg(_("E965: missing property type name"));
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100209 return;
210 }
Bram Moolenaar8f667172018-12-14 15:38:31 +0100211 type_name = dict_get_string(dict, (char_u *)"type", FALSE);
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100212
213 if (dict_find(dict, (char_u *)"end_lnum", -1) != NULL)
214 {
Bram Moolenaare3d31b02018-12-24 23:07:04 +0100215 end_lnum = dict_get_number(dict, (char_u *)"end_lnum");
216 if (end_lnum < start_lnum)
217 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +0100218 semsg(_(e_invargval), "end_lnum");
Bram Moolenaare3d31b02018-12-24 23:07:04 +0100219 return;
220 }
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100221 }
Bram Moolenaare3d31b02018-12-24 23:07:04 +0100222 else
223 end_lnum = start_lnum;
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100224
225 if (dict_find(dict, (char_u *)"length", -1) != NULL)
Bram Moolenaare3d31b02018-12-24 23:07:04 +0100226 {
227 long length = dict_get_number(dict, (char_u *)"length");
228
Bram Moolenaarb9c67a52019-01-01 19:49:20 +0100229 if (length < 0 || end_lnum > start_lnum)
Bram Moolenaare3d31b02018-12-24 23:07:04 +0100230 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +0100231 semsg(_(e_invargval), "length");
Bram Moolenaare3d31b02018-12-24 23:07:04 +0100232 return;
233 }
Bram Moolenaarb9c67a52019-01-01 19:49:20 +0100234 end_col = start_col + length;
Bram Moolenaare3d31b02018-12-24 23:07:04 +0100235 }
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100236 else if (dict_find(dict, (char_u *)"end_col", -1) != NULL)
237 {
Bram Moolenaare3d31b02018-12-24 23:07:04 +0100238 end_col = dict_get_number(dict, (char_u *)"end_col");
239 if (end_col <= 0)
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100240 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +0100241 semsg(_(e_invargval), "end_col");
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100242 return;
243 }
244 }
Bram Moolenaare3d31b02018-12-24 23:07:04 +0100245 else if (start_lnum == end_lnum)
246 end_col = start_col;
247 else
248 end_col = 1;
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100249
250 if (dict_find(dict, (char_u *)"id", -1) != NULL)
Bram Moolenaar8f667172018-12-14 15:38:31 +0100251 id = dict_get_number(dict, (char_u *)"id");
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100252
Bram Moolenaar7a8d0272019-05-26 23:32:06 +0200253 if (dict_arg != NULL && get_bufnr_from_arg(dict_arg, &buf) == FAIL)
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100254 return;
255
256 type = lookup_prop_type(type_name, buf);
257 if (type == NULL)
258 return;
259
Bram Moolenaare3d31b02018-12-24 23:07:04 +0100260 if (start_lnum < 1 || start_lnum > buf->b_ml.ml_line_count)
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100261 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +0100262 semsg(_(e_invalid_lnum), (long)start_lnum);
Bram Moolenaare3d31b02018-12-24 23:07:04 +0100263 return;
264 }
265 if (end_lnum < start_lnum || end_lnum > buf->b_ml.ml_line_count)
266 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +0100267 semsg(_(e_invalid_lnum), (long)end_lnum);
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100268 return;
269 }
270
Bram Moolenaard79eef22019-05-24 20:41:55 +0200271 if (buf->b_ml.ml_mfp == NULL)
Bram Moolenaar45311b52019-08-13 22:27:32 +0200272 {
273 emsg(_("E275: Cannot add text property to unloaded buffer"));
274 return;
275 }
Bram Moolenaard79eef22019-05-24 20:41:55 +0200276
Bram Moolenaare3d31b02018-12-24 23:07:04 +0100277 for (lnum = start_lnum; lnum <= end_lnum; ++lnum)
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100278 {
Bram Moolenaare3d31b02018-12-24 23:07:04 +0100279 colnr_T col; // start column
280 long length; // in bytes
281
282 // Fetch the line to get the ml_line_len field updated.
283 proplen = get_text_props(buf, lnum, &props, TRUE);
284 textlen = buf->b_ml.ml_line_len - proplen * sizeof(textprop_T);
285
286 if (lnum == start_lnum)
287 col = start_col;
288 else
289 col = 1;
290 if (col - 1 > (colnr_T)textlen)
291 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +0100292 semsg(_(e_invalid_col), (long)start_col);
Bram Moolenaare3d31b02018-12-24 23:07:04 +0100293 return;
294 }
295
296 if (lnum == end_lnum)
Bram Moolenaarb9c67a52019-01-01 19:49:20 +0100297 length = end_col - col;
Bram Moolenaare3d31b02018-12-24 23:07:04 +0100298 else
Bram Moolenaar4b7214e2019-01-03 21:55:32 +0100299 length = (int)textlen - col + 1;
Bram Moolenaarb413d2e2018-12-25 23:15:46 +0100300 if (length > (long)textlen)
Bram Moolenaar4b7214e2019-01-03 21:55:32 +0100301 length = (int)textlen; // can include the end-of-line
Bram Moolenaarb9c67a52019-01-01 19:49:20 +0100302 if (length < 0)
303 length = 0; // zero-width property
Bram Moolenaare3d31b02018-12-24 23:07:04 +0100304
Bram Moolenaar8e7d6222020-12-18 19:49:56 +0100305 // Allocate the new line with space for the new property.
Bram Moolenaare3d31b02018-12-24 23:07:04 +0100306 newtext = alloc(buf->b_ml.ml_line_len + sizeof(textprop_T));
307 if (newtext == NULL)
308 return;
309 // Copy the text, including terminating NUL.
310 mch_memmove(newtext, buf->b_ml.ml_line_ptr, textlen);
311
312 // Find the index where to insert the new property.
Bram Moolenaar7a8d0272019-05-26 23:32:06 +0200313 // Since the text properties are not aligned properly when stored with
314 // the text, we need to copy them as bytes before using it as a struct.
Bram Moolenaare3d31b02018-12-24 23:07:04 +0100315 for (i = 0; i < proplen; ++i)
316 {
317 mch_memmove(&tmp_prop, props + i * sizeof(textprop_T),
Bram Moolenaar7a8d0272019-05-26 23:32:06 +0200318 sizeof(textprop_T));
Bram Moolenaare3d31b02018-12-24 23:07:04 +0100319 if (tmp_prop.tp_col >= col)
320 break;
321 }
322 newprops = newtext + textlen;
323 if (i > 0)
324 mch_memmove(newprops, props, sizeof(textprop_T) * i);
325
326 tmp_prop.tp_col = col;
327 tmp_prop.tp_len = length;
328 tmp_prop.tp_id = id;
329 tmp_prop.tp_type = type->pt_id;
330 tmp_prop.tp_flags = (lnum > start_lnum ? TP_FLAG_CONT_PREV : 0)
331 | (lnum < end_lnum ? TP_FLAG_CONT_NEXT : 0);
332 mch_memmove(newprops + i * sizeof(textprop_T), &tmp_prop,
Bram Moolenaar7a8d0272019-05-26 23:32:06 +0200333 sizeof(textprop_T));
Bram Moolenaare3d31b02018-12-24 23:07:04 +0100334
335 if (i < proplen)
336 mch_memmove(newprops + (i + 1) * sizeof(textprop_T),
337 props + i * sizeof(textprop_T),
338 sizeof(textprop_T) * (proplen - i));
339
340 if (buf->b_ml.ml_flags & ML_LINE_DIRTY)
341 vim_free(buf->b_ml.ml_line_ptr);
342 buf->b_ml.ml_line_ptr = newtext;
343 buf->b_ml.ml_line_len += sizeof(textprop_T);
344 buf->b_ml.ml_flags |= ML_LINE_DIRTY;
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100345 }
346
Bram Moolenaarb413d2e2018-12-25 23:15:46 +0100347 buf->b_has_textprop = TRUE; // this is never reset
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100348 redraw_buf_later(buf, NOT_VALID);
349}
350
351/*
Bram Moolenaarfb95e212018-12-14 12:18:11 +0100352 * Fetch the text properties for line "lnum" in buffer "buf".
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100353 * Returns the number of text properties and, when non-zero, a pointer to the
354 * first one in "props" (note that it is not aligned, therefore the char_u
355 * pointer).
356 */
357 int
358get_text_props(buf_T *buf, linenr_T lnum, char_u **props, int will_change)
359{
360 char_u *text;
361 size_t textlen;
362 size_t proplen;
363
Bram Moolenaarb413d2e2018-12-25 23:15:46 +0100364 // Be quick when no text property types have been defined or the buffer,
365 // unless we are adding one.
Bram Moolenaard79eef22019-05-24 20:41:55 +0200366 if ((!buf->b_has_textprop && !will_change) || buf->b_ml.ml_mfp == NULL)
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100367 return 0;
368
369 // Fetch the line to get the ml_line_len field updated.
370 text = ml_get_buf(buf, lnum, will_change);
371 textlen = STRLEN(text) + 1;
372 proplen = buf->b_ml.ml_line_len - textlen;
373 if (proplen % sizeof(textprop_T) != 0)
374 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +0100375 iemsg(_("E967: text property info corrupted"));
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100376 return 0;
377 }
378 if (proplen > 0)
379 *props = text + textlen;
Bram Moolenaar4efe73b2018-12-16 14:37:39 +0100380 return (int)(proplen / sizeof(textprop_T));
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100381}
382
Bram Moolenaar87be9be2020-05-30 15:32:02 +0200383/**
384 * Return the number of text properties on line "lnum" in the current buffer.
385 * When "only_starting" is true only text properties starting in this line will
386 * be considered.
387 */
388 int
389count_props(linenr_T lnum, int only_starting)
390{
391 char_u *props;
392 int proplen = get_text_props(curbuf, lnum, &props, 0);
393 int result = proplen;
394 int i;
395 textprop_T prop;
396
397 if (only_starting)
398 for (i = 0; i < proplen; ++i)
399 {
400 mch_memmove(&prop, props + i * sizeof(prop), sizeof(prop));
401 if (prop.tp_flags & TP_FLAG_CONT_PREV)
402 --result;
403 }
404 return result;
405}
406
Bram Moolenaar4164bb22019-01-04 23:09:49 +0100407/*
Bram Moolenaar12034e22019-08-25 22:25:02 +0200408 * Find text property "type_id" in the visible lines of window "wp".
409 * Match "id" when it is > 0.
410 * Returns FAIL when not found.
411 */
412 int
413find_visible_prop(win_T *wp, int type_id, int id, textprop_T *prop,
414 linenr_T *found_lnum)
415{
416 linenr_T lnum;
417 char_u *props;
418 int count;
419 int i;
420
421 // w_botline may not have been updated yet.
Bram Moolenaar23999d72020-12-23 14:36:00 +0100422 validate_botline_win(wp);
Bram Moolenaar12034e22019-08-25 22:25:02 +0200423 for (lnum = wp->w_topline; lnum < wp->w_botline; ++lnum)
424 {
425 count = get_text_props(wp->w_buffer, lnum, &props, FALSE);
426 for (i = 0; i < count; ++i)
427 {
428 mch_memmove(prop, props + i * sizeof(textprop_T),
429 sizeof(textprop_T));
430 if (prop->tp_type == type_id && (id <= 0 || prop->tp_id == id))
431 {
432 *found_lnum = lnum;
433 return OK;
434 }
435 }
436 }
437 return FAIL;
438}
439
440/*
Bram Moolenaar4164bb22019-01-04 23:09:49 +0100441 * Set the text properties for line "lnum" to "props" with length "len".
442 * If "len" is zero text properties are removed, "props" is not used.
443 * Any existing text properties are dropped.
444 * Only works for the current buffer.
445 */
446 static void
447set_text_props(linenr_T lnum, char_u *props, int len)
448{
Bram Moolenaar8aef43b2019-01-08 20:14:35 +0100449 char_u *text;
450 char_u *newtext;
451 int textlen;
Bram Moolenaar4164bb22019-01-04 23:09:49 +0100452
453 text = ml_get(lnum);
Bram Moolenaar8aef43b2019-01-08 20:14:35 +0100454 textlen = (int)STRLEN(text) + 1;
Bram Moolenaar4164bb22019-01-04 23:09:49 +0100455 newtext = alloc(textlen + len);
456 if (newtext == NULL)
457 return;
458 mch_memmove(newtext, text, textlen);
459 if (len > 0)
460 mch_memmove(newtext + textlen, props, len);
461 if (curbuf->b_ml.ml_flags & ML_LINE_DIRTY)
462 vim_free(curbuf->b_ml.ml_line_ptr);
463 curbuf->b_ml.ml_line_ptr = newtext;
464 curbuf->b_ml.ml_line_len = textlen + len;
465 curbuf->b_ml.ml_flags |= ML_LINE_DIRTY;
466}
467
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100468 static proptype_T *
469find_type_by_id(hashtab_T *ht, int id)
470{
471 long todo;
472 hashitem_T *hi;
473
474 if (ht == NULL)
475 return NULL;
476
477 // TODO: Make this faster by keeping a list of types sorted on ID and use
478 // a binary search.
479
480 todo = (long)ht->ht_used;
481 for (hi = ht->ht_array; todo > 0; ++hi)
482 {
483 if (!HASHITEM_EMPTY(hi))
484 {
485 proptype_T *prop = HI2PT(hi);
486
487 if (prop->pt_id == id)
488 return prop;
489 --todo;
490 }
491 }
492 return NULL;
493}
494
495/*
Bram Moolenaare05a89a2020-01-10 19:56:46 +0100496 * Fill 'dict' with text properties in 'prop'.
497 */
498 static void
499prop_fill_dict(dict_T *dict, textprop_T *prop, buf_T *buf)
500{
501 proptype_T *pt;
502
503 dict_add_number(dict, "col", prop->tp_col);
504 dict_add_number(dict, "length", prop->tp_len);
505 dict_add_number(dict, "id", prop->tp_id);
506 dict_add_number(dict, "start", !(prop->tp_flags & TP_FLAG_CONT_PREV));
507 dict_add_number(dict, "end", !(prop->tp_flags & TP_FLAG_CONT_NEXT));
508 pt = text_prop_type_by_id(buf, prop->tp_type);
509 if (pt != NULL)
510 dict_add_string(dict, "type", pt->pt_name);
511}
512
513/*
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100514 * Find a property type by ID in "buf" or globally.
515 * Returns NULL if not found.
516 */
517 proptype_T *
518text_prop_type_by_id(buf_T *buf, int id)
519{
520 proptype_T *type;
521
522 type = find_type_by_id(buf->b_proptypes, id);
523 if (type == NULL)
524 type = find_type_by_id(global_proptypes, id);
525 return type;
526}
527
528/*
529 * prop_clear({lnum} [, {lnum_end} [, {bufnr}]])
530 */
531 void
532f_prop_clear(typval_T *argvars, typval_T *rettv UNUSED)
533{
Bram Moolenaard155d7a2018-12-21 16:04:21 +0100534 linenr_T start = tv_get_number(&argvars[0]);
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100535 linenr_T end = start;
536 linenr_T lnum;
537 buf_T *buf = curbuf;
Bram Moolenaarda1dbed2021-03-22 19:43:34 +0100538 int did_clear = FALSE;
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100539
540 if (argvars[1].v_type != VAR_UNKNOWN)
541 {
Bram Moolenaard155d7a2018-12-21 16:04:21 +0100542 end = tv_get_number(&argvars[1]);
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100543 if (argvars[2].v_type != VAR_UNKNOWN)
544 {
545 if (get_bufnr_from_arg(&argvars[2], &buf) == FAIL)
546 return;
547 }
548 }
549 if (start < 1 || end < 1)
550 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +0100551 emsg(_(e_invrange));
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100552 return;
553 }
554
555 for (lnum = start; lnum <= end; ++lnum)
556 {
557 char_u *text;
558 size_t len;
559
560 if (lnum > buf->b_ml.ml_line_count)
561 break;
562 text = ml_get_buf(buf, lnum, FALSE);
563 len = STRLEN(text) + 1;
564 if ((size_t)buf->b_ml.ml_line_len > len)
565 {
Bram Moolenaarda1dbed2021-03-22 19:43:34 +0100566 did_clear = TRUE;
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100567 if (!(buf->b_ml.ml_flags & ML_LINE_DIRTY))
568 {
569 char_u *newtext = vim_strsave(text);
570
571 // need to allocate the line now
572 if (newtext == NULL)
573 return;
574 buf->b_ml.ml_line_ptr = newtext;
575 buf->b_ml.ml_flags |= ML_LINE_DIRTY;
576 }
Bram Moolenaar4efe73b2018-12-16 14:37:39 +0100577 buf->b_ml.ml_line_len = (int)len;
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100578 }
579 }
Bram Moolenaarda1dbed2021-03-22 19:43:34 +0100580 if (did_clear)
581 redraw_buf_later(buf, NOT_VALID);
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100582}
583
584/*
Bram Moolenaare05a89a2020-01-10 19:56:46 +0100585 * prop_find({props} [, {direction}])
586 */
587 void
588f_prop_find(typval_T *argvars, typval_T *rettv)
589{
590 pos_T *cursor = &curwin->w_cursor;
591 dict_T *dict;
592 buf_T *buf = curbuf;
593 dictitem_T *di;
Bram Moolenaar87be9be2020-05-30 15:32:02 +0200594 int lnum_start;
595 int start_pos_has_prop = 0;
596 int seen_end = 0;
597 int id = -1;
598 int type_id = -1;
599 int skipstart = 0;
600 int lnum = -1;
601 int col = -1;
602 int dir = 1; // 1 = forward, -1 = backward
Bram Moolenaar24f21fd2021-03-27 22:07:29 +0100603 int both;
Bram Moolenaare05a89a2020-01-10 19:56:46 +0100604
605 if (argvars[0].v_type != VAR_DICT || argvars[0].vval.v_dict == NULL)
606 {
607 emsg(_(e_invarg));
608 return;
609 }
610 dict = argvars[0].vval.v_dict;
611
612 if (get_bufnr_from_arg(&argvars[0], &buf) == FAIL)
613 return;
614 if (buf->b_ml.ml_mfp == NULL)
615 return;
616
617 if (argvars[1].v_type != VAR_UNKNOWN)
618 {
619 char_u *dir_s = tv_get_string(&argvars[1]);
620
621 if (*dir_s == 'b')
622 dir = -1;
623 else if (*dir_s != 'f')
624 {
625 emsg(_(e_invarg));
626 return;
627 }
628 }
629
630 di = dict_find(dict, (char_u *)"lnum", -1);
631 if (di != NULL)
632 lnum = tv_get_number(&di->di_tv);
633
634 di = dict_find(dict, (char_u *)"col", -1);
635 if (di != NULL)
636 col = tv_get_number(&di->di_tv);
637
638 if (lnum == -1)
639 {
640 lnum = cursor->lnum;
641 col = cursor->col + 1;
642 }
643 else if (col == -1)
644 col = 1;
645
646 if (lnum < 1 || lnum > buf->b_ml.ml_line_count)
647 {
648 emsg(_(e_invrange));
649 return;
650 }
651
Bram Moolenaareb245562020-09-03 22:33:44 +0200652 skipstart = dict_get_bool(dict, (char_u *)"skipstart", 0);
Bram Moolenaare05a89a2020-01-10 19:56:46 +0100653
654 if (dict_find(dict, (char_u *)"id", -1) != NULL)
655 id = dict_get_number(dict, (char_u *)"id");
656 if (dict_find(dict, (char_u *)"type", -1))
657 {
658 char_u *name = dict_get_string(dict, (char_u *)"type", FALSE);
659 proptype_T *type = lookup_prop_type(name, buf);
660
661 if (type == NULL)
662 return;
663 type_id = type->pt_id;
664 }
Bram Moolenaar24f21fd2021-03-27 22:07:29 +0100665 both = dict_get_bool(dict, (char_u *)"both", FALSE);
Bram Moolenaare05a89a2020-01-10 19:56:46 +0100666 if (id == -1 && type_id == -1)
667 {
668 emsg(_("E968: Need at least one of 'id' or 'type'"));
669 return;
670 }
Bram Moolenaar24f21fd2021-03-27 22:07:29 +0100671 if (both && (id == -1 || type_id == -1))
672 {
673 emsg(_("E860: Need 'id' and 'type' with 'both'"));
674 return;
675 }
Bram Moolenaare05a89a2020-01-10 19:56:46 +0100676
677 lnum_start = lnum;
678
679 if (rettv_dict_alloc(rettv) == FAIL)
680 return;
681
682 while (1)
683 {
684 char_u *text = ml_get_buf(buf, lnum, FALSE);
685 size_t textlen = STRLEN(text) + 1;
686 int count = (int)((buf->b_ml.ml_line_len - textlen)
Bram Moolenaar87be9be2020-05-30 15:32:02 +0200687 / sizeof(textprop_T));
Bram Moolenaare05a89a2020-01-10 19:56:46 +0100688 int i;
689 textprop_T prop;
690 int prop_start;
691 int prop_end;
692
693 for (i = 0; i < count; ++i)
694 {
695 mch_memmove(&prop, text + textlen + i * sizeof(textprop_T),
696 sizeof(textprop_T));
697
Bram Moolenaar346f18e2020-03-13 21:36:40 +0100698 if (lnum == lnum_start)
Bram Moolenaar965fd8d2020-03-14 07:46:40 +0100699 {
Bram Moolenaar346f18e2020-03-13 21:36:40 +0100700 if (dir < 0)
701 {
702 if (col < prop.tp_col)
703 break;
704 }
705 else if (prop.tp_col + prop.tp_len - (prop.tp_len != 0) < col)
706 continue;
Bram Moolenaar965fd8d2020-03-14 07:46:40 +0100707 }
Bram Moolenaar24f21fd2021-03-27 22:07:29 +0100708 if (both ? prop.tp_id == id && prop.tp_type == type_id
709 : prop.tp_id == id || prop.tp_type == type_id)
Bram Moolenaare05a89a2020-01-10 19:56:46 +0100710 {
711 // Check if the starting position has text props.
Bram Moolenaar66b98852020-03-11 19:15:52 +0100712 if (lnum_start == lnum
713 && col >= prop.tp_col
714 && (col <= prop.tp_col + prop.tp_len
715 - (prop.tp_len != 0)))
716 start_pos_has_prop = 1;
Bram Moolenaare05a89a2020-01-10 19:56:46 +0100717
718 prop_start = !(prop.tp_flags & TP_FLAG_CONT_PREV);
719 prop_end = !(prop.tp_flags & TP_FLAG_CONT_NEXT);
720 if (!prop_start && prop_end && dir > 0)
721 seen_end = 1;
722
723 // Skip lines without the start flag.
724 if (!prop_start)
725 {
726 // Always search backwards for start when search started
727 // on a prop and we're not skipping.
728 if (start_pos_has_prop && !skipstart)
729 dir = -1;
Bram Moolenaar4da7a252020-09-02 19:59:00 +0200730 continue;
Bram Moolenaare05a89a2020-01-10 19:56:46 +0100731 }
732
733 // If skipstart is true, skip the prop at start pos (even if
734 // continued from another line).
735 if (start_pos_has_prop && skipstart && !seen_end)
736 {
737 start_pos_has_prop = 0;
Bram Moolenaar4da7a252020-09-02 19:59:00 +0200738 continue;
Bram Moolenaare05a89a2020-01-10 19:56:46 +0100739 }
740
Bram Moolenaare05a89a2020-01-10 19:56:46 +0100741 prop_fill_dict(rettv->vval.v_dict, &prop, buf);
742 dict_add_number(rettv->vval.v_dict, "lnum", lnum);
743
744 return;
745 }
746 }
747
748 if (dir > 0)
749 {
750 if (lnum >= buf->b_ml.ml_line_count)
751 break;
752 lnum++;
753 }
754 else
755 {
756 if (lnum <= 1)
757 break;
758 lnum--;
759 }
Bram Moolenaar66b98852020-03-11 19:15:52 +0100760 // Adjust col to indicate that we're continuing from prev/next line.
761 col = dir < 0 ? buf->b_ml.ml_line_len : 1;
Bram Moolenaare05a89a2020-01-10 19:56:46 +0100762 }
763}
764
765/*
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100766 * prop_list({lnum} [, {bufnr}])
767 */
768 void
769f_prop_list(typval_T *argvars, typval_T *rettv)
770{
Bram Moolenaard155d7a2018-12-21 16:04:21 +0100771 linenr_T lnum = tv_get_number(&argvars[0]);
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100772 buf_T *buf = curbuf;
773
774 if (argvars[1].v_type != VAR_UNKNOWN)
775 {
776 if (get_bufnr_from_arg(&argvars[1], &buf) == FAIL)
777 return;
778 }
779 if (lnum < 1 || lnum > buf->b_ml.ml_line_count)
780 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +0100781 emsg(_(e_invrange));
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100782 return;
783 }
784
785 if (rettv_list_alloc(rettv) == OK)
786 {
787 char_u *text = ml_get_buf(buf, lnum, FALSE);
788 size_t textlen = STRLEN(text) + 1;
Bram Moolenaar4efe73b2018-12-16 14:37:39 +0100789 int count = (int)((buf->b_ml.ml_line_len - textlen)
790 / sizeof(textprop_T));
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100791 int i;
792 textprop_T prop;
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100793
794 for (i = 0; i < count; ++i)
795 {
796 dict_T *d = dict_alloc();
797
798 if (d == NULL)
799 break;
800 mch_memmove(&prop, text + textlen + i * sizeof(textprop_T),
801 sizeof(textprop_T));
Bram Moolenaare05a89a2020-01-10 19:56:46 +0100802 prop_fill_dict(d, &prop, buf);
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100803 list_append_dict(rettv->vval.v_list, d);
804 }
805 }
806}
807
808/*
809 * prop_remove({props} [, {lnum} [, {lnum_end}]])
810 */
811 void
812f_prop_remove(typval_T *argvars, typval_T *rettv)
813{
814 linenr_T start = 1;
815 linenr_T end = 0;
816 linenr_T lnum;
817 dict_T *dict;
818 buf_T *buf = curbuf;
Bram Moolenaara5a40c52020-09-05 20:50:49 +0200819 int do_all;
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100820 int id = -1;
821 int type_id = -1;
Bram Moolenaara5a40c52020-09-05 20:50:49 +0200822 int both;
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100823
824 rettv->vval.v_number = 0;
825 if (argvars[0].v_type != VAR_DICT || argvars[0].vval.v_dict == NULL)
826 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +0100827 emsg(_(e_invarg));
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100828 return;
829 }
830
831 if (argvars[1].v_type != VAR_UNKNOWN)
832 {
Bram Moolenaard155d7a2018-12-21 16:04:21 +0100833 start = tv_get_number(&argvars[1]);
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100834 end = start;
835 if (argvars[2].v_type != VAR_UNKNOWN)
Bram Moolenaard155d7a2018-12-21 16:04:21 +0100836 end = tv_get_number(&argvars[2]);
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100837 if (start < 1 || end < 1)
838 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +0100839 emsg(_(e_invrange));
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100840 return;
841 }
842 }
843
844 dict = argvars[0].vval.v_dict;
Bram Moolenaarf0884c52019-05-24 21:22:29 +0200845 if (get_bufnr_from_arg(&argvars[0], &buf) == FAIL)
846 return;
847 if (buf->b_ml.ml_mfp == NULL)
848 return;
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100849
Bram Moolenaara5a40c52020-09-05 20:50:49 +0200850 do_all = dict_get_bool(dict, (char_u *)"all", FALSE);
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100851
852 if (dict_find(dict, (char_u *)"id", -1) != NULL)
Bram Moolenaar8f667172018-12-14 15:38:31 +0100853 id = dict_get_number(dict, (char_u *)"id");
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100854 if (dict_find(dict, (char_u *)"type", -1))
855 {
Bram Moolenaar8f667172018-12-14 15:38:31 +0100856 char_u *name = dict_get_string(dict, (char_u *)"type", FALSE);
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100857 proptype_T *type = lookup_prop_type(name, buf);
858
859 if (type == NULL)
860 return;
861 type_id = type->pt_id;
862 }
Bram Moolenaara5a40c52020-09-05 20:50:49 +0200863 both = dict_get_bool(dict, (char_u *)"both", FALSE);
864
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100865 if (id == -1 && type_id == -1)
866 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +0100867 emsg(_("E968: Need at least one of 'id' or 'type'"));
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100868 return;
869 }
Bram Moolenaar49b79bd2020-03-05 21:52:55 +0100870 if (both && (id == -1 || type_id == -1))
871 {
872 emsg(_("E860: Need 'id' and 'type' with 'both'"));
873 return;
874 }
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100875
876 if (end == 0)
877 end = buf->b_ml.ml_line_count;
878 for (lnum = start; lnum <= end; ++lnum)
879 {
880 char_u *text;
881 size_t len;
882
883 if (lnum > buf->b_ml.ml_line_count)
884 break;
885 text = ml_get_buf(buf, lnum, FALSE);
886 len = STRLEN(text) + 1;
887 if ((size_t)buf->b_ml.ml_line_len > len)
888 {
Bram Moolenaar87be9be2020-05-30 15:32:02 +0200889 static textprop_T textprop; // static because of alignment
890 unsigned idx;
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100891
892 for (idx = 0; idx < (buf->b_ml.ml_line_len - len)
893 / sizeof(textprop_T); ++idx)
894 {
895 char_u *cur_prop = buf->b_ml.ml_line_ptr + len
896 + idx * sizeof(textprop_T);
897 size_t taillen;
898
899 mch_memmove(&textprop, cur_prop, sizeof(textprop_T));
Bram Moolenaar49b79bd2020-03-05 21:52:55 +0100900 if (both ? textprop.tp_id == id && textprop.tp_type == type_id
901 : textprop.tp_id == id || textprop.tp_type == type_id)
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100902 {
903 if (!(buf->b_ml.ml_flags & ML_LINE_DIRTY))
904 {
905 char_u *newptr = alloc(buf->b_ml.ml_line_len);
906
907 // need to allocate the line to be able to change it
908 if (newptr == NULL)
909 return;
910 mch_memmove(newptr, buf->b_ml.ml_line_ptr,
911 buf->b_ml.ml_line_len);
912 buf->b_ml.ml_line_ptr = newptr;
Bram Moolenaar0a2f5782019-03-22 13:20:43 +0100913 buf->b_ml.ml_flags |= ML_LINE_DIRTY;
914
915 cur_prop = buf->b_ml.ml_line_ptr + len
Bram Moolenaarf0884c52019-05-24 21:22:29 +0200916 + idx * sizeof(textprop_T);
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100917 }
918
919 taillen = buf->b_ml.ml_line_len - len
920 - (idx + 1) * sizeof(textprop_T);
921 if (taillen > 0)
922 mch_memmove(cur_prop, cur_prop + sizeof(textprop_T),
923 taillen);
924 buf->b_ml.ml_line_len -= sizeof(textprop_T);
925 --idx;
926
927 ++rettv->vval.v_number;
928 if (!do_all)
929 break;
930 }
931 }
932 }
933 }
Bram Moolenaar09f8b3a2021-03-21 22:29:54 +0100934 if (rettv->vval.v_number > 0)
935 redraw_buf_later(buf, NOT_VALID);
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100936}
937
938/*
939 * Common for f_prop_type_add() and f_prop_type_change().
940 */
Bram Moolenaar5843f5f2019-08-20 20:13:45 +0200941 static void
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100942prop_type_set(typval_T *argvars, int add)
943{
944 char_u *name;
945 buf_T *buf = NULL;
946 dict_T *dict;
947 dictitem_T *di;
948 proptype_T *prop;
949
Bram Moolenaard155d7a2018-12-21 16:04:21 +0100950 name = tv_get_string(&argvars[0]);
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100951 if (*name == NUL)
952 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +0100953 emsg(_(e_invarg));
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100954 return;
955 }
956
957 if (get_bufnr_from_arg(&argvars[1], &buf) == FAIL)
958 return;
959 dict = argvars[1].vval.v_dict;
960
961 prop = find_prop(name, buf);
962 if (add)
963 {
964 hashtab_T **htp;
965
966 if (prop != NULL)
967 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +0100968 semsg(_("E969: Property type %s already defined"), name);
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100969 return;
970 }
Bram Moolenaar47ed5532019-08-08 20:49:14 +0200971 prop = alloc_clear(offsetof(proptype_T, pt_name) + STRLEN(name) + 1);
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100972 if (prop == NULL)
973 return;
974 STRCPY(prop->pt_name, name);
975 prop->pt_id = ++proptype_id;
Bram Moolenaar0743ef92019-11-13 16:37:31 +0100976 prop->pt_flags = PT_FLAG_COMBINE;
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100977 htp = buf == NULL ? &global_proptypes : &buf->b_proptypes;
978 if (*htp == NULL)
979 {
Bram Moolenaarc799fe22019-05-28 23:08:19 +0200980 *htp = ALLOC_ONE(hashtab_T);
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100981 if (*htp == NULL)
Bram Moolenaarfb95e212018-12-14 12:18:11 +0100982 {
983 vim_free(prop);
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100984 return;
Bram Moolenaarfb95e212018-12-14 12:18:11 +0100985 }
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100986 hash_init(*htp);
987 }
Bram Moolenaarfb95e212018-12-14 12:18:11 +0100988 hash_add(*htp, PT2HIKEY(prop));
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100989 }
990 else
991 {
992 if (prop == NULL)
993 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +0100994 semsg(_(e_type_not_exist), name);
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100995 return;
996 }
997 }
998
999 if (dict != NULL)
1000 {
1001 di = dict_find(dict, (char_u *)"highlight", -1);
1002 if (di != NULL)
1003 {
1004 char_u *highlight;
1005 int hl_id = 0;
1006
Bram Moolenaar8f667172018-12-14 15:38:31 +01001007 highlight = dict_get_string(dict, (char_u *)"highlight", FALSE);
Bram Moolenaar98aefe72018-12-13 22:20:09 +01001008 if (highlight != NULL && *highlight != NUL)
1009 hl_id = syn_name2id(highlight);
1010 if (hl_id <= 0)
1011 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01001012 semsg(_("E970: Unknown highlight group name: '%s'"),
Bram Moolenaar98aefe72018-12-13 22:20:09 +01001013 highlight == NULL ? (char_u *)"" : highlight);
1014 return;
1015 }
1016 prop->pt_hl_id = hl_id;
1017 }
1018
Bram Moolenaar58187f12019-05-05 16:33:47 +02001019 di = dict_find(dict, (char_u *)"combine", -1);
1020 if (di != NULL)
1021 {
Bram Moolenaarfa2e38d2020-09-05 21:00:00 +02001022 if (tv_get_bool(&di->di_tv))
Bram Moolenaar58187f12019-05-05 16:33:47 +02001023 prop->pt_flags |= PT_FLAG_COMBINE;
1024 else
1025 prop->pt_flags &= ~PT_FLAG_COMBINE;
1026 }
1027
Bram Moolenaar98aefe72018-12-13 22:20:09 +01001028 di = dict_find(dict, (char_u *)"priority", -1);
1029 if (di != NULL)
Bram Moolenaard155d7a2018-12-21 16:04:21 +01001030 prop->pt_priority = tv_get_number(&di->di_tv);
Bram Moolenaar98aefe72018-12-13 22:20:09 +01001031
1032 di = dict_find(dict, (char_u *)"start_incl", -1);
1033 if (di != NULL)
1034 {
Bram Moolenaarfa2e38d2020-09-05 21:00:00 +02001035 if (tv_get_bool(&di->di_tv))
Bram Moolenaar98aefe72018-12-13 22:20:09 +01001036 prop->pt_flags |= PT_FLAG_INS_START_INCL;
1037 else
1038 prop->pt_flags &= ~PT_FLAG_INS_START_INCL;
1039 }
1040
1041 di = dict_find(dict, (char_u *)"end_incl", -1);
1042 if (di != NULL)
1043 {
Bram Moolenaarfa2e38d2020-09-05 21:00:00 +02001044 if (tv_get_bool(&di->di_tv))
Bram Moolenaar98aefe72018-12-13 22:20:09 +01001045 prop->pt_flags |= PT_FLAG_INS_END_INCL;
1046 else
1047 prop->pt_flags &= ~PT_FLAG_INS_END_INCL;
1048 }
1049 }
1050}
1051
1052/*
1053 * prop_type_add({name}, {props})
1054 */
1055 void
1056f_prop_type_add(typval_T *argvars, typval_T *rettv UNUSED)
1057{
1058 prop_type_set(argvars, TRUE);
1059}
1060
1061/*
1062 * prop_type_change({name}, {props})
1063 */
1064 void
1065f_prop_type_change(typval_T *argvars, typval_T *rettv UNUSED)
1066{
1067 prop_type_set(argvars, FALSE);
1068}
1069
1070/*
1071 * prop_type_delete({name} [, {bufnr}])
1072 */
1073 void
1074f_prop_type_delete(typval_T *argvars, typval_T *rettv UNUSED)
1075{
1076 char_u *name;
1077 buf_T *buf = NULL;
1078 hashitem_T *hi;
1079
Bram Moolenaard155d7a2018-12-21 16:04:21 +01001080 name = tv_get_string(&argvars[0]);
Bram Moolenaar98aefe72018-12-13 22:20:09 +01001081 if (*name == NUL)
1082 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01001083 emsg(_(e_invarg));
Bram Moolenaar98aefe72018-12-13 22:20:09 +01001084 return;
1085 }
1086
1087 if (argvars[1].v_type != VAR_UNKNOWN)
1088 {
1089 if (get_bufnr_from_arg(&argvars[1], &buf) == FAIL)
1090 return;
1091 }
1092
1093 hi = find_prop_hi(name, buf);
1094 if (hi != NULL)
1095 {
1096 hashtab_T *ht;
Bram Moolenaarfb95e212018-12-14 12:18:11 +01001097 proptype_T *prop = HI2PT(hi);
Bram Moolenaar98aefe72018-12-13 22:20:09 +01001098
1099 if (buf == NULL)
1100 ht = global_proptypes;
1101 else
1102 ht = buf->b_proptypes;
1103 hash_remove(ht, hi);
Bram Moolenaarfb95e212018-12-14 12:18:11 +01001104 vim_free(prop);
Bram Moolenaar98aefe72018-12-13 22:20:09 +01001105 }
1106}
1107
1108/*
1109 * prop_type_get({name} [, {bufnr}])
1110 */
1111 void
Bram Moolenaar3d8a5132020-01-04 16:13:49 +01001112f_prop_type_get(typval_T *argvars, typval_T *rettv)
Bram Moolenaar98aefe72018-12-13 22:20:09 +01001113{
Bram Moolenaard155d7a2018-12-21 16:04:21 +01001114 char_u *name = tv_get_string(&argvars[0]);
Bram Moolenaar98aefe72018-12-13 22:20:09 +01001115
1116 if (*name == NUL)
1117 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01001118 emsg(_(e_invarg));
Bram Moolenaar98aefe72018-12-13 22:20:09 +01001119 return;
1120 }
1121 if (rettv_dict_alloc(rettv) == OK)
1122 {
1123 proptype_T *prop = NULL;
1124 buf_T *buf = NULL;
1125
1126 if (argvars[1].v_type != VAR_UNKNOWN)
1127 {
1128 if (get_bufnr_from_arg(&argvars[1], &buf) == FAIL)
1129 return;
1130 }
1131
1132 prop = find_prop(name, buf);
1133 if (prop != NULL)
1134 {
1135 dict_T *d = rettv->vval.v_dict;
1136
1137 if (prop->pt_hl_id > 0)
1138 dict_add_string(d, "highlight", syn_id2name(prop->pt_hl_id));
1139 dict_add_number(d, "priority", prop->pt_priority);
Bram Moolenaar58187f12019-05-05 16:33:47 +02001140 dict_add_number(d, "combine",
1141 (prop->pt_flags & PT_FLAG_COMBINE) ? 1 : 0);
Bram Moolenaar98aefe72018-12-13 22:20:09 +01001142 dict_add_number(d, "start_incl",
1143 (prop->pt_flags & PT_FLAG_INS_START_INCL) ? 1 : 0);
1144 dict_add_number(d, "end_incl",
1145 (prop->pt_flags & PT_FLAG_INS_END_INCL) ? 1 : 0);
1146 if (buf != NULL)
1147 dict_add_number(d, "bufnr", buf->b_fnum);
1148 }
1149 }
1150}
1151
1152 static void
1153list_types(hashtab_T *ht, list_T *l)
1154{
1155 long todo;
1156 hashitem_T *hi;
1157
1158 todo = (long)ht->ht_used;
1159 for (hi = ht->ht_array; todo > 0; ++hi)
1160 {
1161 if (!HASHITEM_EMPTY(hi))
1162 {
1163 proptype_T *prop = HI2PT(hi);
1164
1165 list_append_string(l, prop->pt_name, -1);
1166 --todo;
1167 }
1168 }
1169}
1170
1171/*
1172 * prop_type_list([{bufnr}])
1173 */
1174 void
1175f_prop_type_list(typval_T *argvars, typval_T *rettv UNUSED)
1176{
1177 buf_T *buf = NULL;
1178
1179 if (rettv_list_alloc(rettv) == OK)
1180 {
1181 if (argvars[0].v_type != VAR_UNKNOWN)
1182 {
1183 if (get_bufnr_from_arg(&argvars[0], &buf) == FAIL)
1184 return;
1185 }
1186 if (buf == NULL)
1187 {
1188 if (global_proptypes != NULL)
1189 list_types(global_proptypes, rettv->vval.v_list);
1190 }
1191 else if (buf->b_proptypes != NULL)
1192 list_types(buf->b_proptypes, rettv->vval.v_list);
1193 }
1194}
1195
1196/*
1197 * Free all property types in "ht".
1198 */
1199 static void
1200clear_ht_prop_types(hashtab_T *ht)
1201{
1202 long todo;
1203 hashitem_T *hi;
1204
1205 if (ht == NULL)
1206 return;
1207
1208 todo = (long)ht->ht_used;
1209 for (hi = ht->ht_array; todo > 0; ++hi)
1210 {
1211 if (!HASHITEM_EMPTY(hi))
1212 {
1213 proptype_T *prop = HI2PT(hi);
1214
1215 vim_free(prop);
1216 --todo;
1217 }
1218 }
1219
1220 hash_clear(ht);
1221 vim_free(ht);
1222}
1223
1224#if defined(EXITFREE) || defined(PROTO)
1225/*
Bram Moolenaarfb95e212018-12-14 12:18:11 +01001226 * Free all global property types.
Bram Moolenaar98aefe72018-12-13 22:20:09 +01001227 */
1228 void
1229clear_global_prop_types(void)
1230{
1231 clear_ht_prop_types(global_proptypes);
1232 global_proptypes = NULL;
1233}
1234#endif
1235
1236/*
1237 * Free all property types for "buf".
1238 */
1239 void
1240clear_buf_prop_types(buf_T *buf)
1241{
1242 clear_ht_prop_types(buf->b_proptypes);
1243 buf->b_proptypes = NULL;
1244}
1245
Bram Moolenaar87be9be2020-05-30 15:32:02 +02001246// Struct used to return two values from adjust_prop().
1247typedef struct
1248{
1249 int dirty; // if the property was changed
1250 int can_drop; // whether after this change, the prop may be removed
1251} adjustres_T;
1252
1253/*
1254 * Adjust the property for "added" bytes (can be negative) inserted at "col".
1255 *
1256 * Note that "col" is zero-based, while tp_col is one-based.
1257 * Only for the current buffer.
1258 * "flags" can have:
1259 * APC_SUBSTITUTE: Text is replaced, not inserted.
1260 */
1261 static adjustres_T
1262adjust_prop(
1263 textprop_T *prop,
1264 colnr_T col,
1265 int added,
1266 int flags)
1267{
1268 proptype_T *pt = text_prop_type_by_id(curbuf, prop->tp_type);
1269 int start_incl = (pt != NULL
1270 && (pt->pt_flags & PT_FLAG_INS_START_INCL))
1271 || (flags & APC_SUBSTITUTE);
1272 int end_incl = (pt != NULL
1273 && (pt->pt_flags & PT_FLAG_INS_END_INCL));
1274 // Do not drop zero-width props if they later can increase in
1275 // size.
1276 int droppable = !(start_incl || end_incl);
1277 adjustres_T res = {TRUE, FALSE};
1278
1279 if (added > 0)
1280 {
1281 if (col + 1 <= prop->tp_col
1282 - (start_incl || (prop->tp_len == 0 && end_incl)))
1283 // Change is entirely before the text property: Only shift
1284 prop->tp_col += added;
1285 else if (col + 1 < prop->tp_col + prop->tp_len + end_incl)
1286 // Insertion was inside text property
1287 prop->tp_len += added;
1288 }
1289 else if (prop->tp_col > col + 1)
1290 {
1291 if (prop->tp_col + added < col + 1)
1292 {
1293 prop->tp_len += (prop->tp_col - 1 - col) + added;
1294 prop->tp_col = col + 1;
1295 if (prop->tp_len <= 0)
1296 {
1297 prop->tp_len = 0;
1298 res.can_drop = droppable;
1299 }
1300 }
1301 else
1302 prop->tp_col += added;
1303 }
1304 else if (prop->tp_len > 0 && prop->tp_col + prop->tp_len > col)
1305 {
1306 int after = col - added - (prop->tp_col - 1 + prop->tp_len);
1307
1308 prop->tp_len += after > 0 ? added + after : added;
1309 res.can_drop = prop->tp_len <= 0 && droppable;
1310 }
1311 else
1312 res.dirty = FALSE;
1313
1314 return res;
1315}
1316
Bram Moolenaarb9c67a52019-01-01 19:49:20 +01001317/*
1318 * Adjust the columns of text properties in line "lnum" after position "col" to
1319 * shift by "bytes_added" (can be negative).
Bram Moolenaar44746aa2019-01-02 00:02:11 +01001320 * Note that "col" is zero-based, while tp_col is one-based.
1321 * Only for the current buffer.
Bram Moolenaarf3333b02019-05-19 22:53:40 +02001322 * "flags" can have:
1323 * APC_SAVE_FOR_UNDO: Call u_savesub() before making changes to the line.
1324 * APC_SUBSTITUTE: Text is replaced, not inserted.
Bram Moolenaar8055d172019-05-17 22:57:26 +02001325 * Caller is expected to check b_has_textprop and "bytes_added" being non-zero.
Bram Moolenaar338dfda2019-05-19 15:19:57 +02001326 * Returns TRUE when props were changed.
Bram Moolenaarb9c67a52019-01-01 19:49:20 +01001327 */
Bram Moolenaar338dfda2019-05-19 15:19:57 +02001328 int
Bram Moolenaar196d1572019-01-02 23:47:18 +01001329adjust_prop_columns(
1330 linenr_T lnum,
1331 colnr_T col,
Bram Moolenaar338dfda2019-05-19 15:19:57 +02001332 int bytes_added,
Bram Moolenaarf3333b02019-05-19 22:53:40 +02001333 int flags)
Bram Moolenaarb9c67a52019-01-01 19:49:20 +01001334{
Bram Moolenaar44746aa2019-01-02 00:02:11 +01001335 int proplen;
1336 char_u *props;
Bram Moolenaar44746aa2019-01-02 00:02:11 +01001337 int dirty = FALSE;
Bram Moolenaar196d1572019-01-02 23:47:18 +01001338 int ri, wi;
1339 size_t textlen;
1340
1341 if (text_prop_frozen > 0)
Bram Moolenaar338dfda2019-05-19 15:19:57 +02001342 return FALSE;
Bram Moolenaar44746aa2019-01-02 00:02:11 +01001343
1344 proplen = get_text_props(curbuf, lnum, &props, TRUE);
1345 if (proplen == 0)
Bram Moolenaar338dfda2019-05-19 15:19:57 +02001346 return FALSE;
Bram Moolenaar196d1572019-01-02 23:47:18 +01001347 textlen = curbuf->b_ml.ml_line_len - proplen * sizeof(textprop_T);
Bram Moolenaar44746aa2019-01-02 00:02:11 +01001348
Bram Moolenaar196d1572019-01-02 23:47:18 +01001349 wi = 0; // write index
1350 for (ri = 0; ri < proplen; ++ri)
Bram Moolenaar44746aa2019-01-02 00:02:11 +01001351 {
Bram Moolenaar12f20032020-02-26 22:06:00 +01001352 textprop_T prop;
Bram Moolenaar87be9be2020-05-30 15:32:02 +02001353 adjustres_T res;
Bram Moolenaarf3333b02019-05-19 22:53:40 +02001354
Bram Moolenaar87be9be2020-05-30 15:32:02 +02001355 mch_memmove(&prop, props + ri * sizeof(prop), sizeof(prop));
1356 res = adjust_prop(&prop, col, bytes_added, flags);
1357 if (res.dirty)
Bram Moolenaarf3333b02019-05-19 22:53:40 +02001358 {
Bram Moolenaar338dfda2019-05-19 15:19:57 +02001359 // Save for undo if requested and not done yet.
Bram Moolenaarcf070112020-06-29 23:02:21 +02001360 if ((flags & APC_SAVE_FOR_UNDO) && !dirty
1361 && u_savesub(lnum) == FAIL)
1362 return FALSE;
Bram Moolenaar44746aa2019-01-02 00:02:11 +01001363 dirty = TRUE;
Bram Moolenaar8902b312020-09-20 21:04:35 +02001364
1365 // u_savesub() may have updated curbuf->b_ml, fetch it again
1366 if (curbuf->b_ml.ml_line_lnum != lnum)
1367 proplen = get_text_props(curbuf, lnum, &props, TRUE);
Bram Moolenaar44746aa2019-01-02 00:02:11 +01001368 }
Bram Moolenaar87be9be2020-05-30 15:32:02 +02001369 if (res.can_drop)
1370 continue; // Drop this text property
Bram Moolenaar12f20032020-02-26 22:06:00 +01001371 mch_memmove(props + wi * sizeof(textprop_T), &prop, sizeof(textprop_T));
Bram Moolenaar196d1572019-01-02 23:47:18 +01001372 ++wi;
1373 }
1374 if (dirty)
1375 {
Bram Moolenaar4614f532019-01-06 12:54:55 +01001376 colnr_T newlen = (int)textlen + wi * (colnr_T)sizeof(textprop_T);
1377
1378 if ((curbuf->b_ml.ml_flags & ML_LINE_DIRTY) == 0)
1379 curbuf->b_ml.ml_line_ptr =
1380 vim_memsave(curbuf->b_ml.ml_line_ptr, newlen);
Bram Moolenaar196d1572019-01-02 23:47:18 +01001381 curbuf->b_ml.ml_flags |= ML_LINE_DIRTY;
Bram Moolenaar4614f532019-01-06 12:54:55 +01001382 curbuf->b_ml.ml_line_len = newlen;
Bram Moolenaar44746aa2019-01-02 00:02:11 +01001383 }
Bram Moolenaar338dfda2019-05-19 15:19:57 +02001384 return dirty;
Bram Moolenaarb9c67a52019-01-01 19:49:20 +01001385}
1386
Bram Moolenaar4164bb22019-01-04 23:09:49 +01001387/*
1388 * Adjust text properties for a line that was split in two.
Bram Moolenaar45dd07f2019-05-15 22:45:37 +02001389 * "lnum_props" is the line that has the properties from before the split.
1390 * "lnum_top" is the top line.
1391 * "kept" is the number of bytes kept in the first line, while
Bram Moolenaar4164bb22019-01-04 23:09:49 +01001392 * "deleted" is the number of bytes deleted.
1393 */
1394 void
Bram Moolenaar45dd07f2019-05-15 22:45:37 +02001395adjust_props_for_split(
1396 linenr_T lnum_props,
1397 linenr_T lnum_top,
1398 int kept,
1399 int deleted)
Bram Moolenaar4164bb22019-01-04 23:09:49 +01001400{
1401 char_u *props;
1402 int count;
1403 garray_T prevprop;
1404 garray_T nextprop;
1405 int i;
1406 int skipped = kept + deleted;
1407
1408 if (!curbuf->b_has_textprop)
1409 return;
Bram Moolenaar45dd07f2019-05-15 22:45:37 +02001410
1411 // Get the text properties from "lnum_props".
1412 count = get_text_props(curbuf, lnum_props, &props, FALSE);
Bram Moolenaar4164bb22019-01-04 23:09:49 +01001413 ga_init2(&prevprop, sizeof(textprop_T), 10);
1414 ga_init2(&nextprop, sizeof(textprop_T), 10);
1415
Bram Moolenaar4164bb22019-01-04 23:09:49 +01001416 // Keep the relevant ones in the first line, reducing the length if needed.
1417 // Copy the ones that include the split to the second line.
1418 // Move the ones after the split to the second line.
1419 for (i = 0; i < count; ++i)
1420 {
1421 textprop_T prop;
Bram Moolenaar87be9be2020-05-30 15:32:02 +02001422 proptype_T *pt;
1423 int start_incl, end_incl;
1424 int cont_prev, cont_next;
Bram Moolenaar4164bb22019-01-04 23:09:49 +01001425
1426 // copy the prop to an aligned structure
1427 mch_memmove(&prop, props + i * sizeof(textprop_T), sizeof(textprop_T));
1428
Bram Moolenaar87be9be2020-05-30 15:32:02 +02001429 pt = text_prop_type_by_id(curbuf, prop.tp_type);
1430 start_incl = (pt != NULL && (pt->pt_flags & PT_FLAG_INS_START_INCL));
1431 end_incl = (pt != NULL && (pt->pt_flags & PT_FLAG_INS_END_INCL));
1432 cont_prev = prop.tp_col + !start_incl <= kept;
1433 cont_next = skipped <= prop.tp_col + prop.tp_len - !end_incl;
1434
1435 if (cont_prev && ga_grow(&prevprop, 1) == OK)
Bram Moolenaar4164bb22019-01-04 23:09:49 +01001436 {
Bram Moolenaar87be9be2020-05-30 15:32:02 +02001437 textprop_T *p = ((textprop_T *)prevprop.ga_data) + prevprop.ga_len;
1438
Bram Moolenaar4164bb22019-01-04 23:09:49 +01001439 *p = prop;
Bram Moolenaar87be9be2020-05-30 15:32:02 +02001440 ++prevprop.ga_len;
Bram Moolenaar4164bb22019-01-04 23:09:49 +01001441 if (p->tp_col + p->tp_len >= kept)
1442 p->tp_len = kept - p->tp_col;
Bram Moolenaar87be9be2020-05-30 15:32:02 +02001443 if (cont_next)
1444 p->tp_flags |= TP_FLAG_CONT_NEXT;
Bram Moolenaar4164bb22019-01-04 23:09:49 +01001445 }
1446
Bram Moolenaar5c65e6a2019-05-17 11:08:56 +02001447 // Only add the property to the next line if the length is bigger than
1448 // zero.
Bram Moolenaar87be9be2020-05-30 15:32:02 +02001449 if (cont_next && ga_grow(&nextprop, 1) == OK)
Bram Moolenaar4164bb22019-01-04 23:09:49 +01001450 {
Bram Moolenaar87be9be2020-05-30 15:32:02 +02001451 textprop_T *p = ((textprop_T *)nextprop.ga_data) + nextprop.ga_len;
Bram Moolenaar4164bb22019-01-04 23:09:49 +01001452 *p = prop;
Bram Moolenaar87be9be2020-05-30 15:32:02 +02001453 ++nextprop.ga_len;
Bram Moolenaar4164bb22019-01-04 23:09:49 +01001454 if (p->tp_col > skipped)
1455 p->tp_col -= skipped - 1;
1456 else
1457 {
1458 p->tp_len -= skipped - p->tp_col;
1459 p->tp_col = 1;
1460 }
Bram Moolenaar87be9be2020-05-30 15:32:02 +02001461 if (cont_prev)
1462 p->tp_flags |= TP_FLAG_CONT_PREV;
Bram Moolenaar4164bb22019-01-04 23:09:49 +01001463 }
1464 }
1465
Bram Moolenaar45dd07f2019-05-15 22:45:37 +02001466 set_text_props(lnum_top, prevprop.ga_data,
1467 prevprop.ga_len * sizeof(textprop_T));
Bram Moolenaar4164bb22019-01-04 23:09:49 +01001468 ga_clear(&prevprop);
Bram Moolenaar45dd07f2019-05-15 22:45:37 +02001469 set_text_props(lnum_top + 1, nextprop.ga_data,
1470 nextprop.ga_len * sizeof(textprop_T));
Bram Moolenaar4164bb22019-01-04 23:09:49 +01001471 ga_clear(&nextprop);
1472}
1473
Bram Moolenaar80e737c2019-05-17 19:56:34 +02001474/*
Bram Moolenaar87be9be2020-05-30 15:32:02 +02001475 * Prepend properties of joined line "lnum" to "new_props".
Bram Moolenaar80e737c2019-05-17 19:56:34 +02001476 */
1477 void
Bram Moolenaar87be9be2020-05-30 15:32:02 +02001478prepend_joined_props(
1479 char_u *new_props,
1480 int propcount,
1481 int *props_remaining,
Bram Moolenaar80e737c2019-05-17 19:56:34 +02001482 linenr_T lnum,
Bram Moolenaar87be9be2020-05-30 15:32:02 +02001483 int add_all,
Bram Moolenaar80e737c2019-05-17 19:56:34 +02001484 long col,
1485 int removed)
1486{
Bram Moolenaar87be9be2020-05-30 15:32:02 +02001487 char_u *props;
1488 int proplen = get_text_props(curbuf, lnum, &props, FALSE);
1489 int i;
Bram Moolenaar80e737c2019-05-17 19:56:34 +02001490
Bram Moolenaar87be9be2020-05-30 15:32:02 +02001491 for (i = proplen; i-- > 0; )
Bram Moolenaar80e737c2019-05-17 19:56:34 +02001492 {
Bram Moolenaar87be9be2020-05-30 15:32:02 +02001493 textprop_T prop;
1494 int end;
Bram Moolenaar80e737c2019-05-17 19:56:34 +02001495
Bram Moolenaar87be9be2020-05-30 15:32:02 +02001496 mch_memmove(&prop, props + i * sizeof(prop), sizeof(prop));
1497 end = !(prop.tp_flags & TP_FLAG_CONT_NEXT);
1498
1499 adjust_prop(&prop, 0, -removed, 0); // Remove leading spaces
Bram Moolenaar8e7d6222020-12-18 19:49:56 +01001500 adjust_prop(&prop, -1, col, 0); // Make line start at its final column
Bram Moolenaar87be9be2020-05-30 15:32:02 +02001501
1502 if (add_all || end)
1503 mch_memmove(new_props + --(*props_remaining) * sizeof(prop),
1504 &prop, sizeof(prop));
1505 else
1506 {
1507 int j;
1508 int found = FALSE;
1509
1510 // Search for continuing prop.
1511 for (j = *props_remaining; j < propcount; ++j)
1512 {
1513 textprop_T op;
1514
1515 mch_memmove(&op, new_props + j * sizeof(op), sizeof(op));
1516 if ((op.tp_flags & TP_FLAG_CONT_PREV)
1517 && op.tp_id == prop.tp_id && op.tp_type == prop.tp_type)
Bram Moolenaar80e737c2019-05-17 19:56:34 +02001518 {
Bram Moolenaar87be9be2020-05-30 15:32:02 +02001519 found = TRUE;
1520 op.tp_len += op.tp_col - prop.tp_col;
1521 op.tp_col = prop.tp_col;
1522 // Start/end is taken care of when deleting joined lines
1523 op.tp_flags = prop.tp_flags;
1524 mch_memmove(new_props + j * sizeof(op), &op, sizeof(op));
1525 break;
Bram Moolenaar80e737c2019-05-17 19:56:34 +02001526 }
1527 }
Bram Moolenaar87be9be2020-05-30 15:32:02 +02001528 if (!found)
1529 internal_error("text property above joined line not found");
Bram Moolenaar80e737c2019-05-17 19:56:34 +02001530 }
Bram Moolenaar80e737c2019-05-17 19:56:34 +02001531 }
1532}
1533
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001534#endif // FEAT_PROP_POPUP