blob: 8c1e46ca680e2b07377d24c4336f983bd17e2015 [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 Moolenaarc6663882019-02-22 19:14:54 +010014 * - When using 'cursorline' attributes should be merged. (#3912)
Bram Moolenaarb9c67a52019-01-01 19:49:20 +010015 * - Adjust text property column and length when text is inserted/deleted.
Bram Moolenaar45dd07f2019-05-15 22:45:37 +020016 * -> splitting a line can create a zero-length property. Don't highlight it
17 * and extend it when inserting text.
Bram Moolenaar4164bb22019-01-04 23:09:49 +010018 * -> a :substitute with a multi-line match
Bram Moolenaar45dd07f2019-05-15 22:45:37 +020019 * -> join two lines, also with BS in Insert mode
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010020 * -> search for changed_bytes() from misc1.c
Bram Moolenaarb9c67a52019-01-01 19:49:20 +010021 * - Perhaps we only need TP_FLAG_CONT_NEXT and can drop TP_FLAG_CONT_PREV?
Bram Moolenaarb56ac042018-12-28 23:22:40 +010022 * - Add an arrray for global_proptypes, to quickly lookup a prop type by ID
23 * - Add an arrray for b_proptypes, to quickly lookup a prop type by ID
24 * - Checking the text length to detect text properties is slow. Use a flag in
25 * the index, like DB_MARKED?
Bram Moolenaarb413d2e2018-12-25 23:15:46 +010026 * - Also test line2byte() with many lines, so that ml_updatechunk() is taken
27 * into account.
Bram Moolenaarc6663882019-02-22 19:14:54 +010028 * - Perhaps have a window-local option to disable highlighting from text
29 * properties?
Bram Moolenaar98aefe72018-12-13 22:20:09 +010030 */
31
32#include "vim.h"
33
34#if defined(FEAT_TEXT_PROP) || defined(PROTO)
35
36/*
37 * In a hashtable item "hi_key" points to "pt_name" in a proptype_T.
38 * This avoids adding a pointer to the hashtable item.
39 * PT2HIKEY() converts a proptype pointer to a hashitem key pointer.
40 * HIKEY2PT() converts a hashitem key pointer to a proptype pointer.
41 * HI2PT() converts a hashitem pointer to a proptype pointer.
42 */
43#define PT2HIKEY(p) ((p)->pt_name)
44#define HIKEY2PT(p) ((proptype_T *)((p) - offsetof(proptype_T, pt_name)))
45#define HI2PT(hi) HIKEY2PT((hi)->hi_key)
46
47// The global text property types.
48static hashtab_T *global_proptypes = NULL;
49
50// The last used text property type ID.
51static int proptype_id = 0;
52
53static char_u e_type_not_exist[] = N_("E971: Property type %s does not exist");
54static char_u e_invalid_col[] = N_("E964: Invalid column number: %ld");
Bram Moolenaare3d31b02018-12-24 23:07:04 +010055static char_u e_invalid_lnum[] = N_("E966: Invalid line number: %ld");
Bram Moolenaar98aefe72018-12-13 22:20:09 +010056
57/*
58 * Find a property type by name, return the hashitem.
59 * Returns NULL if the item can't be found.
60 */
61 static hashitem_T *
62find_prop_hi(char_u *name, buf_T *buf)
63{
64 hashtab_T *ht;
65 hashitem_T *hi;
66
67 if (*name == NUL)
68 return NULL;
69 if (buf == NULL)
70 ht = global_proptypes;
71 else
72 ht = buf->b_proptypes;
73
74 if (ht == NULL)
75 return NULL;
76 hi = hash_find(ht, name);
77 if (HASHITEM_EMPTY(hi))
78 return NULL;
79 return hi;
80}
81
82/*
83 * Like find_prop_hi() but return the property type.
84 */
85 static proptype_T *
86find_prop(char_u *name, buf_T *buf)
87{
88 hashitem_T *hi = find_prop_hi(name, buf);
89
90 if (hi == NULL)
91 return NULL;
92 return HI2PT(hi);
93}
94
95/*
96 * Lookup a property type by name. First in "buf" and when not found in the
97 * global types.
98 * When not found gives an error message and returns NULL.
99 */
100 static proptype_T *
101lookup_prop_type(char_u *name, buf_T *buf)
102{
103 proptype_T *type = find_prop(name, buf);
104
105 if (type == NULL)
106 type = find_prop(name, NULL);
107 if (type == NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +0100108 semsg(_(e_type_not_exist), name);
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100109 return type;
110}
111
112/*
113 * Get an optional "bufnr" item from the dict in "arg".
114 * When the argument is not used or "bufnr" is not present then "buf" is
115 * unchanged.
116 * If "bufnr" is valid or not present return OK.
117 * When "arg" is not a dict or "bufnr" is invalide return FAIL.
118 */
119 static int
120get_bufnr_from_arg(typval_T *arg, buf_T **buf)
121{
122 dictitem_T *di;
123
124 if (arg->v_type != VAR_DICT)
125 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +0100126 emsg(_(e_dictreq));
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100127 return FAIL;
128 }
129 if (arg->vval.v_dict == NULL)
130 return OK; // NULL dict is like an empty dict
131 di = dict_find(arg->vval.v_dict, (char_u *)"bufnr", -1);
132 if (di != NULL)
133 {
Bram Moolenaarf2d79fa2019-01-03 22:19:27 +0100134 *buf = tv_get_buf(&di->di_tv, FALSE);
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100135 if (*buf == NULL)
136 return FAIL;
137 }
138 return OK;
139}
140
141/*
142 * prop_add({lnum}, {col}, {props})
143 */
144 void
145f_prop_add(typval_T *argvars, typval_T *rettv UNUSED)
146{
147 linenr_T lnum;
Bram Moolenaare3d31b02018-12-24 23:07:04 +0100148 linenr_T start_lnum;
149 linenr_T end_lnum;
150 colnr_T start_col;
151 colnr_T end_col;
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100152 dict_T *dict;
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100153 char_u *type_name;
154 proptype_T *type;
155 buf_T *buf = curbuf;
156 int id = 0;
157 char_u *newtext;
158 int proplen;
159 size_t textlen;
Bram Moolenaarc6663882019-02-22 19:14:54 +0100160 char_u *props = NULL;
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100161 char_u *newprops;
Bram Moolenaarfb95e212018-12-14 12:18:11 +0100162 textprop_T tmp_prop;
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100163 int i;
164
Bram Moolenaare3d31b02018-12-24 23:07:04 +0100165 start_lnum = tv_get_number(&argvars[0]);
166 start_col = tv_get_number(&argvars[1]);
167 if (start_col < 1)
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100168 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +0100169 semsg(_(e_invalid_col), (long)start_col);
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100170 return;
171 }
172 if (argvars[2].v_type != VAR_DICT)
173 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +0100174 emsg(_(e_dictreq));
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100175 return;
176 }
177 dict = argvars[2].vval.v_dict;
178
179 if (dict == NULL || dict_find(dict, (char_u *)"type", -1) == NULL)
180 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +0100181 emsg(_("E965: missing property type name"));
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100182 return;
183 }
Bram Moolenaar8f667172018-12-14 15:38:31 +0100184 type_name = dict_get_string(dict, (char_u *)"type", FALSE);
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100185
186 if (dict_find(dict, (char_u *)"end_lnum", -1) != NULL)
187 {
Bram Moolenaare3d31b02018-12-24 23:07:04 +0100188 end_lnum = dict_get_number(dict, (char_u *)"end_lnum");
189 if (end_lnum < start_lnum)
190 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +0100191 semsg(_(e_invargval), "end_lnum");
Bram Moolenaare3d31b02018-12-24 23:07:04 +0100192 return;
193 }
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100194 }
Bram Moolenaare3d31b02018-12-24 23:07:04 +0100195 else
196 end_lnum = start_lnum;
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100197
198 if (dict_find(dict, (char_u *)"length", -1) != NULL)
Bram Moolenaare3d31b02018-12-24 23:07:04 +0100199 {
200 long length = dict_get_number(dict, (char_u *)"length");
201
Bram Moolenaarb9c67a52019-01-01 19:49:20 +0100202 if (length < 0 || end_lnum > start_lnum)
Bram Moolenaare3d31b02018-12-24 23:07:04 +0100203 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +0100204 semsg(_(e_invargval), "length");
Bram Moolenaare3d31b02018-12-24 23:07:04 +0100205 return;
206 }
Bram Moolenaarb9c67a52019-01-01 19:49:20 +0100207 end_col = start_col + length;
Bram Moolenaare3d31b02018-12-24 23:07:04 +0100208 }
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100209 else if (dict_find(dict, (char_u *)"end_col", -1) != NULL)
210 {
Bram Moolenaare3d31b02018-12-24 23:07:04 +0100211 end_col = dict_get_number(dict, (char_u *)"end_col");
212 if (end_col <= 0)
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100213 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +0100214 semsg(_(e_invargval), "end_col");
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100215 return;
216 }
217 }
Bram Moolenaare3d31b02018-12-24 23:07:04 +0100218 else if (start_lnum == end_lnum)
219 end_col = start_col;
220 else
221 end_col = 1;
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100222
223 if (dict_find(dict, (char_u *)"id", -1) != NULL)
Bram Moolenaar8f667172018-12-14 15:38:31 +0100224 id = dict_get_number(dict, (char_u *)"id");
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100225
226 if (get_bufnr_from_arg(&argvars[2], &buf) == FAIL)
227 return;
228
229 type = lookup_prop_type(type_name, buf);
230 if (type == NULL)
231 return;
232
Bram Moolenaare3d31b02018-12-24 23:07:04 +0100233 if (start_lnum < 1 || start_lnum > buf->b_ml.ml_line_count)
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100234 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +0100235 semsg(_(e_invalid_lnum), (long)start_lnum);
Bram Moolenaare3d31b02018-12-24 23:07:04 +0100236 return;
237 }
238 if (end_lnum < start_lnum || end_lnum > buf->b_ml.ml_line_count)
239 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +0100240 semsg(_(e_invalid_lnum), (long)end_lnum);
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100241 return;
242 }
243
Bram Moolenaare3d31b02018-12-24 23:07:04 +0100244 for (lnum = start_lnum; lnum <= end_lnum; ++lnum)
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100245 {
Bram Moolenaare3d31b02018-12-24 23:07:04 +0100246 colnr_T col; // start column
247 long length; // in bytes
248
249 // Fetch the line to get the ml_line_len field updated.
250 proplen = get_text_props(buf, lnum, &props, TRUE);
251 textlen = buf->b_ml.ml_line_len - proplen * sizeof(textprop_T);
252
253 if (lnum == start_lnum)
254 col = start_col;
255 else
256 col = 1;
257 if (col - 1 > (colnr_T)textlen)
258 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +0100259 semsg(_(e_invalid_col), (long)start_col);
Bram Moolenaare3d31b02018-12-24 23:07:04 +0100260 return;
261 }
262
263 if (lnum == end_lnum)
Bram Moolenaarb9c67a52019-01-01 19:49:20 +0100264 length = end_col - col;
Bram Moolenaare3d31b02018-12-24 23:07:04 +0100265 else
Bram Moolenaar4b7214e2019-01-03 21:55:32 +0100266 length = (int)textlen - col + 1;
Bram Moolenaarb413d2e2018-12-25 23:15:46 +0100267 if (length > (long)textlen)
Bram Moolenaar4b7214e2019-01-03 21:55:32 +0100268 length = (int)textlen; // can include the end-of-line
Bram Moolenaarb9c67a52019-01-01 19:49:20 +0100269 if (length < 0)
270 length = 0; // zero-width property
Bram Moolenaare3d31b02018-12-24 23:07:04 +0100271
272 // Allocate the new line with space for the new proprety.
273 newtext = alloc(buf->b_ml.ml_line_len + sizeof(textprop_T));
274 if (newtext == NULL)
275 return;
276 // Copy the text, including terminating NUL.
277 mch_memmove(newtext, buf->b_ml.ml_line_ptr, textlen);
278
279 // Find the index where to insert the new property.
280 // Since the text properties are not aligned properly when stored with the
281 // text, we need to copy them as bytes before using it as a struct.
282 for (i = 0; i < proplen; ++i)
283 {
284 mch_memmove(&tmp_prop, props + i * sizeof(textprop_T),
285 sizeof(textprop_T));
286 if (tmp_prop.tp_col >= col)
287 break;
288 }
289 newprops = newtext + textlen;
290 if (i > 0)
291 mch_memmove(newprops, props, sizeof(textprop_T) * i);
292
293 tmp_prop.tp_col = col;
294 tmp_prop.tp_len = length;
295 tmp_prop.tp_id = id;
296 tmp_prop.tp_type = type->pt_id;
297 tmp_prop.tp_flags = (lnum > start_lnum ? TP_FLAG_CONT_PREV : 0)
298 | (lnum < end_lnum ? TP_FLAG_CONT_NEXT : 0);
299 mch_memmove(newprops + i * sizeof(textprop_T), &tmp_prop,
300 sizeof(textprop_T));
301
302 if (i < proplen)
303 mch_memmove(newprops + (i + 1) * sizeof(textprop_T),
304 props + i * sizeof(textprop_T),
305 sizeof(textprop_T) * (proplen - i));
306
307 if (buf->b_ml.ml_flags & ML_LINE_DIRTY)
308 vim_free(buf->b_ml.ml_line_ptr);
309 buf->b_ml.ml_line_ptr = newtext;
310 buf->b_ml.ml_line_len += sizeof(textprop_T);
311 buf->b_ml.ml_flags |= ML_LINE_DIRTY;
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100312 }
313
Bram Moolenaarb413d2e2018-12-25 23:15:46 +0100314 buf->b_has_textprop = TRUE; // this is never reset
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100315 redraw_buf_later(buf, NOT_VALID);
316}
317
318/*
Bram Moolenaarfb95e212018-12-14 12:18:11 +0100319 * Fetch the text properties for line "lnum" in buffer "buf".
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100320 * Returns the number of text properties and, when non-zero, a pointer to the
321 * first one in "props" (note that it is not aligned, therefore the char_u
322 * pointer).
323 */
324 int
325get_text_props(buf_T *buf, linenr_T lnum, char_u **props, int will_change)
326{
327 char_u *text;
328 size_t textlen;
329 size_t proplen;
330
Bram Moolenaarb413d2e2018-12-25 23:15:46 +0100331 // Be quick when no text property types have been defined or the buffer,
332 // unless we are adding one.
333 if (!buf->b_has_textprop && !will_change)
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100334 return 0;
335
336 // Fetch the line to get the ml_line_len field updated.
337 text = ml_get_buf(buf, lnum, will_change);
338 textlen = STRLEN(text) + 1;
339 proplen = buf->b_ml.ml_line_len - textlen;
340 if (proplen % sizeof(textprop_T) != 0)
341 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +0100342 iemsg(_("E967: text property info corrupted"));
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100343 return 0;
344 }
345 if (proplen > 0)
346 *props = text + textlen;
Bram Moolenaar4efe73b2018-12-16 14:37:39 +0100347 return (int)(proplen / sizeof(textprop_T));
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100348}
349
Bram Moolenaar4164bb22019-01-04 23:09:49 +0100350/*
351 * Set the text properties for line "lnum" to "props" with length "len".
352 * If "len" is zero text properties are removed, "props" is not used.
353 * Any existing text properties are dropped.
354 * Only works for the current buffer.
355 */
356 static void
357set_text_props(linenr_T lnum, char_u *props, int len)
358{
Bram Moolenaar8aef43b2019-01-08 20:14:35 +0100359 char_u *text;
360 char_u *newtext;
361 int textlen;
Bram Moolenaar4164bb22019-01-04 23:09:49 +0100362
363 text = ml_get(lnum);
Bram Moolenaar8aef43b2019-01-08 20:14:35 +0100364 textlen = (int)STRLEN(text) + 1;
Bram Moolenaar4164bb22019-01-04 23:09:49 +0100365 newtext = alloc(textlen + len);
366 if (newtext == NULL)
367 return;
368 mch_memmove(newtext, text, textlen);
369 if (len > 0)
370 mch_memmove(newtext + textlen, props, len);
371 if (curbuf->b_ml.ml_flags & ML_LINE_DIRTY)
372 vim_free(curbuf->b_ml.ml_line_ptr);
373 curbuf->b_ml.ml_line_ptr = newtext;
374 curbuf->b_ml.ml_line_len = textlen + len;
375 curbuf->b_ml.ml_flags |= ML_LINE_DIRTY;
376}
377
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100378 static proptype_T *
379find_type_by_id(hashtab_T *ht, int id)
380{
381 long todo;
382 hashitem_T *hi;
383
384 if (ht == NULL)
385 return NULL;
386
387 // TODO: Make this faster by keeping a list of types sorted on ID and use
388 // a binary search.
389
390 todo = (long)ht->ht_used;
391 for (hi = ht->ht_array; todo > 0; ++hi)
392 {
393 if (!HASHITEM_EMPTY(hi))
394 {
395 proptype_T *prop = HI2PT(hi);
396
397 if (prop->pt_id == id)
398 return prop;
399 --todo;
400 }
401 }
402 return NULL;
403}
404
405/*
406 * Find a property type by ID in "buf" or globally.
407 * Returns NULL if not found.
408 */
409 proptype_T *
410text_prop_type_by_id(buf_T *buf, int id)
411{
412 proptype_T *type;
413
414 type = find_type_by_id(buf->b_proptypes, id);
415 if (type == NULL)
416 type = find_type_by_id(global_proptypes, id);
417 return type;
418}
419
420/*
421 * prop_clear({lnum} [, {lnum_end} [, {bufnr}]])
422 */
423 void
424f_prop_clear(typval_T *argvars, typval_T *rettv UNUSED)
425{
Bram Moolenaard155d7a2018-12-21 16:04:21 +0100426 linenr_T start = tv_get_number(&argvars[0]);
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100427 linenr_T end = start;
428 linenr_T lnum;
429 buf_T *buf = curbuf;
430
431 if (argvars[1].v_type != VAR_UNKNOWN)
432 {
Bram Moolenaard155d7a2018-12-21 16:04:21 +0100433 end = tv_get_number(&argvars[1]);
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100434 if (argvars[2].v_type != VAR_UNKNOWN)
435 {
436 if (get_bufnr_from_arg(&argvars[2], &buf) == FAIL)
437 return;
438 }
439 }
440 if (start < 1 || end < 1)
441 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +0100442 emsg(_(e_invrange));
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100443 return;
444 }
445
446 for (lnum = start; lnum <= end; ++lnum)
447 {
448 char_u *text;
449 size_t len;
450
451 if (lnum > buf->b_ml.ml_line_count)
452 break;
453 text = ml_get_buf(buf, lnum, FALSE);
454 len = STRLEN(text) + 1;
455 if ((size_t)buf->b_ml.ml_line_len > len)
456 {
457 if (!(buf->b_ml.ml_flags & ML_LINE_DIRTY))
458 {
459 char_u *newtext = vim_strsave(text);
460
461 // need to allocate the line now
462 if (newtext == NULL)
463 return;
464 buf->b_ml.ml_line_ptr = newtext;
465 buf->b_ml.ml_flags |= ML_LINE_DIRTY;
466 }
Bram Moolenaar4efe73b2018-12-16 14:37:39 +0100467 buf->b_ml.ml_line_len = (int)len;
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100468 }
469 }
470 redraw_buf_later(buf, NOT_VALID);
471}
472
473/*
474 * prop_list({lnum} [, {bufnr}])
475 */
476 void
477f_prop_list(typval_T *argvars, typval_T *rettv)
478{
Bram Moolenaard155d7a2018-12-21 16:04:21 +0100479 linenr_T lnum = tv_get_number(&argvars[0]);
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100480 buf_T *buf = curbuf;
481
482 if (argvars[1].v_type != VAR_UNKNOWN)
483 {
484 if (get_bufnr_from_arg(&argvars[1], &buf) == FAIL)
485 return;
486 }
487 if (lnum < 1 || lnum > buf->b_ml.ml_line_count)
488 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +0100489 emsg(_(e_invrange));
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100490 return;
491 }
492
493 if (rettv_list_alloc(rettv) == OK)
494 {
495 char_u *text = ml_get_buf(buf, lnum, FALSE);
496 size_t textlen = STRLEN(text) + 1;
Bram Moolenaar4efe73b2018-12-16 14:37:39 +0100497 int count = (int)((buf->b_ml.ml_line_len - textlen)
498 / sizeof(textprop_T));
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100499 int i;
500 textprop_T prop;
501 proptype_T *pt;
502
503 for (i = 0; i < count; ++i)
504 {
505 dict_T *d = dict_alloc();
506
507 if (d == NULL)
508 break;
509 mch_memmove(&prop, text + textlen + i * sizeof(textprop_T),
510 sizeof(textprop_T));
511 dict_add_number(d, "col", prop.tp_col);
512 dict_add_number(d, "length", prop.tp_len);
513 dict_add_number(d, "id", prop.tp_id);
514 dict_add_number(d, "start", !(prop.tp_flags & TP_FLAG_CONT_PREV));
515 dict_add_number(d, "end", !(prop.tp_flags & TP_FLAG_CONT_NEXT));
516 pt = text_prop_type_by_id(buf, prop.tp_type);
517 if (pt != NULL)
518 dict_add_string(d, "type", pt->pt_name);
519
520 list_append_dict(rettv->vval.v_list, d);
521 }
522 }
523}
524
525/*
526 * prop_remove({props} [, {lnum} [, {lnum_end}]])
527 */
528 void
529f_prop_remove(typval_T *argvars, typval_T *rettv)
530{
531 linenr_T start = 1;
532 linenr_T end = 0;
533 linenr_T lnum;
534 dict_T *dict;
535 buf_T *buf = curbuf;
536 dictitem_T *di;
537 int do_all = FALSE;
538 int id = -1;
539 int type_id = -1;
540
541 rettv->vval.v_number = 0;
542 if (argvars[0].v_type != VAR_DICT || argvars[0].vval.v_dict == NULL)
543 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +0100544 emsg(_(e_invarg));
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100545 return;
546 }
547
548 if (argvars[1].v_type != VAR_UNKNOWN)
549 {
Bram Moolenaard155d7a2018-12-21 16:04:21 +0100550 start = tv_get_number(&argvars[1]);
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100551 end = start;
552 if (argvars[2].v_type != VAR_UNKNOWN)
Bram Moolenaard155d7a2018-12-21 16:04:21 +0100553 end = tv_get_number(&argvars[2]);
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100554 if (start < 1 || end < 1)
555 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +0100556 emsg(_(e_invrange));
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100557 return;
558 }
559 }
560
561 dict = argvars[0].vval.v_dict;
562 di = dict_find(dict, (char_u *)"bufnr", -1);
563 if (di != NULL)
564 {
Bram Moolenaarf2d79fa2019-01-03 22:19:27 +0100565 buf = tv_get_buf(&di->di_tv, FALSE);
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100566 if (buf == NULL)
567 return;
568 }
569
570 di = dict_find(dict, (char_u*)"all", -1);
571 if (di != NULL)
Bram Moolenaar8f667172018-12-14 15:38:31 +0100572 do_all = dict_get_number(dict, (char_u *)"all");
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100573
574 if (dict_find(dict, (char_u *)"id", -1) != NULL)
Bram Moolenaar8f667172018-12-14 15:38:31 +0100575 id = dict_get_number(dict, (char_u *)"id");
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100576 if (dict_find(dict, (char_u *)"type", -1))
577 {
Bram Moolenaar8f667172018-12-14 15:38:31 +0100578 char_u *name = dict_get_string(dict, (char_u *)"type", FALSE);
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100579 proptype_T *type = lookup_prop_type(name, buf);
580
581 if (type == NULL)
582 return;
583 type_id = type->pt_id;
584 }
585 if (id == -1 && type_id == -1)
586 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +0100587 emsg(_("E968: Need at least one of 'id' or 'type'"));
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100588 return;
589 }
590
591 if (end == 0)
592 end = buf->b_ml.ml_line_count;
593 for (lnum = start; lnum <= end; ++lnum)
594 {
595 char_u *text;
596 size_t len;
597
598 if (lnum > buf->b_ml.ml_line_count)
599 break;
600 text = ml_get_buf(buf, lnum, FALSE);
601 len = STRLEN(text) + 1;
602 if ((size_t)buf->b_ml.ml_line_len > len)
603 {
604 static textprop_T textprop; // static because of alignment
605 unsigned idx;
606
607 for (idx = 0; idx < (buf->b_ml.ml_line_len - len)
608 / sizeof(textprop_T); ++idx)
609 {
610 char_u *cur_prop = buf->b_ml.ml_line_ptr + len
611 + idx * sizeof(textprop_T);
612 size_t taillen;
613
614 mch_memmove(&textprop, cur_prop, sizeof(textprop_T));
615 if (textprop.tp_id == id || textprop.tp_type == type_id)
616 {
617 if (!(buf->b_ml.ml_flags & ML_LINE_DIRTY))
618 {
619 char_u *newptr = alloc(buf->b_ml.ml_line_len);
620
621 // need to allocate the line to be able to change it
622 if (newptr == NULL)
623 return;
624 mch_memmove(newptr, buf->b_ml.ml_line_ptr,
625 buf->b_ml.ml_line_len);
626 buf->b_ml.ml_line_ptr = newptr;
Bram Moolenaar0a2f5782019-03-22 13:20:43 +0100627 buf->b_ml.ml_flags |= ML_LINE_DIRTY;
628
629 cur_prop = buf->b_ml.ml_line_ptr + len
630 + idx * sizeof(textprop_T);
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100631 }
632
633 taillen = buf->b_ml.ml_line_len - len
634 - (idx + 1) * sizeof(textprop_T);
635 if (taillen > 0)
636 mch_memmove(cur_prop, cur_prop + sizeof(textprop_T),
637 taillen);
638 buf->b_ml.ml_line_len -= sizeof(textprop_T);
639 --idx;
640
641 ++rettv->vval.v_number;
642 if (!do_all)
643 break;
644 }
645 }
646 }
647 }
648 redraw_buf_later(buf, NOT_VALID);
649}
650
651/*
652 * Common for f_prop_type_add() and f_prop_type_change().
653 */
654 void
655prop_type_set(typval_T *argvars, int add)
656{
657 char_u *name;
658 buf_T *buf = NULL;
659 dict_T *dict;
660 dictitem_T *di;
661 proptype_T *prop;
662
Bram Moolenaard155d7a2018-12-21 16:04:21 +0100663 name = tv_get_string(&argvars[0]);
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100664 if (*name == NUL)
665 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +0100666 emsg(_(e_invarg));
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100667 return;
668 }
669
670 if (get_bufnr_from_arg(&argvars[1], &buf) == FAIL)
671 return;
672 dict = argvars[1].vval.v_dict;
673
674 prop = find_prop(name, buf);
675 if (add)
676 {
677 hashtab_T **htp;
678
679 if (prop != NULL)
680 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +0100681 semsg(_("E969: Property type %s already defined"), name);
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100682 return;
683 }
Bram Moolenaar4efe73b2018-12-16 14:37:39 +0100684 prop = (proptype_T *)alloc_clear((int)(sizeof(proptype_T) + STRLEN(name)));
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100685 if (prop == NULL)
686 return;
687 STRCPY(prop->pt_name, name);
688 prop->pt_id = ++proptype_id;
689 htp = buf == NULL ? &global_proptypes : &buf->b_proptypes;
690 if (*htp == NULL)
691 {
692 *htp = (hashtab_T *)alloc(sizeof(hashtab_T));
693 if (*htp == NULL)
Bram Moolenaarfb95e212018-12-14 12:18:11 +0100694 {
695 vim_free(prop);
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100696 return;
Bram Moolenaarfb95e212018-12-14 12:18:11 +0100697 }
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100698 hash_init(*htp);
699 }
Bram Moolenaarfb95e212018-12-14 12:18:11 +0100700 hash_add(*htp, PT2HIKEY(prop));
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100701 }
702 else
703 {
704 if (prop == NULL)
705 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +0100706 semsg(_(e_type_not_exist), name);
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100707 return;
708 }
709 }
710
711 if (dict != NULL)
712 {
713 di = dict_find(dict, (char_u *)"highlight", -1);
714 if (di != NULL)
715 {
716 char_u *highlight;
717 int hl_id = 0;
718
Bram Moolenaar8f667172018-12-14 15:38:31 +0100719 highlight = dict_get_string(dict, (char_u *)"highlight", FALSE);
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100720 if (highlight != NULL && *highlight != NUL)
721 hl_id = syn_name2id(highlight);
722 if (hl_id <= 0)
723 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +0100724 semsg(_("E970: Unknown highlight group name: '%s'"),
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100725 highlight == NULL ? (char_u *)"" : highlight);
726 return;
727 }
728 prop->pt_hl_id = hl_id;
729 }
730
Bram Moolenaar58187f12019-05-05 16:33:47 +0200731 di = dict_find(dict, (char_u *)"combine", -1);
732 if (di != NULL)
733 {
734 if (tv_get_number(&di->di_tv))
735 prop->pt_flags |= PT_FLAG_COMBINE;
736 else
737 prop->pt_flags &= ~PT_FLAG_COMBINE;
738 }
739
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100740 di = dict_find(dict, (char_u *)"priority", -1);
741 if (di != NULL)
Bram Moolenaard155d7a2018-12-21 16:04:21 +0100742 prop->pt_priority = tv_get_number(&di->di_tv);
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100743
744 di = dict_find(dict, (char_u *)"start_incl", -1);
745 if (di != NULL)
746 {
Bram Moolenaard155d7a2018-12-21 16:04:21 +0100747 if (tv_get_number(&di->di_tv))
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100748 prop->pt_flags |= PT_FLAG_INS_START_INCL;
749 else
750 prop->pt_flags &= ~PT_FLAG_INS_START_INCL;
751 }
752
753 di = dict_find(dict, (char_u *)"end_incl", -1);
754 if (di != NULL)
755 {
Bram Moolenaard155d7a2018-12-21 16:04:21 +0100756 if (tv_get_number(&di->di_tv))
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100757 prop->pt_flags |= PT_FLAG_INS_END_INCL;
758 else
759 prop->pt_flags &= ~PT_FLAG_INS_END_INCL;
760 }
761 }
762}
763
764/*
765 * prop_type_add({name}, {props})
766 */
767 void
768f_prop_type_add(typval_T *argvars, typval_T *rettv UNUSED)
769{
770 prop_type_set(argvars, TRUE);
771}
772
773/*
774 * prop_type_change({name}, {props})
775 */
776 void
777f_prop_type_change(typval_T *argvars, typval_T *rettv UNUSED)
778{
779 prop_type_set(argvars, FALSE);
780}
781
782/*
783 * prop_type_delete({name} [, {bufnr}])
784 */
785 void
786f_prop_type_delete(typval_T *argvars, typval_T *rettv UNUSED)
787{
788 char_u *name;
789 buf_T *buf = NULL;
790 hashitem_T *hi;
791
Bram Moolenaard155d7a2018-12-21 16:04:21 +0100792 name = tv_get_string(&argvars[0]);
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100793 if (*name == NUL)
794 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +0100795 emsg(_(e_invarg));
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100796 return;
797 }
798
799 if (argvars[1].v_type != VAR_UNKNOWN)
800 {
801 if (get_bufnr_from_arg(&argvars[1], &buf) == FAIL)
802 return;
803 }
804
805 hi = find_prop_hi(name, buf);
806 if (hi != NULL)
807 {
808 hashtab_T *ht;
Bram Moolenaarfb95e212018-12-14 12:18:11 +0100809 proptype_T *prop = HI2PT(hi);
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100810
811 if (buf == NULL)
812 ht = global_proptypes;
813 else
814 ht = buf->b_proptypes;
815 hash_remove(ht, hi);
Bram Moolenaarfb95e212018-12-14 12:18:11 +0100816 vim_free(prop);
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100817 }
818}
819
820/*
821 * prop_type_get({name} [, {bufnr}])
822 */
823 void
824f_prop_type_get(typval_T *argvars, typval_T *rettv UNUSED)
825{
Bram Moolenaard155d7a2018-12-21 16:04:21 +0100826 char_u *name = tv_get_string(&argvars[0]);
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100827
828 if (*name == NUL)
829 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +0100830 emsg(_(e_invarg));
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100831 return;
832 }
833 if (rettv_dict_alloc(rettv) == OK)
834 {
835 proptype_T *prop = NULL;
836 buf_T *buf = NULL;
837
838 if (argvars[1].v_type != VAR_UNKNOWN)
839 {
840 if (get_bufnr_from_arg(&argvars[1], &buf) == FAIL)
841 return;
842 }
843
844 prop = find_prop(name, buf);
845 if (prop != NULL)
846 {
847 dict_T *d = rettv->vval.v_dict;
848
849 if (prop->pt_hl_id > 0)
850 dict_add_string(d, "highlight", syn_id2name(prop->pt_hl_id));
851 dict_add_number(d, "priority", prop->pt_priority);
Bram Moolenaar58187f12019-05-05 16:33:47 +0200852 dict_add_number(d, "combine",
853 (prop->pt_flags & PT_FLAG_COMBINE) ? 1 : 0);
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100854 dict_add_number(d, "start_incl",
855 (prop->pt_flags & PT_FLAG_INS_START_INCL) ? 1 : 0);
856 dict_add_number(d, "end_incl",
857 (prop->pt_flags & PT_FLAG_INS_END_INCL) ? 1 : 0);
858 if (buf != NULL)
859 dict_add_number(d, "bufnr", buf->b_fnum);
860 }
861 }
862}
863
864 static void
865list_types(hashtab_T *ht, list_T *l)
866{
867 long todo;
868 hashitem_T *hi;
869
870 todo = (long)ht->ht_used;
871 for (hi = ht->ht_array; todo > 0; ++hi)
872 {
873 if (!HASHITEM_EMPTY(hi))
874 {
875 proptype_T *prop = HI2PT(hi);
876
877 list_append_string(l, prop->pt_name, -1);
878 --todo;
879 }
880 }
881}
882
883/*
884 * prop_type_list([{bufnr}])
885 */
886 void
887f_prop_type_list(typval_T *argvars, typval_T *rettv UNUSED)
888{
889 buf_T *buf = NULL;
890
891 if (rettv_list_alloc(rettv) == OK)
892 {
893 if (argvars[0].v_type != VAR_UNKNOWN)
894 {
895 if (get_bufnr_from_arg(&argvars[0], &buf) == FAIL)
896 return;
897 }
898 if (buf == NULL)
899 {
900 if (global_proptypes != NULL)
901 list_types(global_proptypes, rettv->vval.v_list);
902 }
903 else if (buf->b_proptypes != NULL)
904 list_types(buf->b_proptypes, rettv->vval.v_list);
905 }
906}
907
908/*
909 * Free all property types in "ht".
910 */
911 static void
912clear_ht_prop_types(hashtab_T *ht)
913{
914 long todo;
915 hashitem_T *hi;
916
917 if (ht == NULL)
918 return;
919
920 todo = (long)ht->ht_used;
921 for (hi = ht->ht_array; todo > 0; ++hi)
922 {
923 if (!HASHITEM_EMPTY(hi))
924 {
925 proptype_T *prop = HI2PT(hi);
926
927 vim_free(prop);
928 --todo;
929 }
930 }
931
932 hash_clear(ht);
933 vim_free(ht);
934}
935
936#if defined(EXITFREE) || defined(PROTO)
937/*
Bram Moolenaarfb95e212018-12-14 12:18:11 +0100938 * Free all global property types.
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100939 */
940 void
941clear_global_prop_types(void)
942{
943 clear_ht_prop_types(global_proptypes);
944 global_proptypes = NULL;
945}
946#endif
947
948/*
949 * Free all property types for "buf".
950 */
951 void
952clear_buf_prop_types(buf_T *buf)
953{
954 clear_ht_prop_types(buf->b_proptypes);
955 buf->b_proptypes = NULL;
956}
957
Bram Moolenaarb9c67a52019-01-01 19:49:20 +0100958/*
959 * Adjust the columns of text properties in line "lnum" after position "col" to
960 * shift by "bytes_added" (can be negative).
Bram Moolenaar44746aa2019-01-02 00:02:11 +0100961 * Note that "col" is zero-based, while tp_col is one-based.
962 * Only for the current buffer.
963 * Called is expected to check b_has_textprop and "bytes_added" being non-zero.
Bram Moolenaarb9c67a52019-01-01 19:49:20 +0100964 */
965 void
Bram Moolenaar196d1572019-01-02 23:47:18 +0100966adjust_prop_columns(
967 linenr_T lnum,
968 colnr_T col,
969 int bytes_added)
Bram Moolenaarb9c67a52019-01-01 19:49:20 +0100970{
Bram Moolenaar44746aa2019-01-02 00:02:11 +0100971 int proplen;
972 char_u *props;
973 textprop_T tmp_prop;
974 proptype_T *pt;
975 int dirty = FALSE;
Bram Moolenaar196d1572019-01-02 23:47:18 +0100976 int ri, wi;
977 size_t textlen;
978
979 if (text_prop_frozen > 0)
980 return;
Bram Moolenaar44746aa2019-01-02 00:02:11 +0100981
982 proplen = get_text_props(curbuf, lnum, &props, TRUE);
983 if (proplen == 0)
984 return;
Bram Moolenaar196d1572019-01-02 23:47:18 +0100985 textlen = curbuf->b_ml.ml_line_len - proplen * sizeof(textprop_T);
Bram Moolenaar44746aa2019-01-02 00:02:11 +0100986
Bram Moolenaar196d1572019-01-02 23:47:18 +0100987 wi = 0; // write index
988 for (ri = 0; ri < proplen; ++ri)
Bram Moolenaar44746aa2019-01-02 00:02:11 +0100989 {
Bram Moolenaar196d1572019-01-02 23:47:18 +0100990 mch_memmove(&tmp_prop, props + ri * sizeof(textprop_T),
Bram Moolenaar44746aa2019-01-02 00:02:11 +0100991 sizeof(textprop_T));
992 pt = text_prop_type_by_id(curbuf, tmp_prop.tp_type);
993
Bram Moolenaar196d1572019-01-02 23:47:18 +0100994 if (bytes_added > 0
Bram Moolenaar4614f532019-01-06 12:54:55 +0100995 ? (tmp_prop.tp_col >= col
996 + (pt != NULL && (pt->pt_flags & PT_FLAG_INS_START_INCL)
997 ? 2 : 1))
Bram Moolenaar196d1572019-01-02 23:47:18 +0100998 : (tmp_prop.tp_col > col + 1))
Bram Moolenaar44746aa2019-01-02 00:02:11 +0100999 {
1000 tmp_prop.tp_col += bytes_added;
1001 dirty = TRUE;
1002 }
Bram Moolenaar196d1572019-01-02 23:47:18 +01001003 else if (tmp_prop.tp_len > 0
1004 && tmp_prop.tp_col + tmp_prop.tp_len > col
Bram Moolenaar4614f532019-01-06 12:54:55 +01001005 + ((pt != NULL && (pt->pt_flags & PT_FLAG_INS_END_INCL))
Bram Moolenaar196d1572019-01-02 23:47:18 +01001006 ? 0 : 1))
Bram Moolenaar44746aa2019-01-02 00:02:11 +01001007 {
1008 tmp_prop.tp_len += bytes_added;
1009 dirty = TRUE;
Bram Moolenaar196d1572019-01-02 23:47:18 +01001010 if (tmp_prop.tp_len <= 0)
1011 continue; // drop this text property
Bram Moolenaar44746aa2019-01-02 00:02:11 +01001012 }
Bram Moolenaar196d1572019-01-02 23:47:18 +01001013 mch_memmove(props + wi * sizeof(textprop_T), &tmp_prop,
Bram Moolenaar44746aa2019-01-02 00:02:11 +01001014 sizeof(textprop_T));
Bram Moolenaar196d1572019-01-02 23:47:18 +01001015 ++wi;
1016 }
1017 if (dirty)
1018 {
Bram Moolenaar4614f532019-01-06 12:54:55 +01001019 colnr_T newlen = (int)textlen + wi * (colnr_T)sizeof(textprop_T);
1020
1021 if ((curbuf->b_ml.ml_flags & ML_LINE_DIRTY) == 0)
1022 curbuf->b_ml.ml_line_ptr =
1023 vim_memsave(curbuf->b_ml.ml_line_ptr, newlen);
Bram Moolenaar196d1572019-01-02 23:47:18 +01001024 curbuf->b_ml.ml_flags |= ML_LINE_DIRTY;
Bram Moolenaar4614f532019-01-06 12:54:55 +01001025 curbuf->b_ml.ml_line_len = newlen;
Bram Moolenaar44746aa2019-01-02 00:02:11 +01001026 }
Bram Moolenaarb9c67a52019-01-01 19:49:20 +01001027}
1028
Bram Moolenaar4164bb22019-01-04 23:09:49 +01001029/*
1030 * Adjust text properties for a line that was split in two.
Bram Moolenaar45dd07f2019-05-15 22:45:37 +02001031 * "lnum_props" is the line that has the properties from before the split.
1032 * "lnum_top" is the top line.
1033 * "kept" is the number of bytes kept in the first line, while
Bram Moolenaar4164bb22019-01-04 23:09:49 +01001034 * "deleted" is the number of bytes deleted.
1035 */
1036 void
Bram Moolenaar45dd07f2019-05-15 22:45:37 +02001037adjust_props_for_split(
1038 linenr_T lnum_props,
1039 linenr_T lnum_top,
1040 int kept,
1041 int deleted)
Bram Moolenaar4164bb22019-01-04 23:09:49 +01001042{
1043 char_u *props;
1044 int count;
1045 garray_T prevprop;
1046 garray_T nextprop;
1047 int i;
1048 int skipped = kept + deleted;
1049
1050 if (!curbuf->b_has_textprop)
1051 return;
Bram Moolenaar45dd07f2019-05-15 22:45:37 +02001052
1053 // Get the text properties from "lnum_props".
1054 count = get_text_props(curbuf, lnum_props, &props, FALSE);
Bram Moolenaar4164bb22019-01-04 23:09:49 +01001055 ga_init2(&prevprop, sizeof(textprop_T), 10);
1056 ga_init2(&nextprop, sizeof(textprop_T), 10);
1057
Bram Moolenaar4164bb22019-01-04 23:09:49 +01001058 // Keep the relevant ones in the first line, reducing the length if needed.
1059 // Copy the ones that include the split to the second line.
1060 // Move the ones after the split to the second line.
1061 for (i = 0; i < count; ++i)
1062 {
1063 textprop_T prop;
1064 textprop_T *p;
1065
1066 // copy the prop to an aligned structure
1067 mch_memmove(&prop, props + i * sizeof(textprop_T), sizeof(textprop_T));
1068
1069 if (prop.tp_col < kept && ga_grow(&prevprop, 1) == OK)
1070 {
1071 p = ((textprop_T *)prevprop.ga_data) + prevprop.ga_len;
1072 *p = prop;
1073 if (p->tp_col + p->tp_len >= kept)
1074 p->tp_len = kept - p->tp_col;
1075 ++prevprop.ga_len;
1076 }
1077
1078 if (prop.tp_col + prop.tp_len >= skipped && ga_grow(&nextprop, 1) == OK)
1079 {
1080 p = ((textprop_T *)nextprop.ga_data) + nextprop.ga_len;
1081 *p = prop;
1082 if (p->tp_col > skipped)
1083 p->tp_col -= skipped - 1;
1084 else
1085 {
1086 p->tp_len -= skipped - p->tp_col;
1087 p->tp_col = 1;
1088 }
1089 ++nextprop.ga_len;
1090 }
1091 }
1092
Bram Moolenaar45dd07f2019-05-15 22:45:37 +02001093 set_text_props(lnum_top, prevprop.ga_data,
1094 prevprop.ga_len * sizeof(textprop_T));
Bram Moolenaar4164bb22019-01-04 23:09:49 +01001095 ga_clear(&prevprop);
Bram Moolenaar45dd07f2019-05-15 22:45:37 +02001096 set_text_props(lnum_top + 1, nextprop.ga_data,
1097 nextprop.ga_len * sizeof(textprop_T));
Bram Moolenaar4164bb22019-01-04 23:09:49 +01001098 ga_clear(&nextprop);
1099}
1100
Bram Moolenaar98aefe72018-12-13 22:20:09 +01001101#endif // FEAT_TEXT_PROP