annotate src/textprop.c @ 16772:18093a6accb5 v8.1.1388

patch 8.1.1388: errors when calling prop_remove() for an unloaded buffer commit https://github.com/vim/vim/commit/f0884c5f3f5a25481d1e16f0979aa978a6690bb1 Author: Bram Moolenaar <Bram@vim.org> Date: Fri May 24 21:22:29 2019 +0200 patch 8.1.1388: errors when calling prop_remove() for an unloaded buffer Problem: Errors when calling prop_remove() for an unloaded buffer. Solution: Bail out when the buffer is not loaded. Add a few more tests for failing when the buffer number is invalid.
author Bram Moolenaar <Bram@vim.org>
date Fri, 24 May 2019 21:30:05 +0200
parents 09c81f17f83c
children fc58fee685e2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15138
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1 /* vi:set ts=8 sts=4 sw=4 noet:
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2 *
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3 * VIM - Vi IMproved by Bram Moolenaar
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4 *
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5 * Do ":help uganda" in Vim to read copying and usage conditions.
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6 * Do ":help credits" in Vim to see a list of people who contributed.
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7 * See README.txt for an overview of the Vim source code.
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8 */
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
10 /*
16662
1fc9cd08cf3c patch 8.1.1333: text properties don't always move after changes
Bram Moolenaar <Bram@vim.org>
parents: 16549
diff changeset
11 * Text properties implementation. See ":help text-properties".
15138
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
12 *
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
13 * TODO:
15335
18c20ceee4b5 patch 8.1.0675: text property column in screen columns is not practical
Bram Moolenaar <Bram@vim.org>
parents: 15294
diff changeset
14 * - Adjust text property column and length when text is inserted/deleted.
16770
09c81f17f83c patch 8.1.1387: calling prop_add() in an empty buffer doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 16768
diff changeset
15 * -> :substitute with multiple matches, issue #4427
15367
273649cad196 patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents: 15355
diff changeset
16 * -> a :substitute with a multi-line match
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15390
diff changeset
17 * -> search for changed_bytes() from misc1.c
16678
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
18 * -> search for mark_col_adjust()
15335
18c20ceee4b5 patch 8.1.0675: text property column in screen columns is not practical
Bram Moolenaar <Bram@vim.org>
parents: 15294
diff changeset
19 * - Perhaps we only need TP_FLAG_CONT_NEXT and can drop TP_FLAG_CONT_PREV?
15294
2d8225cc1315 patch 8.1.0655: when appending a line text property flags are not added
Bram Moolenaar <Bram@vim.org>
parents: 15255
diff changeset
20 * - Add an arrray for global_proptypes, to quickly lookup a prop type by ID
2d8225cc1315 patch 8.1.0655: when appending a line text property flags are not added
Bram Moolenaar <Bram@vim.org>
parents: 15255
diff changeset
21 * - Add an arrray for b_proptypes, to quickly lookup a prop type by ID
2d8225cc1315 patch 8.1.0655: when appending a line text property flags are not added
Bram Moolenaar <Bram@vim.org>
parents: 15255
diff changeset
22 * - Checking the text length to detect text properties is slow. Use a flag in
2d8225cc1315 patch 8.1.0655: when appending a line text property flags are not added
Bram Moolenaar <Bram@vim.org>
parents: 15255
diff changeset
23 * the index, like DB_MARKED?
15255
19e79a1ed6b6 patch 8.1.0636: line2byte() gives wrong values with text properties
Bram Moolenaar <Bram@vim.org>
parents: 15251
diff changeset
24 * - Also test line2byte() with many lines, so that ml_updatechunk() is taken
19e79a1ed6b6 patch 8.1.0636: line2byte() gives wrong values with text properties
Bram Moolenaar <Bram@vim.org>
parents: 15251
diff changeset
25 * into account.
15939
8013b532a1f7 patch 8.1.0975: using STRNCPY() wrongly. Warning for uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
26 * - Perhaps have a window-local option to disable highlighting from text
8013b532a1f7 patch 8.1.0975: using STRNCPY() wrongly. Warning for uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
27 * properties?
15138
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
28 */
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
29
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
30 #include "vim.h"
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
31
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
32 #if defined(FEAT_TEXT_PROP) || defined(PROTO)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
33
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
34 /*
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
35 * In a hashtable item "hi_key" points to "pt_name" in a proptype_T.
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
36 * This avoids adding a pointer to the hashtable item.
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
37 * PT2HIKEY() converts a proptype pointer to a hashitem key pointer.
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
38 * HIKEY2PT() converts a hashitem key pointer to a proptype pointer.
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
39 * HI2PT() converts a hashitem pointer to a proptype pointer.
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
40 */
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
41 #define PT2HIKEY(p) ((p)->pt_name)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
42 #define HIKEY2PT(p) ((proptype_T *)((p) - offsetof(proptype_T, pt_name)))
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
43 #define HI2PT(hi) HIKEY2PT((hi)->hi_key)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
44
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
45 // The global text property types.
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
46 static hashtab_T *global_proptypes = NULL;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
47
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
48 // The last used text property type ID.
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
49 static int proptype_id = 0;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
50
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
51 static char_u e_type_not_exist[] = N_("E971: Property type %s does not exist");
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
52 static char_u e_invalid_col[] = N_("E964: Invalid column number: %ld");
15251
17525ca95e1e patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
53 static char_u e_invalid_lnum[] = N_("E966: Invalid line number: %ld");
15138
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
54
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
55 /*
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
56 * Find a property type by name, return the hashitem.
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
57 * Returns NULL if the item can't be found.
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
58 */
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
59 static hashitem_T *
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
60 find_prop_hi(char_u *name, buf_T *buf)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
61 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
62 hashtab_T *ht;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
63 hashitem_T *hi;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
64
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
65 if (*name == NUL)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
66 return NULL;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
67 if (buf == NULL)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
68 ht = global_proptypes;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
69 else
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
70 ht = buf->b_proptypes;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
71
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
72 if (ht == NULL)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
73 return NULL;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
74 hi = hash_find(ht, name);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
75 if (HASHITEM_EMPTY(hi))
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
76 return NULL;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
77 return hi;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
78 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
79
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
80 /*
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
81 * Like find_prop_hi() but return the property type.
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
82 */
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
83 static proptype_T *
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
84 find_prop(char_u *name, buf_T *buf)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
85 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
86 hashitem_T *hi = find_prop_hi(name, buf);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
87
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
88 if (hi == NULL)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
89 return NULL;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
90 return HI2PT(hi);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
91 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
92
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
93 /*
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
94 * Lookup a property type by name. First in "buf" and when not found in the
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
95 * global types.
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
96 * When not found gives an error message and returns NULL.
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
97 */
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
98 static proptype_T *
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
99 lookup_prop_type(char_u *name, buf_T *buf)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
100 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
101 proptype_T *type = find_prop(name, buf);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
102
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
103 if (type == NULL)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
104 type = find_prop(name, NULL);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
105 if (type == NULL)
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15390
diff changeset
106 semsg(_(e_type_not_exist), name);
15138
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
107 return type;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
108 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
109
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
110 /*
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
111 * Get an optional "bufnr" item from the dict in "arg".
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
112 * When the argument is not used or "bufnr" is not present then "buf" is
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
113 * unchanged.
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
114 * If "bufnr" is valid or not present return OK.
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
115 * When "arg" is not a dict or "bufnr" is invalide return FAIL.
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
116 */
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
117 static int
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
118 get_bufnr_from_arg(typval_T *arg, buf_T **buf)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
119 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
120 dictitem_T *di;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
121
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
122 if (arg->v_type != VAR_DICT)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
123 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15390
diff changeset
124 emsg(_(e_dictreq));
15138
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
125 return FAIL;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
126 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
127 if (arg->vval.v_dict == NULL)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
128 return OK; // NULL dict is like an empty dict
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
129 di = dict_find(arg->vval.v_dict, (char_u *)"bufnr", -1);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
130 if (di != NULL)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
131 {
16772
18093a6accb5 patch 8.1.1388: errors when calling prop_remove() for an unloaded buffer
Bram Moolenaar <Bram@vim.org>
parents: 16770
diff changeset
132 *buf = get_buf_arg(&di->di_tv);
15138
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
133 if (*buf == NULL)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
134 return FAIL;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
135 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
136 return OK;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
137 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
138
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
139 /*
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
140 * prop_add({lnum}, {col}, {props})
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
141 */
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
142 void
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
143 f_prop_add(typval_T *argvars, typval_T *rettv UNUSED)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
144 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
145 linenr_T lnum;
15251
17525ca95e1e patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
146 linenr_T start_lnum;
17525ca95e1e patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
147 linenr_T end_lnum;
17525ca95e1e patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
148 colnr_T start_col;
17525ca95e1e patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
149 colnr_T end_col;
15138
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
150 dict_T *dict;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
151 char_u *type_name;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
152 proptype_T *type;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
153 buf_T *buf = curbuf;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
154 int id = 0;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
155 char_u *newtext;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
156 int proplen;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
157 size_t textlen;
15939
8013b532a1f7 patch 8.1.0975: using STRNCPY() wrongly. Warning for uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
158 char_u *props = NULL;
15138
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
159 char_u *newprops;
15144
7960bf50d345 patch 8.1.0582: text properties are not enabled
Bram Moolenaar <Bram@vim.org>
parents: 15138
diff changeset
160 textprop_T tmp_prop;
15138
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
161 int i;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
162
15251
17525ca95e1e patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
163 start_lnum = tv_get_number(&argvars[0]);
17525ca95e1e patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
164 start_col = tv_get_number(&argvars[1]);
17525ca95e1e patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
165 if (start_col < 1)
15138
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
166 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15390
diff changeset
167 semsg(_(e_invalid_col), (long)start_col);
15138
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
168 return;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
169 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
170 if (argvars[2].v_type != VAR_DICT)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
171 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15390
diff changeset
172 emsg(_(e_dictreq));
15138
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
173 return;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
174 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
175 dict = argvars[2].vval.v_dict;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
176
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
177 if (dict == NULL || dict_find(dict, (char_u *)"type", -1) == NULL)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
178 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15390
diff changeset
179 emsg(_("E965: missing property type name"));
15138
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
180 return;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
181 }
15146
7903dce131d4 patch 8.1.0583: using illogical name for get_dict_number()/get_dict_string()
Bram Moolenaar <Bram@vim.org>
parents: 15144
diff changeset
182 type_name = dict_get_string(dict, (char_u *)"type", FALSE);
15138
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
183
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
184 if (dict_find(dict, (char_u *)"end_lnum", -1) != NULL)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
185 {
15251
17525ca95e1e patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
186 end_lnum = dict_get_number(dict, (char_u *)"end_lnum");
17525ca95e1e patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
187 if (end_lnum < start_lnum)
17525ca95e1e patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
188 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15390
diff changeset
189 semsg(_(e_invargval), "end_lnum");
15251
17525ca95e1e patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
190 return;
17525ca95e1e patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
191 }
15138
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
192 }
15251
17525ca95e1e patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
193 else
17525ca95e1e patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
194 end_lnum = start_lnum;
15138
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
195
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
196 if (dict_find(dict, (char_u *)"length", -1) != NULL)
15251
17525ca95e1e patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
197 {
17525ca95e1e patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
198 long length = dict_get_number(dict, (char_u *)"length");
17525ca95e1e patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
199
15335
18c20ceee4b5 patch 8.1.0675: text property column in screen columns is not practical
Bram Moolenaar <Bram@vim.org>
parents: 15294
diff changeset
200 if (length < 0 || end_lnum > start_lnum)
15251
17525ca95e1e patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
201 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15390
diff changeset
202 semsg(_(e_invargval), "length");
15251
17525ca95e1e patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
203 return;
17525ca95e1e patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
204 }
15335
18c20ceee4b5 patch 8.1.0675: text property column in screen columns is not practical
Bram Moolenaar <Bram@vim.org>
parents: 15294
diff changeset
205 end_col = start_col + length;
15251
17525ca95e1e patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
206 }
15138
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
207 else if (dict_find(dict, (char_u *)"end_col", -1) != NULL)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
208 {
15251
17525ca95e1e patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
209 end_col = dict_get_number(dict, (char_u *)"end_col");
17525ca95e1e patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
210 if (end_col <= 0)
15138
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
211 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15390
diff changeset
212 semsg(_(e_invargval), "end_col");
15138
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
213 return;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
214 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
215 }
15251
17525ca95e1e patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
216 else if (start_lnum == end_lnum)
17525ca95e1e patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
217 end_col = start_col;
17525ca95e1e patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
218 else
17525ca95e1e patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
219 end_col = 1;
15138
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
220
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
221 if (dict_find(dict, (char_u *)"id", -1) != NULL)
15146
7903dce131d4 patch 8.1.0583: using illogical name for get_dict_number()/get_dict_string()
Bram Moolenaar <Bram@vim.org>
parents: 15144
diff changeset
222 id = dict_get_number(dict, (char_u *)"id");
15138
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
223
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
224 if (get_bufnr_from_arg(&argvars[2], &buf) == FAIL)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
225 return;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
226
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
227 type = lookup_prop_type(type_name, buf);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
228 if (type == NULL)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
229 return;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
230
15251
17525ca95e1e patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
231 if (start_lnum < 1 || start_lnum > buf->b_ml.ml_line_count)
15138
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
232 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15390
diff changeset
233 semsg(_(e_invalid_lnum), (long)start_lnum);
15138
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
234 return;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
235 }
15251
17525ca95e1e patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
236 if (end_lnum < start_lnum || end_lnum > buf->b_ml.ml_line_count)
15138
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
237 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15390
diff changeset
238 semsg(_(e_invalid_lnum), (long)end_lnum);
15138
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
239 return;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
240 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
241
16770
09c81f17f83c patch 8.1.1387: calling prop_add() in an empty buffer doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 16768
diff changeset
242 if (buf->b_ml.ml_mfp == NULL)
09c81f17f83c patch 8.1.1387: calling prop_add() in an empty buffer doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 16768
diff changeset
243 ml_open(buf);
09c81f17f83c patch 8.1.1387: calling prop_add() in an empty buffer doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 16768
diff changeset
244
15251
17525ca95e1e patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
245 for (lnum = start_lnum; lnum <= end_lnum; ++lnum)
17525ca95e1e patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
246 {
17525ca95e1e patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
247 colnr_T col; // start column
17525ca95e1e patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
248 long length; // in bytes
17525ca95e1e patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
249
17525ca95e1e patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
250 // Fetch the line to get the ml_line_len field updated.
17525ca95e1e patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
251 proplen = get_text_props(buf, lnum, &props, TRUE);
17525ca95e1e patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
252 textlen = buf->b_ml.ml_line_len - proplen * sizeof(textprop_T);
17525ca95e1e patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
253
17525ca95e1e patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
254 if (lnum == start_lnum)
17525ca95e1e patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
255 col = start_col;
17525ca95e1e patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
256 else
17525ca95e1e patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
257 col = 1;
17525ca95e1e patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
258 if (col - 1 > (colnr_T)textlen)
17525ca95e1e patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
259 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15390
diff changeset
260 semsg(_(e_invalid_col), (long)start_col);
15251
17525ca95e1e patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
261 return;
17525ca95e1e patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
262 }
17525ca95e1e patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
263
17525ca95e1e patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
264 if (lnum == end_lnum)
15335
18c20ceee4b5 patch 8.1.0675: text property column in screen columns is not practical
Bram Moolenaar <Bram@vim.org>
parents: 15294
diff changeset
265 length = end_col - col;
15251
17525ca95e1e patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
266 else
15353
21580db06cf3 patch 8.1.0684: warnings from 64-bit compiler
Bram Moolenaar <Bram@vim.org>
parents: 15349
diff changeset
267 length = (int)textlen - col + 1;
15255
19e79a1ed6b6 patch 8.1.0636: line2byte() gives wrong values with text properties
Bram Moolenaar <Bram@vim.org>
parents: 15251
diff changeset
268 if (length > (long)textlen)
15353
21580db06cf3 patch 8.1.0684: warnings from 64-bit compiler
Bram Moolenaar <Bram@vim.org>
parents: 15349
diff changeset
269 length = (int)textlen; // can include the end-of-line
15335
18c20ceee4b5 patch 8.1.0675: text property column in screen columns is not practical
Bram Moolenaar <Bram@vim.org>
parents: 15294
diff changeset
270 if (length < 0)
18c20ceee4b5 patch 8.1.0675: text property column in screen columns is not practical
Bram Moolenaar <Bram@vim.org>
parents: 15294
diff changeset
271 length = 0; // zero-width property
15138
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
272
15251
17525ca95e1e patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
273 // Allocate the new line with space for the new proprety.
17525ca95e1e patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
274 newtext = alloc(buf->b_ml.ml_line_len + sizeof(textprop_T));
17525ca95e1e patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
275 if (newtext == NULL)
17525ca95e1e patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
276 return;
17525ca95e1e patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
277 // Copy the text, including terminating NUL.
17525ca95e1e patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
278 mch_memmove(newtext, buf->b_ml.ml_line_ptr, textlen);
17525ca95e1e patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
279
17525ca95e1e patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
280 // Find the index where to insert the new property.
17525ca95e1e patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
281 // Since the text properties are not aligned properly when stored with the
17525ca95e1e patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
282 // text, we need to copy them as bytes before using it as a struct.
17525ca95e1e patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
283 for (i = 0; i < proplen; ++i)
17525ca95e1e patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
284 {
17525ca95e1e patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
285 mch_memmove(&tmp_prop, props + i * sizeof(textprop_T),
17525ca95e1e patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
286 sizeof(textprop_T));
17525ca95e1e patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
287 if (tmp_prop.tp_col >= col)
17525ca95e1e patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
288 break;
17525ca95e1e patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
289 }
17525ca95e1e patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
290 newprops = newtext + textlen;
17525ca95e1e patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
291 if (i > 0)
17525ca95e1e patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
292 mch_memmove(newprops, props, sizeof(textprop_T) * i);
17525ca95e1e patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
293
17525ca95e1e patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
294 tmp_prop.tp_col = col;
17525ca95e1e patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
295 tmp_prop.tp_len = length;
17525ca95e1e patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
296 tmp_prop.tp_id = id;
17525ca95e1e patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
297 tmp_prop.tp_type = type->pt_id;
17525ca95e1e patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
298 tmp_prop.tp_flags = (lnum > start_lnum ? TP_FLAG_CONT_PREV : 0)
17525ca95e1e patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
299 | (lnum < end_lnum ? TP_FLAG_CONT_NEXT : 0);
17525ca95e1e patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
300 mch_memmove(newprops + i * sizeof(textprop_T), &tmp_prop,
17525ca95e1e patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
301 sizeof(textprop_T));
17525ca95e1e patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
302
17525ca95e1e patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
303 if (i < proplen)
17525ca95e1e patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
304 mch_memmove(newprops + (i + 1) * sizeof(textprop_T),
17525ca95e1e patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
305 props + i * sizeof(textprop_T),
17525ca95e1e patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
306 sizeof(textprop_T) * (proplen - i));
17525ca95e1e patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
307
17525ca95e1e patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
308 if (buf->b_ml.ml_flags & ML_LINE_DIRTY)
17525ca95e1e patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
309 vim_free(buf->b_ml.ml_line_ptr);
17525ca95e1e patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
310 buf->b_ml.ml_line_ptr = newtext;
17525ca95e1e patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
311 buf->b_ml.ml_line_len += sizeof(textprop_T);
17525ca95e1e patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
312 buf->b_ml.ml_flags |= ML_LINE_DIRTY;
15138
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
313 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
314
15255
19e79a1ed6b6 patch 8.1.0636: line2byte() gives wrong values with text properties
Bram Moolenaar <Bram@vim.org>
parents: 15251
diff changeset
315 buf->b_has_textprop = TRUE; // this is never reset
15138
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
316 redraw_buf_later(buf, NOT_VALID);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
317 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
318
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
319 /*
15144
7960bf50d345 patch 8.1.0582: text properties are not enabled
Bram Moolenaar <Bram@vim.org>
parents: 15138
diff changeset
320 * Fetch the text properties for line "lnum" in buffer "buf".
15138
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
321 * Returns the number of text properties and, when non-zero, a pointer to the
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
322 * first one in "props" (note that it is not aligned, therefore the char_u
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
323 * pointer).
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
324 */
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
325 int
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
326 get_text_props(buf_T *buf, linenr_T lnum, char_u **props, int will_change)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
327 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
328 char_u *text;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
329 size_t textlen;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
330 size_t proplen;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
331
15255
19e79a1ed6b6 patch 8.1.0636: line2byte() gives wrong values with text properties
Bram Moolenaar <Bram@vim.org>
parents: 15251
diff changeset
332 // Be quick when no text property types have been defined or the buffer,
19e79a1ed6b6 patch 8.1.0636: line2byte() gives wrong values with text properties
Bram Moolenaar <Bram@vim.org>
parents: 15251
diff changeset
333 // unless we are adding one.
16770
09c81f17f83c patch 8.1.1387: calling prop_add() in an empty buffer doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 16768
diff changeset
334 if ((!buf->b_has_textprop && !will_change) || buf->b_ml.ml_mfp == NULL)
15138
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
335 return 0;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
336
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
337 // Fetch the line to get the ml_line_len field updated.
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
338 text = ml_get_buf(buf, lnum, will_change);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
339 textlen = STRLEN(text) + 1;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
340 proplen = buf->b_ml.ml_line_len - textlen;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
341 if (proplen % sizeof(textprop_T) != 0)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
342 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15390
diff changeset
343 iemsg(_("E967: text property info corrupted"));
15138
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
344 return 0;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
345 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
346 if (proplen > 0)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
347 *props = text + textlen;
15182
4b2de998ebd6 patch 8.1.0601: a few compiler warnings
Bram Moolenaar <Bram@vim.org>
parents: 15146
diff changeset
348 return (int)(proplen / sizeof(textprop_T));
15138
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
349 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
350
15367
273649cad196 patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents: 15355
diff changeset
351 /*
273649cad196 patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents: 15355
diff changeset
352 * Set the text properties for line "lnum" to "props" with length "len".
273649cad196 patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents: 15355
diff changeset
353 * If "len" is zero text properties are removed, "props" is not used.
273649cad196 patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents: 15355
diff changeset
354 * Any existing text properties are dropped.
273649cad196 patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents: 15355
diff changeset
355 * Only works for the current buffer.
273649cad196 patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents: 15355
diff changeset
356 */
273649cad196 patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents: 15355
diff changeset
357 static void
273649cad196 patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents: 15355
diff changeset
358 set_text_props(linenr_T lnum, char_u *props, int len)
273649cad196 patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents: 15355
diff changeset
359 {
15390
00aa76a735e7 patch 8.1.0703: compiler warnings with 64-bit compiler
Bram Moolenaar <Bram@vim.org>
parents: 15373
diff changeset
360 char_u *text;
00aa76a735e7 patch 8.1.0703: compiler warnings with 64-bit compiler
Bram Moolenaar <Bram@vim.org>
parents: 15373
diff changeset
361 char_u *newtext;
00aa76a735e7 patch 8.1.0703: compiler warnings with 64-bit compiler
Bram Moolenaar <Bram@vim.org>
parents: 15373
diff changeset
362 int textlen;
15367
273649cad196 patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents: 15355
diff changeset
363
273649cad196 patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents: 15355
diff changeset
364 text = ml_get(lnum);
15390
00aa76a735e7 patch 8.1.0703: compiler warnings with 64-bit compiler
Bram Moolenaar <Bram@vim.org>
parents: 15373
diff changeset
365 textlen = (int)STRLEN(text) + 1;
15367
273649cad196 patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents: 15355
diff changeset
366 newtext = alloc(textlen + len);
273649cad196 patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents: 15355
diff changeset
367 if (newtext == NULL)
273649cad196 patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents: 15355
diff changeset
368 return;
273649cad196 patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents: 15355
diff changeset
369 mch_memmove(newtext, text, textlen);
273649cad196 patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents: 15355
diff changeset
370 if (len > 0)
273649cad196 patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents: 15355
diff changeset
371 mch_memmove(newtext + textlen, props, len);
273649cad196 patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents: 15355
diff changeset
372 if (curbuf->b_ml.ml_flags & ML_LINE_DIRTY)
273649cad196 patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents: 15355
diff changeset
373 vim_free(curbuf->b_ml.ml_line_ptr);
273649cad196 patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents: 15355
diff changeset
374 curbuf->b_ml.ml_line_ptr = newtext;
273649cad196 patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents: 15355
diff changeset
375 curbuf->b_ml.ml_line_len = textlen + len;
273649cad196 patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents: 15355
diff changeset
376 curbuf->b_ml.ml_flags |= ML_LINE_DIRTY;
273649cad196 patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents: 15355
diff changeset
377 }
273649cad196 patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents: 15355
diff changeset
378
15138
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
379 static proptype_T *
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
380 find_type_by_id(hashtab_T *ht, int id)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
381 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
382 long todo;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
383 hashitem_T *hi;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
384
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
385 if (ht == NULL)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
386 return NULL;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
387
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
388 // TODO: Make this faster by keeping a list of types sorted on ID and use
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
389 // a binary search.
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
390
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
391 todo = (long)ht->ht_used;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
392 for (hi = ht->ht_array; todo > 0; ++hi)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
393 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
394 if (!HASHITEM_EMPTY(hi))
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
395 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
396 proptype_T *prop = HI2PT(hi);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
397
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
398 if (prop->pt_id == id)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
399 return prop;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
400 --todo;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
401 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
402 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
403 return NULL;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
404 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
405
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
406 /*
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
407 * Find a property type by ID in "buf" or globally.
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
408 * Returns NULL if not found.
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
409 */
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
410 proptype_T *
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
411 text_prop_type_by_id(buf_T *buf, int id)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
412 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
413 proptype_T *type;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
414
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
415 type = find_type_by_id(buf->b_proptypes, id);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
416 if (type == NULL)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
417 type = find_type_by_id(global_proptypes, id);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
418 return type;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
419 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
420
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
421 /*
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
422 * prop_clear({lnum} [, {lnum_end} [, {bufnr}]])
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
423 */
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
424 void
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
425 f_prop_clear(typval_T *argvars, typval_T *rettv UNUSED)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
426 {
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15182
diff changeset
427 linenr_T start = tv_get_number(&argvars[0]);
15138
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
428 linenr_T end = start;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
429 linenr_T lnum;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
430 buf_T *buf = curbuf;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
431
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
432 if (argvars[1].v_type != VAR_UNKNOWN)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
433 {
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15182
diff changeset
434 end = tv_get_number(&argvars[1]);
15138
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
435 if (argvars[2].v_type != VAR_UNKNOWN)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
436 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
437 if (get_bufnr_from_arg(&argvars[2], &buf) == FAIL)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
438 return;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
439 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
440 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
441 if (start < 1 || end < 1)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
442 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15390
diff changeset
443 emsg(_(e_invrange));
15138
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
444 return;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
445 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
446
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
447 for (lnum = start; lnum <= end; ++lnum)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
448 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
449 char_u *text;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
450 size_t len;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
451
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
452 if (lnum > buf->b_ml.ml_line_count)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
453 break;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
454 text = ml_get_buf(buf, lnum, FALSE);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
455 len = STRLEN(text) + 1;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
456 if ((size_t)buf->b_ml.ml_line_len > len)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
457 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
458 if (!(buf->b_ml.ml_flags & ML_LINE_DIRTY))
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
459 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
460 char_u *newtext = vim_strsave(text);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
461
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
462 // need to allocate the line now
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
463 if (newtext == NULL)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
464 return;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
465 buf->b_ml.ml_line_ptr = newtext;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
466 buf->b_ml.ml_flags |= ML_LINE_DIRTY;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
467 }
15182
4b2de998ebd6 patch 8.1.0601: a few compiler warnings
Bram Moolenaar <Bram@vim.org>
parents: 15146
diff changeset
468 buf->b_ml.ml_line_len = (int)len;
15138
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
469 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
470 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
471 redraw_buf_later(buf, NOT_VALID);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
472 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
473
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
474 /*
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
475 * prop_list({lnum} [, {bufnr}])
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
476 */
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
477 void
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
478 f_prop_list(typval_T *argvars, typval_T *rettv)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
479 {
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15182
diff changeset
480 linenr_T lnum = tv_get_number(&argvars[0]);
15138
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
481 buf_T *buf = curbuf;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
482
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
483 if (argvars[1].v_type != VAR_UNKNOWN)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
484 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
485 if (get_bufnr_from_arg(&argvars[1], &buf) == FAIL)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
486 return;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
487 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
488 if (lnum < 1 || lnum > buf->b_ml.ml_line_count)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
489 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15390
diff changeset
490 emsg(_(e_invrange));
15138
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
491 return;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
492 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
493
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
494 if (rettv_list_alloc(rettv) == OK)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
495 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
496 char_u *text = ml_get_buf(buf, lnum, FALSE);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
497 size_t textlen = STRLEN(text) + 1;
15182
4b2de998ebd6 patch 8.1.0601: a few compiler warnings
Bram Moolenaar <Bram@vim.org>
parents: 15146
diff changeset
498 int count = (int)((buf->b_ml.ml_line_len - textlen)
4b2de998ebd6 patch 8.1.0601: a few compiler warnings
Bram Moolenaar <Bram@vim.org>
parents: 15146
diff changeset
499 / sizeof(textprop_T));
15138
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
500 int i;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
501 textprop_T prop;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
502 proptype_T *pt;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
503
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
504 for (i = 0; i < count; ++i)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
505 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
506 dict_T *d = dict_alloc();
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
507
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
508 if (d == NULL)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
509 break;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
510 mch_memmove(&prop, text + textlen + i * sizeof(textprop_T),
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
511 sizeof(textprop_T));
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
512 dict_add_number(d, "col", prop.tp_col);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
513 dict_add_number(d, "length", prop.tp_len);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
514 dict_add_number(d, "id", prop.tp_id);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
515 dict_add_number(d, "start", !(prop.tp_flags & TP_FLAG_CONT_PREV));
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
516 dict_add_number(d, "end", !(prop.tp_flags & TP_FLAG_CONT_NEXT));
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
517 pt = text_prop_type_by_id(buf, prop.tp_type);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
518 if (pt != NULL)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
519 dict_add_string(d, "type", pt->pt_name);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
520
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
521 list_append_dict(rettv->vval.v_list, d);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
522 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
523 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
524 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
525
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
526 /*
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
527 * prop_remove({props} [, {lnum} [, {lnum_end}]])
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
528 */
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
529 void
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
530 f_prop_remove(typval_T *argvars, typval_T *rettv)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
531 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
532 linenr_T start = 1;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
533 linenr_T end = 0;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
534 linenr_T lnum;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
535 dict_T *dict;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
536 buf_T *buf = curbuf;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
537 dictitem_T *di;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
538 int do_all = FALSE;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
539 int id = -1;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
540 int type_id = -1;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
541
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
542 rettv->vval.v_number = 0;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
543 if (argvars[0].v_type != VAR_DICT || argvars[0].vval.v_dict == NULL)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
544 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15390
diff changeset
545 emsg(_(e_invarg));
15138
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
546 return;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
547 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
548
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
549 if (argvars[1].v_type != VAR_UNKNOWN)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
550 {
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15182
diff changeset
551 start = tv_get_number(&argvars[1]);
15138
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
552 end = start;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
553 if (argvars[2].v_type != VAR_UNKNOWN)
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15182
diff changeset
554 end = tv_get_number(&argvars[2]);
15138
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
555 if (start < 1 || end < 1)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
556 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15390
diff changeset
557 emsg(_(e_invrange));
15138
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
558 return;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
559 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
560 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
561
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
562 dict = argvars[0].vval.v_dict;
16772
18093a6accb5 patch 8.1.1388: errors when calling prop_remove() for an unloaded buffer
Bram Moolenaar <Bram@vim.org>
parents: 16770
diff changeset
563 if (get_bufnr_from_arg(&argvars[0], &buf) == FAIL)
18093a6accb5 patch 8.1.1388: errors when calling prop_remove() for an unloaded buffer
Bram Moolenaar <Bram@vim.org>
parents: 16770
diff changeset
564 return;
18093a6accb5 patch 8.1.1388: errors when calling prop_remove() for an unloaded buffer
Bram Moolenaar <Bram@vim.org>
parents: 16770
diff changeset
565 if (buf->b_ml.ml_mfp == NULL)
18093a6accb5 patch 8.1.1388: errors when calling prop_remove() for an unloaded buffer
Bram Moolenaar <Bram@vim.org>
parents: 16770
diff changeset
566 return;
15138
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
567
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
568 di = dict_find(dict, (char_u*)"all", -1);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
569 if (di != NULL)
15146
7903dce131d4 patch 8.1.0583: using illogical name for get_dict_number()/get_dict_string()
Bram Moolenaar <Bram@vim.org>
parents: 15144
diff changeset
570 do_all = dict_get_number(dict, (char_u *)"all");
15138
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
571
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
572 if (dict_find(dict, (char_u *)"id", -1) != NULL)
15146
7903dce131d4 patch 8.1.0583: using illogical name for get_dict_number()/get_dict_string()
Bram Moolenaar <Bram@vim.org>
parents: 15144
diff changeset
573 id = dict_get_number(dict, (char_u *)"id");
15138
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
574 if (dict_find(dict, (char_u *)"type", -1))
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
575 {
15146
7903dce131d4 patch 8.1.0583: using illogical name for get_dict_number()/get_dict_string()
Bram Moolenaar <Bram@vim.org>
parents: 15144
diff changeset
576 char_u *name = dict_get_string(dict, (char_u *)"type", FALSE);
15138
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
577 proptype_T *type = lookup_prop_type(name, buf);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
578
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
579 if (type == NULL)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
580 return;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
581 type_id = type->pt_id;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
582 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
583 if (id == -1 && type_id == -1)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
584 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15390
diff changeset
585 emsg(_("E968: Need at least one of 'id' or 'type'"));
15138
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
586 return;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
587 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
588
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
589 if (end == 0)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
590 end = buf->b_ml.ml_line_count;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
591 for (lnum = start; lnum <= end; ++lnum)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
592 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
593 char_u *text;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
594 size_t len;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
595
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
596 if (lnum > buf->b_ml.ml_line_count)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
597 break;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
598 text = ml_get_buf(buf, lnum, FALSE);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
599 len = STRLEN(text) + 1;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
600 if ((size_t)buf->b_ml.ml_line_len > len)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
601 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
602 static textprop_T textprop; // static because of alignment
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
603 unsigned idx;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
604
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
605 for (idx = 0; idx < (buf->b_ml.ml_line_len - len)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
606 / sizeof(textprop_T); ++idx)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
607 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
608 char_u *cur_prop = buf->b_ml.ml_line_ptr + len
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
609 + idx * sizeof(textprop_T);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
610 size_t taillen;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
611
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
612 mch_memmove(&textprop, cur_prop, sizeof(textprop_T));
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
613 if (textprop.tp_id == id || textprop.tp_type == type_id)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
614 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
615 if (!(buf->b_ml.ml_flags & ML_LINE_DIRTY))
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
616 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
617 char_u *newptr = alloc(buf->b_ml.ml_line_len);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
618
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
619 // need to allocate the line to be able to change it
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
620 if (newptr == NULL)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
621 return;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
622 mch_memmove(newptr, buf->b_ml.ml_line_ptr,
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
623 buf->b_ml.ml_line_len);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
624 buf->b_ml.ml_line_ptr = newptr;
16060
176872829dc2 patch 8.1.1035: prop_remove() second argument is not optional
Bram Moolenaar <Bram@vim.org>
parents: 15939
diff changeset
625 buf->b_ml.ml_flags |= ML_LINE_DIRTY;
176872829dc2 patch 8.1.1035: prop_remove() second argument is not optional
Bram Moolenaar <Bram@vim.org>
parents: 15939
diff changeset
626
176872829dc2 patch 8.1.1035: prop_remove() second argument is not optional
Bram Moolenaar <Bram@vim.org>
parents: 15939
diff changeset
627 cur_prop = buf->b_ml.ml_line_ptr + len
16772
18093a6accb5 patch 8.1.1388: errors when calling prop_remove() for an unloaded buffer
Bram Moolenaar <Bram@vim.org>
parents: 16770
diff changeset
628 + idx * sizeof(textprop_T);
15138
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
629 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
630
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
631 taillen = buf->b_ml.ml_line_len - len
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
632 - (idx + 1) * sizeof(textprop_T);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
633 if (taillen > 0)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
634 mch_memmove(cur_prop, cur_prop + sizeof(textprop_T),
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
635 taillen);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
636 buf->b_ml.ml_line_len -= sizeof(textprop_T);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
637 --idx;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
638
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
639 ++rettv->vval.v_number;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
640 if (!do_all)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
641 break;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
642 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
643 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
644 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
645 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
646 redraw_buf_later(buf, NOT_VALID);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
647 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
648
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
649 /*
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
650 * Common for f_prop_type_add() and f_prop_type_change().
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
651 */
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
652 void
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
653 prop_type_set(typval_T *argvars, int add)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
654 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
655 char_u *name;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
656 buf_T *buf = NULL;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
657 dict_T *dict;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
658 dictitem_T *di;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
659 proptype_T *prop;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
660
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15182
diff changeset
661 name = tv_get_string(&argvars[0]);
15138
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
662 if (*name == NUL)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
663 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15390
diff changeset
664 emsg(_(e_invarg));
15138
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
665 return;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
666 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
667
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
668 if (get_bufnr_from_arg(&argvars[1], &buf) == FAIL)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
669 return;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
670 dict = argvars[1].vval.v_dict;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
671
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
672 prop = find_prop(name, buf);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
673 if (add)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
674 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
675 hashtab_T **htp;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
676
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
677 if (prop != NULL)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
678 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15390
diff changeset
679 semsg(_("E969: Property type %s already defined"), name);
15138
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
680 return;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
681 }
16768
695d9ef00b03 patch 8.1.1386: unessesary type casts for lalloc()
Bram Moolenaar <Bram@vim.org>
parents: 16748
diff changeset
682 prop = (proptype_T *)alloc_clear(sizeof(proptype_T) + STRLEN(name));
15138
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
683 if (prop == NULL)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
684 return;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
685 STRCPY(prop->pt_name, name);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
686 prop->pt_id = ++proptype_id;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
687 htp = buf == NULL ? &global_proptypes : &buf->b_proptypes;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
688 if (*htp == NULL)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
689 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
690 *htp = (hashtab_T *)alloc(sizeof(hashtab_T));
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
691 if (*htp == NULL)
15144
7960bf50d345 patch 8.1.0582: text properties are not enabled
Bram Moolenaar <Bram@vim.org>
parents: 15138
diff changeset
692 {
7960bf50d345 patch 8.1.0582: text properties are not enabled
Bram Moolenaar <Bram@vim.org>
parents: 15138
diff changeset
693 vim_free(prop);
15138
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
694 return;
15144
7960bf50d345 patch 8.1.0582: text properties are not enabled
Bram Moolenaar <Bram@vim.org>
parents: 15138
diff changeset
695 }
15138
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
696 hash_init(*htp);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
697 }
15144
7960bf50d345 patch 8.1.0582: text properties are not enabled
Bram Moolenaar <Bram@vim.org>
parents: 15138
diff changeset
698 hash_add(*htp, PT2HIKEY(prop));
15138
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
699 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
700 else
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
701 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
702 if (prop == NULL)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
703 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15390
diff changeset
704 semsg(_(e_type_not_exist), name);
15138
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
705 return;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
706 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
707 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
708
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
709 if (dict != NULL)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
710 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
711 di = dict_find(dict, (char_u *)"highlight", -1);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
712 if (di != NULL)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
713 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
714 char_u *highlight;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
715 int hl_id = 0;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
716
15146
7903dce131d4 patch 8.1.0583: using illogical name for get_dict_number()/get_dict_string()
Bram Moolenaar <Bram@vim.org>
parents: 15144
diff changeset
717 highlight = dict_get_string(dict, (char_u *)"highlight", FALSE);
15138
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
718 if (highlight != NULL && *highlight != NUL)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
719 hl_id = syn_name2id(highlight);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
720 if (hl_id <= 0)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
721 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15390
diff changeset
722 semsg(_("E970: Unknown highlight group name: '%s'"),
15138
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
723 highlight == NULL ? (char_u *)"" : highlight);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
724 return;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
725 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
726 prop->pt_hl_id = hl_id;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
727 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
728
16549
08557bad0b9d patch 8.1.1278: missing change for "combine" field
Bram Moolenaar <Bram@vim.org>
parents: 16060
diff changeset
729 di = dict_find(dict, (char_u *)"combine", -1);
08557bad0b9d patch 8.1.1278: missing change for "combine" field
Bram Moolenaar <Bram@vim.org>
parents: 16060
diff changeset
730 if (di != NULL)
08557bad0b9d patch 8.1.1278: missing change for "combine" field
Bram Moolenaar <Bram@vim.org>
parents: 16060
diff changeset
731 {
08557bad0b9d patch 8.1.1278: missing change for "combine" field
Bram Moolenaar <Bram@vim.org>
parents: 16060
diff changeset
732 if (tv_get_number(&di->di_tv))
08557bad0b9d patch 8.1.1278: missing change for "combine" field
Bram Moolenaar <Bram@vim.org>
parents: 16060
diff changeset
733 prop->pt_flags |= PT_FLAG_COMBINE;
08557bad0b9d patch 8.1.1278: missing change for "combine" field
Bram Moolenaar <Bram@vim.org>
parents: 16060
diff changeset
734 else
08557bad0b9d patch 8.1.1278: missing change for "combine" field
Bram Moolenaar <Bram@vim.org>
parents: 16060
diff changeset
735 prop->pt_flags &= ~PT_FLAG_COMBINE;
08557bad0b9d patch 8.1.1278: missing change for "combine" field
Bram Moolenaar <Bram@vim.org>
parents: 16060
diff changeset
736 }
08557bad0b9d patch 8.1.1278: missing change for "combine" field
Bram Moolenaar <Bram@vim.org>
parents: 16060
diff changeset
737
15138
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
738 di = dict_find(dict, (char_u *)"priority", -1);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
739 if (di != NULL)
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15182
diff changeset
740 prop->pt_priority = tv_get_number(&di->di_tv);
15138
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
741
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
742 di = dict_find(dict, (char_u *)"start_incl", -1);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
743 if (di != NULL)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
744 {
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15182
diff changeset
745 if (tv_get_number(&di->di_tv))
15138
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
746 prop->pt_flags |= PT_FLAG_INS_START_INCL;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
747 else
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
748 prop->pt_flags &= ~PT_FLAG_INS_START_INCL;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
749 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
750
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
751 di = dict_find(dict, (char_u *)"end_incl", -1);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
752 if (di != NULL)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
753 {
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15182
diff changeset
754 if (tv_get_number(&di->di_tv))
15138
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
755 prop->pt_flags |= PT_FLAG_INS_END_INCL;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
756 else
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
757 prop->pt_flags &= ~PT_FLAG_INS_END_INCL;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
758 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
759 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
760 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
761
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
762 /*
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
763 * prop_type_add({name}, {props})
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
764 */
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
765 void
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
766 f_prop_type_add(typval_T *argvars, typval_T *rettv UNUSED)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
767 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
768 prop_type_set(argvars, TRUE);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
769 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
770
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
771 /*
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
772 * prop_type_change({name}, {props})
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
773 */
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
774 void
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
775 f_prop_type_change(typval_T *argvars, typval_T *rettv UNUSED)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
776 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
777 prop_type_set(argvars, FALSE);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
778 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
779
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
780 /*
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
781 * prop_type_delete({name} [, {bufnr}])
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
782 */
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
783 void
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
784 f_prop_type_delete(typval_T *argvars, typval_T *rettv UNUSED)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
785 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
786 char_u *name;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
787 buf_T *buf = NULL;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
788 hashitem_T *hi;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
789
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15182
diff changeset
790 name = tv_get_string(&argvars[0]);
15138
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
791 if (*name == NUL)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
792 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15390
diff changeset
793 emsg(_(e_invarg));
15138
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
794 return;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
795 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
796
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
797 if (argvars[1].v_type != VAR_UNKNOWN)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
798 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
799 if (get_bufnr_from_arg(&argvars[1], &buf) == FAIL)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
800 return;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
801 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
802
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
803 hi = find_prop_hi(name, buf);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
804 if (hi != NULL)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
805 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
806 hashtab_T *ht;
15144
7960bf50d345 patch 8.1.0582: text properties are not enabled
Bram Moolenaar <Bram@vim.org>
parents: 15138
diff changeset
807 proptype_T *prop = HI2PT(hi);
15138
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
808
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
809 if (buf == NULL)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
810 ht = global_proptypes;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
811 else
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
812 ht = buf->b_proptypes;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
813 hash_remove(ht, hi);
15144
7960bf50d345 patch 8.1.0582: text properties are not enabled
Bram Moolenaar <Bram@vim.org>
parents: 15138
diff changeset
814 vim_free(prop);
15138
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
815 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
816 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
817
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
818 /*
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
819 * prop_type_get({name} [, {bufnr}])
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
820 */
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
821 void
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
822 f_prop_type_get(typval_T *argvars, typval_T *rettv UNUSED)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
823 {
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15182
diff changeset
824 char_u *name = tv_get_string(&argvars[0]);
15138
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
825
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
826 if (*name == NUL)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
827 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15390
diff changeset
828 emsg(_(e_invarg));
15138
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
829 return;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
830 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
831 if (rettv_dict_alloc(rettv) == OK)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
832 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
833 proptype_T *prop = NULL;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
834 buf_T *buf = NULL;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
835
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
836 if (argvars[1].v_type != VAR_UNKNOWN)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
837 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
838 if (get_bufnr_from_arg(&argvars[1], &buf) == FAIL)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
839 return;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
840 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
841
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
842 prop = find_prop(name, buf);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
843 if (prop != NULL)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
844 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
845 dict_T *d = rettv->vval.v_dict;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
846
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
847 if (prop->pt_hl_id > 0)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
848 dict_add_string(d, "highlight", syn_id2name(prop->pt_hl_id));
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
849 dict_add_number(d, "priority", prop->pt_priority);
16549
08557bad0b9d patch 8.1.1278: missing change for "combine" field
Bram Moolenaar <Bram@vim.org>
parents: 16060
diff changeset
850 dict_add_number(d, "combine",
08557bad0b9d patch 8.1.1278: missing change for "combine" field
Bram Moolenaar <Bram@vim.org>
parents: 16060
diff changeset
851 (prop->pt_flags & PT_FLAG_COMBINE) ? 1 : 0);
15138
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
852 dict_add_number(d, "start_incl",
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
853 (prop->pt_flags & PT_FLAG_INS_START_INCL) ? 1 : 0);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
854 dict_add_number(d, "end_incl",
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
855 (prop->pt_flags & PT_FLAG_INS_END_INCL) ? 1 : 0);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
856 if (buf != NULL)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
857 dict_add_number(d, "bufnr", buf->b_fnum);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
858 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
859 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
860 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
861
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
862 static void
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
863 list_types(hashtab_T *ht, list_T *l)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
864 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
865 long todo;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
866 hashitem_T *hi;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
867
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
868 todo = (long)ht->ht_used;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
869 for (hi = ht->ht_array; todo > 0; ++hi)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
870 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
871 if (!HASHITEM_EMPTY(hi))
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
872 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
873 proptype_T *prop = HI2PT(hi);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
874
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
875 list_append_string(l, prop->pt_name, -1);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
876 --todo;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
877 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
878 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
879 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
880
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
881 /*
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
882 * prop_type_list([{bufnr}])
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
883 */
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
884 void
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
885 f_prop_type_list(typval_T *argvars, typval_T *rettv UNUSED)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
886 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
887 buf_T *buf = NULL;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
888
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
889 if (rettv_list_alloc(rettv) == OK)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
890 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
891 if (argvars[0].v_type != VAR_UNKNOWN)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
892 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
893 if (get_bufnr_from_arg(&argvars[0], &buf) == FAIL)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
894 return;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
895 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
896 if (buf == NULL)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
897 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
898 if (global_proptypes != NULL)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
899 list_types(global_proptypes, rettv->vval.v_list);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
900 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
901 else if (buf->b_proptypes != NULL)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
902 list_types(buf->b_proptypes, rettv->vval.v_list);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
903 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
904 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
905
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
906 /*
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
907 * Free all property types in "ht".
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
908 */
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
909 static void
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
910 clear_ht_prop_types(hashtab_T *ht)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
911 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
912 long todo;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
913 hashitem_T *hi;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
914
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
915 if (ht == NULL)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
916 return;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
917
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
918 todo = (long)ht->ht_used;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
919 for (hi = ht->ht_array; todo > 0; ++hi)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
920 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
921 if (!HASHITEM_EMPTY(hi))
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
922 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
923 proptype_T *prop = HI2PT(hi);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
924
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
925 vim_free(prop);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
926 --todo;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
927 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
928 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
929
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
930 hash_clear(ht);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
931 vim_free(ht);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
932 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
933
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
934 #if defined(EXITFREE) || defined(PROTO)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
935 /*
15144
7960bf50d345 patch 8.1.0582: text properties are not enabled
Bram Moolenaar <Bram@vim.org>
parents: 15138
diff changeset
936 * Free all global property types.
15138
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
937 */
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
938 void
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
939 clear_global_prop_types(void)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
940 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
941 clear_ht_prop_types(global_proptypes);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
942 global_proptypes = NULL;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
943 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
944 #endif
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
945
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
946 /*
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
947 * Free all property types for "buf".
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
948 */
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
949 void
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
950 clear_buf_prop_types(buf_T *buf)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
951 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
952 clear_ht_prop_types(buf->b_proptypes);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
953 buf->b_proptypes = NULL;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
954 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
955
15335
18c20ceee4b5 patch 8.1.0675: text property column in screen columns is not practical
Bram Moolenaar <Bram@vim.org>
parents: 15294
diff changeset
956 /*
18c20ceee4b5 patch 8.1.0675: text property column in screen columns is not practical
Bram Moolenaar <Bram@vim.org>
parents: 15294
diff changeset
957 * Adjust the columns of text properties in line "lnum" after position "col" to
18c20ceee4b5 patch 8.1.0675: text property column in screen columns is not practical
Bram Moolenaar <Bram@vim.org>
parents: 15294
diff changeset
958 * shift by "bytes_added" (can be negative).
15341
03a7a9fdb792 patch 8.1.0678: text properties as not adjusted for inserted text
Bram Moolenaar <Bram@vim.org>
parents: 15335
diff changeset
959 * Note that "col" is zero-based, while tp_col is one-based.
03a7a9fdb792 patch 8.1.0678: text properties as not adjusted for inserted text
Bram Moolenaar <Bram@vim.org>
parents: 15335
diff changeset
960 * Only for the current buffer.
16714
ba592f30c082 patch 8.1.1359: text property wrong after :substitute with backslash
Bram Moolenaar <Bram@vim.org>
parents: 16698
diff changeset
961 * "flags" can have:
ba592f30c082 patch 8.1.1359: text property wrong after :substitute with backslash
Bram Moolenaar <Bram@vim.org>
parents: 16698
diff changeset
962 * APC_SAVE_FOR_UNDO: Call u_savesub() before making changes to the line.
ba592f30c082 patch 8.1.1359: text property wrong after :substitute with backslash
Bram Moolenaar <Bram@vim.org>
parents: 16698
diff changeset
963 * APC_SUBSTITUTE: Text is replaced, not inserted.
16682
7847d281cbbf patch 8.1.1343: text properties not adjusted for Visual block mode delete
Bram Moolenaar <Bram@vim.org>
parents: 16678
diff changeset
964 * Caller is expected to check b_has_textprop and "bytes_added" being non-zero.
16698
23af483c4ceb patch 8.1.1351: text property wrong after :substitute
Bram Moolenaar <Bram@vim.org>
parents: 16682
diff changeset
965 * Returns TRUE when props were changed.
15335
18c20ceee4b5 patch 8.1.0675: text property column in screen columns is not practical
Bram Moolenaar <Bram@vim.org>
parents: 15294
diff changeset
966 */
16698
23af483c4ceb patch 8.1.1351: text property wrong after :substitute
Bram Moolenaar <Bram@vim.org>
parents: 16682
diff changeset
967 int
15349
6abee072b93c patch 8.1.0682: text properties not adjusted when backspacing replaced text
Bram Moolenaar <Bram@vim.org>
parents: 15341
diff changeset
968 adjust_prop_columns(
6abee072b93c patch 8.1.0682: text properties not adjusted when backspacing replaced text
Bram Moolenaar <Bram@vim.org>
parents: 15341
diff changeset
969 linenr_T lnum,
6abee072b93c patch 8.1.0682: text properties not adjusted when backspacing replaced text
Bram Moolenaar <Bram@vim.org>
parents: 15341
diff changeset
970 colnr_T col,
16698
23af483c4ceb patch 8.1.1351: text property wrong after :substitute
Bram Moolenaar <Bram@vim.org>
parents: 16682
diff changeset
971 int bytes_added,
16714
ba592f30c082 patch 8.1.1359: text property wrong after :substitute with backslash
Bram Moolenaar <Bram@vim.org>
parents: 16698
diff changeset
972 int flags)
15335
18c20ceee4b5 patch 8.1.0675: text property column in screen columns is not practical
Bram Moolenaar <Bram@vim.org>
parents: 15294
diff changeset
973 {
15341
03a7a9fdb792 patch 8.1.0678: text properties as not adjusted for inserted text
Bram Moolenaar <Bram@vim.org>
parents: 15335
diff changeset
974 int proplen;
03a7a9fdb792 patch 8.1.0678: text properties as not adjusted for inserted text
Bram Moolenaar <Bram@vim.org>
parents: 15335
diff changeset
975 char_u *props;
03a7a9fdb792 patch 8.1.0678: text properties as not adjusted for inserted text
Bram Moolenaar <Bram@vim.org>
parents: 15335
diff changeset
976 textprop_T tmp_prop;
03a7a9fdb792 patch 8.1.0678: text properties as not adjusted for inserted text
Bram Moolenaar <Bram@vim.org>
parents: 15335
diff changeset
977 proptype_T *pt;
03a7a9fdb792 patch 8.1.0678: text properties as not adjusted for inserted text
Bram Moolenaar <Bram@vim.org>
parents: 15335
diff changeset
978 int dirty = FALSE;
15349
6abee072b93c patch 8.1.0682: text properties not adjusted when backspacing replaced text
Bram Moolenaar <Bram@vim.org>
parents: 15341
diff changeset
979 int ri, wi;
6abee072b93c patch 8.1.0682: text properties not adjusted when backspacing replaced text
Bram Moolenaar <Bram@vim.org>
parents: 15341
diff changeset
980 size_t textlen;
6abee072b93c patch 8.1.0682: text properties not adjusted when backspacing replaced text
Bram Moolenaar <Bram@vim.org>
parents: 15341
diff changeset
981
6abee072b93c patch 8.1.0682: text properties not adjusted when backspacing replaced text
Bram Moolenaar <Bram@vim.org>
parents: 15341
diff changeset
982 if (text_prop_frozen > 0)
16698
23af483c4ceb patch 8.1.1351: text property wrong after :substitute
Bram Moolenaar <Bram@vim.org>
parents: 16682
diff changeset
983 return FALSE;
15341
03a7a9fdb792 patch 8.1.0678: text properties as not adjusted for inserted text
Bram Moolenaar <Bram@vim.org>
parents: 15335
diff changeset
984
03a7a9fdb792 patch 8.1.0678: text properties as not adjusted for inserted text
Bram Moolenaar <Bram@vim.org>
parents: 15335
diff changeset
985 proplen = get_text_props(curbuf, lnum, &props, TRUE);
03a7a9fdb792 patch 8.1.0678: text properties as not adjusted for inserted text
Bram Moolenaar <Bram@vim.org>
parents: 15335
diff changeset
986 if (proplen == 0)
16698
23af483c4ceb patch 8.1.1351: text property wrong after :substitute
Bram Moolenaar <Bram@vim.org>
parents: 16682
diff changeset
987 return FALSE;
15349
6abee072b93c patch 8.1.0682: text properties not adjusted when backspacing replaced text
Bram Moolenaar <Bram@vim.org>
parents: 15341
diff changeset
988 textlen = curbuf->b_ml.ml_line_len - proplen * sizeof(textprop_T);
15341
03a7a9fdb792 patch 8.1.0678: text properties as not adjusted for inserted text
Bram Moolenaar <Bram@vim.org>
parents: 15335
diff changeset
989
15349
6abee072b93c patch 8.1.0682: text properties not adjusted when backspacing replaced text
Bram Moolenaar <Bram@vim.org>
parents: 15341
diff changeset
990 wi = 0; // write index
6abee072b93c patch 8.1.0682: text properties not adjusted when backspacing replaced text
Bram Moolenaar <Bram@vim.org>
parents: 15341
diff changeset
991 for (ri = 0; ri < proplen; ++ri)
15341
03a7a9fdb792 patch 8.1.0678: text properties as not adjusted for inserted text
Bram Moolenaar <Bram@vim.org>
parents: 15335
diff changeset
992 {
16714
ba592f30c082 patch 8.1.1359: text property wrong after :substitute with backslash
Bram Moolenaar <Bram@vim.org>
parents: 16698
diff changeset
993 int start_incl;
ba592f30c082 patch 8.1.1359: text property wrong after :substitute with backslash
Bram Moolenaar <Bram@vim.org>
parents: 16698
diff changeset
994
15349
6abee072b93c patch 8.1.0682: text properties not adjusted when backspacing replaced text
Bram Moolenaar <Bram@vim.org>
parents: 15341
diff changeset
995 mch_memmove(&tmp_prop, props + ri * sizeof(textprop_T),
15341
03a7a9fdb792 patch 8.1.0678: text properties as not adjusted for inserted text
Bram Moolenaar <Bram@vim.org>
parents: 15335
diff changeset
996 sizeof(textprop_T));
03a7a9fdb792 patch 8.1.0678: text properties as not adjusted for inserted text
Bram Moolenaar <Bram@vim.org>
parents: 15335
diff changeset
997 pt = text_prop_type_by_id(curbuf, tmp_prop.tp_type);
16714
ba592f30c082 patch 8.1.1359: text property wrong after :substitute with backslash
Bram Moolenaar <Bram@vim.org>
parents: 16698
diff changeset
998 start_incl = (flags & APC_SUBSTITUTE) ||
ba592f30c082 patch 8.1.1359: text property wrong after :substitute with backslash
Bram Moolenaar <Bram@vim.org>
parents: 16698
diff changeset
999 (pt != NULL && (pt->pt_flags & PT_FLAG_INS_START_INCL));
15341
03a7a9fdb792 patch 8.1.0678: text properties as not adjusted for inserted text
Bram Moolenaar <Bram@vim.org>
parents: 15335
diff changeset
1000
15349
6abee072b93c patch 8.1.0682: text properties not adjusted when backspacing replaced text
Bram Moolenaar <Bram@vim.org>
parents: 15341
diff changeset
1001 if (bytes_added > 0
16714
ba592f30c082 patch 8.1.1359: text property wrong after :substitute with backslash
Bram Moolenaar <Bram@vim.org>
parents: 16698
diff changeset
1002 && (tmp_prop.tp_col >= col + (start_incl ? 2 : 1)))
ba592f30c082 patch 8.1.1359: text property wrong after :substitute with backslash
Bram Moolenaar <Bram@vim.org>
parents: 16698
diff changeset
1003 {
ba592f30c082 patch 8.1.1359: text property wrong after :substitute with backslash
Bram Moolenaar <Bram@vim.org>
parents: 16698
diff changeset
1004 if (tmp_prop.tp_col < col + (start_incl ? 2 : 1))
ba592f30c082 patch 8.1.1359: text property wrong after :substitute with backslash
Bram Moolenaar <Bram@vim.org>
parents: 16698
diff changeset
1005 {
ba592f30c082 patch 8.1.1359: text property wrong after :substitute with backslash
Bram Moolenaar <Bram@vim.org>
parents: 16698
diff changeset
1006 tmp_prop.tp_len += (tmp_prop.tp_col - 1 - col) + bytes_added;
ba592f30c082 patch 8.1.1359: text property wrong after :substitute with backslash
Bram Moolenaar <Bram@vim.org>
parents: 16698
diff changeset
1007 tmp_prop.tp_col = col + 1;
ba592f30c082 patch 8.1.1359: text property wrong after :substitute with backslash
Bram Moolenaar <Bram@vim.org>
parents: 16698
diff changeset
1008 }
ba592f30c082 patch 8.1.1359: text property wrong after :substitute with backslash
Bram Moolenaar <Bram@vim.org>
parents: 16698
diff changeset
1009 else
ba592f30c082 patch 8.1.1359: text property wrong after :substitute with backslash
Bram Moolenaar <Bram@vim.org>
parents: 16698
diff changeset
1010 tmp_prop.tp_col += bytes_added;
ba592f30c082 patch 8.1.1359: text property wrong after :substitute with backslash
Bram Moolenaar <Bram@vim.org>
parents: 16698
diff changeset
1011 // Save for undo if requested and not done yet.
ba592f30c082 patch 8.1.1359: text property wrong after :substitute with backslash
Bram Moolenaar <Bram@vim.org>
parents: 16698
diff changeset
1012 if ((flags & APC_SAVE_FOR_UNDO) && !dirty)
ba592f30c082 patch 8.1.1359: text property wrong after :substitute with backslash
Bram Moolenaar <Bram@vim.org>
parents: 16698
diff changeset
1013 u_savesub(lnum);
ba592f30c082 patch 8.1.1359: text property wrong after :substitute with backslash
Bram Moolenaar <Bram@vim.org>
parents: 16698
diff changeset
1014 dirty = TRUE;
ba592f30c082 patch 8.1.1359: text property wrong after :substitute with backslash
Bram Moolenaar <Bram@vim.org>
parents: 16698
diff changeset
1015 }
ba592f30c082 patch 8.1.1359: text property wrong after :substitute with backslash
Bram Moolenaar <Bram@vim.org>
parents: 16698
diff changeset
1016 else if (bytes_added <= 0 && (tmp_prop.tp_col > col + 1))
15341
03a7a9fdb792 patch 8.1.0678: text properties as not adjusted for inserted text
Bram Moolenaar <Bram@vim.org>
parents: 15335
diff changeset
1017 {
16682
7847d281cbbf patch 8.1.1343: text properties not adjusted for Visual block mode delete
Bram Moolenaar <Bram@vim.org>
parents: 16678
diff changeset
1018 if (tmp_prop.tp_col + bytes_added < col + 1)
7847d281cbbf patch 8.1.1343: text properties not adjusted for Visual block mode delete
Bram Moolenaar <Bram@vim.org>
parents: 16678
diff changeset
1019 {
7847d281cbbf patch 8.1.1343: text properties not adjusted for Visual block mode delete
Bram Moolenaar <Bram@vim.org>
parents: 16678
diff changeset
1020 tmp_prop.tp_len += (tmp_prop.tp_col - 1 - col) + bytes_added;
7847d281cbbf patch 8.1.1343: text properties not adjusted for Visual block mode delete
Bram Moolenaar <Bram@vim.org>
parents: 16678
diff changeset
1021 tmp_prop.tp_col = col + 1;
7847d281cbbf patch 8.1.1343: text properties not adjusted for Visual block mode delete
Bram Moolenaar <Bram@vim.org>
parents: 16678
diff changeset
1022 }
7847d281cbbf patch 8.1.1343: text properties not adjusted for Visual block mode delete
Bram Moolenaar <Bram@vim.org>
parents: 16678
diff changeset
1023 else
7847d281cbbf patch 8.1.1343: text properties not adjusted for Visual block mode delete
Bram Moolenaar <Bram@vim.org>
parents: 16678
diff changeset
1024 tmp_prop.tp_col += bytes_added;
16698
23af483c4ceb patch 8.1.1351: text property wrong after :substitute
Bram Moolenaar <Bram@vim.org>
parents: 16682
diff changeset
1025 // Save for undo if requested and not done yet.
16714
ba592f30c082 patch 8.1.1359: text property wrong after :substitute with backslash
Bram Moolenaar <Bram@vim.org>
parents: 16698
diff changeset
1026 if ((flags & APC_SAVE_FOR_UNDO) && !dirty)
16698
23af483c4ceb patch 8.1.1351: text property wrong after :substitute
Bram Moolenaar <Bram@vim.org>
parents: 16682
diff changeset
1027 u_savesub(lnum);
15341
03a7a9fdb792 patch 8.1.0678: text properties as not adjusted for inserted text
Bram Moolenaar <Bram@vim.org>
parents: 15335
diff changeset
1028 dirty = TRUE;
16682
7847d281cbbf patch 8.1.1343: text properties not adjusted for Visual block mode delete
Bram Moolenaar <Bram@vim.org>
parents: 16678
diff changeset
1029 if (tmp_prop.tp_len <= 0)
7847d281cbbf patch 8.1.1343: text properties not adjusted for Visual block mode delete
Bram Moolenaar <Bram@vim.org>
parents: 16678
diff changeset
1030 continue; // drop this text property
15341
03a7a9fdb792 patch 8.1.0678: text properties as not adjusted for inserted text
Bram Moolenaar <Bram@vim.org>
parents: 15335
diff changeset
1031 }
15349
6abee072b93c patch 8.1.0682: text properties not adjusted when backspacing replaced text
Bram Moolenaar <Bram@vim.org>
parents: 15341
diff changeset
1032 else if (tmp_prop.tp_len > 0
6abee072b93c patch 8.1.0682: text properties not adjusted when backspacing replaced text
Bram Moolenaar <Bram@vim.org>
parents: 15341
diff changeset
1033 && tmp_prop.tp_col + tmp_prop.tp_len > col
15373
44dd3ce11201 patch 8.1.0694: when using text props may free memory that is not allocated
Bram Moolenaar <Bram@vim.org>
parents: 15367
diff changeset
1034 + ((pt != NULL && (pt->pt_flags & PT_FLAG_INS_END_INCL))
15349
6abee072b93c patch 8.1.0682: text properties not adjusted when backspacing replaced text
Bram Moolenaar <Bram@vim.org>
parents: 15341
diff changeset
1035 ? 0 : 1))
15341
03a7a9fdb792 patch 8.1.0678: text properties as not adjusted for inserted text
Bram Moolenaar <Bram@vim.org>
parents: 15335
diff changeset
1036 {
16682
7847d281cbbf patch 8.1.1343: text properties not adjusted for Visual block mode delete
Bram Moolenaar <Bram@vim.org>
parents: 16678
diff changeset
1037 int after = col - bytes_added
7847d281cbbf patch 8.1.1343: text properties not adjusted for Visual block mode delete
Bram Moolenaar <Bram@vim.org>
parents: 16678
diff changeset
1038 - (tmp_prop.tp_col - 1 + tmp_prop.tp_len);
7847d281cbbf patch 8.1.1343: text properties not adjusted for Visual block mode delete
Bram Moolenaar <Bram@vim.org>
parents: 16678
diff changeset
1039 if (after > 0)
7847d281cbbf patch 8.1.1343: text properties not adjusted for Visual block mode delete
Bram Moolenaar <Bram@vim.org>
parents: 16678
diff changeset
1040 tmp_prop.tp_len += bytes_added + after;
7847d281cbbf patch 8.1.1343: text properties not adjusted for Visual block mode delete
Bram Moolenaar <Bram@vim.org>
parents: 16678
diff changeset
1041 else
7847d281cbbf patch 8.1.1343: text properties not adjusted for Visual block mode delete
Bram Moolenaar <Bram@vim.org>
parents: 16678
diff changeset
1042 tmp_prop.tp_len += bytes_added;
16698
23af483c4ceb patch 8.1.1351: text property wrong after :substitute
Bram Moolenaar <Bram@vim.org>
parents: 16682
diff changeset
1043 // Save for undo if requested and not done yet.
16714
ba592f30c082 patch 8.1.1359: text property wrong after :substitute with backslash
Bram Moolenaar <Bram@vim.org>
parents: 16698
diff changeset
1044 if ((flags & APC_SAVE_FOR_UNDO) && !dirty)
16698
23af483c4ceb patch 8.1.1351: text property wrong after :substitute
Bram Moolenaar <Bram@vim.org>
parents: 16682
diff changeset
1045 u_savesub(lnum);
15341
03a7a9fdb792 patch 8.1.0678: text properties as not adjusted for inserted text
Bram Moolenaar <Bram@vim.org>
parents: 15335
diff changeset
1046 dirty = TRUE;
15349
6abee072b93c patch 8.1.0682: text properties not adjusted when backspacing replaced text
Bram Moolenaar <Bram@vim.org>
parents: 15341
diff changeset
1047 if (tmp_prop.tp_len <= 0)
6abee072b93c patch 8.1.0682: text properties not adjusted when backspacing replaced text
Bram Moolenaar <Bram@vim.org>
parents: 15341
diff changeset
1048 continue; // drop this text property
15341
03a7a9fdb792 patch 8.1.0678: text properties as not adjusted for inserted text
Bram Moolenaar <Bram@vim.org>
parents: 15335
diff changeset
1049 }
15349
6abee072b93c patch 8.1.0682: text properties not adjusted when backspacing replaced text
Bram Moolenaar <Bram@vim.org>
parents: 15341
diff changeset
1050 mch_memmove(props + wi * sizeof(textprop_T), &tmp_prop,
15341
03a7a9fdb792 patch 8.1.0678: text properties as not adjusted for inserted text
Bram Moolenaar <Bram@vim.org>
parents: 15335
diff changeset
1051 sizeof(textprop_T));
15349
6abee072b93c patch 8.1.0682: text properties not adjusted when backspacing replaced text
Bram Moolenaar <Bram@vim.org>
parents: 15341
diff changeset
1052 ++wi;
6abee072b93c patch 8.1.0682: text properties not adjusted when backspacing replaced text
Bram Moolenaar <Bram@vim.org>
parents: 15341
diff changeset
1053 }
6abee072b93c patch 8.1.0682: text properties not adjusted when backspacing replaced text
Bram Moolenaar <Bram@vim.org>
parents: 15341
diff changeset
1054 if (dirty)
6abee072b93c patch 8.1.0682: text properties not adjusted when backspacing replaced text
Bram Moolenaar <Bram@vim.org>
parents: 15341
diff changeset
1055 {
15373
44dd3ce11201 patch 8.1.0694: when using text props may free memory that is not allocated
Bram Moolenaar <Bram@vim.org>
parents: 15367
diff changeset
1056 colnr_T newlen = (int)textlen + wi * (colnr_T)sizeof(textprop_T);
44dd3ce11201 patch 8.1.0694: when using text props may free memory that is not allocated
Bram Moolenaar <Bram@vim.org>
parents: 15367
diff changeset
1057
44dd3ce11201 patch 8.1.0694: when using text props may free memory that is not allocated
Bram Moolenaar <Bram@vim.org>
parents: 15367
diff changeset
1058 if ((curbuf->b_ml.ml_flags & ML_LINE_DIRTY) == 0)
44dd3ce11201 patch 8.1.0694: when using text props may free memory that is not allocated
Bram Moolenaar <Bram@vim.org>
parents: 15367
diff changeset
1059 curbuf->b_ml.ml_line_ptr =
44dd3ce11201 patch 8.1.0694: when using text props may free memory that is not allocated
Bram Moolenaar <Bram@vim.org>
parents: 15367
diff changeset
1060 vim_memsave(curbuf->b_ml.ml_line_ptr, newlen);
15349
6abee072b93c patch 8.1.0682: text properties not adjusted when backspacing replaced text
Bram Moolenaar <Bram@vim.org>
parents: 15341
diff changeset
1061 curbuf->b_ml.ml_flags |= ML_LINE_DIRTY;
15373
44dd3ce11201 patch 8.1.0694: when using text props may free memory that is not allocated
Bram Moolenaar <Bram@vim.org>
parents: 15367
diff changeset
1062 curbuf->b_ml.ml_line_len = newlen;
15341
03a7a9fdb792 patch 8.1.0678: text properties as not adjusted for inserted text
Bram Moolenaar <Bram@vim.org>
parents: 15335
diff changeset
1063 }
16698
23af483c4ceb patch 8.1.1351: text property wrong after :substitute
Bram Moolenaar <Bram@vim.org>
parents: 16682
diff changeset
1064 return dirty;
15335
18c20ceee4b5 patch 8.1.0675: text property column in screen columns is not practical
Bram Moolenaar <Bram@vim.org>
parents: 15294
diff changeset
1065 }
18c20ceee4b5 patch 8.1.0675: text property column in screen columns is not practical
Bram Moolenaar <Bram@vim.org>
parents: 15294
diff changeset
1066
15367
273649cad196 patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents: 15355
diff changeset
1067 /*
273649cad196 patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents: 15355
diff changeset
1068 * Adjust text properties for a line that was split in two.
16662
1fc9cd08cf3c patch 8.1.1333: text properties don't always move after changes
Bram Moolenaar <Bram@vim.org>
parents: 16549
diff changeset
1069 * "lnum_props" is the line that has the properties from before the split.
1fc9cd08cf3c patch 8.1.1333: text properties don't always move after changes
Bram Moolenaar <Bram@vim.org>
parents: 16549
diff changeset
1070 * "lnum_top" is the top line.
1fc9cd08cf3c patch 8.1.1333: text properties don't always move after changes
Bram Moolenaar <Bram@vim.org>
parents: 16549
diff changeset
1071 * "kept" is the number of bytes kept in the first line, while
15367
273649cad196 patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents: 15355
diff changeset
1072 * "deleted" is the number of bytes deleted.
273649cad196 patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents: 15355
diff changeset
1073 */
273649cad196 patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents: 15355
diff changeset
1074 void
16662
1fc9cd08cf3c patch 8.1.1333: text properties don't always move after changes
Bram Moolenaar <Bram@vim.org>
parents: 16549
diff changeset
1075 adjust_props_for_split(
1fc9cd08cf3c patch 8.1.1333: text properties don't always move after changes
Bram Moolenaar <Bram@vim.org>
parents: 16549
diff changeset
1076 linenr_T lnum_props,
1fc9cd08cf3c patch 8.1.1333: text properties don't always move after changes
Bram Moolenaar <Bram@vim.org>
parents: 16549
diff changeset
1077 linenr_T lnum_top,
1fc9cd08cf3c patch 8.1.1333: text properties don't always move after changes
Bram Moolenaar <Bram@vim.org>
parents: 16549
diff changeset
1078 int kept,
1fc9cd08cf3c patch 8.1.1333: text properties don't always move after changes
Bram Moolenaar <Bram@vim.org>
parents: 16549
diff changeset
1079 int deleted)
15367
273649cad196 patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents: 15355
diff changeset
1080 {
273649cad196 patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents: 15355
diff changeset
1081 char_u *props;
273649cad196 patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents: 15355
diff changeset
1082 int count;
273649cad196 patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents: 15355
diff changeset
1083 garray_T prevprop;
273649cad196 patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents: 15355
diff changeset
1084 garray_T nextprop;
273649cad196 patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents: 15355
diff changeset
1085 int i;
273649cad196 patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents: 15355
diff changeset
1086 int skipped = kept + deleted;
273649cad196 patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents: 15355
diff changeset
1087
273649cad196 patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents: 15355
diff changeset
1088 if (!curbuf->b_has_textprop)
273649cad196 patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents: 15355
diff changeset
1089 return;
16662
1fc9cd08cf3c patch 8.1.1333: text properties don't always move after changes
Bram Moolenaar <Bram@vim.org>
parents: 16549
diff changeset
1090
1fc9cd08cf3c patch 8.1.1333: text properties don't always move after changes
Bram Moolenaar <Bram@vim.org>
parents: 16549
diff changeset
1091 // Get the text properties from "lnum_props".
1fc9cd08cf3c patch 8.1.1333: text properties don't always move after changes
Bram Moolenaar <Bram@vim.org>
parents: 16549
diff changeset
1092 count = get_text_props(curbuf, lnum_props, &props, FALSE);
15367
273649cad196 patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents: 15355
diff changeset
1093 ga_init2(&prevprop, sizeof(textprop_T), 10);
273649cad196 patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents: 15355
diff changeset
1094 ga_init2(&nextprop, sizeof(textprop_T), 10);
273649cad196 patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents: 15355
diff changeset
1095
273649cad196 patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents: 15355
diff changeset
1096 // Keep the relevant ones in the first line, reducing the length if needed.
273649cad196 patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents: 15355
diff changeset
1097 // Copy the ones that include the split to the second line.
273649cad196 patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents: 15355
diff changeset
1098 // Move the ones after the split to the second line.
273649cad196 patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents: 15355
diff changeset
1099 for (i = 0; i < count; ++i)
273649cad196 patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents: 15355
diff changeset
1100 {
273649cad196 patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents: 15355
diff changeset
1101 textprop_T prop;
273649cad196 patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents: 15355
diff changeset
1102 textprop_T *p;
273649cad196 patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents: 15355
diff changeset
1103
273649cad196 patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents: 15355
diff changeset
1104 // copy the prop to an aligned structure
273649cad196 patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents: 15355
diff changeset
1105 mch_memmove(&prop, props + i * sizeof(textprop_T), sizeof(textprop_T));
273649cad196 patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents: 15355
diff changeset
1106
273649cad196 patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents: 15355
diff changeset
1107 if (prop.tp_col < kept && ga_grow(&prevprop, 1) == OK)
273649cad196 patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents: 15355
diff changeset
1108 {
273649cad196 patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents: 15355
diff changeset
1109 p = ((textprop_T *)prevprop.ga_data) + prevprop.ga_len;
273649cad196 patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents: 15355
diff changeset
1110 *p = prop;
273649cad196 patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents: 15355
diff changeset
1111 if (p->tp_col + p->tp_len >= kept)
273649cad196 patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents: 15355
diff changeset
1112 p->tp_len = kept - p->tp_col;
273649cad196 patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents: 15355
diff changeset
1113 ++prevprop.ga_len;
273649cad196 patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents: 15355
diff changeset
1114 }
273649cad196 patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents: 15355
diff changeset
1115
16670
5733d8e33bce patch 8.1.1337: get empty text prop when splitting line just after text prop
Bram Moolenaar <Bram@vim.org>
parents: 16662
diff changeset
1116 // Only add the property to the next line if the length is bigger than
5733d8e33bce patch 8.1.1337: get empty text prop when splitting line just after text prop
Bram Moolenaar <Bram@vim.org>
parents: 16662
diff changeset
1117 // zero.
5733d8e33bce patch 8.1.1337: get empty text prop when splitting line just after text prop
Bram Moolenaar <Bram@vim.org>
parents: 16662
diff changeset
1118 if (prop.tp_col + prop.tp_len > skipped && ga_grow(&nextprop, 1) == OK)
15367
273649cad196 patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents: 15355
diff changeset
1119 {
273649cad196 patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents: 15355
diff changeset
1120 p = ((textprop_T *)nextprop.ga_data) + nextprop.ga_len;
273649cad196 patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents: 15355
diff changeset
1121 *p = prop;
273649cad196 patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents: 15355
diff changeset
1122 if (p->tp_col > skipped)
273649cad196 patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents: 15355
diff changeset
1123 p->tp_col -= skipped - 1;
273649cad196 patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents: 15355
diff changeset
1124 else
273649cad196 patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents: 15355
diff changeset
1125 {
273649cad196 patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents: 15355
diff changeset
1126 p->tp_len -= skipped - p->tp_col;
273649cad196 patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents: 15355
diff changeset
1127 p->tp_col = 1;
273649cad196 patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents: 15355
diff changeset
1128 }
273649cad196 patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents: 15355
diff changeset
1129 ++nextprop.ga_len;
273649cad196 patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents: 15355
diff changeset
1130 }
273649cad196 patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents: 15355
diff changeset
1131 }
273649cad196 patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents: 15355
diff changeset
1132
16662
1fc9cd08cf3c patch 8.1.1333: text properties don't always move after changes
Bram Moolenaar <Bram@vim.org>
parents: 16549
diff changeset
1133 set_text_props(lnum_top, prevprop.ga_data,
1fc9cd08cf3c patch 8.1.1333: text properties don't always move after changes
Bram Moolenaar <Bram@vim.org>
parents: 16549
diff changeset
1134 prevprop.ga_len * sizeof(textprop_T));
15367
273649cad196 patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents: 15355
diff changeset
1135 ga_clear(&prevprop);
16662
1fc9cd08cf3c patch 8.1.1333: text properties don't always move after changes
Bram Moolenaar <Bram@vim.org>
parents: 16549
diff changeset
1136 set_text_props(lnum_top + 1, nextprop.ga_data,
1fc9cd08cf3c patch 8.1.1333: text properties don't always move after changes
Bram Moolenaar <Bram@vim.org>
parents: 16549
diff changeset
1137 nextprop.ga_len * sizeof(textprop_T));
15367
273649cad196 patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents: 15355
diff changeset
1138 ga_clear(&nextprop);
273649cad196 patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents: 15355
diff changeset
1139 }
273649cad196 patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents: 15355
diff changeset
1140
16678
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
1141 /*
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
1142 * Line "lnum" has been joined and will end up at column "col" in the new line.
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
1143 * "removed" bytes have been removed from the start of the line, properties
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
1144 * there are to be discarded.
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
1145 * Move the adjusted text properties to an allocated string, store it in
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
1146 * "prop_line" and adjust the columns.
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
1147 */
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
1148 void
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
1149 adjust_props_for_join(
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
1150 linenr_T lnum,
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
1151 textprop_T **prop_line,
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
1152 int *prop_length,
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
1153 long col,
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
1154 int removed)
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
1155 {
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
1156 int proplen;
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
1157 char_u *props;
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
1158 int ri;
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
1159 int wi = 0;
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
1160
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
1161 proplen = get_text_props(curbuf, lnum, &props, FALSE);
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
1162 if (proplen > 0)
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
1163 {
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
1164 *prop_line = (textprop_T *)alloc(proplen * (int)sizeof(textprop_T));
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
1165 if (*prop_line != NULL)
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
1166 {
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
1167 for (ri = 0; ri < proplen; ++ri)
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
1168 {
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
1169 textprop_T *cp = *prop_line + wi;
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
1170
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
1171 mch_memmove(cp, props + ri * sizeof(textprop_T),
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
1172 sizeof(textprop_T));
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
1173 if (cp->tp_col + cp->tp_len > removed)
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
1174 {
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
1175 if (cp->tp_col > removed)
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
1176 cp->tp_col += col;
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
1177 else
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
1178 {
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
1179 // property was partly deleted, make it shorter
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
1180 cp->tp_len -= removed - cp->tp_col;
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
1181 cp->tp_col = col;
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
1182 }
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
1183 ++wi;
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
1184 }
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
1185 }
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
1186 }
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
1187 *prop_length = wi;
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
1188 }
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
1189 }
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
1190
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
1191 /*
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
1192 * After joining lines: concatenate the text and the properties of all joined
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
1193 * lines into one line and replace the line.
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
1194 */
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
1195 void
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
1196 join_prop_lines(
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
1197 linenr_T lnum,
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
1198 char_u *newp,
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
1199 textprop_T **prop_lines,
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
1200 int *prop_lengths,
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
1201 int count)
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
1202 {
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
1203 size_t proplen = 0;
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
1204 size_t oldproplen;
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
1205 char_u *props;
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
1206 int i;
16748
75703a39d875 patch 8.1.1376: warnings for size_t/int mixups
Bram Moolenaar <Bram@vim.org>
parents: 16714
diff changeset
1207 size_t len;
16678
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
1208 char_u *line;
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
1209 size_t l;
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
1210
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
1211 for (i = 0; i < count - 1; ++i)
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
1212 proplen += prop_lengths[i];
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
1213 if (proplen == 0)
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
1214 {
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
1215 ml_replace(lnum, newp, FALSE);
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
1216 return;
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
1217 }
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
1218
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
1219 // get existing properties of the joined line
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
1220 oldproplen = get_text_props(curbuf, lnum, &props, FALSE);
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
1221
16748
75703a39d875 patch 8.1.1376: warnings for size_t/int mixups
Bram Moolenaar <Bram@vim.org>
parents: 16714
diff changeset
1222 len = STRLEN(newp) + 1;
75703a39d875 patch 8.1.1376: warnings for size_t/int mixups
Bram Moolenaar <Bram@vim.org>
parents: 16714
diff changeset
1223 line = alloc((int)(len + (oldproplen + proplen) * sizeof(textprop_T)));
16678
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
1224 if (line == NULL)
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
1225 return;
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
1226 mch_memmove(line, newp, len);
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
1227 l = oldproplen * sizeof(textprop_T);
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
1228 mch_memmove(line + len, props, l);
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
1229 len += l;
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
1230
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
1231 for (i = 0; i < count - 1; ++i)
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
1232 if (prop_lines[i] != NULL)
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
1233 {
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
1234 l = prop_lengths[i] * sizeof(textprop_T);
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
1235 mch_memmove(line + len, prop_lines[i], l);
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
1236 len += l;
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
1237 vim_free(prop_lines[i]);
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
1238 }
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
1239
16748
75703a39d875 patch 8.1.1376: warnings for size_t/int mixups
Bram Moolenaar <Bram@vim.org>
parents: 16714
diff changeset
1240 ml_replace_len(lnum, line, (colnr_T)len, TRUE, FALSE);
16678
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
1241 vim_free(newp);
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
1242 vim_free(prop_lines);
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
1243 vim_free(prop_lengths);
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
1244 }
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16676
diff changeset
1245
15138
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1246 #endif // FEAT_TEXT_PROP