Mercurial > vim
annotate src/textprop.c @ 26427:549cd187f215
Added tag v8.2.3744 for changeset c59d60e21ef5c5e92f1048412534124e0cd79efb
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 05 Dec 2021 14:30:03 +0100 |
parents | 685206b54ecf |
children | 2df40c348c70 |
rev | line source |
---|---|
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2 * |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3 * VIM - Vi IMproved by Bram Moolenaar |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4 * |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5 * Do ":help uganda" in Vim to read copying and usage conditions. |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6 * Do ":help credits" in Vim to see a list of people who contributed. |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
7 * See README.txt for an overview of the Vim source code. |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
8 */ |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
9 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
10 /* |
16662
1fc9cd08cf3c
patch 8.1.1333: text properties don't always move after changes
Bram Moolenaar <Bram@vim.org>
parents:
16549
diff
changeset
|
11 * Text properties implementation. See ":help text-properties". |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
12 * |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
13 * TODO: |
15335
18c20ceee4b5
patch 8.1.0675: text property column in screen columns is not practical
Bram Moolenaar <Bram@vim.org>
parents:
15294
diff
changeset
|
14 * - Adjust text property column and length when text is inserted/deleted. |
15367
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
15 * -> a :substitute with a multi-line match |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15390
diff
changeset
|
16 * -> search for changed_bytes() from misc1.c |
16678
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16676
diff
changeset
|
17 * -> search for mark_col_adjust() |
15335
18c20ceee4b5
patch 8.1.0675: text property column in screen columns is not practical
Bram Moolenaar <Bram@vim.org>
parents:
15294
diff
changeset
|
18 * - Perhaps we only need TP_FLAG_CONT_NEXT and can drop TP_FLAG_CONT_PREV? |
18498
9e6d5a4abb1c
patch 8.1.2243: typos in comments
Bram Moolenaar <Bram@vim.org>
parents:
18442
diff
changeset
|
19 * - Add an array for global_proptypes, to quickly lookup a prop type by ID |
9e6d5a4abb1c
patch 8.1.2243: typos in comments
Bram Moolenaar <Bram@vim.org>
parents:
18442
diff
changeset
|
20 * - Add an array for b_proptypes, to quickly lookup a prop type by ID |
15294
2d8225cc1315
patch 8.1.0655: when appending a line text property flags are not added
Bram Moolenaar <Bram@vim.org>
parents:
15255
diff
changeset
|
21 * - Checking the text length to detect text properties is slow. Use a flag in |
2d8225cc1315
patch 8.1.0655: when appending a line text property flags are not added
Bram Moolenaar <Bram@vim.org>
parents:
15255
diff
changeset
|
22 * the index, like DB_MARKED? |
15255
19e79a1ed6b6
patch 8.1.0636: line2byte() gives wrong values with text properties
Bram Moolenaar <Bram@vim.org>
parents:
15251
diff
changeset
|
23 * - Also test line2byte() with many lines, so that ml_updatechunk() is taken |
19e79a1ed6b6
patch 8.1.0636: line2byte() gives wrong values with text properties
Bram Moolenaar <Bram@vim.org>
parents:
15251
diff
changeset
|
24 * into account. |
15939
8013b532a1f7
patch 8.1.0975: using STRNCPY() wrongly. Warning for uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
25 * - Perhaps have a window-local option to disable highlighting from text |
8013b532a1f7
patch 8.1.0975: using STRNCPY() wrongly. Warning for uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
26 * properties? |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
27 */ |
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 #include "vim.h" |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
30 |
18763
49b78d6465e5
patch 8.1.2371: FEAT_TEXT_PROP is a confusing name
Bram Moolenaar <Bram@vim.org>
parents:
18631
diff
changeset
|
31 #if defined(FEAT_PROP_POPUP) || defined(PROTO) |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
32 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
33 /* |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
34 * 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
|
35 * 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
|
36 * 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
|
37 * 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
|
38 * 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
|
39 */ |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
40 #define PT2HIKEY(p) ((p)->pt_name) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
41 #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
|
42 #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
|
43 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
44 // The global text property types. |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
45 static hashtab_T *global_proptypes = NULL; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
46 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
47 // 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
|
48 static int proptype_id = 0; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
49 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
50 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
|
51 static char_u e_invalid_col[] = N_("E964: Invalid column number: %ld"); |
15251
17525ca95e1e
patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
52 static char_u e_invalid_lnum[] = N_("E966: Invalid line number: %ld"); |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
53 |
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 * 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
|
56 * 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
|
57 */ |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
58 static hashitem_T * |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
59 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
|
60 { |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
61 hashtab_T *ht; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
62 hashitem_T *hi; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
63 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
64 if (*name == NUL) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
65 return NULL; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
66 if (buf == NULL) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
67 ht = global_proptypes; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
68 else |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
69 ht = buf->b_proptypes; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
70 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
71 if (ht == NULL) |
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 hi = hash_find(ht, name); |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
74 if (HASHITEM_EMPTY(hi)) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
75 return NULL; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
76 return hi; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
77 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
78 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
79 /* |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
80 * 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
|
81 */ |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
82 static proptype_T * |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
83 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
|
84 { |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
85 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
|
86 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
87 if (hi == NULL) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
88 return NULL; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
89 return HI2PT(hi); |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
90 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
91 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
92 /* |
17863
08f1dd29550e
patch 8.1.1928: popup windows don't move with the text when making changes
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
93 * Get the prop type ID of "name". |
08f1dd29550e
patch 8.1.1928: popup windows don't move with the text when making changes
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
94 * When not found return zero. |
08f1dd29550e
patch 8.1.1928: popup windows don't move with the text when making changes
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
95 */ |
08f1dd29550e
patch 8.1.1928: popup windows don't move with the text when making changes
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
96 int |
08f1dd29550e
patch 8.1.1928: popup windows don't move with the text when making changes
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
97 find_prop_type_id(char_u *name, buf_T *buf) |
08f1dd29550e
patch 8.1.1928: popup windows don't move with the text when making changes
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
98 { |
08f1dd29550e
patch 8.1.1928: popup windows don't move with the text when making changes
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
99 proptype_T *pt = find_prop(name, buf); |
08f1dd29550e
patch 8.1.1928: popup windows don't move with the text when making changes
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
100 |
08f1dd29550e
patch 8.1.1928: popup windows don't move with the text when making changes
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
101 if (pt == NULL) |
08f1dd29550e
patch 8.1.1928: popup windows don't move with the text when making changes
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
102 return 0; |
08f1dd29550e
patch 8.1.1928: popup windows don't move with the text when making changes
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
103 return pt->pt_id; |
08f1dd29550e
patch 8.1.1928: popup windows don't move with the text when making changes
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
104 } |
08f1dd29550e
patch 8.1.1928: popup windows don't move with the text when making changes
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
105 |
08f1dd29550e
patch 8.1.1928: popup windows don't move with the text when making changes
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
106 /* |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
107 * 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
|
108 * global types. |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
109 * 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
|
110 */ |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
111 static proptype_T * |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
112 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
|
113 { |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
114 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
|
115 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
116 if (type == NULL) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
117 type = find_prop(name, NULL); |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
118 if (type == NULL) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15390
diff
changeset
|
119 semsg(_(e_type_not_exist), name); |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
120 return type; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
121 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
122 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
123 /* |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
124 * 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
|
125 * 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
|
126 * unchanged. |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
127 * If "bufnr" is valid or not present return OK. |
18498
9e6d5a4abb1c
patch 8.1.2243: typos in comments
Bram Moolenaar <Bram@vim.org>
parents:
18442
diff
changeset
|
128 * When "arg" is not a dict or "bufnr" is invalid return FAIL. |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
129 */ |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
130 static int |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
131 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
|
132 { |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
133 dictitem_T *di; |
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 if (arg->v_type != VAR_DICT) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
136 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15390
diff
changeset
|
137 emsg(_(e_dictreq)); |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
138 return FAIL; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
139 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
140 if (arg->vval.v_dict == NULL) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
141 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
|
142 di = dict_find(arg->vval.v_dict, (char_u *)"bufnr", -1); |
25392
b427a26b0210
patch 8.2.3233: prop_list() and prop_find() do not indicate the buffer
Bram Moolenaar <Bram@vim.org>
parents:
25384
diff
changeset
|
143 if (di != NULL && (di->di_tv.v_type != VAR_NUMBER |
b427a26b0210
patch 8.2.3233: prop_list() and prop_find() do not indicate the buffer
Bram Moolenaar <Bram@vim.org>
parents:
25384
diff
changeset
|
144 || di->di_tv.vval.v_number != 0)) |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
145 { |
16772
18093a6accb5
patch 8.1.1388: errors when calling prop_remove() for an unloaded buffer
Bram Moolenaar <Bram@vim.org>
parents:
16770
diff
changeset
|
146 *buf = get_buf_arg(&di->di_tv); |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
147 if (*buf == NULL) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
148 return FAIL; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
149 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
150 return OK; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
151 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
152 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
153 /* |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
154 * prop_add({lnum}, {col}, {props}) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
155 */ |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
156 void |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
157 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
|
158 { |
15251
17525ca95e1e
patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
159 linenr_T start_lnum; |
17525ca95e1e
patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
160 colnr_T start_col; |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
161 |
25302
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
162 if (in_vim9script() |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
163 && (check_for_number_arg(argvars, 0) == FAIL |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
164 || check_for_number_arg(argvars, 1) == FAIL |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
165 || check_for_dict_arg(argvars, 2) == FAIL)) |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
166 return; |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
167 |
15251
17525ca95e1e
patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
168 start_lnum = tv_get_number(&argvars[0]); |
17525ca95e1e
patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
169 start_col = tv_get_number(&argvars[1]); |
17525ca95e1e
patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
170 if (start_col < 1) |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
171 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15390
diff
changeset
|
172 semsg(_(e_invalid_col), (long)start_col); |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
173 return; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
174 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
175 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
|
176 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15390
diff
changeset
|
177 emsg(_(e_dictreq)); |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
178 return; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
179 } |
16811
0457d49eb2d9
patch 8.1.1407: popup_create() does not support text properties
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
180 |
0457d49eb2d9
patch 8.1.1407: popup_create() does not support text properties
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
181 prop_add_common(start_lnum, start_col, argvars[2].vval.v_dict, |
0457d49eb2d9
patch 8.1.1407: popup_create() does not support text properties
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
182 curbuf, &argvars[2]); |
0457d49eb2d9
patch 8.1.1407: popup_create() does not support text properties
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
183 } |
0457d49eb2d9
patch 8.1.1407: popup_create() does not support text properties
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
184 |
0457d49eb2d9
patch 8.1.1407: popup_create() does not support text properties
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
185 /* |
25640
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
186 * Attach a text property 'type_name' to the text starting |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
187 * at [start_lnum, start_col] and ending at [end_lnum, end_col] in |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
188 * the buffer 'buf' and assign identifier 'id'. |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
189 */ |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
190 static int |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
191 prop_add_one( |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
192 buf_T *buf, |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
193 char_u *type_name, |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
194 int id, |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
195 linenr_T start_lnum, |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
196 linenr_T end_lnum, |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
197 colnr_T start_col, |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
198 colnr_T end_col) |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
199 { |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
200 proptype_T *type; |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
201 linenr_T lnum; |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
202 int proplen; |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
203 char_u *props = NULL; |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
204 char_u *newprops; |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
205 size_t textlen; |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
206 char_u *newtext; |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
207 int i; |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
208 textprop_T tmp_prop; |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
209 |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
210 type = lookup_prop_type(type_name, buf); |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
211 if (type == NULL) |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
212 return FAIL; |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
213 |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
214 if (start_lnum < 1 || start_lnum > buf->b_ml.ml_line_count) |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
215 { |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
216 semsg(_(e_invalid_lnum), (long)start_lnum); |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
217 return FAIL; |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
218 } |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
219 if (end_lnum < start_lnum || end_lnum > buf->b_ml.ml_line_count) |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
220 { |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
221 semsg(_(e_invalid_lnum), (long)end_lnum); |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
222 return FAIL; |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
223 } |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
224 |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
225 if (buf->b_ml.ml_mfp == NULL) |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
226 { |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
227 emsg(_("E275: Cannot add text property to unloaded buffer")); |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
228 return FAIL; |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
229 } |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
230 |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
231 for (lnum = start_lnum; lnum <= end_lnum; ++lnum) |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
232 { |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
233 colnr_T col; // start column |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
234 long length; // in bytes |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
235 |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
236 // Fetch the line to get the ml_line_len field updated. |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
237 proplen = get_text_props(buf, lnum, &props, TRUE); |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
238 textlen = buf->b_ml.ml_line_len - proplen * sizeof(textprop_T); |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
239 |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
240 if (lnum == start_lnum) |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
241 col = start_col; |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
242 else |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
243 col = 1; |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
244 if (col - 1 > (colnr_T)textlen) |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
245 { |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
246 semsg(_(e_invalid_col), (long)start_col); |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
247 return FAIL; |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
248 } |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
249 |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
250 if (lnum == end_lnum) |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
251 length = end_col - col; |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
252 else |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
253 length = (int)textlen - col + 1; |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
254 if (length > (long)textlen) |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
255 length = (int)textlen; // can include the end-of-line |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
256 if (length < 0) |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
257 length = 0; // zero-width property |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
258 |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
259 // Allocate the new line with space for the new property. |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
260 newtext = alloc(buf->b_ml.ml_line_len + sizeof(textprop_T)); |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
261 if (newtext == NULL) |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
262 return FAIL; |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
263 // Copy the text, including terminating NUL. |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
264 mch_memmove(newtext, buf->b_ml.ml_line_ptr, textlen); |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
265 |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
266 // Find the index where to insert the new property. |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
267 // Since the text properties are not aligned properly when stored with |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
268 // the text, we need to copy them as bytes before using it as a struct. |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
269 for (i = 0; i < proplen; ++i) |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
270 { |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
271 mch_memmove(&tmp_prop, props + i * sizeof(textprop_T), |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
272 sizeof(textprop_T)); |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
273 if (tmp_prop.tp_col >= col) |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
274 break; |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
275 } |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
276 newprops = newtext + textlen; |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
277 if (i > 0) |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
278 mch_memmove(newprops, props, sizeof(textprop_T) * i); |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
279 |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
280 tmp_prop.tp_col = col; |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
281 tmp_prop.tp_len = length; |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
282 tmp_prop.tp_id = id; |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
283 tmp_prop.tp_type = type->pt_id; |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
284 tmp_prop.tp_flags = (lnum > start_lnum ? TP_FLAG_CONT_PREV : 0) |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
285 | (lnum < end_lnum ? TP_FLAG_CONT_NEXT : 0); |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
286 mch_memmove(newprops + i * sizeof(textprop_T), &tmp_prop, |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
287 sizeof(textprop_T)); |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
288 |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
289 if (i < proplen) |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
290 mch_memmove(newprops + (i + 1) * sizeof(textprop_T), |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
291 props + i * sizeof(textprop_T), |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
292 sizeof(textprop_T) * (proplen - i)); |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
293 |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
294 if (buf->b_ml.ml_flags & ML_LINE_DIRTY) |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
295 vim_free(buf->b_ml.ml_line_ptr); |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
296 buf->b_ml.ml_line_ptr = newtext; |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
297 buf->b_ml.ml_line_len += sizeof(textprop_T); |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
298 buf->b_ml.ml_flags |= ML_LINE_DIRTY; |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
299 } |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
300 |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
301 changed_lines_buf(buf, start_lnum, end_lnum + 1, 0); |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
302 return OK; |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
303 } |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
304 |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
305 /* |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
306 * prop_add_list() |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
307 * First argument specifies the text property: |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
308 * {'type': <str>, 'id': <num>, 'bufnr': <num>} |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
309 * Second argument is a List where each item is a List with the following |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
310 * entries: [lnum, start_col, end_col] |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
311 */ |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
312 void |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
313 f_prop_add_list(typval_T *argvars, typval_T *rettv UNUSED) |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
314 { |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
315 dict_T *dict; |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
316 char_u *type_name; |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
317 buf_T *buf = curbuf; |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
318 int id = 0; |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
319 listitem_T *li; |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
320 list_T *pos_list; |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
321 linenr_T start_lnum; |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
322 colnr_T start_col; |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
323 linenr_T end_lnum; |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
324 colnr_T end_col; |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
325 int error = FALSE; |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
326 |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
327 if (check_for_dict_arg(argvars, 0) == FAIL |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
328 || check_for_list_arg(argvars, 1) == FAIL) |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
329 return; |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
330 |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
331 if (argvars[1].vval.v_list == NULL) |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
332 { |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
333 emsg(_(e_listreq)); |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
334 return; |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
335 } |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
336 |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
337 dict = argvars[0].vval.v_dict; |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
338 if (dict == NULL || dict_find(dict, (char_u *)"type", -1) == NULL) |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
339 { |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
340 emsg(_("E965: missing property type name")); |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
341 return; |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
342 } |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
343 type_name = dict_get_string(dict, (char_u *)"type", FALSE); |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
344 |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
345 if (dict_find(dict, (char_u *)"id", -1) != NULL) |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
346 id = dict_get_number(dict, (char_u *)"id"); |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
347 |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
348 if (get_bufnr_from_arg(&argvars[0], &buf) == FAIL) |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
349 return; |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
350 |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
351 FOR_ALL_LIST_ITEMS(argvars[1].vval.v_list, li) |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
352 { |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
353 if (li->li_tv.v_type != VAR_LIST || li->li_tv.vval.v_list == NULL) |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
354 { |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
355 emsg(_(e_listreq)); |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
356 return; |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
357 } |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
358 |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
359 pos_list = li->li_tv.vval.v_list; |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
360 start_lnum = list_find_nr(pos_list, 0L, &error); |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
361 start_col = list_find_nr(pos_list, 1L, &error); |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
362 end_lnum = list_find_nr(pos_list, 2L, &error); |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
363 end_col = list_find_nr(pos_list, 3L, &error); |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
364 if (error || start_lnum <= 0 || start_col <= 0 |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
365 || end_lnum <= 0 || end_col <= 0) |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
366 { |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
367 emsg(_(e_invarg)); |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
368 return; |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
369 } |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
370 if (prop_add_one(buf, type_name, id, start_lnum, end_lnum, |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
371 start_col, end_col) == FAIL) |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
372 return; |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
373 } |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
374 |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
375 buf->b_has_textprop = TRUE; // this is never reset |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
376 redraw_buf_later(buf, VALID); |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
377 } |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
378 |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
379 /* |
16811
0457d49eb2d9
patch 8.1.1407: popup_create() does not support text properties
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
380 * Shared between prop_add() and popup_create(). |
0457d49eb2d9
patch 8.1.1407: popup_create() does not support text properties
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
381 * "dict_arg" is the function argument of a dict containing "bufnr". |
0457d49eb2d9
patch 8.1.1407: popup_create() does not support text properties
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
382 * it is NULL for popup_create(). |
0457d49eb2d9
patch 8.1.1407: popup_create() does not support text properties
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
383 */ |
0457d49eb2d9
patch 8.1.1407: popup_create() does not support text properties
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
384 void |
0457d49eb2d9
patch 8.1.1407: popup_create() does not support text properties
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
385 prop_add_common( |
0457d49eb2d9
patch 8.1.1407: popup_create() does not support text properties
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
386 linenr_T start_lnum, |
0457d49eb2d9
patch 8.1.1407: popup_create() does not support text properties
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
387 colnr_T start_col, |
0457d49eb2d9
patch 8.1.1407: popup_create() does not support text properties
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
388 dict_T *dict, |
0457d49eb2d9
patch 8.1.1407: popup_create() does not support text properties
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
389 buf_T *default_buf, |
0457d49eb2d9
patch 8.1.1407: popup_create() does not support text properties
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
390 typval_T *dict_arg) |
0457d49eb2d9
patch 8.1.1407: popup_create() does not support text properties
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
391 { |
0457d49eb2d9
patch 8.1.1407: popup_create() does not support text properties
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
392 linenr_T end_lnum; |
0457d49eb2d9
patch 8.1.1407: popup_create() does not support text properties
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
393 colnr_T end_col; |
0457d49eb2d9
patch 8.1.1407: popup_create() does not support text properties
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
394 char_u *type_name; |
0457d49eb2d9
patch 8.1.1407: popup_create() does not support text properties
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
395 buf_T *buf = default_buf; |
0457d49eb2d9
patch 8.1.1407: popup_create() does not support text properties
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
396 int id = 0; |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
397 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
398 if (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
|
399 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15390
diff
changeset
|
400 emsg(_("E965: missing property type name")); |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
401 return; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
402 } |
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
|
403 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
|
404 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
405 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
|
406 { |
15251
17525ca95e1e
patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
407 end_lnum = dict_get_number(dict, (char_u *)"end_lnum"); |
17525ca95e1e
patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
408 if (end_lnum < start_lnum) |
17525ca95e1e
patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
409 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15390
diff
changeset
|
410 semsg(_(e_invargval), "end_lnum"); |
15251
17525ca95e1e
patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
411 return; |
17525ca95e1e
patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
412 } |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
413 } |
15251
17525ca95e1e
patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
414 else |
17525ca95e1e
patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
415 end_lnum = start_lnum; |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
416 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
417 if (dict_find(dict, (char_u *)"length", -1) != NULL) |
15251
17525ca95e1e
patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
418 { |
17525ca95e1e
patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
419 long length = dict_get_number(dict, (char_u *)"length"); |
17525ca95e1e
patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
420 |
15335
18c20ceee4b5
patch 8.1.0675: text property column in screen columns is not practical
Bram Moolenaar <Bram@vim.org>
parents:
15294
diff
changeset
|
421 if (length < 0 || end_lnum > start_lnum) |
15251
17525ca95e1e
patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
422 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15390
diff
changeset
|
423 semsg(_(e_invargval), "length"); |
15251
17525ca95e1e
patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
424 return; |
17525ca95e1e
patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
425 } |
15335
18c20ceee4b5
patch 8.1.0675: text property column in screen columns is not practical
Bram Moolenaar <Bram@vim.org>
parents:
15294
diff
changeset
|
426 end_col = start_col + length; |
15251
17525ca95e1e
patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
427 } |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
428 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
|
429 { |
15251
17525ca95e1e
patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
430 end_col = dict_get_number(dict, (char_u *)"end_col"); |
17525ca95e1e
patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
431 if (end_col <= 0) |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
432 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15390
diff
changeset
|
433 semsg(_(e_invargval), "end_col"); |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
434 return; |
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 } |
15251
17525ca95e1e
patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
437 else if (start_lnum == end_lnum) |
17525ca95e1e
patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
438 end_col = start_col; |
17525ca95e1e
patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
439 else |
17525ca95e1e
patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
440 end_col = 1; |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
441 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
442 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
|
443 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
|
444 |
16811
0457d49eb2d9
patch 8.1.1407: popup_create() does not support text properties
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
445 if (dict_arg != NULL && get_bufnr_from_arg(dict_arg, &buf) == FAIL) |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
446 return; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
447 |
25640
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
448 prop_add_one(buf, type_name, id, start_lnum, end_lnum, start_col, end_col); |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
449 |
15255
19e79a1ed6b6
patch 8.1.0636: line2byte() gives wrong values with text properties
Bram Moolenaar <Bram@vim.org>
parents:
15251
diff
changeset
|
450 buf->b_has_textprop = TRUE; // this is never reset |
24643
09e64e81c473
patch 8.2.2860: adding a text property causes the whole window to be redawn
Bram Moolenaar <Bram@vim.org>
parents:
24252
diff
changeset
|
451 redraw_buf_later(buf, VALID); |
15138
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 /* |
15144
7960bf50d345
patch 8.1.0582: text properties are not enabled
Bram Moolenaar <Bram@vim.org>
parents:
15138
diff
changeset
|
455 * 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
|
456 * 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
|
457 * 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
|
458 * pointer). |
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 int |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
461 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
|
462 { |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
463 char_u *text; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
464 size_t textlen; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
465 size_t proplen; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
466 |
15255
19e79a1ed6b6
patch 8.1.0636: line2byte() gives wrong values with text properties
Bram Moolenaar <Bram@vim.org>
parents:
15251
diff
changeset
|
467 // Be quick when no text property types have been defined or the buffer, |
19e79a1ed6b6
patch 8.1.0636: line2byte() gives wrong values with text properties
Bram Moolenaar <Bram@vim.org>
parents:
15251
diff
changeset
|
468 // unless we are adding one. |
16770
09c81f17f83c
patch 8.1.1387: calling prop_add() in an empty buffer doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
16768
diff
changeset
|
469 if ((!buf->b_has_textprop && !will_change) || buf->b_ml.ml_mfp == NULL) |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
470 return 0; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
471 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
472 // 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
|
473 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
|
474 textlen = STRLEN(text) + 1; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
475 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
|
476 if (proplen % sizeof(textprop_T) != 0) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
477 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15390
diff
changeset
|
478 iemsg(_("E967: text property info corrupted")); |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
479 return 0; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
480 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
481 if (proplen > 0) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
482 *props = text + textlen; |
15182
4b2de998ebd6
patch 8.1.0601: a few compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
483 return (int)(proplen / sizeof(textprop_T)); |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
484 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
485 |
20583
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
486 /** |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
487 * Return the number of text properties on line "lnum" in the current buffer. |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
488 * When "only_starting" is true only text properties starting in this line will |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
489 * be considered. |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
490 */ |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
491 int |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
492 count_props(linenr_T lnum, int only_starting) |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
493 { |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
494 char_u *props; |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
495 int proplen = get_text_props(curbuf, lnum, &props, 0); |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
496 int result = proplen; |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
497 int i; |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
498 textprop_T prop; |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
499 |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
500 if (only_starting) |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
501 for (i = 0; i < proplen; ++i) |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
502 { |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
503 mch_memmove(&prop, props + i * sizeof(prop), sizeof(prop)); |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
504 if (prop.tp_flags & TP_FLAG_CONT_PREV) |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
505 --result; |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
506 } |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
507 return result; |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
508 } |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
509 |
15367
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
510 /* |
17863
08f1dd29550e
patch 8.1.1928: popup windows don't move with the text when making changes
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
511 * Find text property "type_id" in the visible lines of window "wp". |
08f1dd29550e
patch 8.1.1928: popup windows don't move with the text when making changes
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
512 * Match "id" when it is > 0. |
08f1dd29550e
patch 8.1.1928: popup windows don't move with the text when making changes
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
513 * Returns FAIL when not found. |
08f1dd29550e
patch 8.1.1928: popup windows don't move with the text when making changes
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
514 */ |
08f1dd29550e
patch 8.1.1928: popup windows don't move with the text when making changes
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
515 int |
08f1dd29550e
patch 8.1.1928: popup windows don't move with the text when making changes
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
516 find_visible_prop(win_T *wp, int type_id, int id, textprop_T *prop, |
08f1dd29550e
patch 8.1.1928: popup windows don't move with the text when making changes
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
517 linenr_T *found_lnum) |
08f1dd29550e
patch 8.1.1928: popup windows don't move with the text when making changes
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
518 { |
08f1dd29550e
patch 8.1.1928: popup windows don't move with the text when making changes
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
519 linenr_T lnum; |
08f1dd29550e
patch 8.1.1928: popup windows don't move with the text when making changes
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
520 char_u *props; |
08f1dd29550e
patch 8.1.1928: popup windows don't move with the text when making changes
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
521 int count; |
08f1dd29550e
patch 8.1.1928: popup windows don't move with the text when making changes
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
522 int i; |
08f1dd29550e
patch 8.1.1928: popup windows don't move with the text when making changes
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
523 |
08f1dd29550e
patch 8.1.1928: popup windows don't move with the text when making changes
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
524 // w_botline may not have been updated yet. |
23306
90ea5037a7e3
patch 8.2.2198: ml_get error when resizing window and using text property
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
525 validate_botline_win(wp); |
17863
08f1dd29550e
patch 8.1.1928: popup windows don't move with the text when making changes
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
526 for (lnum = wp->w_topline; lnum < wp->w_botline; ++lnum) |
08f1dd29550e
patch 8.1.1928: popup windows don't move with the text when making changes
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
527 { |
08f1dd29550e
patch 8.1.1928: popup windows don't move with the text when making changes
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
528 count = get_text_props(wp->w_buffer, lnum, &props, FALSE); |
08f1dd29550e
patch 8.1.1928: popup windows don't move with the text when making changes
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
529 for (i = 0; i < count; ++i) |
08f1dd29550e
patch 8.1.1928: popup windows don't move with the text when making changes
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
530 { |
08f1dd29550e
patch 8.1.1928: popup windows don't move with the text when making changes
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
531 mch_memmove(prop, props + i * sizeof(textprop_T), |
08f1dd29550e
patch 8.1.1928: popup windows don't move with the text when making changes
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
532 sizeof(textprop_T)); |
08f1dd29550e
patch 8.1.1928: popup windows don't move with the text when making changes
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
533 if (prop->tp_type == type_id && (id <= 0 || prop->tp_id == id)) |
08f1dd29550e
patch 8.1.1928: popup windows don't move with the text when making changes
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
534 { |
08f1dd29550e
patch 8.1.1928: popup windows don't move with the text when making changes
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
535 *found_lnum = lnum; |
08f1dd29550e
patch 8.1.1928: popup windows don't move with the text when making changes
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
536 return OK; |
08f1dd29550e
patch 8.1.1928: popup windows don't move with the text when making changes
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
537 } |
08f1dd29550e
patch 8.1.1928: popup windows don't move with the text when making changes
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
538 } |
08f1dd29550e
patch 8.1.1928: popup windows don't move with the text when making changes
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
539 } |
08f1dd29550e
patch 8.1.1928: popup windows don't move with the text when making changes
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
540 return FAIL; |
08f1dd29550e
patch 8.1.1928: popup windows don't move with the text when making changes
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
541 } |
08f1dd29550e
patch 8.1.1928: popup windows don't move with the text when making changes
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
542 |
08f1dd29550e
patch 8.1.1928: popup windows don't move with the text when making changes
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
543 /* |
15367
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
544 * Set the text properties for line "lnum" to "props" with length "len". |
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
545 * If "len" is zero text properties are removed, "props" is not used. |
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
546 * Any existing text properties are dropped. |
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
547 * Only works for the current buffer. |
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
548 */ |
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
549 static void |
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
550 set_text_props(linenr_T lnum, char_u *props, int len) |
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
551 { |
15390
00aa76a735e7
patch 8.1.0703: compiler warnings with 64-bit compiler
Bram Moolenaar <Bram@vim.org>
parents:
15373
diff
changeset
|
552 char_u *text; |
00aa76a735e7
patch 8.1.0703: compiler warnings with 64-bit compiler
Bram Moolenaar <Bram@vim.org>
parents:
15373
diff
changeset
|
553 char_u *newtext; |
00aa76a735e7
patch 8.1.0703: compiler warnings with 64-bit compiler
Bram Moolenaar <Bram@vim.org>
parents:
15373
diff
changeset
|
554 int textlen; |
15367
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
555 |
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
556 text = ml_get(lnum); |
15390
00aa76a735e7
patch 8.1.0703: compiler warnings with 64-bit compiler
Bram Moolenaar <Bram@vim.org>
parents:
15373
diff
changeset
|
557 textlen = (int)STRLEN(text) + 1; |
15367
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
558 newtext = alloc(textlen + len); |
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
559 if (newtext == NULL) |
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
560 return; |
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
561 mch_memmove(newtext, text, textlen); |
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
562 if (len > 0) |
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
563 mch_memmove(newtext + textlen, props, len); |
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
564 if (curbuf->b_ml.ml_flags & ML_LINE_DIRTY) |
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
565 vim_free(curbuf->b_ml.ml_line_ptr); |
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
566 curbuf->b_ml.ml_line_ptr = newtext; |
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
567 curbuf->b_ml.ml_line_len = textlen + len; |
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
568 curbuf->b_ml.ml_flags |= ML_LINE_DIRTY; |
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
569 } |
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
570 |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
571 static proptype_T * |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
572 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
|
573 { |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
574 long todo; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
575 hashitem_T *hi; |
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 if (ht == NULL) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
578 return NULL; |
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 // 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
|
581 // a binary search. |
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 todo = (long)ht->ht_used; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
584 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
|
585 { |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
586 if (!HASHITEM_EMPTY(hi)) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
587 { |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
588 proptype_T *prop = HI2PT(hi); |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
589 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
590 if (prop->pt_id == id) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
591 return prop; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
592 --todo; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
593 } |
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 return NULL; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
596 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
597 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
598 /* |
19100
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
599 * Fill 'dict' with text properties in 'prop'. |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
600 */ |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
601 static void |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
602 prop_fill_dict(dict_T *dict, textprop_T *prop, buf_T *buf) |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
603 { |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
604 proptype_T *pt; |
25392
b427a26b0210
patch 8.2.3233: prop_list() and prop_find() do not indicate the buffer
Bram Moolenaar <Bram@vim.org>
parents:
25384
diff
changeset
|
605 int buflocal = TRUE; |
19100
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
606 |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
607 dict_add_number(dict, "col", prop->tp_col); |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
608 dict_add_number(dict, "length", prop->tp_len); |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
609 dict_add_number(dict, "id", prop->tp_id); |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
610 dict_add_number(dict, "start", !(prop->tp_flags & TP_FLAG_CONT_PREV)); |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
611 dict_add_number(dict, "end", !(prop->tp_flags & TP_FLAG_CONT_NEXT)); |
25392
b427a26b0210
patch 8.2.3233: prop_list() and prop_find() do not indicate the buffer
Bram Moolenaar <Bram@vim.org>
parents:
25384
diff
changeset
|
612 |
b427a26b0210
patch 8.2.3233: prop_list() and prop_find() do not indicate the buffer
Bram Moolenaar <Bram@vim.org>
parents:
25384
diff
changeset
|
613 pt = find_type_by_id(buf->b_proptypes, prop->tp_type); |
b427a26b0210
patch 8.2.3233: prop_list() and prop_find() do not indicate the buffer
Bram Moolenaar <Bram@vim.org>
parents:
25384
diff
changeset
|
614 if (pt == NULL) |
b427a26b0210
patch 8.2.3233: prop_list() and prop_find() do not indicate the buffer
Bram Moolenaar <Bram@vim.org>
parents:
25384
diff
changeset
|
615 { |
b427a26b0210
patch 8.2.3233: prop_list() and prop_find() do not indicate the buffer
Bram Moolenaar <Bram@vim.org>
parents:
25384
diff
changeset
|
616 pt = find_type_by_id(global_proptypes, prop->tp_type); |
b427a26b0210
patch 8.2.3233: prop_list() and prop_find() do not indicate the buffer
Bram Moolenaar <Bram@vim.org>
parents:
25384
diff
changeset
|
617 buflocal = FALSE; |
b427a26b0210
patch 8.2.3233: prop_list() and prop_find() do not indicate the buffer
Bram Moolenaar <Bram@vim.org>
parents:
25384
diff
changeset
|
618 } |
19100
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
619 if (pt != NULL) |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
620 dict_add_string(dict, "type", pt->pt_name); |
25392
b427a26b0210
patch 8.2.3233: prop_list() and prop_find() do not indicate the buffer
Bram Moolenaar <Bram@vim.org>
parents:
25384
diff
changeset
|
621 |
b427a26b0210
patch 8.2.3233: prop_list() and prop_find() do not indicate the buffer
Bram Moolenaar <Bram@vim.org>
parents:
25384
diff
changeset
|
622 if (buflocal) |
b427a26b0210
patch 8.2.3233: prop_list() and prop_find() do not indicate the buffer
Bram Moolenaar <Bram@vim.org>
parents:
25384
diff
changeset
|
623 dict_add_number(dict, "type_bufnr", buf->b_fnum); |
b427a26b0210
patch 8.2.3233: prop_list() and prop_find() do not indicate the buffer
Bram Moolenaar <Bram@vim.org>
parents:
25384
diff
changeset
|
624 else |
b427a26b0210
patch 8.2.3233: prop_list() and prop_find() do not indicate the buffer
Bram Moolenaar <Bram@vim.org>
parents:
25384
diff
changeset
|
625 dict_add_number(dict, "type_bufnr", 0); |
19100
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
626 } |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
627 |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
628 /* |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
629 * 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
|
630 * Returns NULL if not found. |
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 proptype_T * |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
633 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
|
634 { |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
635 proptype_T *type; |
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 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
|
638 if (type == NULL) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
639 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
|
640 return type; |
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 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
643 /* |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
644 * prop_clear({lnum} [, {lnum_end} [, {bufnr}]]) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
645 */ |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
646 void |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
647 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
|
648 { |
25302
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
649 linenr_T start; |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
650 linenr_T end; |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
651 linenr_T lnum; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
652 buf_T *buf = curbuf; |
24206
55631f8e0730
patch 8.2.2644: prop_clear() causes a screen update even when nothing changed
Bram Moolenaar <Bram@vim.org>
parents:
24192
diff
changeset
|
653 int did_clear = FALSE; |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
654 |
25302
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
655 if (in_vim9script() |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
656 && (check_for_number_arg(argvars, 0) == FAIL |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
657 || check_for_opt_number_arg(argvars, 1) == FAIL |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
658 || (argvars[1].v_type != VAR_UNKNOWN |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
659 && check_for_opt_dict_arg(argvars, 2) == FAIL))) |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
660 return; |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
661 |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
662 start = tv_get_number(&argvars[0]); |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
663 end = start; |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
664 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
|
665 { |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15182
diff
changeset
|
666 end = tv_get_number(&argvars[1]); |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
667 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
|
668 { |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
669 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
|
670 return; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
671 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
672 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
673 if (start < 1 || end < 1) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
674 { |
25064
8f2262c72178
patch 8.2.3069: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
24649
diff
changeset
|
675 emsg(_(e_invalid_range)); |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
676 return; |
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 for (lnum = start; lnum <= end; ++lnum) |
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 char_u *text; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
682 size_t len; |
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 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
|
685 break; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
686 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
|
687 len = STRLEN(text) + 1; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
688 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
|
689 { |
24206
55631f8e0730
patch 8.2.2644: prop_clear() causes a screen update even when nothing changed
Bram Moolenaar <Bram@vim.org>
parents:
24192
diff
changeset
|
690 did_clear = TRUE; |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
691 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
|
692 { |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
693 char_u *newtext = vim_strsave(text); |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
694 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
695 // need to allocate the line now |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
696 if (newtext == NULL) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
697 return; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
698 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
|
699 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
|
700 } |
15182
4b2de998ebd6
patch 8.1.0601: a few compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
701 buf->b_ml.ml_line_len = (int)len; |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
702 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
703 } |
24206
55631f8e0730
patch 8.2.2644: prop_clear() causes a screen update even when nothing changed
Bram Moolenaar <Bram@vim.org>
parents:
24192
diff
changeset
|
704 if (did_clear) |
55631f8e0730
patch 8.2.2644: prop_clear() causes a screen update even when nothing changed
Bram Moolenaar <Bram@vim.org>
parents:
24192
diff
changeset
|
705 redraw_buf_later(buf, NOT_VALID); |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
706 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
707 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
708 /* |
19100
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
709 * prop_find({props} [, {direction}]) |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
710 */ |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
711 void |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
712 f_prop_find(typval_T *argvars, typval_T *rettv) |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
713 { |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
714 pos_T *cursor = &curwin->w_cursor; |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
715 dict_T *dict; |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
716 buf_T *buf = curbuf; |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
717 dictitem_T *di; |
20583
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
718 int lnum_start; |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
719 int start_pos_has_prop = 0; |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
720 int seen_end = 0; |
25467
6f627d12e81b
patch 8.2.3270: prop_find() finds property with ID -2
Bram Moolenaar <Bram@vim.org>
parents:
25441
diff
changeset
|
721 int id = 0; |
6f627d12e81b
patch 8.2.3270: prop_find() finds property with ID -2
Bram Moolenaar <Bram@vim.org>
parents:
25441
diff
changeset
|
722 int id_found = FALSE; |
20583
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
723 int type_id = -1; |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
724 int skipstart = 0; |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
725 int lnum = -1; |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
726 int col = -1; |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
727 int dir = 1; // 1 = forward, -1 = backward |
24252
7422f2f719a3
patch 8.2.2667: prop_find() cannot find item matching both id and type
Bram Moolenaar <Bram@vim.org>
parents:
24206
diff
changeset
|
728 int both; |
19100
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
729 |
25384
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
730 if (in_vim9script() |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
731 && (check_for_dict_arg(argvars, 0) == FAIL |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
732 || check_for_opt_string_arg(argvars, 1) == FAIL)) |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
733 return; |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
734 |
19100
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
735 if (argvars[0].v_type != VAR_DICT || argvars[0].vval.v_dict == NULL) |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
736 { |
25198
eafc0e07b188
patch 8.2.3135: Vim9: builtin function arguments not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
737 emsg(_(e_dictreq)); |
19100
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
738 return; |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
739 } |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
740 dict = argvars[0].vval.v_dict; |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
741 |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
742 if (get_bufnr_from_arg(&argvars[0], &buf) == FAIL) |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
743 return; |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
744 if (buf->b_ml.ml_mfp == NULL) |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
745 return; |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
746 |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
747 if (argvars[1].v_type != VAR_UNKNOWN) |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
748 { |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
749 char_u *dir_s = tv_get_string(&argvars[1]); |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
750 |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
751 if (*dir_s == 'b') |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
752 dir = -1; |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
753 else if (*dir_s != 'f') |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
754 { |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
755 emsg(_(e_invarg)); |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
756 return; |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
757 } |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
758 } |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
759 |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
760 di = dict_find(dict, (char_u *)"lnum", -1); |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
761 if (di != NULL) |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
762 lnum = tv_get_number(&di->di_tv); |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
763 |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
764 di = dict_find(dict, (char_u *)"col", -1); |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
765 if (di != NULL) |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
766 col = tv_get_number(&di->di_tv); |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
767 |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
768 if (lnum == -1) |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
769 { |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
770 lnum = cursor->lnum; |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
771 col = cursor->col + 1; |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
772 } |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
773 else if (col == -1) |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
774 col = 1; |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
775 |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
776 if (lnum < 1 || lnum > buf->b_ml.ml_line_count) |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
777 { |
25064
8f2262c72178
patch 8.2.3069: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
24649
diff
changeset
|
778 emsg(_(e_invalid_range)); |
19100
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
779 return; |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
780 } |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
781 |
22069
87502e318c19
patch 8.2.1584: Vim9: cannot use "true" for "skipstart" in prop_find()
Bram Moolenaar <Bram@vim.org>
parents:
22037
diff
changeset
|
782 skipstart = dict_get_bool(dict, (char_u *)"skipstart", 0); |
19100
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
783 |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
784 if (dict_find(dict, (char_u *)"id", -1) != NULL) |
25441
e06540cc3371
patch 8.2.3257: calling prop_find() with -1 for ID gives errornous error
Bram Moolenaar <Bram@vim.org>
parents:
25392
diff
changeset
|
785 { |
19100
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
786 id = dict_get_number(dict, (char_u *)"id"); |
25471
3678a11e71fa
patch 8.2.3272: cannot use id zero with prop_find()
Bram Moolenaar <Bram@vim.org>
parents:
25467
diff
changeset
|
787 id_found = TRUE; |
25441
e06540cc3371
patch 8.2.3257: calling prop_find() with -1 for ID gives errornous error
Bram Moolenaar <Bram@vim.org>
parents:
25392
diff
changeset
|
788 } |
19100
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
789 if (dict_find(dict, (char_u *)"type", -1)) |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
790 { |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
791 char_u *name = dict_get_string(dict, (char_u *)"type", FALSE); |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
792 proptype_T *type = lookup_prop_type(name, buf); |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
793 |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
794 if (type == NULL) |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
795 return; |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
796 type_id = type->pt_id; |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
797 } |
24252
7422f2f719a3
patch 8.2.2667: prop_find() cannot find item matching both id and type
Bram Moolenaar <Bram@vim.org>
parents:
24206
diff
changeset
|
798 both = dict_get_bool(dict, (char_u *)"both", FALSE); |
25467
6f627d12e81b
patch 8.2.3270: prop_find() finds property with ID -2
Bram Moolenaar <Bram@vim.org>
parents:
25441
diff
changeset
|
799 if (!id_found && type_id == -1) |
19100
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
800 { |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
801 emsg(_("E968: Need at least one of 'id' or 'type'")); |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
802 return; |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
803 } |
25467
6f627d12e81b
patch 8.2.3270: prop_find() finds property with ID -2
Bram Moolenaar <Bram@vim.org>
parents:
25441
diff
changeset
|
804 if (both && (!id_found || type_id == -1)) |
24252
7422f2f719a3
patch 8.2.2667: prop_find() cannot find item matching both id and type
Bram Moolenaar <Bram@vim.org>
parents:
24206
diff
changeset
|
805 { |
7422f2f719a3
patch 8.2.2667: prop_find() cannot find item matching both id and type
Bram Moolenaar <Bram@vim.org>
parents:
24206
diff
changeset
|
806 emsg(_("E860: Need 'id' and 'type' with 'both'")); |
7422f2f719a3
patch 8.2.2667: prop_find() cannot find item matching both id and type
Bram Moolenaar <Bram@vim.org>
parents:
24206
diff
changeset
|
807 return; |
7422f2f719a3
patch 8.2.2667: prop_find() cannot find item matching both id and type
Bram Moolenaar <Bram@vim.org>
parents:
24206
diff
changeset
|
808 } |
19100
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
809 |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
810 lnum_start = lnum; |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
811 |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
812 if (rettv_dict_alloc(rettv) == FAIL) |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
813 return; |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
814 |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
815 while (1) |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
816 { |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
817 char_u *text = ml_get_buf(buf, lnum, FALSE); |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
818 size_t textlen = STRLEN(text) + 1; |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
819 int count = (int)((buf->b_ml.ml_line_len - textlen) |
20583
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
820 / sizeof(textprop_T)); |
19100
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
821 int i; |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
822 textprop_T prop; |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
823 int prop_start; |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
824 int prop_end; |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
825 |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
826 for (i = 0; i < count; ++i) |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
827 { |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
828 mch_memmove(&prop, text + textlen + i * sizeof(textprop_T), |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
829 sizeof(textprop_T)); |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
830 |
19642
647ef636a11e
patch 8.2.0378: prop_find() does not find all props
Bram Moolenaar <Bram@vim.org>
parents:
19631
diff
changeset
|
831 if (lnum == lnum_start) |
19644
d2153928b376
patch 8.2.0379: gcc warns for ambiguous else
Bram Moolenaar <Bram@vim.org>
parents:
19642
diff
changeset
|
832 { |
19642
647ef636a11e
patch 8.2.0378: prop_find() does not find all props
Bram Moolenaar <Bram@vim.org>
parents:
19631
diff
changeset
|
833 if (dir < 0) |
647ef636a11e
patch 8.2.0378: prop_find() does not find all props
Bram Moolenaar <Bram@vim.org>
parents:
19631
diff
changeset
|
834 { |
647ef636a11e
patch 8.2.0378: prop_find() does not find all props
Bram Moolenaar <Bram@vim.org>
parents:
19631
diff
changeset
|
835 if (col < prop.tp_col) |
647ef636a11e
patch 8.2.0378: prop_find() does not find all props
Bram Moolenaar <Bram@vim.org>
parents:
19631
diff
changeset
|
836 break; |
647ef636a11e
patch 8.2.0378: prop_find() does not find all props
Bram Moolenaar <Bram@vim.org>
parents:
19631
diff
changeset
|
837 } |
647ef636a11e
patch 8.2.0378: prop_find() does not find all props
Bram Moolenaar <Bram@vim.org>
parents:
19631
diff
changeset
|
838 else if (prop.tp_col + prop.tp_len - (prop.tp_len != 0) < col) |
647ef636a11e
patch 8.2.0378: prop_find() does not find all props
Bram Moolenaar <Bram@vim.org>
parents:
19631
diff
changeset
|
839 continue; |
19644
d2153928b376
patch 8.2.0379: gcc warns for ambiguous else
Bram Moolenaar <Bram@vim.org>
parents:
19642
diff
changeset
|
840 } |
24252
7422f2f719a3
patch 8.2.2667: prop_find() cannot find item matching both id and type
Bram Moolenaar <Bram@vim.org>
parents:
24206
diff
changeset
|
841 if (both ? prop.tp_id == id && prop.tp_type == type_id |
25467
6f627d12e81b
patch 8.2.3270: prop_find() finds property with ID -2
Bram Moolenaar <Bram@vim.org>
parents:
25441
diff
changeset
|
842 : (id_found && prop.tp_id == id) |
6f627d12e81b
patch 8.2.3270: prop_find() finds property with ID -2
Bram Moolenaar <Bram@vim.org>
parents:
25441
diff
changeset
|
843 || prop.tp_type == type_id) |
19100
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
844 { |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
845 // Check if the starting position has text props. |
19631
1d493fce1fbd
patch 8.2.0372: prop_find() may not find text property at start of the line
Bram Moolenaar <Bram@vim.org>
parents:
19601
diff
changeset
|
846 if (lnum_start == lnum |
1d493fce1fbd
patch 8.2.0372: prop_find() may not find text property at start of the line
Bram Moolenaar <Bram@vim.org>
parents:
19601
diff
changeset
|
847 && col >= prop.tp_col |
1d493fce1fbd
patch 8.2.0372: prop_find() may not find text property at start of the line
Bram Moolenaar <Bram@vim.org>
parents:
19601
diff
changeset
|
848 && (col <= prop.tp_col + prop.tp_len |
1d493fce1fbd
patch 8.2.0372: prop_find() may not find text property at start of the line
Bram Moolenaar <Bram@vim.org>
parents:
19601
diff
changeset
|
849 - (prop.tp_len != 0))) |
1d493fce1fbd
patch 8.2.0372: prop_find() may not find text property at start of the line
Bram Moolenaar <Bram@vim.org>
parents:
19601
diff
changeset
|
850 start_pos_has_prop = 1; |
19100
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
851 |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
852 prop_start = !(prop.tp_flags & TP_FLAG_CONT_PREV); |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
853 prop_end = !(prop.tp_flags & TP_FLAG_CONT_NEXT); |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
854 if (!prop_start && prop_end && dir > 0) |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
855 seen_end = 1; |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
856 |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
857 // Skip lines without the start flag. |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
858 if (!prop_start) |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
859 { |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
860 // Always search backwards for start when search started |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
861 // on a prop and we're not skipping. |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
862 if (start_pos_has_prop && !skipstart) |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
863 dir = -1; |
22037
35c8996a798e
patch 8.2.1568: prop_find() skips properties in the same line
Bram Moolenaar <Bram@vim.org>
parents:
21081
diff
changeset
|
864 continue; |
19100
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
865 } |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
866 |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
867 // If skipstart is true, skip the prop at start pos (even if |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
868 // continued from another line). |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
869 if (start_pos_has_prop && skipstart && !seen_end) |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
870 { |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
871 start_pos_has_prop = 0; |
22037
35c8996a798e
patch 8.2.1568: prop_find() skips properties in the same line
Bram Moolenaar <Bram@vim.org>
parents:
21081
diff
changeset
|
872 continue; |
19100
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
873 } |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
874 |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
875 prop_fill_dict(rettv->vval.v_dict, &prop, buf); |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
876 dict_add_number(rettv->vval.v_dict, "lnum", lnum); |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
877 |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
878 return; |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
879 } |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
880 } |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
881 |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
882 if (dir > 0) |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
883 { |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
884 if (lnum >= buf->b_ml.ml_line_count) |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
885 break; |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
886 lnum++; |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
887 } |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
888 else |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
889 { |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
890 if (lnum <= 1) |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
891 break; |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
892 lnum--; |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
893 } |
19631
1d493fce1fbd
patch 8.2.0372: prop_find() may not find text property at start of the line
Bram Moolenaar <Bram@vim.org>
parents:
19601
diff
changeset
|
894 // Adjust col to indicate that we're continuing from prev/next line. |
1d493fce1fbd
patch 8.2.0372: prop_find() may not find text property at start of the line
Bram Moolenaar <Bram@vim.org>
parents:
19601
diff
changeset
|
895 col = dir < 0 ? buf->b_ml.ml_line_len : 1; |
19100
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
896 } |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
897 } |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
898 |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
899 /* |
26242
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
900 * Returns TRUE if 'type_or_id' is in the 'types_or_ids' list. |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
901 */ |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
902 static int |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
903 prop_type_or_id_in_list(int *types_or_ids, int len, int type_or_id) |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
904 { |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
905 int i; |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
906 |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
907 for (i = 0; i < len; i++) |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
908 if (types_or_ids[i] == type_or_id) |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
909 return TRUE; |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
910 |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
911 return FALSE; |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
912 } |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
913 |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
914 /* |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
915 * Return all the text properties in line 'lnum' in buffer 'buf' in 'retlist'. |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
916 * If 'prop_types' is not NULL, then return only the text properties with |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
917 * matching property type in the 'prop_types' array. |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
918 * If 'prop_ids' is not NULL, then return only the text properties with |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
919 * an identifier in the 'props_ids' array. |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
920 * If 'add_lnum' is TRUE, then add the line number also to the text property |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
921 * dictionary. |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
922 */ |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
923 static void |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
924 get_props_in_line( |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
925 buf_T *buf, |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
926 linenr_T lnum, |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
927 int *prop_types, |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
928 int prop_types_len, |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
929 int *prop_ids, |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
930 int prop_ids_len, |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
931 list_T *retlist, |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
932 int add_lnum) |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
933 { |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
934 char_u *text = ml_get_buf(buf, lnum, FALSE); |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
935 size_t textlen = STRLEN(text) + 1; |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
936 int count; |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
937 int i; |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
938 textprop_T prop; |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
939 |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
940 count = (int)((buf->b_ml.ml_line_len - textlen) / sizeof(textprop_T)); |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
941 for (i = 0; i < count; ++i) |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
942 { |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
943 mch_memmove(&prop, text + textlen + i * sizeof(textprop_T), |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
944 sizeof(textprop_T)); |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
945 if ((prop_types == NULL |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
946 || prop_type_or_id_in_list(prop_types, prop_types_len, |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
947 prop.tp_type)) |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
948 && (prop_ids == NULL || |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
949 prop_type_or_id_in_list(prop_ids, prop_ids_len, |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
950 prop.tp_id))) |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
951 { |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
952 dict_T *d = dict_alloc(); |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
953 |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
954 if (d == NULL) |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
955 break; |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
956 prop_fill_dict(d, &prop, buf); |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
957 if (add_lnum) |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
958 dict_add_number(d, "lnum", lnum); |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
959 list_append_dict(retlist, d); |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
960 } |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
961 } |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
962 } |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
963 |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
964 /* |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
965 * Convert a List of property type names into an array of property type |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
966 * identifiers. Returns a pointer to the allocated array. Returns NULL on |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
967 * error. 'num_types' is set to the number of returned property types. |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
968 */ |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
969 static int * |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
970 get_prop_types_from_names(list_T *l, buf_T *buf, int *num_types) |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
971 { |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
972 int *prop_types; |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
973 listitem_T *li; |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
974 int i; |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
975 char_u *name; |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
976 proptype_T *type; |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
977 |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
978 *num_types = 0; |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
979 |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
980 prop_types = ALLOC_MULT(int, list_len(l)); |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
981 if (prop_types == NULL) |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
982 return NULL; |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
983 |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
984 i = 0; |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
985 FOR_ALL_LIST_ITEMS(l, li) |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
986 { |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
987 if (li->li_tv.v_type != VAR_STRING) |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
988 { |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
989 emsg(_(e_stringreq)); |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
990 goto errret; |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
991 } |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
992 name = li->li_tv.vval.v_string; |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
993 if (name == NULL) |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
994 goto errret; |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
995 |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
996 type = lookup_prop_type(name, buf); |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
997 if (type == NULL) |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
998 goto errret; |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
999 prop_types[i++] = type->pt_id; |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1000 } |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1001 |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1002 *num_types = i; |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1003 return prop_types; |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1004 |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1005 errret: |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1006 VIM_CLEAR(prop_types); |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1007 return NULL; |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1008 } |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1009 |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1010 /* |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1011 * Convert a List of property identifiers into an array of property |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1012 * identifiers. Returns a pointer to the allocated array. Returns NULL on |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1013 * error. 'num_ids' is set to the number of returned property identifiers. |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1014 */ |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1015 static int * |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1016 get_prop_ids_from_list(list_T *l, int *num_ids) |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1017 { |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1018 int *prop_ids; |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1019 listitem_T *li; |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1020 int i; |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1021 int id; |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1022 int error; |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1023 |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1024 *num_ids = 0; |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1025 |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1026 prop_ids = ALLOC_MULT(int, list_len(l)); |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1027 if (prop_ids == NULL) |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1028 return NULL; |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1029 |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1030 i = 0; |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1031 FOR_ALL_LIST_ITEMS(l, li) |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1032 { |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1033 error = FALSE; |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1034 id = tv_get_number_chk(&li->li_tv, &error); |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1035 if (error) |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1036 goto errret; |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1037 |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1038 prop_ids[i++] = id; |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1039 } |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1040 |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1041 *num_ids = i; |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1042 return prop_ids; |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1043 |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1044 errret: |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1045 VIM_CLEAR(prop_ids); |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1046 return NULL; |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1047 } |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1048 |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1049 /* |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1050 * prop_list({lnum} [, {bufnr}]) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1051 */ |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1052 void |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1053 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
|
1054 { |
26242
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1055 linenr_T lnum; |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1056 linenr_T start_lnum; |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1057 linenr_T end_lnum; |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1058 buf_T *buf = curbuf; |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1059 int add_lnum = FALSE; |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1060 int *prop_types = NULL; |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1061 int prop_types_len = 0; |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1062 int *prop_ids = NULL; |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1063 int prop_ids_len = 0; |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1064 list_T *l; |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1065 dictitem_T *di; |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1066 |
25252
acda780ffc3e
patch 8.2.3162: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25198
diff
changeset
|
1067 if (in_vim9script() |
acda780ffc3e
patch 8.2.3162: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25198
diff
changeset
|
1068 && (check_for_number_arg(argvars, 0) == FAIL |
25302
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
1069 || check_for_opt_dict_arg(argvars, 1) == FAIL)) |
25252
acda780ffc3e
patch 8.2.3162: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25198
diff
changeset
|
1070 return; |
acda780ffc3e
patch 8.2.3162: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25198
diff
changeset
|
1071 |
26242
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1072 if (rettv_list_alloc(rettv) != OK) |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1073 return; |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1074 |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1075 // default: get text properties on current line |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1076 start_lnum = tv_get_number(&argvars[0]); |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1077 end_lnum = start_lnum; |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1078 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
|
1079 { |
26242
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1080 dict_T *d; |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1081 |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1082 if (argvars[1].v_type != VAR_DICT) |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1083 { |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1084 emsg(_(e_dictreq)); |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1085 return; |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1086 } |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1087 d = argvars[1].vval.v_dict; |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1088 |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1089 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
|
1090 return; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1091 |
26242
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1092 if (d != NULL && (di = dict_find(d, (char_u *)"end_lnum", -1)) != NULL) |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1093 { |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1094 if (di->di_tv.v_type != VAR_NUMBER) |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1095 { |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1096 emsg(_(e_numberreq)); |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1097 return; |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1098 } |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1099 end_lnum = tv_get_number(&di->di_tv); |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1100 if (end_lnum < 0) |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1101 // negative end_lnum is used as an offset from the last buffer |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1102 // line |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1103 end_lnum = buf->b_ml.ml_line_count + end_lnum + 1; |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1104 else if (end_lnum > buf->b_ml.ml_line_count) |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1105 end_lnum = buf->b_ml.ml_line_count; |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1106 add_lnum = TRUE; |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1107 } |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1108 if (d != NULL && (di = dict_find(d, (char_u *)"types", -1)) != NULL) |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1109 { |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1110 if (di->di_tv.v_type != VAR_LIST) |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1111 { |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1112 emsg(_(e_listreq)); |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1113 return; |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1114 } |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1115 |
26242
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1116 l = di->di_tv.vval.v_list; |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1117 if (l != NULL && list_len(l) > 0) |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1118 { |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1119 prop_types = get_prop_types_from_names(l, buf, &prop_types_len); |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1120 if (prop_types == NULL) |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1121 return; |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1122 } |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1123 } |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1124 if (d != NULL && (di = dict_find(d, (char_u *)"ids", -1)) != NULL) |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1125 { |
26242
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1126 if (di->di_tv.v_type != VAR_LIST) |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1127 { |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1128 emsg(_(e_listreq)); |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1129 goto errret; |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1130 } |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1131 |
26242
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1132 l = di->di_tv.vval.v_list; |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1133 if (l != NULL && list_len(l) > 0) |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1134 { |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1135 prop_ids = get_prop_ids_from_list(l, &prop_ids_len); |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1136 if (prop_ids == NULL) |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1137 goto errret; |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1138 } |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1139 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1140 } |
26242
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1141 if (start_lnum < 1 || start_lnum > buf->b_ml.ml_line_count |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1142 || end_lnum < 1 || end_lnum < start_lnum) |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1143 emsg(_(e_invalid_range)); |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1144 else |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1145 for (lnum = start_lnum; lnum <= end_lnum; lnum++) |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1146 get_props_in_line(buf, lnum, prop_types, prop_types_len, |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1147 prop_ids, prop_ids_len, |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1148 rettv->vval.v_list, add_lnum); |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1149 |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1150 errret: |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1151 VIM_CLEAR(prop_types); |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1152 VIM_CLEAR(prop_ids); |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1153 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1154 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1155 /* |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1156 * prop_remove({props} [, {lnum} [, {lnum_end}]]) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1157 */ |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1158 void |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1159 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
|
1160 { |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1161 linenr_T start = 1; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1162 linenr_T end = 0; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1163 linenr_T lnum; |
24649
31a7fa6b2e93
patch 8.2.2863: removing a text property does not redraw optimally
Bram Moolenaar <Bram@vim.org>
parents:
24647
diff
changeset
|
1164 linenr_T first_changed = 0; |
31a7fa6b2e93
patch 8.2.2863: removing a text property does not redraw optimally
Bram Moolenaar <Bram@vim.org>
parents:
24647
diff
changeset
|
1165 linenr_T last_changed = 0; |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1166 dict_T *dict; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1167 buf_T *buf = curbuf; |
22125
602e660d5ccf
patch 8.2.1612: Vim9: cannot pass "true" to prop_remove()
Bram Moolenaar <Bram@vim.org>
parents:
22069
diff
changeset
|
1168 int do_all; |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1169 int id = -1; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1170 int type_id = -1; |
22125
602e660d5ccf
patch 8.2.1612: Vim9: cannot pass "true" to prop_remove()
Bram Moolenaar <Bram@vim.org>
parents:
22069
diff
changeset
|
1171 int both; |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1172 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1173 rettv->vval.v_number = 0; |
25302
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
1174 |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
1175 if (in_vim9script() |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
1176 && (check_for_dict_arg(argvars, 0) == FAIL |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
1177 || check_for_opt_number_arg(argvars, 1) == FAIL |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
1178 || (argvars[1].v_type != VAR_UNKNOWN |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
1179 && check_for_opt_number_arg(argvars, 2) == FAIL))) |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
1180 return; |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
1181 |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1182 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
|
1183 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15390
diff
changeset
|
1184 emsg(_(e_invarg)); |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1185 return; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1186 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1187 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1188 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
|
1189 { |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15182
diff
changeset
|
1190 start = tv_get_number(&argvars[1]); |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1191 end = start; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1192 if (argvars[2].v_type != VAR_UNKNOWN) |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15182
diff
changeset
|
1193 end = tv_get_number(&argvars[2]); |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1194 if (start < 1 || end < 1) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1195 { |
25064
8f2262c72178
patch 8.2.3069: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
24649
diff
changeset
|
1196 emsg(_(e_invalid_range)); |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1197 return; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1198 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1199 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1200 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1201 dict = argvars[0].vval.v_dict; |
16772
18093a6accb5
patch 8.1.1388: errors when calling prop_remove() for an unloaded buffer
Bram Moolenaar <Bram@vim.org>
parents:
16770
diff
changeset
|
1202 if (get_bufnr_from_arg(&argvars[0], &buf) == FAIL) |
18093a6accb5
patch 8.1.1388: errors when calling prop_remove() for an unloaded buffer
Bram Moolenaar <Bram@vim.org>
parents:
16770
diff
changeset
|
1203 return; |
18093a6accb5
patch 8.1.1388: errors when calling prop_remove() for an unloaded buffer
Bram Moolenaar <Bram@vim.org>
parents:
16770
diff
changeset
|
1204 if (buf->b_ml.ml_mfp == NULL) |
18093a6accb5
patch 8.1.1388: errors when calling prop_remove() for an unloaded buffer
Bram Moolenaar <Bram@vim.org>
parents:
16770
diff
changeset
|
1205 return; |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1206 |
22125
602e660d5ccf
patch 8.2.1612: Vim9: cannot pass "true" to prop_remove()
Bram Moolenaar <Bram@vim.org>
parents:
22069
diff
changeset
|
1207 do_all = dict_get_bool(dict, (char_u *)"all", FALSE); |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1208 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1209 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
|
1210 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
|
1211 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
|
1212 { |
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
|
1213 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
|
1214 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
|
1215 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1216 if (type == NULL) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1217 return; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1218 type_id = type->pt_id; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1219 } |
22125
602e660d5ccf
patch 8.2.1612: Vim9: cannot pass "true" to prop_remove()
Bram Moolenaar <Bram@vim.org>
parents:
22069
diff
changeset
|
1220 both = dict_get_bool(dict, (char_u *)"both", FALSE); |
602e660d5ccf
patch 8.2.1612: Vim9: cannot pass "true" to prop_remove()
Bram Moolenaar <Bram@vim.org>
parents:
22069
diff
changeset
|
1221 |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1222 if (id == -1 && type_id == -1) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1223 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15390
diff
changeset
|
1224 emsg(_("E968: Need at least one of 'id' or 'type'")); |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1225 return; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1226 } |
19601
67f39cb0a49c
patch 8.2.0357: cannot delete a text property matching both id and type
Bram Moolenaar <Bram@vim.org>
parents:
19534
diff
changeset
|
1227 if (both && (id == -1 || type_id == -1)) |
67f39cb0a49c
patch 8.2.0357: cannot delete a text property matching both id and type
Bram Moolenaar <Bram@vim.org>
parents:
19534
diff
changeset
|
1228 { |
67f39cb0a49c
patch 8.2.0357: cannot delete a text property matching both id and type
Bram Moolenaar <Bram@vim.org>
parents:
19534
diff
changeset
|
1229 emsg(_("E860: Need 'id' and 'type' with 'both'")); |
67f39cb0a49c
patch 8.2.0357: cannot delete a text property matching both id and type
Bram Moolenaar <Bram@vim.org>
parents:
19534
diff
changeset
|
1230 return; |
67f39cb0a49c
patch 8.2.0357: cannot delete a text property matching both id and type
Bram Moolenaar <Bram@vim.org>
parents:
19534
diff
changeset
|
1231 } |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1232 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1233 if (end == 0) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1234 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
|
1235 for (lnum = start; lnum <= end; ++lnum) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1236 { |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1237 char_u *text; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1238 size_t len; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1239 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1240 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
|
1241 break; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1242 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
|
1243 len = STRLEN(text) + 1; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1244 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
|
1245 { |
20583
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1246 static textprop_T textprop; // static because of alignment |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1247 unsigned idx; |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1248 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1249 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
|
1250 / sizeof(textprop_T); ++idx) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1251 { |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1252 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
|
1253 + idx * sizeof(textprop_T); |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1254 size_t taillen; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1255 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1256 mch_memmove(&textprop, cur_prop, sizeof(textprop_T)); |
19601
67f39cb0a49c
patch 8.2.0357: cannot delete a text property matching both id and type
Bram Moolenaar <Bram@vim.org>
parents:
19534
diff
changeset
|
1257 if (both ? textprop.tp_id == id && textprop.tp_type == type_id |
67f39cb0a49c
patch 8.2.0357: cannot delete a text property matching both id and type
Bram Moolenaar <Bram@vim.org>
parents:
19534
diff
changeset
|
1258 : textprop.tp_id == id || textprop.tp_type == type_id) |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1259 { |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1260 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
|
1261 { |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1262 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
|
1263 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1264 // 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
|
1265 if (newptr == NULL) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1266 return; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1267 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
|
1268 buf->b_ml.ml_line_len); |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1269 buf->b_ml.ml_line_ptr = newptr; |
16060
176872829dc2
patch 8.1.1035: prop_remove() second argument is not optional
Bram Moolenaar <Bram@vim.org>
parents:
15939
diff
changeset
|
1270 buf->b_ml.ml_flags |= ML_LINE_DIRTY; |
176872829dc2
patch 8.1.1035: prop_remove() second argument is not optional
Bram Moolenaar <Bram@vim.org>
parents:
15939
diff
changeset
|
1271 |
176872829dc2
patch 8.1.1035: prop_remove() second argument is not optional
Bram Moolenaar <Bram@vim.org>
parents:
15939
diff
changeset
|
1272 cur_prop = buf->b_ml.ml_line_ptr + len |
16772
18093a6accb5
patch 8.1.1388: errors when calling prop_remove() for an unloaded buffer
Bram Moolenaar <Bram@vim.org>
parents:
16770
diff
changeset
|
1273 + idx * sizeof(textprop_T); |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1274 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1275 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1276 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
|
1277 - (idx + 1) * sizeof(textprop_T); |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1278 if (taillen > 0) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1279 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
|
1280 taillen); |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1281 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
|
1282 --idx; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1283 |
24649
31a7fa6b2e93
patch 8.2.2863: removing a text property does not redraw optimally
Bram Moolenaar <Bram@vim.org>
parents:
24647
diff
changeset
|
1284 if (first_changed == 0) |
31a7fa6b2e93
patch 8.2.2863: removing a text property does not redraw optimally
Bram Moolenaar <Bram@vim.org>
parents:
24647
diff
changeset
|
1285 first_changed = lnum; |
31a7fa6b2e93
patch 8.2.2863: removing a text property does not redraw optimally
Bram Moolenaar <Bram@vim.org>
parents:
24647
diff
changeset
|
1286 last_changed = lnum; |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1287 ++rettv->vval.v_number; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1288 if (!do_all) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1289 break; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1290 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1291 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1292 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1293 } |
24649
31a7fa6b2e93
patch 8.2.2863: removing a text property does not redraw optimally
Bram Moolenaar <Bram@vim.org>
parents:
24647
diff
changeset
|
1294 if (first_changed > 0) |
24647
3f6a0ff1c5d3
patch 8.2.2862: removing a text property causes the whole window to be redawn
Bram Moolenaar <Bram@vim.org>
parents:
24643
diff
changeset
|
1295 { |
24649
31a7fa6b2e93
patch 8.2.2863: removing a text property does not redraw optimally
Bram Moolenaar <Bram@vim.org>
parents:
24647
diff
changeset
|
1296 changed_lines_buf(buf, first_changed, last_changed + 1, 0); |
31a7fa6b2e93
patch 8.2.2863: removing a text property does not redraw optimally
Bram Moolenaar <Bram@vim.org>
parents:
24647
diff
changeset
|
1297 redraw_buf_later(buf, VALID); |
24647
3f6a0ff1c5d3
patch 8.2.2862: removing a text property causes the whole window to be redawn
Bram Moolenaar <Bram@vim.org>
parents:
24643
diff
changeset
|
1298 } |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1299 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1300 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1301 /* |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1302 * 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
|
1303 */ |
17789
0f7ae8010787
patch 8.1.1891: functions used in one file are global
Bram Moolenaar <Bram@vim.org>
parents:
17694
diff
changeset
|
1304 static void |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1305 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
|
1306 { |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1307 char_u *name; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1308 buf_T *buf = NULL; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1309 dict_T *dict; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1310 dictitem_T *di; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1311 proptype_T *prop; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1312 |
25384
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
1313 if (in_vim9script() |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
1314 && (check_for_string_arg(argvars, 0) == FAIL |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
1315 || check_for_dict_arg(argvars, 1) == FAIL)) |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
1316 return; |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
1317 |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15182
diff
changeset
|
1318 name = tv_get_string(&argvars[0]); |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1319 if (*name == NUL) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1320 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15390
diff
changeset
|
1321 emsg(_(e_invarg)); |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1322 return; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1323 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1324 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1325 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
|
1326 return; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1327 dict = argvars[1].vval.v_dict; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1328 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1329 prop = find_prop(name, buf); |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1330 if (add) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1331 { |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1332 hashtab_T **htp; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1333 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1334 if (prop != NULL) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1335 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15390
diff
changeset
|
1336 semsg(_("E969: Property type %s already defined"), name); |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1337 return; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1338 } |
17659
121bdff812b4
patch 8.1.1827: allocating more memory than needed for extended structs
Bram Moolenaar <Bram@vim.org>
parents:
16924
diff
changeset
|
1339 prop = alloc_clear(offsetof(proptype_T, pt_name) + STRLEN(name) + 1); |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1340 if (prop == NULL) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1341 return; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1342 STRCPY(prop->pt_name, name); |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1343 prop->pt_id = ++proptype_id; |
18609
efad02c0e3e1
patch 8.1.2298: missing part of 8.1.2296
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1344 prop->pt_flags = PT_FLAG_COMBINE; |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1345 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
|
1346 if (*htp == NULL) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1347 { |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16811
diff
changeset
|
1348 *htp = ALLOC_ONE(hashtab_T); |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1349 if (*htp == NULL) |
15144
7960bf50d345
patch 8.1.0582: text properties are not enabled
Bram Moolenaar <Bram@vim.org>
parents:
15138
diff
changeset
|
1350 { |
7960bf50d345
patch 8.1.0582: text properties are not enabled
Bram Moolenaar <Bram@vim.org>
parents:
15138
diff
changeset
|
1351 vim_free(prop); |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1352 return; |
15144
7960bf50d345
patch 8.1.0582: text properties are not enabled
Bram Moolenaar <Bram@vim.org>
parents:
15138
diff
changeset
|
1353 } |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1354 hash_init(*htp); |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1355 } |
15144
7960bf50d345
patch 8.1.0582: text properties are not enabled
Bram Moolenaar <Bram@vim.org>
parents:
15138
diff
changeset
|
1356 hash_add(*htp, PT2HIKEY(prop)); |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1357 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1358 else |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1359 { |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1360 if (prop == NULL) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1361 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15390
diff
changeset
|
1362 semsg(_(e_type_not_exist), name); |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1363 return; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1364 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1365 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1366 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1367 if (dict != NULL) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1368 { |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1369 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
|
1370 if (di != NULL) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1371 { |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1372 char_u *highlight; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1373 int hl_id = 0; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1374 |
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
|
1375 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
|
1376 if (highlight != NULL && *highlight != NUL) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1377 hl_id = syn_name2id(highlight); |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1378 if (hl_id <= 0) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1379 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15390
diff
changeset
|
1380 semsg(_("E970: Unknown highlight group name: '%s'"), |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1381 highlight == NULL ? (char_u *)"" : highlight); |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1382 return; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1383 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1384 prop->pt_hl_id = hl_id; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1385 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1386 |
16549
08557bad0b9d
patch 8.1.1278: missing change for "combine" field
Bram Moolenaar <Bram@vim.org>
parents:
16060
diff
changeset
|
1387 di = dict_find(dict, (char_u *)"combine", -1); |
08557bad0b9d
patch 8.1.1278: missing change for "combine" field
Bram Moolenaar <Bram@vim.org>
parents:
16060
diff
changeset
|
1388 if (di != NULL) |
08557bad0b9d
patch 8.1.1278: missing change for "combine" field
Bram Moolenaar <Bram@vim.org>
parents:
16060
diff
changeset
|
1389 { |
22127
9d3dfd420a45
patch 8.2.1613: Vim9: cannot pass "true" to prop_type_add()
Bram Moolenaar <Bram@vim.org>
parents:
22125
diff
changeset
|
1390 if (tv_get_bool(&di->di_tv)) |
16549
08557bad0b9d
patch 8.1.1278: missing change for "combine" field
Bram Moolenaar <Bram@vim.org>
parents:
16060
diff
changeset
|
1391 prop->pt_flags |= PT_FLAG_COMBINE; |
08557bad0b9d
patch 8.1.1278: missing change for "combine" field
Bram Moolenaar <Bram@vim.org>
parents:
16060
diff
changeset
|
1392 else |
08557bad0b9d
patch 8.1.1278: missing change for "combine" field
Bram Moolenaar <Bram@vim.org>
parents:
16060
diff
changeset
|
1393 prop->pt_flags &= ~PT_FLAG_COMBINE; |
08557bad0b9d
patch 8.1.1278: missing change for "combine" field
Bram Moolenaar <Bram@vim.org>
parents:
16060
diff
changeset
|
1394 } |
08557bad0b9d
patch 8.1.1278: missing change for "combine" field
Bram Moolenaar <Bram@vim.org>
parents:
16060
diff
changeset
|
1395 |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1396 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
|
1397 if (di != NULL) |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15182
diff
changeset
|
1398 prop->pt_priority = tv_get_number(&di->di_tv); |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1399 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1400 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
|
1401 if (di != NULL) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1402 { |
22127
9d3dfd420a45
patch 8.2.1613: Vim9: cannot pass "true" to prop_type_add()
Bram Moolenaar <Bram@vim.org>
parents:
22125
diff
changeset
|
1403 if (tv_get_bool(&di->di_tv)) |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1404 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
|
1405 else |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1406 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
|
1407 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1408 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1409 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
|
1410 if (di != NULL) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1411 { |
22127
9d3dfd420a45
patch 8.2.1613: Vim9: cannot pass "true" to prop_type_add()
Bram Moolenaar <Bram@vim.org>
parents:
22125
diff
changeset
|
1412 if (tv_get_bool(&di->di_tv)) |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1413 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
|
1414 else |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1415 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
|
1416 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1417 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1418 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1419 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1420 /* |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1421 * prop_type_add({name}, {props}) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1422 */ |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1423 void |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1424 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
|
1425 { |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1426 prop_type_set(argvars, TRUE); |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1427 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1428 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1429 /* |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1430 * prop_type_change({name}, {props}) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1431 */ |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1432 void |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1433 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
|
1434 { |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1435 prop_type_set(argvars, FALSE); |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1436 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1437 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1438 /* |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1439 * prop_type_delete({name} [, {bufnr}]) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1440 */ |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1441 void |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1442 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
|
1443 { |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1444 char_u *name; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1445 buf_T *buf = NULL; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1446 hashitem_T *hi; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1447 |
25384
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
1448 if (in_vim9script() |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
1449 && (check_for_string_arg(argvars, 0) == FAIL |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
1450 || check_for_opt_dict_arg(argvars, 1) == FAIL)) |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
1451 return; |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
1452 |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15182
diff
changeset
|
1453 name = tv_get_string(&argvars[0]); |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1454 if (*name == NUL) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1455 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15390
diff
changeset
|
1456 emsg(_(e_invarg)); |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1457 return; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1458 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1459 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1460 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
|
1461 { |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1462 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
|
1463 return; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1464 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1465 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1466 hi = find_prop_hi(name, buf); |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1467 if (hi != NULL) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1468 { |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1469 hashtab_T *ht; |
15144
7960bf50d345
patch 8.1.0582: text properties are not enabled
Bram Moolenaar <Bram@vim.org>
parents:
15138
diff
changeset
|
1470 proptype_T *prop = HI2PT(hi); |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1471 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1472 if (buf == NULL) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1473 ht = global_proptypes; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1474 else |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1475 ht = buf->b_proptypes; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1476 hash_remove(ht, hi); |
15144
7960bf50d345
patch 8.1.0582: text properties are not enabled
Bram Moolenaar <Bram@vim.org>
parents:
15138
diff
changeset
|
1477 vim_free(prop); |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1478 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1479 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1480 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1481 /* |
25392
b427a26b0210
patch 8.2.3233: prop_list() and prop_find() do not indicate the buffer
Bram Moolenaar <Bram@vim.org>
parents:
25384
diff
changeset
|
1482 * prop_type_get({name} [, {props}]) |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1483 */ |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1484 void |
19049
e47b04b01793
patch 8.2.0085: dead code in builtin functions
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1485 f_prop_type_get(typval_T *argvars, typval_T *rettv) |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1486 { |
25384
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
1487 char_u *name; |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1488 |
25384
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
1489 if (in_vim9script() |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
1490 && (check_for_string_arg(argvars, 0) == FAIL |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
1491 || check_for_opt_dict_arg(argvars, 1) == FAIL)) |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
1492 return; |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
1493 |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
1494 name = tv_get_string(&argvars[0]); |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1495 if (*name == NUL) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1496 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15390
diff
changeset
|
1497 emsg(_(e_invarg)); |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1498 return; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1499 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1500 if (rettv_dict_alloc(rettv) == OK) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1501 { |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1502 proptype_T *prop = NULL; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1503 buf_T *buf = NULL; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1504 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1505 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
|
1506 { |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1507 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
|
1508 return; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1509 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1510 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1511 prop = find_prop(name, buf); |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1512 if (prop != NULL) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1513 { |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1514 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
|
1515 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1516 if (prop->pt_hl_id > 0) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1517 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
|
1518 dict_add_number(d, "priority", prop->pt_priority); |
16549
08557bad0b9d
patch 8.1.1278: missing change for "combine" field
Bram Moolenaar <Bram@vim.org>
parents:
16060
diff
changeset
|
1519 dict_add_number(d, "combine", |
08557bad0b9d
patch 8.1.1278: missing change for "combine" field
Bram Moolenaar <Bram@vim.org>
parents:
16060
diff
changeset
|
1520 (prop->pt_flags & PT_FLAG_COMBINE) ? 1 : 0); |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1521 dict_add_number(d, "start_incl", |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1522 (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
|
1523 dict_add_number(d, "end_incl", |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1524 (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
|
1525 if (buf != NULL) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1526 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
|
1527 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1528 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1529 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1530 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1531 static void |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1532 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
|
1533 { |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1534 long todo; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1535 hashitem_T *hi; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1536 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1537 todo = (long)ht->ht_used; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1538 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
|
1539 { |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1540 if (!HASHITEM_EMPTY(hi)) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1541 { |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1542 proptype_T *prop = HI2PT(hi); |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1543 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1544 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
|
1545 --todo; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1546 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1547 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1548 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1549 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1550 /* |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1551 * prop_type_list([{bufnr}]) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1552 */ |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1553 void |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1554 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
|
1555 { |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1556 buf_T *buf = NULL; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1557 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1558 if (rettv_list_alloc(rettv) == OK) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1559 { |
25384
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
1560 if (in_vim9script() && check_for_opt_dict_arg(argvars, 0) == FAIL) |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
1561 return; |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
1562 |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1563 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
|
1564 { |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1565 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
|
1566 return; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1567 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1568 if (buf == NULL) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1569 { |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1570 if (global_proptypes != NULL) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1571 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
|
1572 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1573 else if (buf->b_proptypes != NULL) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1574 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
|
1575 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1576 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1577 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1578 /* |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1579 * Free all property types in "ht". |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1580 */ |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1581 static void |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1582 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
|
1583 { |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1584 long todo; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1585 hashitem_T *hi; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1586 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1587 if (ht == NULL) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1588 return; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1589 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1590 todo = (long)ht->ht_used; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1591 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
|
1592 { |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1593 if (!HASHITEM_EMPTY(hi)) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1594 { |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1595 proptype_T *prop = HI2PT(hi); |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1596 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1597 vim_free(prop); |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1598 --todo; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1599 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1600 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1601 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1602 hash_clear(ht); |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1603 vim_free(ht); |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1604 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1605 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1606 #if defined(EXITFREE) || defined(PROTO) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1607 /* |
15144
7960bf50d345
patch 8.1.0582: text properties are not enabled
Bram Moolenaar <Bram@vim.org>
parents:
15138
diff
changeset
|
1608 * Free all global property types. |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1609 */ |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1610 void |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1611 clear_global_prop_types(void) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1612 { |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1613 clear_ht_prop_types(global_proptypes); |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1614 global_proptypes = NULL; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1615 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1616 #endif |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1617 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1618 /* |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1619 * Free all property types for "buf". |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1620 */ |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1621 void |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1622 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
|
1623 { |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1624 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
|
1625 buf->b_proptypes = NULL; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1626 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1627 |
20583
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1628 // Struct used to return two values from adjust_prop(). |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1629 typedef struct |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1630 { |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1631 int dirty; // if the property was changed |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1632 int can_drop; // whether after this change, the prop may be removed |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1633 } adjustres_T; |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1634 |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1635 /* |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1636 * Adjust the property for "added" bytes (can be negative) inserted at "col". |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1637 * |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1638 * Note that "col" is zero-based, while tp_col is one-based. |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1639 * Only for the current buffer. |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1640 * "flags" can have: |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1641 * APC_SUBSTITUTE: Text is replaced, not inserted. |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1642 */ |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1643 static adjustres_T |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1644 adjust_prop( |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1645 textprop_T *prop, |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1646 colnr_T col, |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1647 int added, |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1648 int flags) |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1649 { |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1650 proptype_T *pt = text_prop_type_by_id(curbuf, prop->tp_type); |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1651 int start_incl = (pt != NULL |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1652 && (pt->pt_flags & PT_FLAG_INS_START_INCL)) |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1653 || (flags & APC_SUBSTITUTE); |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1654 int end_incl = (pt != NULL |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1655 && (pt->pt_flags & PT_FLAG_INS_END_INCL)); |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1656 // Do not drop zero-width props if they later can increase in |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1657 // size. |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1658 int droppable = !(start_incl || end_incl); |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1659 adjustres_T res = {TRUE, FALSE}; |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1660 |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1661 if (added > 0) |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1662 { |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1663 if (col + 1 <= prop->tp_col |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1664 - (start_incl || (prop->tp_len == 0 && end_incl))) |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1665 // Change is entirely before the text property: Only shift |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1666 prop->tp_col += added; |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1667 else if (col + 1 < prop->tp_col + prop->tp_len + end_incl) |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1668 // Insertion was inside text property |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1669 prop->tp_len += added; |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1670 } |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1671 else if (prop->tp_col > col + 1) |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1672 { |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1673 if (prop->tp_col + added < col + 1) |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1674 { |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1675 prop->tp_len += (prop->tp_col - 1 - col) + added; |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1676 prop->tp_col = col + 1; |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1677 if (prop->tp_len <= 0) |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1678 { |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1679 prop->tp_len = 0; |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1680 res.can_drop = droppable; |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1681 } |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1682 } |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1683 else |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1684 prop->tp_col += added; |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1685 } |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1686 else if (prop->tp_len > 0 && prop->tp_col + prop->tp_len > col) |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1687 { |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1688 int after = col - added - (prop->tp_col - 1 + prop->tp_len); |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1689 |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1690 prop->tp_len += after > 0 ? added + after : added; |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1691 res.can_drop = prop->tp_len <= 0 && droppable; |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1692 } |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1693 else |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1694 res.dirty = FALSE; |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1695 |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1696 return res; |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1697 } |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1698 |
15335
18c20ceee4b5
patch 8.1.0675: text property column in screen columns is not practical
Bram Moolenaar <Bram@vim.org>
parents:
15294
diff
changeset
|
1699 /* |
18c20ceee4b5
patch 8.1.0675: text property column in screen columns is not practical
Bram Moolenaar <Bram@vim.org>
parents:
15294
diff
changeset
|
1700 * Adjust the columns of text properties in line "lnum" after position "col" to |
18c20ceee4b5
patch 8.1.0675: text property column in screen columns is not practical
Bram Moolenaar <Bram@vim.org>
parents:
15294
diff
changeset
|
1701 * shift by "bytes_added" (can be negative). |
15341
03a7a9fdb792
patch 8.1.0678: text properties as not adjusted for inserted text
Bram Moolenaar <Bram@vim.org>
parents:
15335
diff
changeset
|
1702 * Note that "col" is zero-based, while tp_col is one-based. |
03a7a9fdb792
patch 8.1.0678: text properties as not adjusted for inserted text
Bram Moolenaar <Bram@vim.org>
parents:
15335
diff
changeset
|
1703 * Only for the current buffer. |
16714
ba592f30c082
patch 8.1.1359: text property wrong after :substitute with backslash
Bram Moolenaar <Bram@vim.org>
parents:
16698
diff
changeset
|
1704 * "flags" can have: |
ba592f30c082
patch 8.1.1359: text property wrong after :substitute with backslash
Bram Moolenaar <Bram@vim.org>
parents:
16698
diff
changeset
|
1705 * APC_SAVE_FOR_UNDO: Call u_savesub() before making changes to the line. |
ba592f30c082
patch 8.1.1359: text property wrong after :substitute with backslash
Bram Moolenaar <Bram@vim.org>
parents:
16698
diff
changeset
|
1706 * APC_SUBSTITUTE: Text is replaced, not inserted. |
16682
7847d281cbbf
patch 8.1.1343: text properties not adjusted for Visual block mode delete
Bram Moolenaar <Bram@vim.org>
parents:
16678
diff
changeset
|
1707 * Caller is expected to check b_has_textprop and "bytes_added" being non-zero. |
16698
23af483c4ceb
patch 8.1.1351: text property wrong after :substitute
Bram Moolenaar <Bram@vim.org>
parents:
16682
diff
changeset
|
1708 * Returns TRUE when props were changed. |
15335
18c20ceee4b5
patch 8.1.0675: text property column in screen columns is not practical
Bram Moolenaar <Bram@vim.org>
parents:
15294
diff
changeset
|
1709 */ |
16698
23af483c4ceb
patch 8.1.1351: text property wrong after :substitute
Bram Moolenaar <Bram@vim.org>
parents:
16682
diff
changeset
|
1710 int |
15349
6abee072b93c
patch 8.1.0682: text properties not adjusted when backspacing replaced text
Bram Moolenaar <Bram@vim.org>
parents:
15341
diff
changeset
|
1711 adjust_prop_columns( |
6abee072b93c
patch 8.1.0682: text properties not adjusted when backspacing replaced text
Bram Moolenaar <Bram@vim.org>
parents:
15341
diff
changeset
|
1712 linenr_T lnum, |
6abee072b93c
patch 8.1.0682: text properties not adjusted when backspacing replaced text
Bram Moolenaar <Bram@vim.org>
parents:
15341
diff
changeset
|
1713 colnr_T col, |
16698
23af483c4ceb
patch 8.1.1351: text property wrong after :substitute
Bram Moolenaar <Bram@vim.org>
parents:
16682
diff
changeset
|
1714 int bytes_added, |
16714
ba592f30c082
patch 8.1.1359: text property wrong after :substitute with backslash
Bram Moolenaar <Bram@vim.org>
parents:
16698
diff
changeset
|
1715 int flags) |
15335
18c20ceee4b5
patch 8.1.0675: text property column in screen columns is not practical
Bram Moolenaar <Bram@vim.org>
parents:
15294
diff
changeset
|
1716 { |
15341
03a7a9fdb792
patch 8.1.0678: text properties as not adjusted for inserted text
Bram Moolenaar <Bram@vim.org>
parents:
15335
diff
changeset
|
1717 int proplen; |
03a7a9fdb792
patch 8.1.0678: text properties as not adjusted for inserted text
Bram Moolenaar <Bram@vim.org>
parents:
15335
diff
changeset
|
1718 char_u *props; |
03a7a9fdb792
patch 8.1.0678: text properties as not adjusted for inserted text
Bram Moolenaar <Bram@vim.org>
parents:
15335
diff
changeset
|
1719 int dirty = FALSE; |
15349
6abee072b93c
patch 8.1.0682: text properties not adjusted when backspacing replaced text
Bram Moolenaar <Bram@vim.org>
parents:
15341
diff
changeset
|
1720 int ri, wi; |
6abee072b93c
patch 8.1.0682: text properties not adjusted when backspacing replaced text
Bram Moolenaar <Bram@vim.org>
parents:
15341
diff
changeset
|
1721 size_t textlen; |
6abee072b93c
patch 8.1.0682: text properties not adjusted when backspacing replaced text
Bram Moolenaar <Bram@vim.org>
parents:
15341
diff
changeset
|
1722 |
6abee072b93c
patch 8.1.0682: text properties not adjusted when backspacing replaced text
Bram Moolenaar <Bram@vim.org>
parents:
15341
diff
changeset
|
1723 if (text_prop_frozen > 0) |
16698
23af483c4ceb
patch 8.1.1351: text property wrong after :substitute
Bram Moolenaar <Bram@vim.org>
parents:
16682
diff
changeset
|
1724 return FALSE; |
15341
03a7a9fdb792
patch 8.1.0678: text properties as not adjusted for inserted text
Bram Moolenaar <Bram@vim.org>
parents:
15335
diff
changeset
|
1725 |
03a7a9fdb792
patch 8.1.0678: text properties as not adjusted for inserted text
Bram Moolenaar <Bram@vim.org>
parents:
15335
diff
changeset
|
1726 proplen = get_text_props(curbuf, lnum, &props, TRUE); |
03a7a9fdb792
patch 8.1.0678: text properties as not adjusted for inserted text
Bram Moolenaar <Bram@vim.org>
parents:
15335
diff
changeset
|
1727 if (proplen == 0) |
16698
23af483c4ceb
patch 8.1.1351: text property wrong after :substitute
Bram Moolenaar <Bram@vim.org>
parents:
16682
diff
changeset
|
1728 return FALSE; |
15349
6abee072b93c
patch 8.1.0682: text properties not adjusted when backspacing replaced text
Bram Moolenaar <Bram@vim.org>
parents:
15341
diff
changeset
|
1729 textlen = curbuf->b_ml.ml_line_len - proplen * sizeof(textprop_T); |
15341
03a7a9fdb792
patch 8.1.0678: text properties as not adjusted for inserted text
Bram Moolenaar <Bram@vim.org>
parents:
15335
diff
changeset
|
1730 |
15349
6abee072b93c
patch 8.1.0682: text properties not adjusted when backspacing replaced text
Bram Moolenaar <Bram@vim.org>
parents:
15341
diff
changeset
|
1731 wi = 0; // write index |
6abee072b93c
patch 8.1.0682: text properties not adjusted when backspacing replaced text
Bram Moolenaar <Bram@vim.org>
parents:
15341
diff
changeset
|
1732 for (ri = 0; ri < proplen; ++ri) |
15341
03a7a9fdb792
patch 8.1.0678: text properties as not adjusted for inserted text
Bram Moolenaar <Bram@vim.org>
parents:
15335
diff
changeset
|
1733 { |
19534
36ec10251b2b
patch 8.2.0324: text property not updated correctly when inserting/deleting
Bram Moolenaar <Bram@vim.org>
parents:
19100
diff
changeset
|
1734 textprop_T prop; |
20583
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1735 adjustres_T res; |
19534
36ec10251b2b
patch 8.2.0324: text property not updated correctly when inserting/deleting
Bram Moolenaar <Bram@vim.org>
parents:
19100
diff
changeset
|
1736 |
20583
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1737 mch_memmove(&prop, props + ri * sizeof(prop), sizeof(prop)); |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1738 res = adjust_prop(&prop, col, bytes_added, flags); |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1739 if (res.dirty) |
19534
36ec10251b2b
patch 8.2.0324: text property not updated correctly when inserting/deleting
Bram Moolenaar <Bram@vim.org>
parents:
19100
diff
changeset
|
1740 { |
16714
ba592f30c082
patch 8.1.1359: text property wrong after :substitute with backslash
Bram Moolenaar <Bram@vim.org>
parents:
16698
diff
changeset
|
1741 // Save for undo if requested and not done yet. |
21081
71a36879ac2a
patch 8.2.1092: not checking if saving for undo succeeds
Bram Moolenaar <Bram@vim.org>
parents:
20583
diff
changeset
|
1742 if ((flags & APC_SAVE_FOR_UNDO) && !dirty |
71a36879ac2a
patch 8.2.1092: not checking if saving for undo succeeds
Bram Moolenaar <Bram@vim.org>
parents:
20583
diff
changeset
|
1743 && u_savesub(lnum) == FAIL) |
71a36879ac2a
patch 8.2.1092: not checking if saving for undo succeeds
Bram Moolenaar <Bram@vim.org>
parents:
20583
diff
changeset
|
1744 return FALSE; |
16714
ba592f30c082
patch 8.1.1359: text property wrong after :substitute with backslash
Bram Moolenaar <Bram@vim.org>
parents:
16698
diff
changeset
|
1745 dirty = TRUE; |
22331
0271c2b8bb35
patch 8.2.1714: text properties corrupted with substitute command
Bram Moolenaar <Bram@vim.org>
parents:
22127
diff
changeset
|
1746 |
0271c2b8bb35
patch 8.2.1714: text properties corrupted with substitute command
Bram Moolenaar <Bram@vim.org>
parents:
22127
diff
changeset
|
1747 // u_savesub() may have updated curbuf->b_ml, fetch it again |
0271c2b8bb35
patch 8.2.1714: text properties corrupted with substitute command
Bram Moolenaar <Bram@vim.org>
parents:
22127
diff
changeset
|
1748 if (curbuf->b_ml.ml_line_lnum != lnum) |
0271c2b8bb35
patch 8.2.1714: text properties corrupted with substitute command
Bram Moolenaar <Bram@vim.org>
parents:
22127
diff
changeset
|
1749 proplen = get_text_props(curbuf, lnum, &props, TRUE); |
19534
36ec10251b2b
patch 8.2.0324: text property not updated correctly when inserting/deleting
Bram Moolenaar <Bram@vim.org>
parents:
19100
diff
changeset
|
1750 } |
20583
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1751 if (res.can_drop) |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1752 continue; // Drop this text property |
19534
36ec10251b2b
patch 8.2.0324: text property not updated correctly when inserting/deleting
Bram Moolenaar <Bram@vim.org>
parents:
19100
diff
changeset
|
1753 mch_memmove(props + wi * sizeof(textprop_T), &prop, sizeof(textprop_T)); |
15349
6abee072b93c
patch 8.1.0682: text properties not adjusted when backspacing replaced text
Bram Moolenaar <Bram@vim.org>
parents:
15341
diff
changeset
|
1754 ++wi; |
6abee072b93c
patch 8.1.0682: text properties not adjusted when backspacing replaced text
Bram Moolenaar <Bram@vim.org>
parents:
15341
diff
changeset
|
1755 } |
6abee072b93c
patch 8.1.0682: text properties not adjusted when backspacing replaced text
Bram Moolenaar <Bram@vim.org>
parents:
15341
diff
changeset
|
1756 if (dirty) |
6abee072b93c
patch 8.1.0682: text properties not adjusted when backspacing replaced text
Bram Moolenaar <Bram@vim.org>
parents:
15341
diff
changeset
|
1757 { |
15373
44dd3ce11201
patch 8.1.0694: when using text props may free memory that is not allocated
Bram Moolenaar <Bram@vim.org>
parents:
15367
diff
changeset
|
1758 colnr_T newlen = (int)textlen + wi * (colnr_T)sizeof(textprop_T); |
44dd3ce11201
patch 8.1.0694: when using text props may free memory that is not allocated
Bram Moolenaar <Bram@vim.org>
parents:
15367
diff
changeset
|
1759 |
44dd3ce11201
patch 8.1.0694: when using text props may free memory that is not allocated
Bram Moolenaar <Bram@vim.org>
parents:
15367
diff
changeset
|
1760 if ((curbuf->b_ml.ml_flags & ML_LINE_DIRTY) == 0) |
44dd3ce11201
patch 8.1.0694: when using text props may free memory that is not allocated
Bram Moolenaar <Bram@vim.org>
parents:
15367
diff
changeset
|
1761 curbuf->b_ml.ml_line_ptr = |
44dd3ce11201
patch 8.1.0694: when using text props may free memory that is not allocated
Bram Moolenaar <Bram@vim.org>
parents:
15367
diff
changeset
|
1762 vim_memsave(curbuf->b_ml.ml_line_ptr, newlen); |
15349
6abee072b93c
patch 8.1.0682: text properties not adjusted when backspacing replaced text
Bram Moolenaar <Bram@vim.org>
parents:
15341
diff
changeset
|
1763 curbuf->b_ml.ml_flags |= ML_LINE_DIRTY; |
15373
44dd3ce11201
patch 8.1.0694: when using text props may free memory that is not allocated
Bram Moolenaar <Bram@vim.org>
parents:
15367
diff
changeset
|
1764 curbuf->b_ml.ml_line_len = newlen; |
15341
03a7a9fdb792
patch 8.1.0678: text properties as not adjusted for inserted text
Bram Moolenaar <Bram@vim.org>
parents:
15335
diff
changeset
|
1765 } |
16698
23af483c4ceb
patch 8.1.1351: text property wrong after :substitute
Bram Moolenaar <Bram@vim.org>
parents:
16682
diff
changeset
|
1766 return dirty; |
15335
18c20ceee4b5
patch 8.1.0675: text property column in screen columns is not practical
Bram Moolenaar <Bram@vim.org>
parents:
15294
diff
changeset
|
1767 } |
18c20ceee4b5
patch 8.1.0675: text property column in screen columns is not practical
Bram Moolenaar <Bram@vim.org>
parents:
15294
diff
changeset
|
1768 |
15367
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
1769 /* |
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
1770 * Adjust text properties for a line that was split in two. |
16662
1fc9cd08cf3c
patch 8.1.1333: text properties don't always move after changes
Bram Moolenaar <Bram@vim.org>
parents:
16549
diff
changeset
|
1771 * "lnum_props" is the line that has the properties from before the split. |
1fc9cd08cf3c
patch 8.1.1333: text properties don't always move after changes
Bram Moolenaar <Bram@vim.org>
parents:
16549
diff
changeset
|
1772 * "lnum_top" is the top line. |
1fc9cd08cf3c
patch 8.1.1333: text properties don't always move after changes
Bram Moolenaar <Bram@vim.org>
parents:
16549
diff
changeset
|
1773 * "kept" is the number of bytes kept in the first line, while |
15367
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
1774 * "deleted" is the number of bytes deleted. |
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
1775 */ |
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
1776 void |
16662
1fc9cd08cf3c
patch 8.1.1333: text properties don't always move after changes
Bram Moolenaar <Bram@vim.org>
parents:
16549
diff
changeset
|
1777 adjust_props_for_split( |
1fc9cd08cf3c
patch 8.1.1333: text properties don't always move after changes
Bram Moolenaar <Bram@vim.org>
parents:
16549
diff
changeset
|
1778 linenr_T lnum_props, |
1fc9cd08cf3c
patch 8.1.1333: text properties don't always move after changes
Bram Moolenaar <Bram@vim.org>
parents:
16549
diff
changeset
|
1779 linenr_T lnum_top, |
1fc9cd08cf3c
patch 8.1.1333: text properties don't always move after changes
Bram Moolenaar <Bram@vim.org>
parents:
16549
diff
changeset
|
1780 int kept, |
1fc9cd08cf3c
patch 8.1.1333: text properties don't always move after changes
Bram Moolenaar <Bram@vim.org>
parents:
16549
diff
changeset
|
1781 int deleted) |
15367
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
1782 { |
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
1783 char_u *props; |
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
1784 int count; |
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
1785 garray_T prevprop; |
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
1786 garray_T nextprop; |
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
1787 int i; |
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
1788 int skipped = kept + deleted; |
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
1789 |
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
1790 if (!curbuf->b_has_textprop) |
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
1791 return; |
16662
1fc9cd08cf3c
patch 8.1.1333: text properties don't always move after changes
Bram Moolenaar <Bram@vim.org>
parents:
16549
diff
changeset
|
1792 |
1fc9cd08cf3c
patch 8.1.1333: text properties don't always move after changes
Bram Moolenaar <Bram@vim.org>
parents:
16549
diff
changeset
|
1793 // Get the text properties from "lnum_props". |
1fc9cd08cf3c
patch 8.1.1333: text properties don't always move after changes
Bram Moolenaar <Bram@vim.org>
parents:
16549
diff
changeset
|
1794 count = get_text_props(curbuf, lnum_props, &props, FALSE); |
15367
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
1795 ga_init2(&prevprop, sizeof(textprop_T), 10); |
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
1796 ga_init2(&nextprop, sizeof(textprop_T), 10); |
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
1797 |
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
1798 // Keep the relevant ones in the first line, reducing the length if needed. |
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
1799 // Copy the ones that include the split to the second line. |
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
1800 // Move the ones after the split to the second line. |
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
1801 for (i = 0; i < count; ++i) |
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
1802 { |
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
1803 textprop_T prop; |
20583
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1804 proptype_T *pt; |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1805 int start_incl, end_incl; |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1806 int cont_prev, cont_next; |
15367
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
1807 |
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
1808 // copy the prop to an aligned structure |
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
1809 mch_memmove(&prop, props + i * sizeof(textprop_T), sizeof(textprop_T)); |
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
1810 |
20583
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1811 pt = text_prop_type_by_id(curbuf, prop.tp_type); |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1812 start_incl = (pt != NULL && (pt->pt_flags & PT_FLAG_INS_START_INCL)); |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1813 end_incl = (pt != NULL && (pt->pt_flags & PT_FLAG_INS_END_INCL)); |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1814 cont_prev = prop.tp_col + !start_incl <= kept; |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1815 cont_next = skipped <= prop.tp_col + prop.tp_len - !end_incl; |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1816 |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1817 if (cont_prev && ga_grow(&prevprop, 1) == OK) |
15367
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
1818 { |
20583
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1819 textprop_T *p = ((textprop_T *)prevprop.ga_data) + prevprop.ga_len; |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1820 |
15367
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
1821 *p = prop; |
20583
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1822 ++prevprop.ga_len; |
15367
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
1823 if (p->tp_col + p->tp_len >= kept) |
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
1824 p->tp_len = kept - p->tp_col; |
20583
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1825 if (cont_next) |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1826 p->tp_flags |= TP_FLAG_CONT_NEXT; |
15367
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
1827 } |
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
1828 |
16670
5733d8e33bce
patch 8.1.1337: get empty text prop when splitting line just after text prop
Bram Moolenaar <Bram@vim.org>
parents:
16662
diff
changeset
|
1829 // Only add the property to the next line if the length is bigger than |
5733d8e33bce
patch 8.1.1337: get empty text prop when splitting line just after text prop
Bram Moolenaar <Bram@vim.org>
parents:
16662
diff
changeset
|
1830 // zero. |
20583
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1831 if (cont_next && ga_grow(&nextprop, 1) == OK) |
15367
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
1832 { |
20583
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1833 textprop_T *p = ((textprop_T *)nextprop.ga_data) + nextprop.ga_len; |
15367
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
1834 *p = prop; |
20583
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1835 ++nextprop.ga_len; |
15367
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
1836 if (p->tp_col > skipped) |
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
1837 p->tp_col -= skipped - 1; |
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
1838 else |
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
1839 { |
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
1840 p->tp_len -= skipped - p->tp_col; |
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
1841 p->tp_col = 1; |
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
1842 } |
20583
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1843 if (cont_prev) |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1844 p->tp_flags |= TP_FLAG_CONT_PREV; |
15367
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
1845 } |
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
1846 } |
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
1847 |
16662
1fc9cd08cf3c
patch 8.1.1333: text properties don't always move after changes
Bram Moolenaar <Bram@vim.org>
parents:
16549
diff
changeset
|
1848 set_text_props(lnum_top, prevprop.ga_data, |
1fc9cd08cf3c
patch 8.1.1333: text properties don't always move after changes
Bram Moolenaar <Bram@vim.org>
parents:
16549
diff
changeset
|
1849 prevprop.ga_len * sizeof(textprop_T)); |
15367
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
1850 ga_clear(&prevprop); |
16662
1fc9cd08cf3c
patch 8.1.1333: text properties don't always move after changes
Bram Moolenaar <Bram@vim.org>
parents:
16549
diff
changeset
|
1851 set_text_props(lnum_top + 1, nextprop.ga_data, |
1fc9cd08cf3c
patch 8.1.1333: text properties don't always move after changes
Bram Moolenaar <Bram@vim.org>
parents:
16549
diff
changeset
|
1852 nextprop.ga_len * sizeof(textprop_T)); |
15367
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
1853 ga_clear(&nextprop); |
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
1854 } |
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
1855 |
16678
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16676
diff
changeset
|
1856 /* |
20583
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1857 * Prepend properties of joined line "lnum" to "new_props". |
16678
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16676
diff
changeset
|
1858 */ |
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16676
diff
changeset
|
1859 void |
20583
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1860 prepend_joined_props( |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1861 char_u *new_props, |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1862 int propcount, |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1863 int *props_remaining, |
16678
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16676
diff
changeset
|
1864 linenr_T lnum, |
20583
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1865 int add_all, |
16678
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16676
diff
changeset
|
1866 long col, |
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16676
diff
changeset
|
1867 int removed) |
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16676
diff
changeset
|
1868 { |
20583
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1869 char_u *props; |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1870 int proplen = get_text_props(curbuf, lnum, &props, FALSE); |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1871 int i; |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1872 |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1873 for (i = proplen; i-- > 0; ) |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1874 { |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1875 textprop_T prop; |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1876 int end; |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1877 |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1878 mch_memmove(&prop, props + i * sizeof(prop), sizeof(prop)); |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1879 end = !(prop.tp_flags & TP_FLAG_CONT_NEXT); |
16678
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16676
diff
changeset
|
1880 |
20583
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1881 adjust_prop(&prop, 0, -removed, 0); // Remove leading spaces |
23229
b545334ae654
patch 8.2.2160: various typos
Bram Moolenaar <Bram@vim.org>
parents:
22331
diff
changeset
|
1882 adjust_prop(&prop, -1, col, 0); // Make line start at its final column |
20583
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1883 |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1884 if (add_all || end) |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1885 mch_memmove(new_props + --(*props_remaining) * sizeof(prop), |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1886 &prop, sizeof(prop)); |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1887 else |
16678
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16676
diff
changeset
|
1888 { |
20583
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1889 int j; |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1890 int found = FALSE; |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1891 |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1892 // Search for continuing prop. |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1893 for (j = *props_remaining; j < propcount; ++j) |
16678
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16676
diff
changeset
|
1894 { |
20583
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1895 textprop_T op; |
16678
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16676
diff
changeset
|
1896 |
20583
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1897 mch_memmove(&op, new_props + j * sizeof(op), sizeof(op)); |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1898 if ((op.tp_flags & TP_FLAG_CONT_PREV) |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1899 && op.tp_id == prop.tp_id && op.tp_type == prop.tp_type) |
16678
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16676
diff
changeset
|
1900 { |
20583
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1901 found = TRUE; |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1902 op.tp_len += op.tp_col - prop.tp_col; |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1903 op.tp_col = prop.tp_col; |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1904 // Start/end is taken care of when deleting joined lines |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1905 op.tp_flags = prop.tp_flags; |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1906 mch_memmove(new_props + j * sizeof(op), &op, sizeof(op)); |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1907 break; |
16678
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16676
diff
changeset
|
1908 } |
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16676
diff
changeset
|
1909 } |
20583
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1910 if (!found) |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1911 internal_error("text property above joined line not found"); |
16678
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16676
diff
changeset
|
1912 } |
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16676
diff
changeset
|
1913 } |
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16676
diff
changeset
|
1914 } |
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16676
diff
changeset
|
1915 |
18763
49b78d6465e5
patch 8.1.2371: FEAT_TEXT_PROP is a confusing name
Bram Moolenaar <Bram@vim.org>
parents:
18631
diff
changeset
|
1916 #endif // FEAT_PROP_POPUP |