annotate src/textprop.c @ 15146:7903dce131d4 v8.1.0583

patch 8.1.0583: using illogical name for get_dict_number()/get_dict_string() commit https://github.com/vim/vim/commit/8f66717a1f835b8194139d158c1e2df8b30c3ef3 Author: Bram Moolenaar <Bram@vim.org> Date: Fri Dec 14 15:38:31 2018 +0100 patch 8.1.0583: using illogical name for get_dict_number()/get_dict_string() Problem: Using illogical name for get_dict_number()/get_dict_string(). Solution: Rename to start with dict_.
author Bram Moolenaar <Bram@vim.org>
date Fri, 14 Dec 2018 15:45:06 +0100
parents 7960bf50d345
children 4b2de998ebd6
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 /*
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
11 * Text properties implementation.
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 * Text properties are attached to the text. They move with the text when
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
14 * text is inserted/deleted.
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
15 *
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
16 * Text properties have a user specified ID number, which can be unique.
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
17 * Text properties have a type, which can be used to specify highlighting.
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
18 *
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
19 * TODO:
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
20 * - Add an arrray for global_proptypes, to quickly lookup a proptype by ID
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
21 * - Add an arrray for b_proptypes, to quickly lookup a proptype by ID
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
22 * - adjust property column when text is inserted/deleted
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
23 * - support properties that continue over a line break
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
24 * - add mechanism to keep track of changed lines.
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
25 */
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
26
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
27 #include "vim.h"
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 #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
30
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 * 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
33 * 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
34 * 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
35 * 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
36 * 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
37 */
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
38 #define PT2HIKEY(p) ((p)->pt_name)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
39 #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
40 #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
41
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
42 // The global text property types.
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
43 static hashtab_T *global_proptypes = NULL;
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 last used text property type ID.
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
46 static int proptype_id = 0;
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 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
49 static char_u e_invalid_col[] = N_("E964: Invalid column number: %ld");
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 /*
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
52 * 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
53 * 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
54 */
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
55 static hashitem_T *
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
56 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
57 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
58 hashtab_T *ht;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
59 hashitem_T *hi;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
60
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
61 if (*name == NUL)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
62 return NULL;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
63 if (buf == NULL)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
64 ht = global_proptypes;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
65 else
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
66 ht = buf->b_proptypes;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
67
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
68 if (ht == NULL)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
69 return NULL;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
70 hi = hash_find(ht, name);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
71 if (HASHITEM_EMPTY(hi))
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
72 return NULL;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
73 return hi;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
74 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
75
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
76 /*
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
77 * 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
78 */
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
79 static proptype_T *
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
80 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
81 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
82 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
83
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
84 if (hi == NULL)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
85 return NULL;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
86 return HI2PT(hi);
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
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
89 /*
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
90 * 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
91 * global types.
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
92 * 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
93 */
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
94 static proptype_T *
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
95 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
96 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
97 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
98
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
99 if (type == NULL)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
100 type = find_prop(name, NULL);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
101 if (type == NULL)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
102 EMSG2(_(e_type_not_exist), name);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
103 return type;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
104 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
105
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
106 /*
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
107 * 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
108 * 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
109 * unchanged.
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
110 * 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
111 * 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
112 */
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
113 static int
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
114 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
115 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
116 dictitem_T *di;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
117
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
118 if (arg->v_type != VAR_DICT)
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 EMSG(_(e_dictreq));
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
121 return FAIL;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
122 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
123 if (arg->vval.v_dict == NULL)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
124 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
125 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
126 if (di != NULL)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
127 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
128 *buf = get_buf_tv(&di->di_tv, FALSE);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
129 if (*buf == NULL)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
130 return FAIL;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
131 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
132 return OK;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
133 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
134
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 * prop_add({lnum}, {col}, {props})
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 void
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
139 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
140 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
141 linenr_T lnum;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
142 colnr_T col;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
143 dict_T *dict;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
144 colnr_T length = 1;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
145 char_u *type_name;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
146 proptype_T *type;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
147 buf_T *buf = curbuf;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
148 int id = 0;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
149 char_u *newtext;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
150 int proplen;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
151 size_t textlen;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
152 char_u *props;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
153 char_u *newprops;
15144
7960bf50d345 patch 8.1.0582: text properties are not enabled
Bram Moolenaar <Bram@vim.org>
parents: 15138
diff changeset
154 textprop_T tmp_prop;
15138
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
155 int i;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
156
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
157 lnum = get_tv_number(&argvars[0]);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
158 col = get_tv_number(&argvars[1]);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
159 if (col < 1)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
160 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
161 EMSGN(_(e_invalid_col), (long)col);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
162 return;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
163 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
164 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
165 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
166 EMSG(_(e_dictreq));
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
167 return;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
168 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
169 dict = argvars[2].vval.v_dict;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
170
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
171 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
172 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
173 EMSG(_("E965: missing property type name"));
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
174 return;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
175 }
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
176 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
177
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
178 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
179 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
180 // TODO: handle end_lnum
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
181 EMSG("Sorry, end_lnum not supported yet");
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
182 return;
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
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
185 if (dict_find(dict, (char_u *)"length", -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
186 length = dict_get_number(dict, (char_u *)"length");
15138
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
187 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
188 {
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
189 length = dict_get_number(dict, (char_u *)"end_col") - col;
15138
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
190 if (length <= 0)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
191 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
192 EMSG2(_(e_invargval), "end_col");
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
193 return;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
194 }
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
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
197 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
198 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
199
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
200 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
201 return;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
202
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
203 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
204 if (type == NULL)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
205 return;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
206
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
207 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
208 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
209 EMSGN(_("E966: Invalid line number: %ld"), (long)lnum);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
210 return;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
211 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
212
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
213 // 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
214 proplen = get_text_props(buf, lnum, &props, TRUE);
15144
7960bf50d345 patch 8.1.0582: text properties are not enabled
Bram Moolenaar <Bram@vim.org>
parents: 15138
diff changeset
215 textlen = buf->b_ml.ml_line_len - proplen * sizeof(textprop_T);
15138
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
216
15144
7960bf50d345 patch 8.1.0582: text properties are not enabled
Bram Moolenaar <Bram@vim.org>
parents: 15138
diff changeset
217 if (col >= (colnr_T)textlen - 1)
15138
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
218 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
219 EMSGN(_(e_invalid_col), (long)col);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
220 return;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
221 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
222
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
223 // Allocate the new line with space for the new proprety.
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
224 newtext = alloc(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
225 if (newtext == NULL)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
226 return;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
227 // Copy the text, including terminating NUL.
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
228 mch_memmove(newtext, buf->b_ml.ml_line_ptr, textlen);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
229
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
230 // Find the index where to insert the new property.
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
231 // Since the text properties are not aligned properly when stored with the
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
232 // text, we need to copy them as bytes before using it as a struct.
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
233 for (i = 0; i < proplen; ++i)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
234 {
15144
7960bf50d345 patch 8.1.0582: text properties are not enabled
Bram Moolenaar <Bram@vim.org>
parents: 15138
diff changeset
235 mch_memmove(&tmp_prop, props + i * sizeof(textprop_T),
7960bf50d345 patch 8.1.0582: text properties are not enabled
Bram Moolenaar <Bram@vim.org>
parents: 15138
diff changeset
236 sizeof(textprop_T));
15138
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
237 if (tmp_prop.tp_col >= col)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
238 break;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
239 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
240 newprops = newtext + textlen;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
241 if (i > 0)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
242 mch_memmove(newprops, props, sizeof(textprop_T) * i);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
243
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
244 tmp_prop.tp_col = col;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
245 tmp_prop.tp_len = length;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
246 tmp_prop.tp_id = id;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
247 tmp_prop.tp_type = type->pt_id;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
248 tmp_prop.tp_flags = 0;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
249 mch_memmove(newprops + i * sizeof(textprop_T), &tmp_prop,
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
250 sizeof(textprop_T));
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
251
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
252 if (i < proplen)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
253 mch_memmove(newprops + (i + 1) * sizeof(textprop_T),
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
254 props + i * sizeof(textprop_T),
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
255 sizeof(textprop_T) * (proplen - i));
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
256
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
257 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
258 vim_free(buf->b_ml.ml_line_ptr);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
259 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
260 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
261 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
262
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
263 redraw_buf_later(buf, NOT_VALID);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
264 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
265
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
266 /*
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
267 * Return TRUE if any text properties are defined globally or for buffer
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
268 * "buf".
15138
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
269 */
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
270 int
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
271 has_any_text_properties(buf_T *buf)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
272 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
273 return buf->b_proptypes != NULL || global_proptypes != NULL;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
274 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
275
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
276 /*
15144
7960bf50d345 patch 8.1.0582: text properties are not enabled
Bram Moolenaar <Bram@vim.org>
parents: 15138
diff changeset
277 * 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
278 * 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
279 * 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
280 * pointer).
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
281 */
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
282 int
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
283 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
284 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
285 char_u *text;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
286 size_t textlen;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
287 size_t proplen;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
288
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
289 // Be quick when no text property types are defined.
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
290 if (!has_any_text_properties(buf))
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
291 return 0;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
292
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
293 // 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
294 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
295 textlen = STRLEN(text) + 1;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
296 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
297 if (proplen % sizeof(textprop_T) != 0)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
298 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
299 IEMSG(_("E967: text property info corrupted"));
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
300 return 0;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
301 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
302 if (proplen > 0)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
303 *props = text + textlen;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
304 return proplen / sizeof(textprop_T);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
305 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
306
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
307 static proptype_T *
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
308 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
309 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
310 long todo;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
311 hashitem_T *hi;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
312
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
313 if (ht == NULL)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
314 return NULL;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
315
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
316 // 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
317 // a binary search.
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 todo = (long)ht->ht_used;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
320 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
321 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
322 if (!HASHITEM_EMPTY(hi))
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
323 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
324 proptype_T *prop = HI2PT(hi);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
325
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
326 if (prop->pt_id == id)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
327 return prop;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
328 --todo;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
329 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
330 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
331 return NULL;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
332 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
333
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
334 /*
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
335 * 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
336 * Returns NULL if not found.
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
337 */
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
338 proptype_T *
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
339 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
340 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
341 proptype_T *type;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
342
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
343 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
344 if (type == NULL)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
345 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
346 return type;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
347 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
348
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 * prop_clear({lnum} [, {lnum_end} [, {bufnr}]])
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
351 */
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
352 void
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
353 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
354 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
355 linenr_T start = get_tv_number(&argvars[0]);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
356 linenr_T end = start;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
357 linenr_T lnum;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
358 buf_T *buf = curbuf;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
359
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
360 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
361 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
362 end = get_tv_number(&argvars[1]);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
363 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
364 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
365 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
366 return;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
367 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
368 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
369 if (start < 1 || end < 1)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
370 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
371 EMSG(_(e_invrange));
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
372 return;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
373 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
374
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
375 for (lnum = start; lnum <= end; ++lnum)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
376 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
377 char_u *text;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
378 size_t len;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
379
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
380 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
381 break;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
382 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
383 len = STRLEN(text) + 1;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
384 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
385 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
386 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
387 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
388 char_u *newtext = vim_strsave(text);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
389
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
390 // need to allocate the line now
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
391 if (newtext == NULL)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
392 return;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
393 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
394 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
395 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
396 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
397 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
398 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
399 redraw_buf_later(buf, NOT_VALID);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
400 }
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 * prop_list({lnum} [, {bufnr}])
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 void
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
406 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
407 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
408 linenr_T lnum = get_tv_number(&argvars[0]);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
409 buf_T *buf = curbuf;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
410
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
411 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
412 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
413 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
414 return;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
415 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
416 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
417 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
418 EMSG(_(e_invrange));
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
419 return;
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 if (rettv_list_alloc(rettv) == OK)
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 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
425 size_t textlen = STRLEN(text) + 1;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
426 int count = (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
427 / sizeof(textprop_T);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
428 int i;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
429 textprop_T prop;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
430 proptype_T *pt;
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 for (i = 0; i < count; ++i)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
433 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
434 dict_T *d = dict_alloc();
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
435
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
436 if (d == NULL)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
437 break;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
438 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
439 sizeof(textprop_T));
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
440 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
441 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
442 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
443 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
444 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
445 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
446 if (pt != NULL)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
447 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
448
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
449 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
450 }
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 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
453
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
454 /*
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
455 * prop_remove({props} [, {lnum} [, {lnum_end}]])
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
456 */
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
457 void
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
458 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
459 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
460 linenr_T start = 1;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
461 linenr_T end = 0;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
462 linenr_T lnum;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
463 dict_T *dict;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
464 buf_T *buf = curbuf;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
465 dictitem_T *di;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
466 int do_all = FALSE;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
467 int id = -1;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
468 int type_id = -1;
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 rettv->vval.v_number = 0;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
471 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
472 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
473 EMSG(_(e_invarg));
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
474 return;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
475 }
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 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
478 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
479 start = get_tv_number(&argvars[1]);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
480 end = start;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
481 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
482 end = get_tv_number(&argvars[2]);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
483 if (start < 1 || end < 1)
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 EMSG(_(e_invrange));
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 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
489
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
490 dict = argvars[0].vval.v_dict;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
491 di = dict_find(dict, (char_u *)"bufnr", -1);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
492 if (di != NULL)
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 buf = get_buf_tv(&di->di_tv, FALSE);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
495 if (buf == NULL)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
496 return;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
497 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
498
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
499 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
500 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
501 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
502
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
503 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
504 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
505 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
506 {
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
507 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
508 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
509
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
510 if (type == NULL)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
511 return;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
512 type_id = type->pt_id;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
513 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
514 if (id == -1 && type_id == -1)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
515 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
516 EMSG(_("E968: Need at least one of 'id' or 'type'"));
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
517 return;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
518 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
519
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
520 if (end == 0)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
521 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
522 for (lnum = start; lnum <= end; ++lnum)
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 char_u *text;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
525 size_t len;
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 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
528 break;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
529 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
530 len = STRLEN(text) + 1;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
531 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
532 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
533 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
534 unsigned idx;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
535
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
536 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
537 / sizeof(textprop_T); ++idx)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
538 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
539 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
540 + idx * sizeof(textprop_T);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
541 size_t taillen;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
542
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
543 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
544 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
545 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
546 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
547 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
548 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
549
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
550 // 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
551 if (newptr == NULL)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
552 return;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
553 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
554 buf->b_ml.ml_line_len);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
555 buf->b_ml.ml_line_ptr = newptr;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
556 curbuf->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
557 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
558
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
559 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
560 - (idx + 1) * sizeof(textprop_T);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
561 if (taillen > 0)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
562 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
563 taillen);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
564 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
565 --idx;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
566
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
567 ++rettv->vval.v_number;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
568 if (!do_all)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
569 break;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
570 }
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 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
573 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
574 redraw_buf_later(buf, NOT_VALID);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
575 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
576
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
577 /*
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
578 * 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
579 */
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
580 void
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
581 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
582 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
583 char_u *name;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
584 buf_T *buf = NULL;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
585 dict_T *dict;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
586 dictitem_T *di;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
587 proptype_T *prop;
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 name = get_tv_string(&argvars[0]);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
590 if (*name == NUL)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
591 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
592 EMSG(_(e_invarg));
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
593 return;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
594 }
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 (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
597 return;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
598 dict = argvars[1].vval.v_dict;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
599
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
600 prop = find_prop(name, buf);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
601 if (add)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
602 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
603 hashtab_T **htp;
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 if (prop != NULL)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
606 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
607 EMSG2(_("E969: Property type %s already defined"), name);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
608 return;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
609 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
610 prop = (proptype_T *)alloc_clear(sizeof(proptype_T) + STRLEN(name));
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
611 if (prop == NULL)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
612 return;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
613 STRCPY(prop->pt_name, name);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
614 prop->pt_id = ++proptype_id;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
615 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
616 if (*htp == NULL)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
617 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
618 *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
619 if (*htp == NULL)
15144
7960bf50d345 patch 8.1.0582: text properties are not enabled
Bram Moolenaar <Bram@vim.org>
parents: 15138
diff changeset
620 {
7960bf50d345 patch 8.1.0582: text properties are not enabled
Bram Moolenaar <Bram@vim.org>
parents: 15138
diff changeset
621 vim_free(prop);
15138
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
622 return;
15144
7960bf50d345 patch 8.1.0582: text properties are not enabled
Bram Moolenaar <Bram@vim.org>
parents: 15138
diff changeset
623 }
15138
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
624 hash_init(*htp);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
625 }
15144
7960bf50d345 patch 8.1.0582: text properties are not enabled
Bram Moolenaar <Bram@vim.org>
parents: 15138
diff changeset
626 hash_add(*htp, PT2HIKEY(prop));
15138
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
627 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
628 else
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 if (prop == NULL)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
631 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
632 EMSG2(_(e_type_not_exist), name);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
633 return;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
634 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
635 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
636
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
637 if (dict != NULL)
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 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
640 if (di != NULL)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
641 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
642 char_u *highlight;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
643 int hl_id = 0;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
644
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
645 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
646 if (highlight != NULL && *highlight != NUL)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
647 hl_id = syn_name2id(highlight);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
648 if (hl_id <= 0)
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 EMSG2(_("E970: Unknown highlight group name: '%s'"),
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
651 highlight == NULL ? (char_u *)"" : highlight);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
652 return;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
653 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
654 prop->pt_hl_id = hl_id;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
655 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
656
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
657 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
658 if (di != NULL)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
659 prop->pt_priority = get_tv_number(&di->di_tv);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
660
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
661 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
662 if (di != NULL)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
663 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
664 if (get_tv_number(&di->di_tv))
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
665 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
666 else
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
667 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
668 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
669
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
670 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
671 if (di != NULL)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
672 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
673 if (get_tv_number(&di->di_tv))
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
674 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
675 else
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
676 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
677 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
678 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
679 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
680
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
681 /*
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
682 * prop_type_add({name}, {props})
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
683 */
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
684 void
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
685 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
686 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
687 prop_type_set(argvars, TRUE);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
688 }
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 /*
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
691 * prop_type_change({name}, {props})
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
692 */
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
693 void
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
694 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
695 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
696 prop_type_set(argvars, FALSE);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
697 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
698
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 * prop_type_delete({name} [, {bufnr}])
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 void
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
703 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
704 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
705 char_u *name;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
706 buf_T *buf = NULL;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
707 hashitem_T *hi;
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 name = get_tv_string(&argvars[0]);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
710 if (*name == NUL)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
711 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
712 EMSG(_(e_invarg));
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
713 return;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
714 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
715
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
716 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
717 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
718 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
719 return;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
720 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
721
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
722 hi = find_prop_hi(name, buf);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
723 if (hi != NULL)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
724 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
725 hashtab_T *ht;
15144
7960bf50d345 patch 8.1.0582: text properties are not enabled
Bram Moolenaar <Bram@vim.org>
parents: 15138
diff changeset
726 proptype_T *prop = HI2PT(hi);
15138
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 if (buf == NULL)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
729 ht = global_proptypes;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
730 else
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
731 ht = buf->b_proptypes;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
732 hash_remove(ht, hi);
15144
7960bf50d345 patch 8.1.0582: text properties are not enabled
Bram Moolenaar <Bram@vim.org>
parents: 15138
diff changeset
733 vim_free(prop);
15138
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
734 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
735 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
736
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
737 /*
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
738 * prop_type_get({name} [, {bufnr}])
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
739 */
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
740 void
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
741 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
742 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
743 char_u *name = get_tv_string(&argvars[0]);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
744
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
745 if (*name == NUL)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
746 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
747 EMSG(_(e_invarg));
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
748 return;
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 if (rettv_dict_alloc(rettv) == OK)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
751 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
752 proptype_T *prop = NULL;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
753 buf_T *buf = NULL;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
754
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
755 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
756 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
757 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
758 return;
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 prop = find_prop(name, buf);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
762 if (prop != NULL)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
763 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
764 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
765
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
766 if (prop->pt_hl_id > 0)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
767 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
768 dict_add_number(d, "priority", prop->pt_priority);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
769 dict_add_number(d, "start_incl",
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
770 (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
771 dict_add_number(d, "end_incl",
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
772 (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
773 if (buf != NULL)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
774 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
775 }
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 }
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 static void
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
780 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
781 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
782 long todo;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
783 hashitem_T *hi;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
784
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
785 todo = (long)ht->ht_used;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
786 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
787 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
788 if (!HASHITEM_EMPTY(hi))
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
789 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
790 proptype_T *prop = HI2PT(hi);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
791
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
792 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
793 --todo;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
794 }
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
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 * prop_type_list([{bufnr}])
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
800 */
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
801 void
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
802 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
803 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
804 buf_T *buf = 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 if (rettv_list_alloc(rettv) == OK)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
807 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
808 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
809 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
810 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
811 return;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
812 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
813 if (buf == NULL)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
814 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
815 if (global_proptypes != NULL)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
816 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
817 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
818 else if (buf->b_proptypes != NULL)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
819 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
820 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
821 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
822
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
823 /*
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
824 * Free all property types in "ht".
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 static void
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
827 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
828 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
829 long todo;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
830 hashitem_T *hi;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
831
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
832 if (ht == NULL)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
833 return;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
834
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
835 todo = (long)ht->ht_used;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
836 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
837 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
838 if (!HASHITEM_EMPTY(hi))
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
839 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
840 proptype_T *prop = HI2PT(hi);
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 vim_free(prop);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
843 --todo;
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 }
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 hash_clear(ht);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
848 vim_free(ht);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
849 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
850
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
851 #if defined(EXITFREE) || defined(PROTO)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
852 /*
15144
7960bf50d345 patch 8.1.0582: text properties are not enabled
Bram Moolenaar <Bram@vim.org>
parents: 15138
diff changeset
853 * Free all global property types.
15138
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
854 */
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
855 void
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
856 clear_global_prop_types(void)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
857 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
858 clear_ht_prop_types(global_proptypes);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
859 global_proptypes = NULL;
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 #endif
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
862
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
863 /*
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
864 * Free all property types for "buf".
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
865 */
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
866 void
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
867 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
868 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
869 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
870 buf->b_proptypes = NULL;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
871 }
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 #endif // FEAT_TEXT_PROP