Mercurial > vim
annotate src/textprop.c @ 31424:e31fc75f6aff v9.0.1045
patch 9.0.1045: in a class object members cannot be initialized
Commit: https://github.com/vim/vim/commit/7ce7daf6cd6a7ed27eac060699026640b4b239a8
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Dec 10 18:42:12 2022 +0000
patch 9.0.1045: in a class object members cannot be initialized
Problem: In a class object members cannot be initialized.
Solution: Support initializing object members. Make "dissassemble" work on
an object method.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 10 Dec 2022 19:45:04 +0100 |
parents | 243c35fad9cb |
children | 966c87c57912 |
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 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
14 #include "vim.h" |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
15 |
18763
49b78d6465e5
patch 8.1.2371: FEAT_TEXT_PROP is a confusing name
Bram Moolenaar <Bram@vim.org>
parents:
18631
diff
changeset
|
16 #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
|
17 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
18 /* |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
19 * 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
|
20 * 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
|
21 * 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
|
22 * 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
|
23 * 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
|
24 */ |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
25 #define PT2HIKEY(p) ((p)->pt_name) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
26 #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
|
27 #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
|
28 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
29 // The global text property types. |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
30 static hashtab_T *global_proptypes = NULL; |
29649
a3a966b8b7a7
patch 9.0.0165: looking up a text property type by ID is slow
Bram Moolenaar <Bram@vim.org>
parents:
29627
diff
changeset
|
31 static proptype_T **global_proparray = NULL; |
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 // 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
|
34 static int proptype_id = 0; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
35 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
36 /* |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
37 * 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
|
38 * 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
|
39 */ |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
40 static hashitem_T * |
29649
a3a966b8b7a7
patch 9.0.0165: looking up a text property type by ID is slow
Bram Moolenaar <Bram@vim.org>
parents:
29627
diff
changeset
|
41 find_prop_type_hi(char_u *name, buf_T *buf) |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
42 { |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
43 hashtab_T *ht; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
44 hashitem_T *hi; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
45 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
46 if (*name == NUL) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
47 return NULL; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
48 if (buf == NULL) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
49 ht = global_proptypes; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
50 else |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
51 ht = buf->b_proptypes; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
52 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
53 if (ht == NULL) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
54 return NULL; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
55 hi = hash_find(ht, name); |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
56 if (HASHITEM_EMPTY(hi)) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
57 return NULL; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
58 return hi; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
59 } |
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 /* |
29649
a3a966b8b7a7
patch 9.0.0165: looking up a text property type by ID is slow
Bram Moolenaar <Bram@vim.org>
parents:
29627
diff
changeset
|
62 * Like find_prop_type_hi() but return the property type. |
15138
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 static proptype_T * |
29649
a3a966b8b7a7
patch 9.0.0165: looking up a text property type by ID is slow
Bram Moolenaar <Bram@vim.org>
parents:
29627
diff
changeset
|
65 find_prop_type(char_u *name, buf_T *buf) |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
66 { |
29649
a3a966b8b7a7
patch 9.0.0165: looking up a text property type by ID is slow
Bram Moolenaar <Bram@vim.org>
parents:
29627
diff
changeset
|
67 hashitem_T *hi = find_prop_type_hi(name, buf); |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
68 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
69 if (hi == NULL) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
70 return NULL; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
71 return HI2PT(hi); |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
72 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
73 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
74 /* |
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
|
75 * 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
|
76 * 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
|
77 */ |
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
|
78 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
|
79 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
|
80 { |
29649
a3a966b8b7a7
patch 9.0.0165: looking up a text property type by ID is slow
Bram Moolenaar <Bram@vim.org>
parents:
29627
diff
changeset
|
81 proptype_T *pt = find_prop_type(name, buf); |
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
|
82 |
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
|
83 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
|
84 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
|
85 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
|
86 } |
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
|
87 |
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
|
88 /* |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
89 * 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
|
90 * global types. |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
91 * 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
|
92 */ |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
93 static proptype_T * |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
94 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
|
95 { |
29649
a3a966b8b7a7
patch 9.0.0165: looking up a text property type by ID is slow
Bram Moolenaar <Bram@vim.org>
parents:
29627
diff
changeset
|
96 proptype_T *type = find_prop_type(name, buf); |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
97 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
98 if (type == NULL) |
29649
a3a966b8b7a7
patch 9.0.0165: looking up a text property type by ID is slow
Bram Moolenaar <Bram@vim.org>
parents:
29627
diff
changeset
|
99 type = find_prop_type(name, NULL); |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
100 if (type == NULL) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15390
diff
changeset
|
101 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
|
102 return type; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
103 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
104 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
105 /* |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
106 * 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
|
107 * 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
|
108 * unchanged. |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
109 * 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
|
110 * 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
|
111 */ |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
112 static int |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
113 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
|
114 { |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
115 dictitem_T *di; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
116 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
117 if (arg->v_type != VAR_DICT) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
118 { |
26877
06a137af96f8
patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26865
diff
changeset
|
119 emsg(_(e_dictionary_required)); |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
120 return FAIL; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
121 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
122 if (arg->vval.v_dict == NULL) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
123 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
|
124 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
|
125 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
|
126 || 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
|
127 { |
16772
18093a6accb5
patch 8.1.1388: errors when calling prop_remove() for an unloaded buffer
Bram Moolenaar <Bram@vim.org>
parents:
16770
diff
changeset
|
128 *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
|
129 if (*buf == NULL) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
130 return FAIL; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
131 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
132 return OK; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
133 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
134 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
135 /* |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
136 * prop_add({lnum}, {col}, {props}) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
137 */ |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
138 void |
29451
057c26b5c33a
patch 9.0.0067: cannot show virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
139 f_prop_add(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
|
140 { |
15251
17525ca95e1e
patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
141 linenr_T start_lnum; |
17525ca95e1e
patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
142 colnr_T start_col; |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
143 |
25302
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
144 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
|
145 && (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
|
146 || 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
|
147 || 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
|
148 return; |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
149 |
15251
17525ca95e1e
patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
150 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
|
151 start_col = tv_get_number(&argvars[1]); |
29994
86eb4aba16c3
patch 9.0.0335: checks for Dictionary argument often give a vague error
Bram Moolenaar <Bram@vim.org>
parents:
29826
diff
changeset
|
152 if (check_for_dict_arg(argvars, 2) == FAIL) |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
153 return; |
16811
0457d49eb2d9
patch 8.1.1407: popup_create() does not support text properties
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
154 |
29451
057c26b5c33a
patch 9.0.0067: cannot show virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
155 rettv->vval.v_number = prop_add_common(start_lnum, start_col, |
057c26b5c33a
patch 9.0.0067: cannot show virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
156 argvars[2].vval.v_dict, curbuf, &argvars[2]); |
16811
0457d49eb2d9
patch 8.1.1407: popup_create() does not support text properties
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
157 } |
0457d49eb2d9
patch 8.1.1407: popup_create() does not support text properties
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
158 |
0457d49eb2d9
patch 8.1.1407: popup_create() does not support text properties
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
159 /* |
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
|
160 * 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
|
161 * at [start_lnum, start_col] and ending at [end_lnum, end_col] in |
29451
057c26b5c33a
patch 9.0.0067: cannot show virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
162 * the buffer "buf" and assign identifier "id". |
057c26b5c33a
patch 9.0.0067: cannot show virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
163 * When "text" is not NULL add it to buf->b_textprop_text[-id - 1]. |
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
|
164 */ |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
165 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
|
166 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
|
167 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
|
168 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
|
169 int id, |
29451
057c26b5c33a
patch 9.0.0067: cannot show virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
170 char_u *text_arg, |
29816
bbe62ea78aac
patch 9.0.0247: cannot add padding to virtual text without highlight
Bram Moolenaar <Bram@vim.org>
parents:
29788
diff
changeset
|
171 int text_padding_left, |
29560
14b139cbec49
patch 9.0.0121: cannot put virtual text after or below a line
Bram Moolenaar <Bram@vim.org>
parents:
29552
diff
changeset
|
172 int text_flags, |
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
|
173 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
|
174 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
|
175 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
|
176 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
|
177 { |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
178 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
|
179 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
|
180 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
|
181 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
|
182 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
|
183 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
|
184 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
|
185 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
|
186 textprop_T tmp_prop; |
29451
057c26b5c33a
patch 9.0.0067: cannot show virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
187 char_u *text = text_arg; |
057c26b5c33a
patch 9.0.0067: cannot show virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
188 int res = FAIL; |
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
|
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 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
|
191 if (type == NULL) |
29451
057c26b5c33a
patch 9.0.0067: cannot show virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
192 goto theend; |
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
|
193 |
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 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
|
195 { |
26775
2df40c348c70
patch 8.2.3916: no error for passing an invalid line number to append()
Bram Moolenaar <Bram@vim.org>
parents:
26242
diff
changeset
|
196 semsg(_(e_invalid_line_number_nr), (long)start_lnum); |
29451
057c26b5c33a
patch 9.0.0067: cannot show virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
197 goto theend; |
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
|
198 } |
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 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
|
200 { |
26775
2df40c348c70
patch 8.2.3916: no error for passing an invalid line number to append()
Bram Moolenaar <Bram@vim.org>
parents:
26242
diff
changeset
|
201 semsg(_(e_invalid_line_number_nr), (long)end_lnum); |
29451
057c26b5c33a
patch 9.0.0067: cannot show virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
202 goto theend; |
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
|
203 } |
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 |
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 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
|
206 { |
26897
d02d40f0261c
patch 8.2.3977: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
207 emsg(_(e_cannot_add_text_property_to_unloaded_buffer)); |
29451
057c26b5c33a
patch 9.0.0067: cannot show virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
208 goto theend; |
057c26b5c33a
patch 9.0.0067: cannot show virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
209 } |
057c26b5c33a
patch 9.0.0067: cannot show virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
210 |
057c26b5c33a
patch 9.0.0067: cannot show virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
211 if (text != NULL) |
057c26b5c33a
patch 9.0.0067: cannot show virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
212 { |
29581
4a79bca8a76e
patch 9.0.0131: virtual text with Tab is not displayed correctly
Bram Moolenaar <Bram@vim.org>
parents:
29560
diff
changeset
|
213 garray_T *gap = &buf->b_textprop_text; |
4a79bca8a76e
patch 9.0.0131: virtual text with Tab is not displayed correctly
Bram Moolenaar <Bram@vim.org>
parents:
29560
diff
changeset
|
214 char_u *p; |
29451
057c26b5c33a
patch 9.0.0067: cannot show virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
215 |
057c26b5c33a
patch 9.0.0067: cannot show virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
216 // double check we got the right ID |
057c26b5c33a
patch 9.0.0067: cannot show virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
217 if (-id - 1 != gap->ga_len) |
057c26b5c33a
patch 9.0.0067: cannot show virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
218 iemsg("text prop ID mismatch"); |
057c26b5c33a
patch 9.0.0067: cannot show virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
219 if (gap->ga_growsize == 0) |
057c26b5c33a
patch 9.0.0067: cannot show virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
220 ga_init2(gap, sizeof(char *), 50); |
057c26b5c33a
patch 9.0.0067: cannot show virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
221 if (ga_grow(gap, 1) == FAIL) |
057c26b5c33a
patch 9.0.0067: cannot show virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
222 goto theend; |
057c26b5c33a
patch 9.0.0067: cannot show virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
223 ((char_u **)gap->ga_data)[gap->ga_len++] = text; |
29581
4a79bca8a76e
patch 9.0.0131: virtual text with Tab is not displayed correctly
Bram Moolenaar <Bram@vim.org>
parents:
29560
diff
changeset
|
224 |
29607
33d7c1fa2dac
patch 9.0.0144: text property cannot override 'cursorline' highlight
Bram Moolenaar <Bram@vim.org>
parents:
29585
diff
changeset
|
225 // change any control character (Tab, Newline, etc.) to a Space to make |
33d7c1fa2dac
patch 9.0.0144: text property cannot override 'cursorline' highlight
Bram Moolenaar <Bram@vim.org>
parents:
29585
diff
changeset
|
226 // it simpler to compute the size |
29581
4a79bca8a76e
patch 9.0.0131: virtual text with Tab is not displayed correctly
Bram Moolenaar <Bram@vim.org>
parents:
29560
diff
changeset
|
227 for (p = text; *p != NUL; MB_PTR_ADV(p)) |
29607
33d7c1fa2dac
patch 9.0.0144: text property cannot override 'cursorline' highlight
Bram Moolenaar <Bram@vim.org>
parents:
29585
diff
changeset
|
228 if (*p < ' ') |
29581
4a79bca8a76e
patch 9.0.0131: virtual text with Tab is not displayed correctly
Bram Moolenaar <Bram@vim.org>
parents:
29560
diff
changeset
|
229 *p = ' '; |
29451
057c26b5c33a
patch 9.0.0067: cannot show virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
230 text = NULL; |
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
|
231 } |
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 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
|
234 { |
30233
8d660a45299f
patch 9.0.0452: Visual highlighting extends into virtual text prop
Bram Moolenaar <Bram@vim.org>
parents:
30231
diff
changeset
|
235 colnr_T col; // start column use in tp_col |
8d660a45299f
patch 9.0.0452: Visual highlighting extends into virtual text prop
Bram Moolenaar <Bram@vim.org>
parents:
30231
diff
changeset
|
236 colnr_T sort_col; // column where it appears |
8d660a45299f
patch 9.0.0452: Visual highlighting extends into virtual text prop
Bram Moolenaar <Bram@vim.org>
parents:
30231
diff
changeset
|
237 long length; // in bytes |
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
|
238 |
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 // 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
|
240 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
|
241 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
|
242 |
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 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
|
244 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
|
245 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
|
246 col = 1; |
29560
14b139cbec49
patch 9.0.0121: cannot put virtual text after or below a line
Bram Moolenaar <Bram@vim.org>
parents:
29552
diff
changeset
|
247 if (col - 1 > (colnr_T)textlen && !(col == 0 && text_arg != NULL)) |
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
|
248 { |
26775
2df40c348c70
patch 8.2.3916: no error for passing an invalid line number to append()
Bram Moolenaar <Bram@vim.org>
parents:
26242
diff
changeset
|
249 semsg(_(e_invalid_column_number_nr), (long)start_col); |
29451
057c26b5c33a
patch 9.0.0067: cannot show virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
250 goto theend; |
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
|
251 } |
30233
8d660a45299f
patch 9.0.0452: Visual highlighting extends into virtual text prop
Bram Moolenaar <Bram@vim.org>
parents:
30231
diff
changeset
|
252 sort_col = col; |
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
|
253 |
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 (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
|
255 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
|
256 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
|
257 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
|
258 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
|
259 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
|
260 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
|
261 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
|
262 |
29560
14b139cbec49
patch 9.0.0121: cannot put virtual text after or below a line
Bram Moolenaar <Bram@vim.org>
parents:
29552
diff
changeset
|
263 if (text_arg != NULL) |
14b139cbec49
patch 9.0.0121: cannot put virtual text after or below a line
Bram Moolenaar <Bram@vim.org>
parents:
29552
diff
changeset
|
264 { |
14b139cbec49
patch 9.0.0121: cannot put virtual text after or below a line
Bram Moolenaar <Bram@vim.org>
parents:
29552
diff
changeset
|
265 length = 1; // text is placed on one character |
14b139cbec49
patch 9.0.0121: cannot put virtual text after or below a line
Bram Moolenaar <Bram@vim.org>
parents:
29552
diff
changeset
|
266 if (col == 0) |
29816
bbe62ea78aac
patch 9.0.0247: cannot add padding to virtual text without highlight
Bram Moolenaar <Bram@vim.org>
parents:
29788
diff
changeset
|
267 { |
30233
8d660a45299f
patch 9.0.0452: Visual highlighting extends into virtual text prop
Bram Moolenaar <Bram@vim.org>
parents:
30231
diff
changeset
|
268 col = MAXCOL; // before or after the line |
8d660a45299f
patch 9.0.0452: Visual highlighting extends into virtual text prop
Bram Moolenaar <Bram@vim.org>
parents:
30231
diff
changeset
|
269 if ((text_flags & TP_FLAG_ALIGN_ABOVE) == 0) |
8d660a45299f
patch 9.0.0452: Visual highlighting extends into virtual text prop
Bram Moolenaar <Bram@vim.org>
parents:
30231
diff
changeset
|
270 sort_col = MAXCOL; |
29816
bbe62ea78aac
patch 9.0.0247: cannot add padding to virtual text without highlight
Bram Moolenaar <Bram@vim.org>
parents:
29788
diff
changeset
|
271 length += text_padding_left; |
bbe62ea78aac
patch 9.0.0247: cannot add padding to virtual text without highlight
Bram Moolenaar <Bram@vim.org>
parents:
29788
diff
changeset
|
272 } |
29560
14b139cbec49
patch 9.0.0121: cannot put virtual text after or below a line
Bram Moolenaar <Bram@vim.org>
parents:
29552
diff
changeset
|
273 } |
14b139cbec49
patch 9.0.0121: cannot put virtual text after or below a line
Bram Moolenaar <Bram@vim.org>
parents:
29552
diff
changeset
|
274 |
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
|
275 // 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
|
276 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
|
277 if (newtext == NULL) |
29451
057c26b5c33a
patch 9.0.0067: cannot show virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
278 goto theend; |
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
|
279 // 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
|
280 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
|
281 |
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 // 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
|
283 // 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
|
284 // 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
|
285 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
|
286 { |
30233
8d660a45299f
patch 9.0.0452: Visual highlighting extends into virtual text prop
Bram Moolenaar <Bram@vim.org>
parents:
30231
diff
changeset
|
287 colnr_T prop_col; |
8d660a45299f
patch 9.0.0452: Visual highlighting extends into virtual text prop
Bram Moolenaar <Bram@vim.org>
parents:
30231
diff
changeset
|
288 |
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
|
289 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
|
290 sizeof(textprop_T)); |
30233
8d660a45299f
patch 9.0.0452: Visual highlighting extends into virtual text prop
Bram Moolenaar <Bram@vim.org>
parents:
30231
diff
changeset
|
291 // col is MAXCOL when the text goes above or after the line, when |
8d660a45299f
patch 9.0.0452: Visual highlighting extends into virtual text prop
Bram Moolenaar <Bram@vim.org>
parents:
30231
diff
changeset
|
292 // above we should use column zero for sorting |
8d660a45299f
patch 9.0.0452: Visual highlighting extends into virtual text prop
Bram Moolenaar <Bram@vim.org>
parents:
30231
diff
changeset
|
293 prop_col = (tmp_prop.tp_flags & TP_FLAG_ALIGN_ABOVE) |
8d660a45299f
patch 9.0.0452: Visual highlighting extends into virtual text prop
Bram Moolenaar <Bram@vim.org>
parents:
30231
diff
changeset
|
294 ? 0 : tmp_prop.tp_col; |
8d660a45299f
patch 9.0.0452: Visual highlighting extends into virtual text prop
Bram Moolenaar <Bram@vim.org>
parents:
30231
diff
changeset
|
295 if (prop_col >= sort_col) |
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
|
296 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
|
297 } |
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 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
|
299 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
|
300 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
|
301 |
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 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
|
303 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
|
304 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
|
305 tmp_prop.tp_type = type->pt_id; |
29560
14b139cbec49
patch 9.0.0121: cannot put virtual text after or below a line
Bram Moolenaar <Bram@vim.org>
parents:
29552
diff
changeset
|
306 tmp_prop.tp_flags = text_flags |
14b139cbec49
patch 9.0.0121: cannot put virtual text after or below a line
Bram Moolenaar <Bram@vim.org>
parents:
29552
diff
changeset
|
307 | (lnum > start_lnum ? TP_FLAG_CONT_PREV : 0) |
29730
0eeab24d3faf
patch 9.0.0205: cursor in wrong position when inserting after virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29720
diff
changeset
|
308 | (lnum < end_lnum ? TP_FLAG_CONT_NEXT : 0) |
0eeab24d3faf
patch 9.0.0205: cursor in wrong position when inserting after virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29720
diff
changeset
|
309 | ((type->pt_flags & PT_FLAG_INS_START_INCL) |
0eeab24d3faf
patch 9.0.0205: cursor in wrong position when inserting after virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29720
diff
changeset
|
310 ? TP_FLAG_START_INCL : 0); |
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
|
311 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
|
312 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
|
313 |
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 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
|
315 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
|
316 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
|
317 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
|
318 |
29340
fba9e366ced4
patch 9.0.0013: reproducing memory access errors can be difficult
Bram Moolenaar <Bram@vim.org>
parents:
29175
diff
changeset
|
319 if (buf->b_ml.ml_flags & (ML_LINE_DIRTY | ML_ALLOCATED)) |
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
|
320 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
|
321 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
|
322 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
|
323 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
|
324 } |
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 |
29708
d97b2ce26258
patch 9.0.0194: cursor displayed in wrong position after removing text prop
Bram Moolenaar <Bram@vim.org>
parents:
29696
diff
changeset
|
326 changed_line_display_buf(buf); |
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
|
327 changed_lines_buf(buf, start_lnum, end_lnum + 1, 0); |
29451
057c26b5c33a
patch 9.0.0067: cannot show virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
328 res = OK; |
057c26b5c33a
patch 9.0.0067: cannot show virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
329 |
057c26b5c33a
patch 9.0.0067: cannot show virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
330 theend: |
057c26b5c33a
patch 9.0.0067: cannot show virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
331 vim_free(text); |
057c26b5c33a
patch 9.0.0067: cannot show virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
332 return res; |
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
|
333 } |
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 |
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 * 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
|
337 * 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
|
338 * {'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
|
339 * 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
|
340 * 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
|
341 */ |
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 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
|
343 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
|
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 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
|
346 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
|
347 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
|
348 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
|
349 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
|
350 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
|
351 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
|
352 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
|
353 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
|
354 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
|
355 int error = FALSE; |
30811
c02b74b87608
patch 9.0.0740: prop_add_list() gives multiple errors for invalid argument
Bram Moolenaar <Bram@vim.org>
parents:
30306
diff
changeset
|
356 int prev_did_emsg = did_emsg; |
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
|
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 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
|
359 || 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
|
360 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
|
361 |
30015
adb0de8be4ce
patch 9.0.0345: error message for list argument could be clearer
Bram Moolenaar <Bram@vim.org>
parents:
29994
diff
changeset
|
362 if (check_for_nonnull_list_arg(argvars, 1) == FAIL) |
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
|
363 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
|
364 |
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 dict = argvars[0].vval.v_dict; |
28315
62cc3b60493b
patch 8.2.4683: verbose check with dict_find() to see if a key is present
Bram Moolenaar <Bram@vim.org>
parents:
26966
diff
changeset
|
366 if (dict == NULL || !dict_has_key(dict, "type")) |
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
|
367 { |
26966
ac75c145f0a9
patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26962
diff
changeset
|
368 emsg(_(e_missing_property_type_name)); |
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
|
369 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
|
370 } |
29442
827d9f2b7a71
patch 9.0.0063: too many type casts for dict_get functions
Bram Moolenaar <Bram@vim.org>
parents:
29340
diff
changeset
|
371 type_name = dict_get_string(dict, "type", FALSE); |
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
|
372 |
28315
62cc3b60493b
patch 8.2.4683: verbose check with dict_find() to see if a key is present
Bram Moolenaar <Bram@vim.org>
parents:
26966
diff
changeset
|
373 if (dict_has_key(dict, "id")) |
29442
827d9f2b7a71
patch 9.0.0063: too many type casts for dict_get functions
Bram Moolenaar <Bram@vim.org>
parents:
29340
diff
changeset
|
374 id = dict_get_number(dict, "id"); |
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
|
375 |
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 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
|
377 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
|
378 |
28984
b3828315a0d9
patch 8.2.5014: byte offsets are wrong when using text properties
Bram Moolenaar <Bram@vim.org>
parents:
28863
diff
changeset
|
379 // This must be done _before_ we start adding properties because property |
b3828315a0d9
patch 8.2.5014: byte offsets are wrong when using text properties
Bram Moolenaar <Bram@vim.org>
parents:
28863
diff
changeset
|
380 // changes trigger buffer (memline) reorganisation, which needs this flag |
b3828315a0d9
patch 8.2.5014: byte offsets are wrong when using text properties
Bram Moolenaar <Bram@vim.org>
parents:
28863
diff
changeset
|
381 // to be correctly set. |
b3828315a0d9
patch 8.2.5014: byte offsets are wrong when using text properties
Bram Moolenaar <Bram@vim.org>
parents:
28863
diff
changeset
|
382 buf->b_has_textprop = TRUE; // this is never reset |
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
|
383 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
|
384 { |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
385 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
|
386 { |
26877
06a137af96f8
patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26865
diff
changeset
|
387 emsg(_(e_list_required)); |
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
|
388 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
|
389 } |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
390 |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
391 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
|
392 start_lnum = list_find_nr(pos_list, 0L, &error); |
30811
c02b74b87608
patch 9.0.0740: prop_add_list() gives multiple errors for invalid argument
Bram Moolenaar <Bram@vim.org>
parents:
30306
diff
changeset
|
393 if (!error) |
c02b74b87608
patch 9.0.0740: prop_add_list() gives multiple errors for invalid argument
Bram Moolenaar <Bram@vim.org>
parents:
30306
diff
changeset
|
394 start_col = list_find_nr(pos_list, 1L, &error); |
c02b74b87608
patch 9.0.0740: prop_add_list() gives multiple errors for invalid argument
Bram Moolenaar <Bram@vim.org>
parents:
30306
diff
changeset
|
395 if (!error) |
c02b74b87608
patch 9.0.0740: prop_add_list() gives multiple errors for invalid argument
Bram Moolenaar <Bram@vim.org>
parents:
30306
diff
changeset
|
396 end_lnum = list_find_nr(pos_list, 2L, &error); |
c02b74b87608
patch 9.0.0740: prop_add_list() gives multiple errors for invalid argument
Bram Moolenaar <Bram@vim.org>
parents:
30306
diff
changeset
|
397 if (!error) |
c02b74b87608
patch 9.0.0740: prop_add_list() gives multiple errors for invalid argument
Bram Moolenaar <Bram@vim.org>
parents:
30306
diff
changeset
|
398 end_col = list_find_nr(pos_list, 3L, &error); |
30813
f4956427ee9e
patch 9.0.0741: cannot specify an ID for each item with prop_add_list()
Bram Moolenaar <Bram@vim.org>
parents:
30811
diff
changeset
|
399 int this_id = id; |
f4956427ee9e
patch 9.0.0741: cannot specify an ID for each item with prop_add_list()
Bram Moolenaar <Bram@vim.org>
parents:
30811
diff
changeset
|
400 if (!error && pos_list->lv_len > 4) |
f4956427ee9e
patch 9.0.0741: cannot specify an ID for each item with prop_add_list()
Bram Moolenaar <Bram@vim.org>
parents:
30811
diff
changeset
|
401 this_id = list_find_nr(pos_list, 4L, &error); |
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
|
402 if (error || start_lnum <= 0 || start_col <= 0 |
30811
c02b74b87608
patch 9.0.0740: prop_add_list() gives multiple errors for invalid argument
Bram Moolenaar <Bram@vim.org>
parents:
30306
diff
changeset
|
403 || end_lnum <= 0 || end_col <= 0) |
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
|
404 { |
30811
c02b74b87608
patch 9.0.0740: prop_add_list() gives multiple errors for invalid argument
Bram Moolenaar <Bram@vim.org>
parents:
30306
diff
changeset
|
405 if (prev_did_emsg == did_emsg) |
c02b74b87608
patch 9.0.0740: prop_add_list() gives multiple errors for invalid argument
Bram Moolenaar <Bram@vim.org>
parents:
30306
diff
changeset
|
406 emsg(_(e_invalid_argument)); |
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
|
407 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
|
408 } |
30813
f4956427ee9e
patch 9.0.0741: cannot specify an ID for each item with prop_add_list()
Bram Moolenaar <Bram@vim.org>
parents:
30811
diff
changeset
|
409 if (prop_add_one(buf, type_name, this_id, NULL, 0, 0, |
f4956427ee9e
patch 9.0.0741: cannot specify an ID for each item with prop_add_list()
Bram Moolenaar <Bram@vim.org>
parents:
30811
diff
changeset
|
410 start_lnum, end_lnum, start_col, end_col) == FAIL) |
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
|
411 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
|
412 } |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
413 |
29732
89e1d67814a9
patch 9.0.0206: redraw flags are not named specifically
Bram Moolenaar <Bram@vim.org>
parents:
29730
diff
changeset
|
414 redraw_buf_later(buf, UPD_VALID); |
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
|
415 } |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
416 |
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25471
diff
changeset
|
417 /* |
29451
057c26b5c33a
patch 9.0.0067: cannot show virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
418 * Get the next ID to use for a textprop with text in buffer "buf". |
057c26b5c33a
patch 9.0.0067: cannot show virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
419 */ |
057c26b5c33a
patch 9.0.0067: cannot show virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
420 static int |
057c26b5c33a
patch 9.0.0067: cannot show virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
421 get_textprop_id(buf_T *buf) |
057c26b5c33a
patch 9.0.0067: cannot show virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
422 { |
057c26b5c33a
patch 9.0.0067: cannot show virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
423 // TODO: recycle deleted entries |
057c26b5c33a
patch 9.0.0067: cannot show virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
424 return -(buf->b_textprop_text.ga_len + 1); |
057c26b5c33a
patch 9.0.0067: cannot show virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
425 } |
057c26b5c33a
patch 9.0.0067: cannot show virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
426 |
057c26b5c33a
patch 9.0.0067: cannot show virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
427 /* |
16811
0457d49eb2d9
patch 8.1.1407: popup_create() does not support text properties
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
428 * 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
|
429 * "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
|
430 * it is NULL for popup_create(). |
29451
057c26b5c33a
patch 9.0.0067: cannot show virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
431 * Returns the "id" used for "text" or zero. |
16811
0457d49eb2d9
patch 8.1.1407: popup_create() does not support text properties
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
432 */ |
29451
057c26b5c33a
patch 9.0.0067: cannot show virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
433 int |
16811
0457d49eb2d9
patch 8.1.1407: popup_create() does not support text properties
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
434 prop_add_common( |
0457d49eb2d9
patch 8.1.1407: popup_create() does not support text properties
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
435 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
|
436 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
|
437 dict_T *dict, |
0457d49eb2d9
patch 8.1.1407: popup_create() does not support text properties
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
438 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
|
439 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
|
440 { |
0457d49eb2d9
patch 8.1.1407: popup_create() does not support text properties
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
441 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
|
442 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
|
443 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
|
444 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
|
445 int id = 0; |
29451
057c26b5c33a
patch 9.0.0067: cannot show virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
446 char_u *text = NULL; |
29816
bbe62ea78aac
patch 9.0.0247: cannot add padding to virtual text without highlight
Bram Moolenaar <Bram@vim.org>
parents:
29788
diff
changeset
|
447 int text_padding_left = 0; |
29560
14b139cbec49
patch 9.0.0121: cannot put virtual text after or below a line
Bram Moolenaar <Bram@vim.org>
parents:
29552
diff
changeset
|
448 int flags = 0; |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
449 |
28315
62cc3b60493b
patch 8.2.4683: verbose check with dict_find() to see if a key is present
Bram Moolenaar <Bram@vim.org>
parents:
26966
diff
changeset
|
450 if (dict == NULL || !dict_has_key(dict, "type")) |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
451 { |
26966
ac75c145f0a9
patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26962
diff
changeset
|
452 emsg(_(e_missing_property_type_name)); |
29451
057c26b5c33a
patch 9.0.0067: cannot show virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
453 goto theend; |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
454 } |
29442
827d9f2b7a71
patch 9.0.0063: too many type casts for dict_get functions
Bram Moolenaar <Bram@vim.org>
parents:
29340
diff
changeset
|
455 type_name = dict_get_string(dict, "type", FALSE); |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
456 |
28315
62cc3b60493b
patch 8.2.4683: verbose check with dict_find() to see if a key is present
Bram Moolenaar <Bram@vim.org>
parents:
26966
diff
changeset
|
457 if (dict_has_key(dict, "end_lnum")) |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
458 { |
29442
827d9f2b7a71
patch 9.0.0063: too many type casts for dict_get functions
Bram Moolenaar <Bram@vim.org>
parents:
29340
diff
changeset
|
459 end_lnum = dict_get_number(dict, "end_lnum"); |
15251
17525ca95e1e
patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
460 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
|
461 { |
26865
bce848ec8b1b
patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26775
diff
changeset
|
462 semsg(_(e_invalid_value_for_argument_str), "end_lnum"); |
29451
057c26b5c33a
patch 9.0.0067: cannot show virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
463 goto theend; |
15251
17525ca95e1e
patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
464 } |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
465 } |
15251
17525ca95e1e
patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
466 else |
17525ca95e1e
patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
467 end_lnum = start_lnum; |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
468 |
28315
62cc3b60493b
patch 8.2.4683: verbose check with dict_find() to see if a key is present
Bram Moolenaar <Bram@vim.org>
parents:
26966
diff
changeset
|
469 if (dict_has_key(dict, "length")) |
15251
17525ca95e1e
patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
470 { |
29442
827d9f2b7a71
patch 9.0.0063: too many type casts for dict_get functions
Bram Moolenaar <Bram@vim.org>
parents:
29340
diff
changeset
|
471 long length = dict_get_number(dict, "length"); |
15251
17525ca95e1e
patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
472 |
15335
18c20ceee4b5
patch 8.1.0675: text property column in screen columns is not practical
Bram Moolenaar <Bram@vim.org>
parents:
15294
diff
changeset
|
473 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
|
474 { |
26865
bce848ec8b1b
patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26775
diff
changeset
|
475 semsg(_(e_invalid_value_for_argument_str), "length"); |
29451
057c26b5c33a
patch 9.0.0067: cannot show virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
476 goto theend; |
15251
17525ca95e1e
patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
477 } |
15335
18c20ceee4b5
patch 8.1.0675: text property column in screen columns is not practical
Bram Moolenaar <Bram@vim.org>
parents:
15294
diff
changeset
|
478 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
|
479 } |
28315
62cc3b60493b
patch 8.2.4683: verbose check with dict_find() to see if a key is present
Bram Moolenaar <Bram@vim.org>
parents:
26966
diff
changeset
|
480 else if (dict_has_key(dict, "end_col")) |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
481 { |
29442
827d9f2b7a71
patch 9.0.0063: too many type casts for dict_get functions
Bram Moolenaar <Bram@vim.org>
parents:
29340
diff
changeset
|
482 end_col = dict_get_number(dict, "end_col"); |
15251
17525ca95e1e
patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
483 if (end_col <= 0) |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
484 { |
26865
bce848ec8b1b
patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26775
diff
changeset
|
485 semsg(_(e_invalid_value_for_argument_str), "end_col"); |
29451
057c26b5c33a
patch 9.0.0067: cannot show virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
486 goto theend; |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
487 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
488 } |
15251
17525ca95e1e
patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
489 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
|
490 end_col = start_col; |
17525ca95e1e
patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
491 else |
17525ca95e1e
patch 8.1.0634: text properties cannot cross line boundaries
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
492 end_col = 1; |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
493 |
28315
62cc3b60493b
patch 8.2.4683: verbose check with dict_find() to see if a key is present
Bram Moolenaar <Bram@vim.org>
parents:
26966
diff
changeset
|
494 if (dict_has_key(dict, "id")) |
29442
827d9f2b7a71
patch 9.0.0063: too many type casts for dict_get functions
Bram Moolenaar <Bram@vim.org>
parents:
29340
diff
changeset
|
495 id = dict_get_number(dict, "id"); |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
496 |
29451
057c26b5c33a
patch 9.0.0067: cannot show virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
497 if (dict_has_key(dict, "text")) |
057c26b5c33a
patch 9.0.0067: cannot show virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
498 { |
30306
43d942ff32ce
patch 9.0.0489: using "end_lnum" with virtual text causes problems
Bram Moolenaar <Bram@vim.org>
parents:
30261
diff
changeset
|
499 if (dict_has_key(dict, "length") |
43d942ff32ce
patch 9.0.0489: using "end_lnum" with virtual text causes problems
Bram Moolenaar <Bram@vim.org>
parents:
30261
diff
changeset
|
500 || dict_has_key(dict, "end_col") |
43d942ff32ce
patch 9.0.0489: using "end_lnum" with virtual text causes problems
Bram Moolenaar <Bram@vim.org>
parents:
30261
diff
changeset
|
501 || dict_has_key(dict, "end_lnum")) |
43d942ff32ce
patch 9.0.0489: using "end_lnum" with virtual text causes problems
Bram Moolenaar <Bram@vim.org>
parents:
30261
diff
changeset
|
502 { |
43d942ff32ce
patch 9.0.0489: using "end_lnum" with virtual text causes problems
Bram Moolenaar <Bram@vim.org>
parents:
30261
diff
changeset
|
503 emsg(_(e_cannot_use_length_endcol_and_endlnum_with_text)); |
43d942ff32ce
patch 9.0.0489: using "end_lnum" with virtual text causes problems
Bram Moolenaar <Bram@vim.org>
parents:
30261
diff
changeset
|
504 goto theend; |
43d942ff32ce
patch 9.0.0489: using "end_lnum" with virtual text causes problems
Bram Moolenaar <Bram@vim.org>
parents:
30261
diff
changeset
|
505 } |
43d942ff32ce
patch 9.0.0489: using "end_lnum" with virtual text causes problems
Bram Moolenaar <Bram@vim.org>
parents:
30261
diff
changeset
|
506 |
29451
057c26b5c33a
patch 9.0.0067: cannot show virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
507 text = dict_get_string(dict, "text", TRUE); |
057c26b5c33a
patch 9.0.0067: cannot show virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
508 if (text == NULL) |
057c26b5c33a
patch 9.0.0067: cannot show virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
509 goto theend; |
057c26b5c33a
patch 9.0.0067: cannot show virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
510 // use a default length of 1 to make multiple props show up |
057c26b5c33a
patch 9.0.0067: cannot show virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
511 end_col = start_col + 1; |
29560
14b139cbec49
patch 9.0.0121: cannot put virtual text after or below a line
Bram Moolenaar <Bram@vim.org>
parents:
29552
diff
changeset
|
512 |
14b139cbec49
patch 9.0.0121: cannot put virtual text after or below a line
Bram Moolenaar <Bram@vim.org>
parents:
29552
diff
changeset
|
513 if (dict_has_key(dict, "text_align")) |
14b139cbec49
patch 9.0.0121: cannot put virtual text after or below a line
Bram Moolenaar <Bram@vim.org>
parents:
29552
diff
changeset
|
514 { |
14b139cbec49
patch 9.0.0121: cannot put virtual text after or below a line
Bram Moolenaar <Bram@vim.org>
parents:
29552
diff
changeset
|
515 char_u *p = dict_get_string(dict, "text_align", FALSE); |
14b139cbec49
patch 9.0.0121: cannot put virtual text after or below a line
Bram Moolenaar <Bram@vim.org>
parents:
29552
diff
changeset
|
516 |
14b139cbec49
patch 9.0.0121: cannot put virtual text after or below a line
Bram Moolenaar <Bram@vim.org>
parents:
29552
diff
changeset
|
517 if (p == NULL) |
14b139cbec49
patch 9.0.0121: cannot put virtual text after or below a line
Bram Moolenaar <Bram@vim.org>
parents:
29552
diff
changeset
|
518 goto theend; |
29696
c1c599a367d4
patch 9.0.0188: strange effects when using "text_align" with non-zero column
Bram Moolenaar <Bram@vim.org>
parents:
29664
diff
changeset
|
519 if (start_col != 0) |
c1c599a367d4
patch 9.0.0188: strange effects when using "text_align" with non-zero column
Bram Moolenaar <Bram@vim.org>
parents:
29664
diff
changeset
|
520 { |
c1c599a367d4
patch 9.0.0188: strange effects when using "text_align" with non-zero column
Bram Moolenaar <Bram@vim.org>
parents:
29664
diff
changeset
|
521 emsg(_(e_can_only_use_text_align_when_column_is_zero)); |
c1c599a367d4
patch 9.0.0188: strange effects when using "text_align" with non-zero column
Bram Moolenaar <Bram@vim.org>
parents:
29664
diff
changeset
|
522 goto theend; |
c1c599a367d4
patch 9.0.0188: strange effects when using "text_align" with non-zero column
Bram Moolenaar <Bram@vim.org>
parents:
29664
diff
changeset
|
523 } |
29560
14b139cbec49
patch 9.0.0121: cannot put virtual text after or below a line
Bram Moolenaar <Bram@vim.org>
parents:
29552
diff
changeset
|
524 if (STRCMP(p, "right") == 0) |
14b139cbec49
patch 9.0.0121: cannot put virtual text after or below a line
Bram Moolenaar <Bram@vim.org>
parents:
29552
diff
changeset
|
525 flags |= TP_FLAG_ALIGN_RIGHT; |
30205
ed6f3d2593df
patch 9.0.0438: cannot put virtual text above a line
Bram Moolenaar <Bram@vim.org>
parents:
30015
diff
changeset
|
526 else if (STRCMP(p, "above") == 0) |
ed6f3d2593df
patch 9.0.0438: cannot put virtual text above a line
Bram Moolenaar <Bram@vim.org>
parents:
30015
diff
changeset
|
527 flags |= TP_FLAG_ALIGN_ABOVE; |
29560
14b139cbec49
patch 9.0.0121: cannot put virtual text after or below a line
Bram Moolenaar <Bram@vim.org>
parents:
29552
diff
changeset
|
528 else if (STRCMP(p, "below") == 0) |
14b139cbec49
patch 9.0.0121: cannot put virtual text after or below a line
Bram Moolenaar <Bram@vim.org>
parents:
29552
diff
changeset
|
529 flags |= TP_FLAG_ALIGN_BELOW; |
14b139cbec49
patch 9.0.0121: cannot put virtual text after or below a line
Bram Moolenaar <Bram@vim.org>
parents:
29552
diff
changeset
|
530 else if (STRCMP(p, "after") != 0) |
14b139cbec49
patch 9.0.0121: cannot put virtual text after or below a line
Bram Moolenaar <Bram@vim.org>
parents:
29552
diff
changeset
|
531 { |
14b139cbec49
patch 9.0.0121: cannot put virtual text after or below a line
Bram Moolenaar <Bram@vim.org>
parents:
29552
diff
changeset
|
532 semsg(_(e_invalid_value_for_argument_str_str), "text_align", p); |
14b139cbec49
patch 9.0.0121: cannot put virtual text after or below a line
Bram Moolenaar <Bram@vim.org>
parents:
29552
diff
changeset
|
533 goto theend; |
14b139cbec49
patch 9.0.0121: cannot put virtual text after or below a line
Bram Moolenaar <Bram@vim.org>
parents:
29552
diff
changeset
|
534 } |
14b139cbec49
patch 9.0.0121: cannot put virtual text after or below a line
Bram Moolenaar <Bram@vim.org>
parents:
29552
diff
changeset
|
535 } |
14b139cbec49
patch 9.0.0121: cannot put virtual text after or below a line
Bram Moolenaar <Bram@vim.org>
parents:
29552
diff
changeset
|
536 |
29816
bbe62ea78aac
patch 9.0.0247: cannot add padding to virtual text without highlight
Bram Moolenaar <Bram@vim.org>
parents:
29788
diff
changeset
|
537 if (dict_has_key(dict, "text_padding_left")) |
bbe62ea78aac
patch 9.0.0247: cannot add padding to virtual text without highlight
Bram Moolenaar <Bram@vim.org>
parents:
29788
diff
changeset
|
538 { |
bbe62ea78aac
patch 9.0.0247: cannot add padding to virtual text without highlight
Bram Moolenaar <Bram@vim.org>
parents:
29788
diff
changeset
|
539 text_padding_left = dict_get_number(dict, "text_padding_left"); |
bbe62ea78aac
patch 9.0.0247: cannot add padding to virtual text without highlight
Bram Moolenaar <Bram@vim.org>
parents:
29788
diff
changeset
|
540 if (text_padding_left < 0) |
bbe62ea78aac
patch 9.0.0247: cannot add padding to virtual text without highlight
Bram Moolenaar <Bram@vim.org>
parents:
29788
diff
changeset
|
541 { |
bbe62ea78aac
patch 9.0.0247: cannot add padding to virtual text without highlight
Bram Moolenaar <Bram@vim.org>
parents:
29788
diff
changeset
|
542 semsg(_(e_argument_must_be_positive_str), "text_padding_left"); |
bbe62ea78aac
patch 9.0.0247: cannot add padding to virtual text without highlight
Bram Moolenaar <Bram@vim.org>
parents:
29788
diff
changeset
|
543 goto theend; |
bbe62ea78aac
patch 9.0.0247: cannot add padding to virtual text without highlight
Bram Moolenaar <Bram@vim.org>
parents:
29788
diff
changeset
|
544 } |
bbe62ea78aac
patch 9.0.0247: cannot add padding to virtual text without highlight
Bram Moolenaar <Bram@vim.org>
parents:
29788
diff
changeset
|
545 } |
bbe62ea78aac
patch 9.0.0247: cannot add padding to virtual text without highlight
Bram Moolenaar <Bram@vim.org>
parents:
29788
diff
changeset
|
546 |
29560
14b139cbec49
patch 9.0.0121: cannot put virtual text after or below a line
Bram Moolenaar <Bram@vim.org>
parents:
29552
diff
changeset
|
547 if (dict_has_key(dict, "text_wrap")) |
14b139cbec49
patch 9.0.0121: cannot put virtual text after or below a line
Bram Moolenaar <Bram@vim.org>
parents:
29552
diff
changeset
|
548 { |
14b139cbec49
patch 9.0.0121: cannot put virtual text after or below a line
Bram Moolenaar <Bram@vim.org>
parents:
29552
diff
changeset
|
549 char_u *p = dict_get_string(dict, "text_wrap", FALSE); |
29816
bbe62ea78aac
patch 9.0.0247: cannot add padding to virtual text without highlight
Bram Moolenaar <Bram@vim.org>
parents:
29788
diff
changeset
|
550 |
29560
14b139cbec49
patch 9.0.0121: cannot put virtual text after or below a line
Bram Moolenaar <Bram@vim.org>
parents:
29552
diff
changeset
|
551 if (p == NULL) |
14b139cbec49
patch 9.0.0121: cannot put virtual text after or below a line
Bram Moolenaar <Bram@vim.org>
parents:
29552
diff
changeset
|
552 goto theend; |
14b139cbec49
patch 9.0.0121: cannot put virtual text after or below a line
Bram Moolenaar <Bram@vim.org>
parents:
29552
diff
changeset
|
553 if (STRCMP(p, "wrap") == 0) |
14b139cbec49
patch 9.0.0121: cannot put virtual text after or below a line
Bram Moolenaar <Bram@vim.org>
parents:
29552
diff
changeset
|
554 flags |= TP_FLAG_WRAP; |
14b139cbec49
patch 9.0.0121: cannot put virtual text after or below a line
Bram Moolenaar <Bram@vim.org>
parents:
29552
diff
changeset
|
555 else if (STRCMP(p, "truncate") != 0) |
14b139cbec49
patch 9.0.0121: cannot put virtual text after or below a line
Bram Moolenaar <Bram@vim.org>
parents:
29552
diff
changeset
|
556 { |
14b139cbec49
patch 9.0.0121: cannot put virtual text after or below a line
Bram Moolenaar <Bram@vim.org>
parents:
29552
diff
changeset
|
557 semsg(_(e_invalid_value_for_argument_str_str), "text_wrap", p); |
14b139cbec49
patch 9.0.0121: cannot put virtual text after or below a line
Bram Moolenaar <Bram@vim.org>
parents:
29552
diff
changeset
|
558 goto theend; |
14b139cbec49
patch 9.0.0121: cannot put virtual text after or below a line
Bram Moolenaar <Bram@vim.org>
parents:
29552
diff
changeset
|
559 } |
14b139cbec49
patch 9.0.0121: cannot put virtual text after or below a line
Bram Moolenaar <Bram@vim.org>
parents:
29552
diff
changeset
|
560 } |
14b139cbec49
patch 9.0.0121: cannot put virtual text after or below a line
Bram Moolenaar <Bram@vim.org>
parents:
29552
diff
changeset
|
561 } |
14b139cbec49
patch 9.0.0121: cannot put virtual text after or below a line
Bram Moolenaar <Bram@vim.org>
parents:
29552
diff
changeset
|
562 |
14b139cbec49
patch 9.0.0121: cannot put virtual text after or below a line
Bram Moolenaar <Bram@vim.org>
parents:
29552
diff
changeset
|
563 // Column must be 1 or more for a normal text property; when "text" is |
14b139cbec49
patch 9.0.0121: cannot put virtual text after or below a line
Bram Moolenaar <Bram@vim.org>
parents:
29552
diff
changeset
|
564 // present zero means it goes after the line. |
14b139cbec49
patch 9.0.0121: cannot put virtual text after or below a line
Bram Moolenaar <Bram@vim.org>
parents:
29552
diff
changeset
|
565 if (start_col < (text == NULL ? 1 : 0)) |
14b139cbec49
patch 9.0.0121: cannot put virtual text after or below a line
Bram Moolenaar <Bram@vim.org>
parents:
29552
diff
changeset
|
566 { |
14b139cbec49
patch 9.0.0121: cannot put virtual text after or below a line
Bram Moolenaar <Bram@vim.org>
parents:
29552
diff
changeset
|
567 semsg(_(e_invalid_column_number_nr), (long)start_col); |
14b139cbec49
patch 9.0.0121: cannot put virtual text after or below a line
Bram Moolenaar <Bram@vim.org>
parents:
29552
diff
changeset
|
568 goto theend; |
29451
057c26b5c33a
patch 9.0.0067: cannot show virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
569 } |
29816
bbe62ea78aac
patch 9.0.0247: cannot add padding to virtual text without highlight
Bram Moolenaar <Bram@vim.org>
parents:
29788
diff
changeset
|
570 if (start_col > 0 && text_padding_left > 0) |
bbe62ea78aac
patch 9.0.0247: cannot add padding to virtual text without highlight
Bram Moolenaar <Bram@vim.org>
parents:
29788
diff
changeset
|
571 { |
bbe62ea78aac
patch 9.0.0247: cannot add padding to virtual text without highlight
Bram Moolenaar <Bram@vim.org>
parents:
29788
diff
changeset
|
572 emsg(_(e_can_only_use_left_padding_when_column_is_zero)); |
bbe62ea78aac
patch 9.0.0247: cannot add padding to virtual text without highlight
Bram Moolenaar <Bram@vim.org>
parents:
29788
diff
changeset
|
573 goto theend; |
bbe62ea78aac
patch 9.0.0247: cannot add padding to virtual text without highlight
Bram Moolenaar <Bram@vim.org>
parents:
29788
diff
changeset
|
574 } |
29451
057c26b5c33a
patch 9.0.0067: cannot show virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
575 |
16811
0457d49eb2d9
patch 8.1.1407: popup_create() does not support text properties
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
576 if (dict_arg != NULL && get_bufnr_from_arg(dict_arg, &buf) == FAIL) |
29451
057c26b5c33a
patch 9.0.0067: cannot show virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
577 goto theend; |
057c26b5c33a
patch 9.0.0067: cannot show virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
578 |
057c26b5c33a
patch 9.0.0067: cannot show virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
579 if (id < 0 && buf->b_textprop_text.ga_len > 0) |
057c26b5c33a
patch 9.0.0067: cannot show virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
580 { |
057c26b5c33a
patch 9.0.0067: cannot show virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
581 emsg(_(e_cannot_use_negative_id_after_adding_textprop_with_text)); |
057c26b5c33a
patch 9.0.0067: cannot show virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
582 goto theend; |
057c26b5c33a
patch 9.0.0067: cannot show virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
583 } |
057c26b5c33a
patch 9.0.0067: cannot show virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
584 if (text != NULL) |
057c26b5c33a
patch 9.0.0067: cannot show virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
585 id = get_textprop_id(buf); |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
586 |
28984
b3828315a0d9
patch 8.2.5014: byte offsets are wrong when using text properties
Bram Moolenaar <Bram@vim.org>
parents:
28863
diff
changeset
|
587 // This must be done _before_ we add the property because property changes |
b3828315a0d9
patch 8.2.5014: byte offsets are wrong when using text properties
Bram Moolenaar <Bram@vim.org>
parents:
28863
diff
changeset
|
588 // trigger buffer (memline) reorganisation, which needs this flag to be |
b3828315a0d9
patch 8.2.5014: byte offsets are wrong when using text properties
Bram Moolenaar <Bram@vim.org>
parents:
28863
diff
changeset
|
589 // correctly set. |
b3828315a0d9
patch 8.2.5014: byte offsets are wrong when using text properties
Bram Moolenaar <Bram@vim.org>
parents:
28863
diff
changeset
|
590 buf->b_has_textprop = TRUE; // this is never reset |
b3828315a0d9
patch 8.2.5014: byte offsets are wrong when using text properties
Bram Moolenaar <Bram@vim.org>
parents:
28863
diff
changeset
|
591 |
29816
bbe62ea78aac
patch 9.0.0247: cannot add padding to virtual text without highlight
Bram Moolenaar <Bram@vim.org>
parents:
29788
diff
changeset
|
592 prop_add_one(buf, type_name, id, text, text_padding_left, flags, |
29451
057c26b5c33a
patch 9.0.0067: cannot show virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
593 start_lnum, end_lnum, start_col, end_col); |
057c26b5c33a
patch 9.0.0067: cannot show virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
594 text = NULL; |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
595 |
29732
89e1d67814a9
patch 9.0.0206: redraw flags are not named specifically
Bram Moolenaar <Bram@vim.org>
parents:
29730
diff
changeset
|
596 redraw_buf_later(buf, UPD_VALID); |
29451
057c26b5c33a
patch 9.0.0067: cannot show virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
597 |
057c26b5c33a
patch 9.0.0067: cannot show virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
598 theend: |
057c26b5c33a
patch 9.0.0067: cannot show virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
599 vim_free(text); |
057c26b5c33a
patch 9.0.0067: cannot show virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
600 return id; |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
601 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
602 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
603 /* |
15144
7960bf50d345
patch 8.1.0582: text properties are not enabled
Bram Moolenaar <Bram@vim.org>
parents:
15138
diff
changeset
|
604 * 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
|
605 * 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
|
606 * 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
|
607 * pointer). |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
608 */ |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
609 int |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
610 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
|
611 { |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
612 char_u *text; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
613 size_t textlen; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
614 size_t proplen; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
615 |
15255
19e79a1ed6b6
patch 8.1.0636: line2byte() gives wrong values with text properties
Bram Moolenaar <Bram@vim.org>
parents:
15251
diff
changeset
|
616 // 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
|
617 // 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
|
618 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
|
619 return 0; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
620 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
621 // 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
|
622 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
|
623 textlen = STRLEN(text) + 1; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
624 proplen = buf->b_ml.ml_line_len - textlen; |
29653
aa83cf7bef1c
patch 9.0.0167: checking for text properties could be a bit more efficient
Bram Moolenaar <Bram@vim.org>
parents:
29649
diff
changeset
|
625 if (proplen == 0) |
aa83cf7bef1c
patch 9.0.0167: checking for text properties could be a bit more efficient
Bram Moolenaar <Bram@vim.org>
parents:
29649
diff
changeset
|
626 return 0; |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
627 if (proplen % sizeof(textprop_T) != 0) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
628 { |
26966
ac75c145f0a9
patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26962
diff
changeset
|
629 iemsg(_(e_text_property_info_corrupted)); |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
630 return 0; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
631 } |
29653
aa83cf7bef1c
patch 9.0.0167: checking for text properties could be a bit more efficient
Bram Moolenaar <Bram@vim.org>
parents:
29649
diff
changeset
|
632 *props = text + textlen; |
15182
4b2de998ebd6
patch 8.1.0601: a few compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
633 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
|
634 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
635 |
29621
f1ed6f520d09
patch 9.0.0151: a "below" aligned text property does not work with 'nowrap'
Bram Moolenaar <Bram@vim.org>
parents:
29609
diff
changeset
|
636 /* |
30231
0d084880276a
patch 9.0.0451: virtual text "above" does not work with 'nowrap'
Bram Moolenaar <Bram@vim.org>
parents:
30205
diff
changeset
|
637 * Return the number of text properties with "above" or "below" alignment in |
0d084880276a
patch 9.0.0451: virtual text "above" does not work with 'nowrap'
Bram Moolenaar <Bram@vim.org>
parents:
30205
diff
changeset
|
638 * line "lnum". A "right" aligned property also goes below after a "below" or |
0d084880276a
patch 9.0.0451: virtual text "above" does not work with 'nowrap'
Bram Moolenaar <Bram@vim.org>
parents:
30205
diff
changeset
|
639 * other "right" aligned property. |
29621
f1ed6f520d09
patch 9.0.0151: a "below" aligned text property does not work with 'nowrap'
Bram Moolenaar <Bram@vim.org>
parents:
29609
diff
changeset
|
640 */ |
f1ed6f520d09
patch 9.0.0151: a "below" aligned text property does not work with 'nowrap'
Bram Moolenaar <Bram@vim.org>
parents:
29609
diff
changeset
|
641 int |
30231
0d084880276a
patch 9.0.0451: virtual text "above" does not work with 'nowrap'
Bram Moolenaar <Bram@vim.org>
parents:
30205
diff
changeset
|
642 prop_count_above_below(buf_T *buf, linenr_T lnum) |
29621
f1ed6f520d09
patch 9.0.0151: a "below" aligned text property does not work with 'nowrap'
Bram Moolenaar <Bram@vim.org>
parents:
29609
diff
changeset
|
643 { |
f1ed6f520d09
patch 9.0.0151: a "below" aligned text property does not work with 'nowrap'
Bram Moolenaar <Bram@vim.org>
parents:
29609
diff
changeset
|
644 char_u *props; |
f1ed6f520d09
patch 9.0.0151: a "below" aligned text property does not work with 'nowrap'
Bram Moolenaar <Bram@vim.org>
parents:
29609
diff
changeset
|
645 int count = get_text_props(buf, lnum, &props, FALSE); |
f1ed6f520d09
patch 9.0.0151: a "below" aligned text property does not work with 'nowrap'
Bram Moolenaar <Bram@vim.org>
parents:
29609
diff
changeset
|
646 int result = 0; |
f1ed6f520d09
patch 9.0.0151: a "below" aligned text property does not work with 'nowrap'
Bram Moolenaar <Bram@vim.org>
parents:
29609
diff
changeset
|
647 textprop_T prop; |
f1ed6f520d09
patch 9.0.0151: a "below" aligned text property does not work with 'nowrap'
Bram Moolenaar <Bram@vim.org>
parents:
29609
diff
changeset
|
648 int i; |
29720
bf965640744d
patch 9.0.0200: cursor wrong if 'nowrap' and two right aligned text props
Bram Moolenaar <Bram@vim.org>
parents:
29708
diff
changeset
|
649 int next_right_goes_below = FALSE; |
29621
f1ed6f520d09
patch 9.0.0151: a "below" aligned text property does not work with 'nowrap'
Bram Moolenaar <Bram@vim.org>
parents:
29609
diff
changeset
|
650 |
f1ed6f520d09
patch 9.0.0151: a "below" aligned text property does not work with 'nowrap'
Bram Moolenaar <Bram@vim.org>
parents:
29609
diff
changeset
|
651 if (count == 0) |
f1ed6f520d09
patch 9.0.0151: a "below" aligned text property does not work with 'nowrap'
Bram Moolenaar <Bram@vim.org>
parents:
29609
diff
changeset
|
652 return 0; |
f1ed6f520d09
patch 9.0.0151: a "below" aligned text property does not work with 'nowrap'
Bram Moolenaar <Bram@vim.org>
parents:
29609
diff
changeset
|
653 for (i = 0; i < count; ++i) |
f1ed6f520d09
patch 9.0.0151: a "below" aligned text property does not work with 'nowrap'
Bram Moolenaar <Bram@vim.org>
parents:
29609
diff
changeset
|
654 { |
f1ed6f520d09
patch 9.0.0151: a "below" aligned text property does not work with 'nowrap'
Bram Moolenaar <Bram@vim.org>
parents:
29609
diff
changeset
|
655 mch_memmove(&prop, props + i * sizeof(prop), sizeof(prop)); |
31319
243c35fad9cb
patch 9.0.0993: display errors when adding or removing text property type
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
656 if (prop.tp_col == MAXCOL && text_prop_type_valid(buf, &prop)) |
29720
bf965640744d
patch 9.0.0200: cursor wrong if 'nowrap' and two right aligned text props
Bram Moolenaar <Bram@vim.org>
parents:
29708
diff
changeset
|
657 { |
bf965640744d
patch 9.0.0200: cursor wrong if 'nowrap' and two right aligned text props
Bram Moolenaar <Bram@vim.org>
parents:
29708
diff
changeset
|
658 if ((prop.tp_flags & TP_FLAG_ALIGN_BELOW) |
bf965640744d
patch 9.0.0200: cursor wrong if 'nowrap' and two right aligned text props
Bram Moolenaar <Bram@vim.org>
parents:
29708
diff
changeset
|
659 || (next_right_goes_below |
bf965640744d
patch 9.0.0200: cursor wrong if 'nowrap' and two right aligned text props
Bram Moolenaar <Bram@vim.org>
parents:
29708
diff
changeset
|
660 && (prop.tp_flags & TP_FLAG_ALIGN_RIGHT))) |
bf965640744d
patch 9.0.0200: cursor wrong if 'nowrap' and two right aligned text props
Bram Moolenaar <Bram@vim.org>
parents:
29708
diff
changeset
|
661 { |
bf965640744d
patch 9.0.0200: cursor wrong if 'nowrap' and two right aligned text props
Bram Moolenaar <Bram@vim.org>
parents:
29708
diff
changeset
|
662 next_right_goes_below = TRUE; |
bf965640744d
patch 9.0.0200: cursor wrong if 'nowrap' and two right aligned text props
Bram Moolenaar <Bram@vim.org>
parents:
29708
diff
changeset
|
663 ++result; |
bf965640744d
patch 9.0.0200: cursor wrong if 'nowrap' and two right aligned text props
Bram Moolenaar <Bram@vim.org>
parents:
29708
diff
changeset
|
664 } |
30231
0d084880276a
patch 9.0.0451: virtual text "above" does not work with 'nowrap'
Bram Moolenaar <Bram@vim.org>
parents:
30205
diff
changeset
|
665 else if (prop.tp_flags & TP_FLAG_ALIGN_ABOVE) |
0d084880276a
patch 9.0.0451: virtual text "above" does not work with 'nowrap'
Bram Moolenaar <Bram@vim.org>
parents:
30205
diff
changeset
|
666 { |
0d084880276a
patch 9.0.0451: virtual text "above" does not work with 'nowrap'
Bram Moolenaar <Bram@vim.org>
parents:
30205
diff
changeset
|
667 next_right_goes_below = FALSE; |
0d084880276a
patch 9.0.0451: virtual text "above" does not work with 'nowrap'
Bram Moolenaar <Bram@vim.org>
parents:
30205
diff
changeset
|
668 ++result; |
0d084880276a
patch 9.0.0451: virtual text "above" does not work with 'nowrap'
Bram Moolenaar <Bram@vim.org>
parents:
30205
diff
changeset
|
669 } |
29720
bf965640744d
patch 9.0.0200: cursor wrong if 'nowrap' and two right aligned text props
Bram Moolenaar <Bram@vim.org>
parents:
29708
diff
changeset
|
670 else if (prop.tp_flags & TP_FLAG_ALIGN_RIGHT) |
bf965640744d
patch 9.0.0200: cursor wrong if 'nowrap' and two right aligned text props
Bram Moolenaar <Bram@vim.org>
parents:
29708
diff
changeset
|
671 next_right_goes_below = TRUE; |
bf965640744d
patch 9.0.0200: cursor wrong if 'nowrap' and two right aligned text props
Bram Moolenaar <Bram@vim.org>
parents:
29708
diff
changeset
|
672 } |
29621
f1ed6f520d09
patch 9.0.0151: a "below" aligned text property does not work with 'nowrap'
Bram Moolenaar <Bram@vim.org>
parents:
29609
diff
changeset
|
673 } |
f1ed6f520d09
patch 9.0.0151: a "below" aligned text property does not work with 'nowrap'
Bram Moolenaar <Bram@vim.org>
parents:
29609
diff
changeset
|
674 return result; |
f1ed6f520d09
patch 9.0.0151: a "below" aligned text property does not work with 'nowrap'
Bram Moolenaar <Bram@vim.org>
parents:
29609
diff
changeset
|
675 } |
f1ed6f520d09
patch 9.0.0151: a "below" aligned text property does not work with 'nowrap'
Bram Moolenaar <Bram@vim.org>
parents:
29609
diff
changeset
|
676 |
20583
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
677 /** |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
678 * 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
|
679 * 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
|
680 * be considered. |
29627
dd96f3d8ed85
patch 9.0.0154: text properties wrong after splitting a line
Bram Moolenaar <Bram@vim.org>
parents:
29621
diff
changeset
|
681 * When "last_line" is FALSE then text properties after the line are not |
dd96f3d8ed85
patch 9.0.0154: text properties wrong after splitting a line
Bram Moolenaar <Bram@vim.org>
parents:
29621
diff
changeset
|
682 * counted. |
20583
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
683 */ |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
684 int |
29585
e357bc89bb95
patch 9.0.0133: virtual text after line moves to joined line
Bram Moolenaar <Bram@vim.org>
parents:
29581
diff
changeset
|
685 count_props(linenr_T lnum, int only_starting, int last_line) |
20583
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
686 { |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
687 char_u *props; |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
688 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
|
689 int result = proplen; |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
690 int i; |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
691 textprop_T prop; |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
692 |
29585
e357bc89bb95
patch 9.0.0133: virtual text after line moves to joined line
Bram Moolenaar <Bram@vim.org>
parents:
29581
diff
changeset
|
693 for (i = 0; i < proplen; ++i) |
e357bc89bb95
patch 9.0.0133: virtual text after line moves to joined line
Bram Moolenaar <Bram@vim.org>
parents:
29581
diff
changeset
|
694 { |
e357bc89bb95
patch 9.0.0133: virtual text after line moves to joined line
Bram Moolenaar <Bram@vim.org>
parents:
29581
diff
changeset
|
695 mch_memmove(&prop, props + i * sizeof(prop), sizeof(prop)); |
29627
dd96f3d8ed85
patch 9.0.0154: text properties wrong after splitting a line
Bram Moolenaar <Bram@vim.org>
parents:
29621
diff
changeset
|
696 // A prop is dropped when in the first line and it continues from the |
29585
e357bc89bb95
patch 9.0.0133: virtual text after line moves to joined line
Bram Moolenaar <Bram@vim.org>
parents:
29581
diff
changeset
|
697 // previous line, or when not in the last line and it is virtual text |
e357bc89bb95
patch 9.0.0133: virtual text after line moves to joined line
Bram Moolenaar <Bram@vim.org>
parents:
29581
diff
changeset
|
698 // after the line. |
e357bc89bb95
patch 9.0.0133: virtual text after line moves to joined line
Bram Moolenaar <Bram@vim.org>
parents:
29581
diff
changeset
|
699 if ((only_starting && (prop.tp_flags & TP_FLAG_CONT_PREV)) |
31319
243c35fad9cb
patch 9.0.0993: display errors when adding or removing text property type
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
700 || (!last_line && prop.tp_col == MAXCOL) |
243c35fad9cb
patch 9.0.0993: display errors when adding or removing text property type
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
701 || !text_prop_type_valid(curbuf, &prop)) |
29585
e357bc89bb95
patch 9.0.0133: virtual text after line moves to joined line
Bram Moolenaar <Bram@vim.org>
parents:
29581
diff
changeset
|
702 --result; |
e357bc89bb95
patch 9.0.0133: virtual text after line moves to joined line
Bram Moolenaar <Bram@vim.org>
parents:
29581
diff
changeset
|
703 } |
20583
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
704 return result; |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
705 } |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
706 |
29816
bbe62ea78aac
patch 9.0.0247: cannot add padding to virtual text without highlight
Bram Moolenaar <Bram@vim.org>
parents:
29788
diff
changeset
|
707 static textprop_T *text_prop_compare_props; |
bbe62ea78aac
patch 9.0.0247: cannot add padding to virtual text without highlight
Bram Moolenaar <Bram@vim.org>
parents:
29788
diff
changeset
|
708 static buf_T *text_prop_compare_buf; |
bbe62ea78aac
patch 9.0.0247: cannot add padding to virtual text without highlight
Bram Moolenaar <Bram@vim.org>
parents:
29788
diff
changeset
|
709 |
30205
ed6f3d2593df
patch 9.0.0438: cannot put virtual text above a line
Bram Moolenaar <Bram@vim.org>
parents:
30015
diff
changeset
|
710 /* Score for sorting on position of the text property: 0: above, |
ed6f3d2593df
patch 9.0.0438: cannot put virtual text above a line
Bram Moolenaar <Bram@vim.org>
parents:
30015
diff
changeset
|
711 * 1: after (default), 2: right, 3: below (comes last) |
ed6f3d2593df
patch 9.0.0438: cannot put virtual text above a line
Bram Moolenaar <Bram@vim.org>
parents:
30015
diff
changeset
|
712 */ |
ed6f3d2593df
patch 9.0.0438: cannot put virtual text above a line
Bram Moolenaar <Bram@vim.org>
parents:
30015
diff
changeset
|
713 static int |
ed6f3d2593df
patch 9.0.0438: cannot put virtual text above a line
Bram Moolenaar <Bram@vim.org>
parents:
30015
diff
changeset
|
714 text_prop_order(int flags) |
ed6f3d2593df
patch 9.0.0438: cannot put virtual text above a line
Bram Moolenaar <Bram@vim.org>
parents:
30015
diff
changeset
|
715 { |
ed6f3d2593df
patch 9.0.0438: cannot put virtual text above a line
Bram Moolenaar <Bram@vim.org>
parents:
30015
diff
changeset
|
716 if (flags & TP_FLAG_ALIGN_ABOVE) |
ed6f3d2593df
patch 9.0.0438: cannot put virtual text above a line
Bram Moolenaar <Bram@vim.org>
parents:
30015
diff
changeset
|
717 return 0; |
ed6f3d2593df
patch 9.0.0438: cannot put virtual text above a line
Bram Moolenaar <Bram@vim.org>
parents:
30015
diff
changeset
|
718 if (flags & TP_FLAG_ALIGN_RIGHT) |
ed6f3d2593df
patch 9.0.0438: cannot put virtual text above a line
Bram Moolenaar <Bram@vim.org>
parents:
30015
diff
changeset
|
719 return 2; |
ed6f3d2593df
patch 9.0.0438: cannot put virtual text above a line
Bram Moolenaar <Bram@vim.org>
parents:
30015
diff
changeset
|
720 if (flags & TP_FLAG_ALIGN_BELOW) |
ed6f3d2593df
patch 9.0.0438: cannot put virtual text above a line
Bram Moolenaar <Bram@vim.org>
parents:
30015
diff
changeset
|
721 return 3; |
ed6f3d2593df
patch 9.0.0438: cannot put virtual text above a line
Bram Moolenaar <Bram@vim.org>
parents:
30015
diff
changeset
|
722 return 1; |
ed6f3d2593df
patch 9.0.0438: cannot put virtual text above a line
Bram Moolenaar <Bram@vim.org>
parents:
30015
diff
changeset
|
723 } |
ed6f3d2593df
patch 9.0.0438: cannot put virtual text above a line
Bram Moolenaar <Bram@vim.org>
parents:
30015
diff
changeset
|
724 |
29816
bbe62ea78aac
patch 9.0.0247: cannot add padding to virtual text without highlight
Bram Moolenaar <Bram@vim.org>
parents:
29788
diff
changeset
|
725 /* |
bbe62ea78aac
patch 9.0.0247: cannot add padding to virtual text without highlight
Bram Moolenaar <Bram@vim.org>
parents:
29788
diff
changeset
|
726 * Function passed to qsort() to sort text properties. |
bbe62ea78aac
patch 9.0.0247: cannot add padding to virtual text without highlight
Bram Moolenaar <Bram@vim.org>
parents:
29788
diff
changeset
|
727 * Return 1 if "s1" has priority over "s2", -1 if the other way around, zero if |
bbe62ea78aac
patch 9.0.0247: cannot add padding to virtual text without highlight
Bram Moolenaar <Bram@vim.org>
parents:
29788
diff
changeset
|
728 * both have the same priority. |
bbe62ea78aac
patch 9.0.0247: cannot add padding to virtual text without highlight
Bram Moolenaar <Bram@vim.org>
parents:
29788
diff
changeset
|
729 */ |
bbe62ea78aac
patch 9.0.0247: cannot add padding to virtual text without highlight
Bram Moolenaar <Bram@vim.org>
parents:
29788
diff
changeset
|
730 static int |
bbe62ea78aac
patch 9.0.0247: cannot add padding to virtual text without highlight
Bram Moolenaar <Bram@vim.org>
parents:
29788
diff
changeset
|
731 text_prop_compare(const void *s1, const void *s2) |
bbe62ea78aac
patch 9.0.0247: cannot add padding to virtual text without highlight
Bram Moolenaar <Bram@vim.org>
parents:
29788
diff
changeset
|
732 { |
bbe62ea78aac
patch 9.0.0247: cannot add padding to virtual text without highlight
Bram Moolenaar <Bram@vim.org>
parents:
29788
diff
changeset
|
733 int idx1, idx2; |
bbe62ea78aac
patch 9.0.0247: cannot add padding to virtual text without highlight
Bram Moolenaar <Bram@vim.org>
parents:
29788
diff
changeset
|
734 textprop_T *tp1, *tp2; |
bbe62ea78aac
patch 9.0.0247: cannot add padding to virtual text without highlight
Bram Moolenaar <Bram@vim.org>
parents:
29788
diff
changeset
|
735 proptype_T *pt1, *pt2; |
bbe62ea78aac
patch 9.0.0247: cannot add padding to virtual text without highlight
Bram Moolenaar <Bram@vim.org>
parents:
29788
diff
changeset
|
736 colnr_T col1, col2; |
bbe62ea78aac
patch 9.0.0247: cannot add padding to virtual text without highlight
Bram Moolenaar <Bram@vim.org>
parents:
29788
diff
changeset
|
737 |
bbe62ea78aac
patch 9.0.0247: cannot add padding to virtual text without highlight
Bram Moolenaar <Bram@vim.org>
parents:
29788
diff
changeset
|
738 idx1 = *(int *)s1; |
bbe62ea78aac
patch 9.0.0247: cannot add padding to virtual text without highlight
Bram Moolenaar <Bram@vim.org>
parents:
29788
diff
changeset
|
739 idx2 = *(int *)s2; |
bbe62ea78aac
patch 9.0.0247: cannot add padding to virtual text without highlight
Bram Moolenaar <Bram@vim.org>
parents:
29788
diff
changeset
|
740 tp1 = &text_prop_compare_props[idx1]; |
bbe62ea78aac
patch 9.0.0247: cannot add padding to virtual text without highlight
Bram Moolenaar <Bram@vim.org>
parents:
29788
diff
changeset
|
741 tp2 = &text_prop_compare_props[idx2]; |
bbe62ea78aac
patch 9.0.0247: cannot add padding to virtual text without highlight
Bram Moolenaar <Bram@vim.org>
parents:
29788
diff
changeset
|
742 col1 = tp1->tp_col; |
bbe62ea78aac
patch 9.0.0247: cannot add padding to virtual text without highlight
Bram Moolenaar <Bram@vim.org>
parents:
29788
diff
changeset
|
743 col2 = tp2->tp_col; |
bbe62ea78aac
patch 9.0.0247: cannot add padding to virtual text without highlight
Bram Moolenaar <Bram@vim.org>
parents:
29788
diff
changeset
|
744 if (col1 == MAXCOL && col2 == MAXCOL) |
bbe62ea78aac
patch 9.0.0247: cannot add padding to virtual text without highlight
Bram Moolenaar <Bram@vim.org>
parents:
29788
diff
changeset
|
745 { |
30205
ed6f3d2593df
patch 9.0.0438: cannot put virtual text above a line
Bram Moolenaar <Bram@vim.org>
parents:
30015
diff
changeset
|
746 int order1 = text_prop_order(tp1->tp_flags); |
ed6f3d2593df
patch 9.0.0438: cannot put virtual text above a line
Bram Moolenaar <Bram@vim.org>
parents:
30015
diff
changeset
|
747 int order2 = text_prop_order(tp2->tp_flags); |
29816
bbe62ea78aac
patch 9.0.0247: cannot add padding to virtual text without highlight
Bram Moolenaar <Bram@vim.org>
parents:
29788
diff
changeset
|
748 |
30205
ed6f3d2593df
patch 9.0.0438: cannot put virtual text above a line
Bram Moolenaar <Bram@vim.org>
parents:
30015
diff
changeset
|
749 // both props add text before or after the line, sort on order where it |
ed6f3d2593df
patch 9.0.0438: cannot put virtual text above a line
Bram Moolenaar <Bram@vim.org>
parents:
30015
diff
changeset
|
750 // is added |
ed6f3d2593df
patch 9.0.0438: cannot put virtual text above a line
Bram Moolenaar <Bram@vim.org>
parents:
30015
diff
changeset
|
751 if (order1 != order2) |
ed6f3d2593df
patch 9.0.0438: cannot put virtual text above a line
Bram Moolenaar <Bram@vim.org>
parents:
30015
diff
changeset
|
752 return order1 < order2 ? 1 : -1; |
29816
bbe62ea78aac
patch 9.0.0247: cannot add padding to virtual text without highlight
Bram Moolenaar <Bram@vim.org>
parents:
29788
diff
changeset
|
753 } |
bbe62ea78aac
patch 9.0.0247: cannot add padding to virtual text without highlight
Bram Moolenaar <Bram@vim.org>
parents:
29788
diff
changeset
|
754 |
bbe62ea78aac
patch 9.0.0247: cannot add padding to virtual text without highlight
Bram Moolenaar <Bram@vim.org>
parents:
29788
diff
changeset
|
755 // property that inserts text has priority over one that doesn't |
bbe62ea78aac
patch 9.0.0247: cannot add padding to virtual text without highlight
Bram Moolenaar <Bram@vim.org>
parents:
29788
diff
changeset
|
756 if ((tp1->tp_id < 0) != (tp2->tp_id < 0)) |
bbe62ea78aac
patch 9.0.0247: cannot add padding to virtual text without highlight
Bram Moolenaar <Bram@vim.org>
parents:
29788
diff
changeset
|
757 return tp1->tp_id < 0 ? 1 : -1; |
bbe62ea78aac
patch 9.0.0247: cannot add padding to virtual text without highlight
Bram Moolenaar <Bram@vim.org>
parents:
29788
diff
changeset
|
758 |
bbe62ea78aac
patch 9.0.0247: cannot add padding to virtual text without highlight
Bram Moolenaar <Bram@vim.org>
parents:
29788
diff
changeset
|
759 // check highest priority, defined by the type |
bbe62ea78aac
patch 9.0.0247: cannot add padding to virtual text without highlight
Bram Moolenaar <Bram@vim.org>
parents:
29788
diff
changeset
|
760 pt1 = text_prop_type_by_id(text_prop_compare_buf, tp1->tp_type); |
bbe62ea78aac
patch 9.0.0247: cannot add padding to virtual text without highlight
Bram Moolenaar <Bram@vim.org>
parents:
29788
diff
changeset
|
761 pt2 = text_prop_type_by_id(text_prop_compare_buf, tp2->tp_type); |
bbe62ea78aac
patch 9.0.0247: cannot add padding to virtual text without highlight
Bram Moolenaar <Bram@vim.org>
parents:
29788
diff
changeset
|
762 if (pt1 != pt2) |
bbe62ea78aac
patch 9.0.0247: cannot add padding to virtual text without highlight
Bram Moolenaar <Bram@vim.org>
parents:
29788
diff
changeset
|
763 { |
bbe62ea78aac
patch 9.0.0247: cannot add padding to virtual text without highlight
Bram Moolenaar <Bram@vim.org>
parents:
29788
diff
changeset
|
764 if (pt1 == NULL) |
bbe62ea78aac
patch 9.0.0247: cannot add padding to virtual text without highlight
Bram Moolenaar <Bram@vim.org>
parents:
29788
diff
changeset
|
765 return -1; |
bbe62ea78aac
patch 9.0.0247: cannot add padding to virtual text without highlight
Bram Moolenaar <Bram@vim.org>
parents:
29788
diff
changeset
|
766 if (pt2 == NULL) |
bbe62ea78aac
patch 9.0.0247: cannot add padding to virtual text without highlight
Bram Moolenaar <Bram@vim.org>
parents:
29788
diff
changeset
|
767 return 1; |
bbe62ea78aac
patch 9.0.0247: cannot add padding to virtual text without highlight
Bram Moolenaar <Bram@vim.org>
parents:
29788
diff
changeset
|
768 if (pt1->pt_priority != pt2->pt_priority) |
bbe62ea78aac
patch 9.0.0247: cannot add padding to virtual text without highlight
Bram Moolenaar <Bram@vim.org>
parents:
29788
diff
changeset
|
769 return pt1->pt_priority > pt2->pt_priority ? 1 : -1; |
bbe62ea78aac
patch 9.0.0247: cannot add padding to virtual text without highlight
Bram Moolenaar <Bram@vim.org>
parents:
29788
diff
changeset
|
770 } |
bbe62ea78aac
patch 9.0.0247: cannot add padding to virtual text without highlight
Bram Moolenaar <Bram@vim.org>
parents:
29788
diff
changeset
|
771 |
bbe62ea78aac
patch 9.0.0247: cannot add padding to virtual text without highlight
Bram Moolenaar <Bram@vim.org>
parents:
29788
diff
changeset
|
772 // same priority, one that starts first wins |
bbe62ea78aac
patch 9.0.0247: cannot add padding to virtual text without highlight
Bram Moolenaar <Bram@vim.org>
parents:
29788
diff
changeset
|
773 if (col1 != col2) |
bbe62ea78aac
patch 9.0.0247: cannot add padding to virtual text without highlight
Bram Moolenaar <Bram@vim.org>
parents:
29788
diff
changeset
|
774 return col1 < col2 ? 1 : -1; |
bbe62ea78aac
patch 9.0.0247: cannot add padding to virtual text without highlight
Bram Moolenaar <Bram@vim.org>
parents:
29788
diff
changeset
|
775 |
bbe62ea78aac
patch 9.0.0247: cannot add padding to virtual text without highlight
Bram Moolenaar <Bram@vim.org>
parents:
29788
diff
changeset
|
776 // for a property with text the id can be used as tie breaker |
bbe62ea78aac
patch 9.0.0247: cannot add padding to virtual text without highlight
Bram Moolenaar <Bram@vim.org>
parents:
29788
diff
changeset
|
777 if (tp1->tp_id < 0) |
bbe62ea78aac
patch 9.0.0247: cannot add padding to virtual text without highlight
Bram Moolenaar <Bram@vim.org>
parents:
29788
diff
changeset
|
778 return tp1->tp_id > tp2->tp_id ? 1 : -1; |
bbe62ea78aac
patch 9.0.0247: cannot add padding to virtual text without highlight
Bram Moolenaar <Bram@vim.org>
parents:
29788
diff
changeset
|
779 |
bbe62ea78aac
patch 9.0.0247: cannot add padding to virtual text without highlight
Bram Moolenaar <Bram@vim.org>
parents:
29788
diff
changeset
|
780 return 0; |
bbe62ea78aac
patch 9.0.0247: cannot add padding to virtual text without highlight
Bram Moolenaar <Bram@vim.org>
parents:
29788
diff
changeset
|
781 } |
bbe62ea78aac
patch 9.0.0247: cannot add padding to virtual text without highlight
Bram Moolenaar <Bram@vim.org>
parents:
29788
diff
changeset
|
782 |
bbe62ea78aac
patch 9.0.0247: cannot add padding to virtual text without highlight
Bram Moolenaar <Bram@vim.org>
parents:
29788
diff
changeset
|
783 /* |
bbe62ea78aac
patch 9.0.0247: cannot add padding to virtual text without highlight
Bram Moolenaar <Bram@vim.org>
parents:
29788
diff
changeset
|
784 * Sort "count" text properties using an array if indexes "idxs" into the list |
bbe62ea78aac
patch 9.0.0247: cannot add padding to virtual text without highlight
Bram Moolenaar <Bram@vim.org>
parents:
29788
diff
changeset
|
785 * of text props "props" for buffer "buf". |
bbe62ea78aac
patch 9.0.0247: cannot add padding to virtual text without highlight
Bram Moolenaar <Bram@vim.org>
parents:
29788
diff
changeset
|
786 */ |
bbe62ea78aac
patch 9.0.0247: cannot add padding to virtual text without highlight
Bram Moolenaar <Bram@vim.org>
parents:
29788
diff
changeset
|
787 void |
bbe62ea78aac
patch 9.0.0247: cannot add padding to virtual text without highlight
Bram Moolenaar <Bram@vim.org>
parents:
29788
diff
changeset
|
788 sort_text_props( |
bbe62ea78aac
patch 9.0.0247: cannot add padding to virtual text without highlight
Bram Moolenaar <Bram@vim.org>
parents:
29788
diff
changeset
|
789 buf_T *buf, |
bbe62ea78aac
patch 9.0.0247: cannot add padding to virtual text without highlight
Bram Moolenaar <Bram@vim.org>
parents:
29788
diff
changeset
|
790 textprop_T *props, |
bbe62ea78aac
patch 9.0.0247: cannot add padding to virtual text without highlight
Bram Moolenaar <Bram@vim.org>
parents:
29788
diff
changeset
|
791 int *idxs, |
bbe62ea78aac
patch 9.0.0247: cannot add padding to virtual text without highlight
Bram Moolenaar <Bram@vim.org>
parents:
29788
diff
changeset
|
792 int count) |
bbe62ea78aac
patch 9.0.0247: cannot add padding to virtual text without highlight
Bram Moolenaar <Bram@vim.org>
parents:
29788
diff
changeset
|
793 { |
bbe62ea78aac
patch 9.0.0247: cannot add padding to virtual text without highlight
Bram Moolenaar <Bram@vim.org>
parents:
29788
diff
changeset
|
794 text_prop_compare_buf = buf; |
bbe62ea78aac
patch 9.0.0247: cannot add padding to virtual text without highlight
Bram Moolenaar <Bram@vim.org>
parents:
29788
diff
changeset
|
795 text_prop_compare_props = props; |
bbe62ea78aac
patch 9.0.0247: cannot add padding to virtual text without highlight
Bram Moolenaar <Bram@vim.org>
parents:
29788
diff
changeset
|
796 qsort((void *)idxs, (size_t)count, sizeof(int), text_prop_compare); |
bbe62ea78aac
patch 9.0.0247: cannot add padding to virtual text without highlight
Bram Moolenaar <Bram@vim.org>
parents:
29788
diff
changeset
|
797 } |
bbe62ea78aac
patch 9.0.0247: cannot add padding to virtual text without highlight
Bram Moolenaar <Bram@vim.org>
parents:
29788
diff
changeset
|
798 |
15367
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
799 /* |
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
|
800 * 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
|
801 * 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
|
802 * 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
|
803 */ |
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
|
804 int |
31319
243c35fad9cb
patch 9.0.0993: display errors when adding or removing text property type
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
805 find_visible_prop( |
243c35fad9cb
patch 9.0.0993: display errors when adding or removing text property type
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
806 win_T *wp, |
243c35fad9cb
patch 9.0.0993: display errors when adding or removing text property type
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
807 int type_id, |
243c35fad9cb
patch 9.0.0993: display errors when adding or removing text property type
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
808 int id, |
243c35fad9cb
patch 9.0.0993: display errors when adding or removing text property type
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
809 textprop_T *prop, |
243c35fad9cb
patch 9.0.0993: display errors when adding or removing text property type
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
810 linenr_T *found_lnum) |
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
|
811 { |
31319
243c35fad9cb
patch 9.0.0993: display errors when adding or removing text property type
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
812 // return when "type_id" no longer exists |
243c35fad9cb
patch 9.0.0993: display errors when adding or removing text property type
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
813 if (text_prop_type_by_id(wp->w_buffer, type_id) == NULL) |
243c35fad9cb
patch 9.0.0993: display errors when adding or removing text property type
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
814 return FAIL; |
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
|
815 |
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
|
816 // 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
|
817 validate_botline_win(wp); |
31319
243c35fad9cb
patch 9.0.0993: display errors when adding or removing text property type
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
818 for (linenr_T lnum = wp->w_topline; lnum < wp->w_botline; ++lnum) |
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
|
819 { |
31319
243c35fad9cb
patch 9.0.0993: display errors when adding or removing text property type
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
820 char_u *props; |
243c35fad9cb
patch 9.0.0993: display errors when adding or removing text property type
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
821 int count = get_text_props(wp->w_buffer, lnum, &props, FALSE); |
243c35fad9cb
patch 9.0.0993: display errors when adding or removing text property type
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
822 for (int i = 0; i < count; ++i) |
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
|
823 { |
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
|
824 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
|
825 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
|
826 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
|
827 { |
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
|
828 *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
|
829 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
|
830 } |
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
|
831 } |
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
|
832 } |
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
|
833 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
|
834 } |
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
|
835 |
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
|
836 /* |
15367
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
837 * 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
|
838 * 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
|
839 * 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
|
840 * 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
|
841 */ |
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
842 static void |
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
843 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
|
844 { |
15390
00aa76a735e7
patch 8.1.0703: compiler warnings with 64-bit compiler
Bram Moolenaar <Bram@vim.org>
parents:
15373
diff
changeset
|
845 char_u *text; |
00aa76a735e7
patch 8.1.0703: compiler warnings with 64-bit compiler
Bram Moolenaar <Bram@vim.org>
parents:
15373
diff
changeset
|
846 char_u *newtext; |
00aa76a735e7
patch 8.1.0703: compiler warnings with 64-bit compiler
Bram Moolenaar <Bram@vim.org>
parents:
15373
diff
changeset
|
847 int textlen; |
15367
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
848 |
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
849 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
|
850 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
|
851 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
|
852 if (newtext == NULL) |
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
853 return; |
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
854 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
|
855 if (len > 0) |
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
856 mch_memmove(newtext + textlen, props, len); |
29340
fba9e366ced4
patch 9.0.0013: reproducing memory access errors can be difficult
Bram Moolenaar <Bram@vim.org>
parents:
29175
diff
changeset
|
857 if (curbuf->b_ml.ml_flags & (ML_LINE_DIRTY | ML_ALLOCATED)) |
15367
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
858 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
|
859 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
|
860 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
|
861 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
|
862 } |
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
863 |
29609
e1c370197030
patch 9.0.0145: substitute that joins lines drops text properties
Bram Moolenaar <Bram@vim.org>
parents:
29607
diff
changeset
|
864 /* |
29627
dd96f3d8ed85
patch 9.0.0154: text properties wrong after splitting a line
Bram Moolenaar <Bram@vim.org>
parents:
29621
diff
changeset
|
865 * Add "text_props" with "text_prop_count" text properties to line "lnum". |
29609
e1c370197030
patch 9.0.0145: substitute that joins lines drops text properties
Bram Moolenaar <Bram@vim.org>
parents:
29607
diff
changeset
|
866 */ |
e1c370197030
patch 9.0.0145: substitute that joins lines drops text properties
Bram Moolenaar <Bram@vim.org>
parents:
29607
diff
changeset
|
867 void |
e1c370197030
patch 9.0.0145: substitute that joins lines drops text properties
Bram Moolenaar <Bram@vim.org>
parents:
29607
diff
changeset
|
868 add_text_props(linenr_T lnum, textprop_T *text_props, int text_prop_count) |
e1c370197030
patch 9.0.0145: substitute that joins lines drops text properties
Bram Moolenaar <Bram@vim.org>
parents:
29607
diff
changeset
|
869 { |
e1c370197030
patch 9.0.0145: substitute that joins lines drops text properties
Bram Moolenaar <Bram@vim.org>
parents:
29607
diff
changeset
|
870 char_u *text; |
e1c370197030
patch 9.0.0145: substitute that joins lines drops text properties
Bram Moolenaar <Bram@vim.org>
parents:
29607
diff
changeset
|
871 char_u *newtext; |
e1c370197030
patch 9.0.0145: substitute that joins lines drops text properties
Bram Moolenaar <Bram@vim.org>
parents:
29607
diff
changeset
|
872 int proplen = text_prop_count * (int)sizeof(textprop_T); |
e1c370197030
patch 9.0.0145: substitute that joins lines drops text properties
Bram Moolenaar <Bram@vim.org>
parents:
29607
diff
changeset
|
873 |
e1c370197030
patch 9.0.0145: substitute that joins lines drops text properties
Bram Moolenaar <Bram@vim.org>
parents:
29607
diff
changeset
|
874 text = ml_get(lnum); |
e1c370197030
patch 9.0.0145: substitute that joins lines drops text properties
Bram Moolenaar <Bram@vim.org>
parents:
29607
diff
changeset
|
875 newtext = alloc(curbuf->b_ml.ml_line_len + proplen); |
e1c370197030
patch 9.0.0145: substitute that joins lines drops text properties
Bram Moolenaar <Bram@vim.org>
parents:
29607
diff
changeset
|
876 if (newtext == NULL) |
e1c370197030
patch 9.0.0145: substitute that joins lines drops text properties
Bram Moolenaar <Bram@vim.org>
parents:
29607
diff
changeset
|
877 return; |
e1c370197030
patch 9.0.0145: substitute that joins lines drops text properties
Bram Moolenaar <Bram@vim.org>
parents:
29607
diff
changeset
|
878 mch_memmove(newtext, text, curbuf->b_ml.ml_line_len); |
e1c370197030
patch 9.0.0145: substitute that joins lines drops text properties
Bram Moolenaar <Bram@vim.org>
parents:
29607
diff
changeset
|
879 mch_memmove(newtext + curbuf->b_ml.ml_line_len, text_props, proplen); |
e1c370197030
patch 9.0.0145: substitute that joins lines drops text properties
Bram Moolenaar <Bram@vim.org>
parents:
29607
diff
changeset
|
880 if (curbuf->b_ml.ml_flags & (ML_LINE_DIRTY | ML_ALLOCATED)) |
e1c370197030
patch 9.0.0145: substitute that joins lines drops text properties
Bram Moolenaar <Bram@vim.org>
parents:
29607
diff
changeset
|
881 vim_free(curbuf->b_ml.ml_line_ptr); |
e1c370197030
patch 9.0.0145: substitute that joins lines drops text properties
Bram Moolenaar <Bram@vim.org>
parents:
29607
diff
changeset
|
882 curbuf->b_ml.ml_line_ptr = newtext; |
e1c370197030
patch 9.0.0145: substitute that joins lines drops text properties
Bram Moolenaar <Bram@vim.org>
parents:
29607
diff
changeset
|
883 curbuf->b_ml.ml_line_len += proplen; |
e1c370197030
patch 9.0.0145: substitute that joins lines drops text properties
Bram Moolenaar <Bram@vim.org>
parents:
29607
diff
changeset
|
884 curbuf->b_ml.ml_flags |= ML_LINE_DIRTY; |
e1c370197030
patch 9.0.0145: substitute that joins lines drops text properties
Bram Moolenaar <Bram@vim.org>
parents:
29607
diff
changeset
|
885 } |
e1c370197030
patch 9.0.0145: substitute that joins lines drops text properties
Bram Moolenaar <Bram@vim.org>
parents:
29607
diff
changeset
|
886 |
29649
a3a966b8b7a7
patch 9.0.0165: looking up a text property type by ID is slow
Bram Moolenaar <Bram@vim.org>
parents:
29627
diff
changeset
|
887 /* |
a3a966b8b7a7
patch 9.0.0165: looking up a text property type by ID is slow
Bram Moolenaar <Bram@vim.org>
parents:
29627
diff
changeset
|
888 * Function passed to qsort() for sorting proptype_T on pt_id. |
a3a966b8b7a7
patch 9.0.0165: looking up a text property type by ID is slow
Bram Moolenaar <Bram@vim.org>
parents:
29627
diff
changeset
|
889 */ |
a3a966b8b7a7
patch 9.0.0165: looking up a text property type by ID is slow
Bram Moolenaar <Bram@vim.org>
parents:
29627
diff
changeset
|
890 static int |
a3a966b8b7a7
patch 9.0.0165: looking up a text property type by ID is slow
Bram Moolenaar <Bram@vim.org>
parents:
29627
diff
changeset
|
891 compare_pt(const void *s1, const void *s2) |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
892 { |
29649
a3a966b8b7a7
patch 9.0.0165: looking up a text property type by ID is slow
Bram Moolenaar <Bram@vim.org>
parents:
29627
diff
changeset
|
893 proptype_T *tp1 = *(proptype_T **)s1; |
a3a966b8b7a7
patch 9.0.0165: looking up a text property type by ID is slow
Bram Moolenaar <Bram@vim.org>
parents:
29627
diff
changeset
|
894 proptype_T *tp2 = *(proptype_T **)s2; |
a3a966b8b7a7
patch 9.0.0165: looking up a text property type by ID is slow
Bram Moolenaar <Bram@vim.org>
parents:
29627
diff
changeset
|
895 |
a3a966b8b7a7
patch 9.0.0165: looking up a text property type by ID is slow
Bram Moolenaar <Bram@vim.org>
parents:
29627
diff
changeset
|
896 return tp1->pt_id == tp2->pt_id ? 0 : tp1->pt_id < tp2->pt_id ? -1 : 1; |
a3a966b8b7a7
patch 9.0.0165: looking up a text property type by ID is slow
Bram Moolenaar <Bram@vim.org>
parents:
29627
diff
changeset
|
897 } |
a3a966b8b7a7
patch 9.0.0165: looking up a text property type by ID is slow
Bram Moolenaar <Bram@vim.org>
parents:
29627
diff
changeset
|
898 |
a3a966b8b7a7
patch 9.0.0165: looking up a text property type by ID is slow
Bram Moolenaar <Bram@vim.org>
parents:
29627
diff
changeset
|
899 static proptype_T * |
a3a966b8b7a7
patch 9.0.0165: looking up a text property type by ID is slow
Bram Moolenaar <Bram@vim.org>
parents:
29627
diff
changeset
|
900 find_type_by_id(hashtab_T *ht, proptype_T ***array, int id) |
a3a966b8b7a7
patch 9.0.0165: looking up a text property type by ID is slow
Bram Moolenaar <Bram@vim.org>
parents:
29627
diff
changeset
|
901 { |
a3a966b8b7a7
patch 9.0.0165: looking up a text property type by ID is slow
Bram Moolenaar <Bram@vim.org>
parents:
29627
diff
changeset
|
902 int low = 0; |
a3a966b8b7a7
patch 9.0.0165: looking up a text property type by ID is slow
Bram Moolenaar <Bram@vim.org>
parents:
29627
diff
changeset
|
903 int high; |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
904 |
29664
6569c71c5ca5
patch 9.0.0172: trying to allocate zero bytes
Bram Moolenaar <Bram@vim.org>
parents:
29657
diff
changeset
|
905 if (ht == NULL || ht->ht_used == 0) |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
906 return NULL; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
907 |
30986
360f286b5869
patch 9.0.0828: various typos
Bram Moolenaar <Bram@vim.org>
parents:
30813
diff
changeset
|
908 // Make the lookup faster by creating an array with pointers to |
29649
a3a966b8b7a7
patch 9.0.0165: looking up a text property type by ID is slow
Bram Moolenaar <Bram@vim.org>
parents:
29627
diff
changeset
|
909 // hashtable entries, sorted on pt_id. |
a3a966b8b7a7
patch 9.0.0165: looking up a text property type by ID is slow
Bram Moolenaar <Bram@vim.org>
parents:
29627
diff
changeset
|
910 if (*array == NULL) |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
911 { |
29649
a3a966b8b7a7
patch 9.0.0165: looking up a text property type by ID is slow
Bram Moolenaar <Bram@vim.org>
parents:
29627
diff
changeset
|
912 long todo; |
a3a966b8b7a7
patch 9.0.0165: looking up a text property type by ID is slow
Bram Moolenaar <Bram@vim.org>
parents:
29627
diff
changeset
|
913 hashitem_T *hi; |
a3a966b8b7a7
patch 9.0.0165: looking up a text property type by ID is slow
Bram Moolenaar <Bram@vim.org>
parents:
29627
diff
changeset
|
914 int i = 0; |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
915 |
29649
a3a966b8b7a7
patch 9.0.0165: looking up a text property type by ID is slow
Bram Moolenaar <Bram@vim.org>
parents:
29627
diff
changeset
|
916 *array = ALLOC_MULT(proptype_T *, ht->ht_used); |
a3a966b8b7a7
patch 9.0.0165: looking up a text property type by ID is slow
Bram Moolenaar <Bram@vim.org>
parents:
29627
diff
changeset
|
917 if (*array == NULL) |
a3a966b8b7a7
patch 9.0.0165: looking up a text property type by ID is slow
Bram Moolenaar <Bram@vim.org>
parents:
29627
diff
changeset
|
918 return NULL; |
a3a966b8b7a7
patch 9.0.0165: looking up a text property type by ID is slow
Bram Moolenaar <Bram@vim.org>
parents:
29627
diff
changeset
|
919 todo = (long)ht->ht_used; |
a3a966b8b7a7
patch 9.0.0165: looking up a text property type by ID is slow
Bram Moolenaar <Bram@vim.org>
parents:
29627
diff
changeset
|
920 for (hi = ht->ht_array; todo > 0; ++hi) |
a3a966b8b7a7
patch 9.0.0165: looking up a text property type by ID is slow
Bram Moolenaar <Bram@vim.org>
parents:
29627
diff
changeset
|
921 { |
a3a966b8b7a7
patch 9.0.0165: looking up a text property type by ID is slow
Bram Moolenaar <Bram@vim.org>
parents:
29627
diff
changeset
|
922 if (!HASHITEM_EMPTY(hi)) |
a3a966b8b7a7
patch 9.0.0165: looking up a text property type by ID is slow
Bram Moolenaar <Bram@vim.org>
parents:
29627
diff
changeset
|
923 { |
a3a966b8b7a7
patch 9.0.0165: looking up a text property type by ID is slow
Bram Moolenaar <Bram@vim.org>
parents:
29627
diff
changeset
|
924 (*array)[i++] = HI2PT(hi); |
a3a966b8b7a7
patch 9.0.0165: looking up a text property type by ID is slow
Bram Moolenaar <Bram@vim.org>
parents:
29627
diff
changeset
|
925 --todo; |
a3a966b8b7a7
patch 9.0.0165: looking up a text property type by ID is slow
Bram Moolenaar <Bram@vim.org>
parents:
29627
diff
changeset
|
926 } |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
927 } |
29649
a3a966b8b7a7
patch 9.0.0165: looking up a text property type by ID is slow
Bram Moolenaar <Bram@vim.org>
parents:
29627
diff
changeset
|
928 qsort((void *)*array, ht->ht_used, sizeof(proptype_T *), compare_pt); |
a3a966b8b7a7
patch 9.0.0165: looking up a text property type by ID is slow
Bram Moolenaar <Bram@vim.org>
parents:
29627
diff
changeset
|
929 } |
a3a966b8b7a7
patch 9.0.0165: looking up a text property type by ID is slow
Bram Moolenaar <Bram@vim.org>
parents:
29627
diff
changeset
|
930 |
a3a966b8b7a7
patch 9.0.0165: looking up a text property type by ID is slow
Bram Moolenaar <Bram@vim.org>
parents:
29627
diff
changeset
|
931 // binary search in the sorted array |
a3a966b8b7a7
patch 9.0.0165: looking up a text property type by ID is slow
Bram Moolenaar <Bram@vim.org>
parents:
29627
diff
changeset
|
932 high = ht->ht_used; |
a3a966b8b7a7
patch 9.0.0165: looking up a text property type by ID is slow
Bram Moolenaar <Bram@vim.org>
parents:
29627
diff
changeset
|
933 while (high > low) |
a3a966b8b7a7
patch 9.0.0165: looking up a text property type by ID is slow
Bram Moolenaar <Bram@vim.org>
parents:
29627
diff
changeset
|
934 { |
a3a966b8b7a7
patch 9.0.0165: looking up a text property type by ID is slow
Bram Moolenaar <Bram@vim.org>
parents:
29627
diff
changeset
|
935 int m = (high + low) / 2; |
a3a966b8b7a7
patch 9.0.0165: looking up a text property type by ID is slow
Bram Moolenaar <Bram@vim.org>
parents:
29627
diff
changeset
|
936 |
a3a966b8b7a7
patch 9.0.0165: looking up a text property type by ID is slow
Bram Moolenaar <Bram@vim.org>
parents:
29627
diff
changeset
|
937 if ((*array)[m]->pt_id == id) |
a3a966b8b7a7
patch 9.0.0165: looking up a text property type by ID is slow
Bram Moolenaar <Bram@vim.org>
parents:
29627
diff
changeset
|
938 return (*array)[m]; |
a3a966b8b7a7
patch 9.0.0165: looking up a text property type by ID is slow
Bram Moolenaar <Bram@vim.org>
parents:
29627
diff
changeset
|
939 if ((*array)[m]->pt_id > id) |
a3a966b8b7a7
patch 9.0.0165: looking up a text property type by ID is slow
Bram Moolenaar <Bram@vim.org>
parents:
29627
diff
changeset
|
940 high = m; |
a3a966b8b7a7
patch 9.0.0165: looking up a text property type by ID is slow
Bram Moolenaar <Bram@vim.org>
parents:
29627
diff
changeset
|
941 else |
a3a966b8b7a7
patch 9.0.0165: looking up a text property type by ID is slow
Bram Moolenaar <Bram@vim.org>
parents:
29627
diff
changeset
|
942 low = m + 1; |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
943 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
944 return NULL; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
945 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
946 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
947 /* |
19100
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
948 * 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
|
949 */ |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
950 static void |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
951 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
|
952 { |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
953 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
|
954 int buflocal = TRUE; |
19100
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
955 |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
956 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
|
957 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
|
958 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
|
959 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
|
960 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
|
961 |
29649
a3a966b8b7a7
patch 9.0.0165: looking up a text property type by ID is slow
Bram Moolenaar <Bram@vim.org>
parents:
29627
diff
changeset
|
962 pt = find_type_by_id(buf->b_proptypes, &buf->b_proparray, prop->tp_type); |
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
|
963 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
|
964 { |
29649
a3a966b8b7a7
patch 9.0.0165: looking up a text property type by ID is slow
Bram Moolenaar <Bram@vim.org>
parents:
29627
diff
changeset
|
965 pt = find_type_by_id(global_proptypes, &global_proparray, |
a3a966b8b7a7
patch 9.0.0165: looking up a text property type by ID is slow
Bram Moolenaar <Bram@vim.org>
parents:
29627
diff
changeset
|
966 prop->tp_type); |
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
|
967 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
|
968 } |
19100
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
969 if (pt != NULL) |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
970 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
|
971 |
b427a26b0210
patch 8.2.3233: prop_list() and prop_find() do not indicate the buffer
Bram Moolenaar <Bram@vim.org>
parents:
25384
diff
changeset
|
972 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
|
973 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
|
974 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
|
975 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
|
976 } |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
977 |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
978 /* |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
979 * 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
|
980 * Returns NULL if not found. |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
981 */ |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
982 proptype_T * |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
983 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
|
984 { |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
985 proptype_T *type; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
986 |
29649
a3a966b8b7a7
patch 9.0.0165: looking up a text property type by ID is slow
Bram Moolenaar <Bram@vim.org>
parents:
29627
diff
changeset
|
987 type = find_type_by_id(buf->b_proptypes, &buf->b_proparray, id); |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
988 if (type == NULL) |
29649
a3a966b8b7a7
patch 9.0.0165: looking up a text property type by ID is slow
Bram Moolenaar <Bram@vim.org>
parents:
29627
diff
changeset
|
989 type = find_type_by_id(global_proptypes, &global_proparray, id); |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
990 return type; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
991 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
992 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
993 /* |
31319
243c35fad9cb
patch 9.0.0993: display errors when adding or removing text property type
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
994 * Return TRUE if "prop" is a valid text property type. |
243c35fad9cb
patch 9.0.0993: display errors when adding or removing text property type
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
995 */ |
243c35fad9cb
patch 9.0.0993: display errors when adding or removing text property type
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
996 int |
243c35fad9cb
patch 9.0.0993: display errors when adding or removing text property type
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
997 text_prop_type_valid(buf_T *buf, textprop_T *prop) |
243c35fad9cb
patch 9.0.0993: display errors when adding or removing text property type
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
998 { |
243c35fad9cb
patch 9.0.0993: display errors when adding or removing text property type
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
999 return text_prop_type_by_id(buf, prop->tp_type) != NULL; |
243c35fad9cb
patch 9.0.0993: display errors when adding or removing text property type
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
1000 } |
243c35fad9cb
patch 9.0.0993: display errors when adding or removing text property type
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
1001 |
243c35fad9cb
patch 9.0.0993: display errors when adding or removing text property type
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
1002 /* |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1003 * prop_clear({lnum} [, {lnum_end} [, {bufnr}]]) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1004 */ |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1005 void |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1006 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
|
1007 { |
25302
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
1008 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
|
1009 linenr_T end; |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1010 linenr_T lnum; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1011 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
|
1012 int did_clear = FALSE; |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1013 |
25302
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
1014 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
|
1015 && (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
|
1016 || 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
|
1017 || (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
|
1018 && 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
|
1019 return; |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
1020 |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
1021 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
|
1022 end = start; |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1023 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
|
1024 { |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15182
diff
changeset
|
1025 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
|
1026 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
|
1027 { |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1028 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
|
1029 return; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1030 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1031 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1032 if (start < 1 || end < 1) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1033 { |
25064
8f2262c72178
patch 8.2.3069: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
24649
diff
changeset
|
1034 emsg(_(e_invalid_range)); |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1035 return; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1036 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1037 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1038 for (lnum = start; lnum <= end; ++lnum) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1039 { |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1040 char_u *text; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1041 size_t len; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1042 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1043 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
|
1044 break; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1045 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
|
1046 len = STRLEN(text) + 1; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1047 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
|
1048 { |
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
|
1049 did_clear = TRUE; |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1050 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
|
1051 { |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1052 char_u *newtext = vim_strsave(text); |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1053 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1054 // need to allocate the line now |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1055 if (newtext == NULL) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1056 return; |
29340
fba9e366ced4
patch 9.0.0013: reproducing memory access errors can be difficult
Bram Moolenaar <Bram@vim.org>
parents:
29175
diff
changeset
|
1057 if (buf->b_ml.ml_flags & ML_ALLOCATED) |
fba9e366ced4
patch 9.0.0013: reproducing memory access errors can be difficult
Bram Moolenaar <Bram@vim.org>
parents:
29175
diff
changeset
|
1058 vim_free(buf->b_ml.ml_line_ptr); |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1059 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
|
1060 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
|
1061 } |
15182
4b2de998ebd6
patch 8.1.0601: a few compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
1062 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
|
1063 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1064 } |
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
|
1065 if (did_clear) |
29732
89e1d67814a9
patch 9.0.0206: redraw flags are not named specifically
Bram Moolenaar <Bram@vim.org>
parents:
29730
diff
changeset
|
1066 redraw_buf_later(buf, UPD_NOT_VALID); |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1067 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1068 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1069 /* |
19100
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
1070 * prop_find({props} [, {direction}]) |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
1071 */ |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
1072 void |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
1073 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
|
1074 { |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
1075 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
|
1076 dict_T *dict; |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
1077 buf_T *buf = curbuf; |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
1078 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
|
1079 int lnum_start; |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1080 int start_pos_has_prop = 0; |
28526
171f9def0398
patch 8.2.4787: prop_find() does not find the right property
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
1081 int seen_end = FALSE; |
25467
6f627d12e81b
patch 8.2.3270: prop_find() finds property with ID -2
Bram Moolenaar <Bram@vim.org>
parents:
25441
diff
changeset
|
1082 int id = 0; |
6f627d12e81b
patch 8.2.3270: prop_find() finds property with ID -2
Bram Moolenaar <Bram@vim.org>
parents:
25441
diff
changeset
|
1083 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
|
1084 int type_id = -1; |
28526
171f9def0398
patch 8.2.4787: prop_find() does not find the right property
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
1085 int skipstart = FALSE; |
20583
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1086 int lnum = -1; |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1087 int col = -1; |
28526
171f9def0398
patch 8.2.4787: prop_find() does not find the right property
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
1088 int dir = FORWARD; // FORWARD == 1, BACKWARD == -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
|
1089 int both; |
19100
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
1090 |
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
|
1091 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
|
1092 && (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
|
1093 || 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
|
1094 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
|
1095 |
29994
86eb4aba16c3
patch 9.0.0335: checks for Dictionary argument often give a vague error
Bram Moolenaar <Bram@vim.org>
parents:
29826
diff
changeset
|
1096 if (check_for_nonnull_dict_arg(argvars, 0) == FAIL) |
19100
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
1097 return; |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
1098 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
|
1099 |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
1100 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
|
1101 return; |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
1102 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
|
1103 return; |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
1104 |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
1105 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
|
1106 { |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
1107 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
|
1108 |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
1109 if (*dir_s == 'b') |
28526
171f9def0398
patch 8.2.4787: prop_find() does not find the right property
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
1110 dir = BACKWARD; |
19100
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
1111 else if (*dir_s != 'f') |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
1112 { |
26865
bce848ec8b1b
patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26775
diff
changeset
|
1113 emsg(_(e_invalid_argument)); |
19100
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
1114 return; |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
1115 } |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
1116 } |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
1117 |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
1118 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
|
1119 if (di != NULL) |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
1120 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
|
1121 |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
1122 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
|
1123 if (di != NULL) |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
1124 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
|
1125 |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
1126 if (lnum == -1) |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
1127 { |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
1128 lnum = cursor->lnum; |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
1129 col = cursor->col + 1; |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
1130 } |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
1131 else if (col == -1) |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
1132 col = 1; |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
1133 |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
1134 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
|
1135 { |
25064
8f2262c72178
patch 8.2.3069: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
24649
diff
changeset
|
1136 emsg(_(e_invalid_range)); |
19100
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
1137 return; |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
1138 } |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
1139 |
29442
827d9f2b7a71
patch 9.0.0063: too many type casts for dict_get functions
Bram Moolenaar <Bram@vim.org>
parents:
29340
diff
changeset
|
1140 skipstart = dict_get_bool(dict, "skipstart", 0); |
19100
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
1141 |
28315
62cc3b60493b
patch 8.2.4683: verbose check with dict_find() to see if a key is present
Bram Moolenaar <Bram@vim.org>
parents:
26966
diff
changeset
|
1142 if (dict_has_key(dict, "id")) |
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
|
1143 { |
29442
827d9f2b7a71
patch 9.0.0063: too many type casts for dict_get functions
Bram Moolenaar <Bram@vim.org>
parents:
29340
diff
changeset
|
1144 id = dict_get_number(dict, "id"); |
25471
3678a11e71fa
patch 8.2.3272: cannot use id zero with prop_find()
Bram Moolenaar <Bram@vim.org>
parents:
25467
diff
changeset
|
1145 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
|
1146 } |
28315
62cc3b60493b
patch 8.2.4683: verbose check with dict_find() to see if a key is present
Bram Moolenaar <Bram@vim.org>
parents:
26966
diff
changeset
|
1147 if (dict_has_key(dict, "type")) |
19100
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
1148 { |
29442
827d9f2b7a71
patch 9.0.0063: too many type casts for dict_get functions
Bram Moolenaar <Bram@vim.org>
parents:
29340
diff
changeset
|
1149 char_u *name = dict_get_string(dict, "type", FALSE); |
19100
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
1150 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
|
1151 |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
1152 if (type == NULL) |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
1153 return; |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
1154 type_id = type->pt_id; |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
1155 } |
29442
827d9f2b7a71
patch 9.0.0063: too many type casts for dict_get functions
Bram Moolenaar <Bram@vim.org>
parents:
29340
diff
changeset
|
1156 both = dict_get_bool(dict, "both", FALSE); |
25467
6f627d12e81b
patch 8.2.3270: prop_find() finds property with ID -2
Bram Moolenaar <Bram@vim.org>
parents:
25441
diff
changeset
|
1157 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
|
1158 { |
26966
ac75c145f0a9
patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26962
diff
changeset
|
1159 emsg(_(e_need_at_least_one_of_id_or_type)); |
19100
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
1160 return; |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
1161 } |
25467
6f627d12e81b
patch 8.2.3270: prop_find() finds property with ID -2
Bram Moolenaar <Bram@vim.org>
parents:
25441
diff
changeset
|
1162 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
|
1163 { |
29788
d08aa1bfe319
patch 9.0.0233: removing multiple text properties takes many calls
Bram Moolenaar <Bram@vim.org>
parents:
29748
diff
changeset
|
1164 emsg(_(e_need_id_and_type_or_types_with_both)); |
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
|
1165 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
|
1166 } |
19100
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
1167 |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
1168 lnum_start = lnum; |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
1169 |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
1170 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
|
1171 return; |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
1172 |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
1173 while (1) |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
1174 { |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
1175 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
|
1176 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
|
1177 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
|
1178 / sizeof(textprop_T)); |
19100
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
1179 int i; |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
1180 textprop_T prop; |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
1181 int prop_start; |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
1182 int prop_end; |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
1183 |
28526
171f9def0398
patch 8.2.4787: prop_find() does not find the right property
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
1184 for (i = dir == BACKWARD ? count - 1 : 0; i >= 0 && i < count; i += dir) |
19100
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
1185 { |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
1186 mch_memmove(&prop, text + textlen + i * sizeof(textprop_T), |
28526
171f9def0398
patch 8.2.4787: prop_find() does not find the right property
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
1187 sizeof(textprop_T)); |
19100
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
1188 |
28526
171f9def0398
patch 8.2.4787: prop_find() does not find the right property
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
1189 // For the very first line try to find the first property before or |
171f9def0398
patch 8.2.4787: prop_find() does not find the right property
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
1190 // after `col`, depending on the search direction. |
19642
647ef636a11e
patch 8.2.0378: prop_find() does not find all props
Bram Moolenaar <Bram@vim.org>
parents:
19631
diff
changeset
|
1191 if (lnum == lnum_start) |
19644
d2153928b376
patch 8.2.0379: gcc warns for ambiguous else
Bram Moolenaar <Bram@vim.org>
parents:
19642
diff
changeset
|
1192 { |
28526
171f9def0398
patch 8.2.4787: prop_find() does not find the right property
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
1193 if (dir == BACKWARD) |
19642
647ef636a11e
patch 8.2.0378: prop_find() does not find all props
Bram Moolenaar <Bram@vim.org>
parents:
19631
diff
changeset
|
1194 { |
28526
171f9def0398
patch 8.2.4787: prop_find() does not find the right property
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
1195 if (prop.tp_col > col) |
171f9def0398
patch 8.2.4787: prop_find() does not find the right property
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
1196 continue; |
19642
647ef636a11e
patch 8.2.0378: prop_find() does not find all props
Bram Moolenaar <Bram@vim.org>
parents:
19631
diff
changeset
|
1197 } |
647ef636a11e
patch 8.2.0378: prop_find() does not find all props
Bram Moolenaar <Bram@vim.org>
parents:
19631
diff
changeset
|
1198 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
|
1199 continue; |
19644
d2153928b376
patch 8.2.0379: gcc warns for ambiguous else
Bram Moolenaar <Bram@vim.org>
parents:
19642
diff
changeset
|
1200 } |
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
|
1201 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
|
1202 : (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
|
1203 || 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
|
1204 { |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
1205 // 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
|
1206 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
|
1207 && 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
|
1208 && (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
|
1209 - (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
|
1210 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
|
1211 |
28526
171f9def0398
patch 8.2.4787: prop_find() does not find the right property
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
1212 // The property was not continued from last line, it starts on |
171f9def0398
patch 8.2.4787: prop_find() does not find the right property
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
1213 // this line. |
19100
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
1214 prop_start = !(prop.tp_flags & TP_FLAG_CONT_PREV); |
28526
171f9def0398
patch 8.2.4787: prop_find() does not find the right property
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
1215 // The property does not continue on the next line, it ends on |
171f9def0398
patch 8.2.4787: prop_find() does not find the right property
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
1216 // this line. |
19100
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
1217 prop_end = !(prop.tp_flags & TP_FLAG_CONT_NEXT); |
28526
171f9def0398
patch 8.2.4787: prop_find() does not find the right property
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
1218 if (!prop_start && prop_end && dir == FORWARD) |
19100
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
1219 seen_end = 1; |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
1220 |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
1221 // 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
|
1222 if (!prop_start) |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
1223 { |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
1224 // 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
|
1225 // 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
|
1226 if (start_pos_has_prop && !skipstart) |
28526
171f9def0398
patch 8.2.4787: prop_find() does not find the right property
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
1227 dir = BACKWARD; |
22037
35c8996a798e
patch 8.2.1568: prop_find() skips properties in the same line
Bram Moolenaar <Bram@vim.org>
parents:
21081
diff
changeset
|
1228 continue; |
19100
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
1229 } |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
1230 |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
1231 // 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
|
1232 // continued from another line). |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
1233 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
|
1234 { |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
1235 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
|
1236 continue; |
19100
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
1237 } |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
1238 |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
1239 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
|
1240 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
|
1241 |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
1242 return; |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
1243 } |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
1244 } |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
1245 |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
1246 if (dir > 0) |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
1247 { |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
1248 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
|
1249 break; |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
1250 lnum++; |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
1251 } |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
1252 else |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
1253 { |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
1254 if (lnum <= 1) |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
1255 break; |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
1256 lnum--; |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
1257 } |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
1258 } |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
1259 } |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
1260 |
91bb12995034
patch 8.2.0110: prop_find() is not implemented
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
1261 /* |
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
|
1262 * 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
|
1263 */ |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1264 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
|
1265 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
|
1266 { |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1267 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
|
1268 |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1269 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
|
1270 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
|
1271 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
|
1272 |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1273 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
|
1274 } |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1275 |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1276 /* |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1277 * 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
|
1278 * 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
|
1279 * 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
|
1280 * 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
|
1281 * 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
|
1282 * 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
|
1283 * 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
|
1284 */ |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1285 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
|
1286 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
|
1287 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
|
1288 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
|
1289 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
|
1290 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
|
1291 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
|
1292 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
|
1293 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
|
1294 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
|
1295 { |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1296 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
|
1297 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
|
1298 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
|
1299 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
|
1300 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
|
1301 |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1302 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
|
1303 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
|
1304 { |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1305 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
|
1306 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
|
1307 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
|
1308 || 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
|
1309 prop.tp_type)) |
29451
057c26b5c33a
patch 9.0.0067: cannot show virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
1310 && (prop_ids == NULL |
057c26b5c33a
patch 9.0.0067: cannot show virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
1311 || prop_type_or_id_in_list(prop_ids, prop_ids_len, |
057c26b5c33a
patch 9.0.0067: cannot show virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
1312 prop.tp_id))) |
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
|
1313 { |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1314 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
|
1315 |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1316 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
|
1317 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
|
1318 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
|
1319 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
|
1320 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
|
1321 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
|
1322 } |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1323 } |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1324 } |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1325 |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1326 /* |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1327 * 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
|
1328 * 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
|
1329 * 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
|
1330 */ |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1331 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
|
1332 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
|
1333 { |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1334 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
|
1335 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
|
1336 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
|
1337 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
|
1338 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
|
1339 |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1340 *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
|
1341 |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1342 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
|
1343 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
|
1344 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
|
1345 |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1346 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
|
1347 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
|
1348 { |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1349 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
|
1350 { |
26877
06a137af96f8
patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26865
diff
changeset
|
1351 emsg(_(e_string_required)); |
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
|
1352 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
|
1353 } |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1354 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
|
1355 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
|
1356 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
|
1357 |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1358 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
|
1359 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
|
1360 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
|
1361 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
|
1362 } |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1363 |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1364 *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
|
1365 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
|
1366 |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1367 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
|
1368 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
|
1369 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
|
1370 } |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1371 |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1372 /* |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1373 * 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
|
1374 * 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
|
1375 * 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
|
1376 */ |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1377 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
|
1378 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
|
1379 { |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1380 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
|
1381 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
|
1382 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
|
1383 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
|
1384 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
|
1385 |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1386 *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
|
1387 |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1388 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
|
1389 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
|
1390 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
|
1391 |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1392 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
|
1393 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
|
1394 { |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1395 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
|
1396 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
|
1397 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
|
1398 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
|
1399 |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1400 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
|
1401 } |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1402 |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1403 *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
|
1404 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
|
1405 |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1406 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
|
1407 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
|
1408 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
|
1409 } |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1410 |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1411 /* |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1412 * prop_list({lnum} [, {bufnr}]) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1413 */ |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1414 void |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1415 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
|
1416 { |
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
|
1417 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
|
1418 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
|
1419 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
|
1420 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
|
1421 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
|
1422 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
|
1423 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
|
1424 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
|
1425 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
|
1426 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
|
1427 dictitem_T *di; |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1428 |
25252
acda780ffc3e
patch 8.2.3162: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25198
diff
changeset
|
1429 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
|
1430 && (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
|
1431 || 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
|
1432 return; |
acda780ffc3e
patch 8.2.3162: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25198
diff
changeset
|
1433 |
29175
755ab148288b
patch 8.2.5107: some callers of rettv_list_alloc() check for not OK
Bram Moolenaar <Bram@vim.org>
parents:
28984
diff
changeset
|
1434 if (rettv_list_alloc(rettv) == FAIL) |
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
|
1435 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
|
1436 |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1437 // 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
|
1438 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
|
1439 end_lnum = start_lnum; |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1440 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
|
1441 { |
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
|
1442 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
|
1443 |
29994
86eb4aba16c3
patch 9.0.0335: checks for Dictionary argument often give a vague error
Bram Moolenaar <Bram@vim.org>
parents:
29826
diff
changeset
|
1444 if (check_for_dict_arg(argvars, 1) == FAIL) |
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
|
1445 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
|
1446 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
|
1447 |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1448 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
|
1449 return; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1450 |
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
|
1451 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
|
1452 { |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1453 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
|
1454 { |
26877
06a137af96f8
patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26865
diff
changeset
|
1455 emsg(_(e_number_required)); |
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
|
1456 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
|
1457 } |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1458 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
|
1459 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
|
1460 // 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
|
1461 // 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
|
1462 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
|
1463 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
|
1464 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
|
1465 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
|
1466 } |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1467 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
|
1468 { |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1469 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
|
1470 { |
26877
06a137af96f8
patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26865
diff
changeset
|
1471 emsg(_(e_list_required)); |
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
|
1472 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
|
1473 } |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1474 |
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
|
1475 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
|
1476 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
|
1477 { |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1478 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
|
1479 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
|
1480 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
|
1481 } |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1482 } |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1483 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
|
1484 { |
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
|
1485 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
|
1486 { |
26877
06a137af96f8
patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26865
diff
changeset
|
1487 emsg(_(e_list_required)); |
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
|
1488 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
|
1489 } |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1490 |
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
|
1491 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
|
1492 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
|
1493 { |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1494 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
|
1495 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
|
1496 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
|
1497 } |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1498 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1499 } |
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
|
1500 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
|
1501 || 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
|
1502 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
|
1503 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
|
1504 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
|
1505 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
|
1506 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
|
1507 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
|
1508 |
685206b54ecf
patch 8.2.3652: can only get text properties one line at a time
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1509 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
|
1510 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
|
1511 VIM_CLEAR(prop_ids); |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1512 } |
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 /* |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1515 * prop_remove({props} [, {lnum} [, {lnum_end}]]) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1516 */ |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1517 void |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1518 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
|
1519 { |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1520 linenr_T start = 1; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1521 linenr_T end = 0; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1522 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
|
1523 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
|
1524 linenr_T last_changed = 0; |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1525 dict_T *dict; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1526 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
|
1527 int do_all; |
29552
89a97f70e8eb
patch 9.0.0117: text of removed textprop with text is not freed
Bram Moolenaar <Bram@vim.org>
parents:
29451
diff
changeset
|
1528 int id = -MAXCOL; |
29788
d08aa1bfe319
patch 9.0.0233: removing multiple text properties takes many calls
Bram Moolenaar <Bram@vim.org>
parents:
29748
diff
changeset
|
1529 int type_id = -1; // for a single "type" |
d08aa1bfe319
patch 9.0.0233: removing multiple text properties takes many calls
Bram Moolenaar <Bram@vim.org>
parents:
29748
diff
changeset
|
1530 int *type_ids = NULL; // array, for a list of "types", allocated |
d08aa1bfe319
patch 9.0.0233: removing multiple text properties takes many calls
Bram Moolenaar <Bram@vim.org>
parents:
29748
diff
changeset
|
1531 int num_type_ids = 0; // number of elements in "type_ids" |
22125
602e660d5ccf
patch 8.2.1612: Vim9: cannot pass "true" to prop_remove()
Bram Moolenaar <Bram@vim.org>
parents:
22069
diff
changeset
|
1532 int both; |
29552
89a97f70e8eb
patch 9.0.0117: text of removed textprop with text is not freed
Bram Moolenaar <Bram@vim.org>
parents:
29451
diff
changeset
|
1533 int did_remove_text = FALSE; |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1534 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1535 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
|
1536 |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
1537 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
|
1538 && (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
|
1539 || 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
|
1540 || (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
|
1541 && 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
|
1542 return; |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
1543 |
29994
86eb4aba16c3
patch 9.0.0335: checks for Dictionary argument often give a vague error
Bram Moolenaar <Bram@vim.org>
parents:
29826
diff
changeset
|
1544 if (check_for_nonnull_dict_arg(argvars, 0) == FAIL) |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1545 return; |
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 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
|
1548 { |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15182
diff
changeset
|
1549 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
|
1550 end = start; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1551 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
|
1552 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
|
1553 if (start < 1 || end < 1) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1554 { |
25064
8f2262c72178
patch 8.2.3069: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
24649
diff
changeset
|
1555 emsg(_(e_invalid_range)); |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1556 return; |
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 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1559 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1560 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
|
1561 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
|
1562 return; |
18093a6accb5
patch 8.1.1388: errors when calling prop_remove() for an unloaded buffer
Bram Moolenaar <Bram@vim.org>
parents:
16770
diff
changeset
|
1563 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
|
1564 return; |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1565 |
29442
827d9f2b7a71
patch 9.0.0063: too many type casts for dict_get functions
Bram Moolenaar <Bram@vim.org>
parents:
29340
diff
changeset
|
1566 do_all = dict_get_bool(dict, "all", FALSE); |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1567 |
28315
62cc3b60493b
patch 8.2.4683: verbose check with dict_find() to see if a key is present
Bram Moolenaar <Bram@vim.org>
parents:
26966
diff
changeset
|
1568 if (dict_has_key(dict, "id")) |
29442
827d9f2b7a71
patch 9.0.0063: too many type casts for dict_get functions
Bram Moolenaar <Bram@vim.org>
parents:
29340
diff
changeset
|
1569 id = dict_get_number(dict, "id"); |
29788
d08aa1bfe319
patch 9.0.0233: removing multiple text properties takes many calls
Bram Moolenaar <Bram@vim.org>
parents:
29748
diff
changeset
|
1570 |
d08aa1bfe319
patch 9.0.0233: removing multiple text properties takes many calls
Bram Moolenaar <Bram@vim.org>
parents:
29748
diff
changeset
|
1571 // if a specific type was supplied "type": check that (and ignore "types". |
d08aa1bfe319
patch 9.0.0233: removing multiple text properties takes many calls
Bram Moolenaar <Bram@vim.org>
parents:
29748
diff
changeset
|
1572 // Otherwise check against the list of "types". |
28315
62cc3b60493b
patch 8.2.4683: verbose check with dict_find() to see if a key is present
Bram Moolenaar <Bram@vim.org>
parents:
26966
diff
changeset
|
1573 if (dict_has_key(dict, "type")) |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1574 { |
29442
827d9f2b7a71
patch 9.0.0063: too many type casts for dict_get functions
Bram Moolenaar <Bram@vim.org>
parents:
29340
diff
changeset
|
1575 char_u *name = dict_get_string(dict, "type", FALSE); |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1576 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
|
1577 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1578 if (type == NULL) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1579 return; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1580 type_id = type->pt_id; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1581 } |
29788
d08aa1bfe319
patch 9.0.0233: removing multiple text properties takes many calls
Bram Moolenaar <Bram@vim.org>
parents:
29748
diff
changeset
|
1582 if (dict_has_key(dict, "types")) |
d08aa1bfe319
patch 9.0.0233: removing multiple text properties takes many calls
Bram Moolenaar <Bram@vim.org>
parents:
29748
diff
changeset
|
1583 { |
d08aa1bfe319
patch 9.0.0233: removing multiple text properties takes many calls
Bram Moolenaar <Bram@vim.org>
parents:
29748
diff
changeset
|
1584 typval_T types; |
d08aa1bfe319
patch 9.0.0233: removing multiple text properties takes many calls
Bram Moolenaar <Bram@vim.org>
parents:
29748
diff
changeset
|
1585 listitem_T *li = NULL; |
d08aa1bfe319
patch 9.0.0233: removing multiple text properties takes many calls
Bram Moolenaar <Bram@vim.org>
parents:
29748
diff
changeset
|
1586 |
d08aa1bfe319
patch 9.0.0233: removing multiple text properties takes many calls
Bram Moolenaar <Bram@vim.org>
parents:
29748
diff
changeset
|
1587 dict_get_tv(dict, "types", &types); |
d08aa1bfe319
patch 9.0.0233: removing multiple text properties takes many calls
Bram Moolenaar <Bram@vim.org>
parents:
29748
diff
changeset
|
1588 if (types.v_type == VAR_LIST && types.vval.v_list->lv_len > 0) |
d08aa1bfe319
patch 9.0.0233: removing multiple text properties takes many calls
Bram Moolenaar <Bram@vim.org>
parents:
29748
diff
changeset
|
1589 { |
d08aa1bfe319
patch 9.0.0233: removing multiple text properties takes many calls
Bram Moolenaar <Bram@vim.org>
parents:
29748
diff
changeset
|
1590 type_ids = alloc( sizeof(int) * types.vval.v_list->lv_len ); |
d08aa1bfe319
patch 9.0.0233: removing multiple text properties takes many calls
Bram Moolenaar <Bram@vim.org>
parents:
29748
diff
changeset
|
1591 |
d08aa1bfe319
patch 9.0.0233: removing multiple text properties takes many calls
Bram Moolenaar <Bram@vim.org>
parents:
29748
diff
changeset
|
1592 FOR_ALL_LIST_ITEMS(types.vval.v_list, li) |
d08aa1bfe319
patch 9.0.0233: removing multiple text properties takes many calls
Bram Moolenaar <Bram@vim.org>
parents:
29748
diff
changeset
|
1593 { |
d08aa1bfe319
patch 9.0.0233: removing multiple text properties takes many calls
Bram Moolenaar <Bram@vim.org>
parents:
29748
diff
changeset
|
1594 proptype_T *prop_type; |
d08aa1bfe319
patch 9.0.0233: removing multiple text properties takes many calls
Bram Moolenaar <Bram@vim.org>
parents:
29748
diff
changeset
|
1595 |
d08aa1bfe319
patch 9.0.0233: removing multiple text properties takes many calls
Bram Moolenaar <Bram@vim.org>
parents:
29748
diff
changeset
|
1596 if (li->li_tv.v_type != VAR_STRING) |
d08aa1bfe319
patch 9.0.0233: removing multiple text properties takes many calls
Bram Moolenaar <Bram@vim.org>
parents:
29748
diff
changeset
|
1597 continue; |
d08aa1bfe319
patch 9.0.0233: removing multiple text properties takes many calls
Bram Moolenaar <Bram@vim.org>
parents:
29748
diff
changeset
|
1598 |
d08aa1bfe319
patch 9.0.0233: removing multiple text properties takes many calls
Bram Moolenaar <Bram@vim.org>
parents:
29748
diff
changeset
|
1599 prop_type = lookup_prop_type(li->li_tv.vval.v_string, buf); |
d08aa1bfe319
patch 9.0.0233: removing multiple text properties takes many calls
Bram Moolenaar <Bram@vim.org>
parents:
29748
diff
changeset
|
1600 |
d08aa1bfe319
patch 9.0.0233: removing multiple text properties takes many calls
Bram Moolenaar <Bram@vim.org>
parents:
29748
diff
changeset
|
1601 if (!prop_type) |
d08aa1bfe319
patch 9.0.0233: removing multiple text properties takes many calls
Bram Moolenaar <Bram@vim.org>
parents:
29748
diff
changeset
|
1602 goto cleanup_prop_remove; |
d08aa1bfe319
patch 9.0.0233: removing multiple text properties takes many calls
Bram Moolenaar <Bram@vim.org>
parents:
29748
diff
changeset
|
1603 |
d08aa1bfe319
patch 9.0.0233: removing multiple text properties takes many calls
Bram Moolenaar <Bram@vim.org>
parents:
29748
diff
changeset
|
1604 type_ids[num_type_ids++] = prop_type->pt_id; |
d08aa1bfe319
patch 9.0.0233: removing multiple text properties takes many calls
Bram Moolenaar <Bram@vim.org>
parents:
29748
diff
changeset
|
1605 } |
d08aa1bfe319
patch 9.0.0233: removing multiple text properties takes many calls
Bram Moolenaar <Bram@vim.org>
parents:
29748
diff
changeset
|
1606 } |
d08aa1bfe319
patch 9.0.0233: removing multiple text properties takes many calls
Bram Moolenaar <Bram@vim.org>
parents:
29748
diff
changeset
|
1607 } |
29442
827d9f2b7a71
patch 9.0.0063: too many type casts for dict_get functions
Bram Moolenaar <Bram@vim.org>
parents:
29340
diff
changeset
|
1608 both = dict_get_bool(dict, "both", FALSE); |
22125
602e660d5ccf
patch 8.2.1612: Vim9: cannot pass "true" to prop_remove()
Bram Moolenaar <Bram@vim.org>
parents:
22069
diff
changeset
|
1609 |
29788
d08aa1bfe319
patch 9.0.0233: removing multiple text properties takes many calls
Bram Moolenaar <Bram@vim.org>
parents:
29748
diff
changeset
|
1610 if (id == -MAXCOL && (type_id == -1 && num_type_ids == 0)) |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1611 { |
26966
ac75c145f0a9
patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26962
diff
changeset
|
1612 emsg(_(e_need_at_least_one_of_id_or_type)); |
29788
d08aa1bfe319
patch 9.0.0233: removing multiple text properties takes many calls
Bram Moolenaar <Bram@vim.org>
parents:
29748
diff
changeset
|
1613 goto cleanup_prop_remove; |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1614 } |
29788
d08aa1bfe319
patch 9.0.0233: removing multiple text properties takes many calls
Bram Moolenaar <Bram@vim.org>
parents:
29748
diff
changeset
|
1615 if (both && (id == -MAXCOL || (type_id == -1 && num_type_ids == 0))) |
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
|
1616 { |
29788
d08aa1bfe319
patch 9.0.0233: removing multiple text properties takes many calls
Bram Moolenaar <Bram@vim.org>
parents:
29748
diff
changeset
|
1617 emsg(_(e_need_id_and_type_or_types_with_both)); |
d08aa1bfe319
patch 9.0.0233: removing multiple text properties takes many calls
Bram Moolenaar <Bram@vim.org>
parents:
29748
diff
changeset
|
1618 goto cleanup_prop_remove; |
d08aa1bfe319
patch 9.0.0233: removing multiple text properties takes many calls
Bram Moolenaar <Bram@vim.org>
parents:
29748
diff
changeset
|
1619 } |
d08aa1bfe319
patch 9.0.0233: removing multiple text properties takes many calls
Bram Moolenaar <Bram@vim.org>
parents:
29748
diff
changeset
|
1620 if (type_id != -1 && num_type_ids > 0) |
d08aa1bfe319
patch 9.0.0233: removing multiple text properties takes many calls
Bram Moolenaar <Bram@vim.org>
parents:
29748
diff
changeset
|
1621 { |
d08aa1bfe319
patch 9.0.0233: removing multiple text properties takes many calls
Bram Moolenaar <Bram@vim.org>
parents:
29748
diff
changeset
|
1622 emsg(_(e_cannot_specify_both_type_and_types)); |
d08aa1bfe319
patch 9.0.0233: removing multiple text properties takes many calls
Bram Moolenaar <Bram@vim.org>
parents:
29748
diff
changeset
|
1623 goto cleanup_prop_remove; |
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
|
1624 } |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1625 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1626 if (end == 0) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1627 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
|
1628 for (lnum = start; lnum <= end; ++lnum) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1629 { |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1630 char_u *text; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1631 size_t len; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1632 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1633 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
|
1634 break; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1635 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
|
1636 len = STRLEN(text) + 1; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1637 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
|
1638 { |
20583
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
1639 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
|
1640 unsigned idx; |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1641 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1642 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
|
1643 / sizeof(textprop_T); ++idx) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1644 { |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1645 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
|
1646 + idx * sizeof(textprop_T); |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1647 size_t taillen; |
29788
d08aa1bfe319
patch 9.0.0233: removing multiple text properties takes many calls
Bram Moolenaar <Bram@vim.org>
parents:
29748
diff
changeset
|
1648 int matches_id = 0; |
d08aa1bfe319
patch 9.0.0233: removing multiple text properties takes many calls
Bram Moolenaar <Bram@vim.org>
parents:
29748
diff
changeset
|
1649 int matches_type = 0; |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1650 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1651 mch_memmove(&textprop, cur_prop, sizeof(textprop_T)); |
29788
d08aa1bfe319
patch 9.0.0233: removing multiple text properties takes many calls
Bram Moolenaar <Bram@vim.org>
parents:
29748
diff
changeset
|
1652 |
d08aa1bfe319
patch 9.0.0233: removing multiple text properties takes many calls
Bram Moolenaar <Bram@vim.org>
parents:
29748
diff
changeset
|
1653 matches_id = textprop.tp_id == id; |
d08aa1bfe319
patch 9.0.0233: removing multiple text properties takes many calls
Bram Moolenaar <Bram@vim.org>
parents:
29748
diff
changeset
|
1654 if (num_type_ids > 0) |
d08aa1bfe319
patch 9.0.0233: removing multiple text properties takes many calls
Bram Moolenaar <Bram@vim.org>
parents:
29748
diff
changeset
|
1655 { |
d08aa1bfe319
patch 9.0.0233: removing multiple text properties takes many calls
Bram Moolenaar <Bram@vim.org>
parents:
29748
diff
changeset
|
1656 int idx2; |
d08aa1bfe319
patch 9.0.0233: removing multiple text properties takes many calls
Bram Moolenaar <Bram@vim.org>
parents:
29748
diff
changeset
|
1657 |
d08aa1bfe319
patch 9.0.0233: removing multiple text properties takes many calls
Bram Moolenaar <Bram@vim.org>
parents:
29748
diff
changeset
|
1658 for (idx2 = 0; !matches_type && idx2 < num_type_ids; ++idx2) |
d08aa1bfe319
patch 9.0.0233: removing multiple text properties takes many calls
Bram Moolenaar <Bram@vim.org>
parents:
29748
diff
changeset
|
1659 matches_type = textprop.tp_type == type_ids[idx2]; |
d08aa1bfe319
patch 9.0.0233: removing multiple text properties takes many calls
Bram Moolenaar <Bram@vim.org>
parents:
29748
diff
changeset
|
1660 } |
d08aa1bfe319
patch 9.0.0233: removing multiple text properties takes many calls
Bram Moolenaar <Bram@vim.org>
parents:
29748
diff
changeset
|
1661 else |
d08aa1bfe319
patch 9.0.0233: removing multiple text properties takes many calls
Bram Moolenaar <Bram@vim.org>
parents:
29748
diff
changeset
|
1662 { |
d08aa1bfe319
patch 9.0.0233: removing multiple text properties takes many calls
Bram Moolenaar <Bram@vim.org>
parents:
29748
diff
changeset
|
1663 matches_type = textprop.tp_type == type_id; |
d08aa1bfe319
patch 9.0.0233: removing multiple text properties takes many calls
Bram Moolenaar <Bram@vim.org>
parents:
29748
diff
changeset
|
1664 } |
d08aa1bfe319
patch 9.0.0233: removing multiple text properties takes many calls
Bram Moolenaar <Bram@vim.org>
parents:
29748
diff
changeset
|
1665 |
d08aa1bfe319
patch 9.0.0233: removing multiple text properties takes many calls
Bram Moolenaar <Bram@vim.org>
parents:
29748
diff
changeset
|
1666 if (both ? matches_id && matches_type |
d08aa1bfe319
patch 9.0.0233: removing multiple text properties takes many calls
Bram Moolenaar <Bram@vim.org>
parents:
29748
diff
changeset
|
1667 : matches_id || matches_type) |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1668 { |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1669 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
|
1670 { |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1671 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
|
1672 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1673 // 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
|
1674 if (newptr == NULL) |
29788
d08aa1bfe319
patch 9.0.0233: removing multiple text properties takes many calls
Bram Moolenaar <Bram@vim.org>
parents:
29748
diff
changeset
|
1675 goto cleanup_prop_remove; |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1676 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
|
1677 buf->b_ml.ml_line_len); |
29340
fba9e366ced4
patch 9.0.0013: reproducing memory access errors can be difficult
Bram Moolenaar <Bram@vim.org>
parents:
29175
diff
changeset
|
1678 if (buf->b_ml.ml_flags & ML_ALLOCATED) |
fba9e366ced4
patch 9.0.0013: reproducing memory access errors can be difficult
Bram Moolenaar <Bram@vim.org>
parents:
29175
diff
changeset
|
1679 vim_free(buf->b_ml.ml_line_ptr); |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1680 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
|
1681 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
|
1682 |
176872829dc2
patch 8.1.1035: prop_remove() second argument is not optional
Bram Moolenaar <Bram@vim.org>
parents:
15939
diff
changeset
|
1683 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
|
1684 + idx * sizeof(textprop_T); |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1685 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1686 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1687 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
|
1688 - (idx + 1) * sizeof(textprop_T); |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1689 if (taillen > 0) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1690 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
|
1691 taillen); |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1692 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
|
1693 --idx; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1694 |
29552
89a97f70e8eb
patch 9.0.0117: text of removed textprop with text is not freed
Bram Moolenaar <Bram@vim.org>
parents:
29451
diff
changeset
|
1695 if (textprop.tp_id < 0) |
89a97f70e8eb
patch 9.0.0117: text of removed textprop with text is not freed
Bram Moolenaar <Bram@vim.org>
parents:
29451
diff
changeset
|
1696 { |
89a97f70e8eb
patch 9.0.0117: text of removed textprop with text is not freed
Bram Moolenaar <Bram@vim.org>
parents:
29451
diff
changeset
|
1697 garray_T *gap = &buf->b_textprop_text; |
89a97f70e8eb
patch 9.0.0117: text of removed textprop with text is not freed
Bram Moolenaar <Bram@vim.org>
parents:
29451
diff
changeset
|
1698 int ii = -textprop.tp_id - 1; |
89a97f70e8eb
patch 9.0.0117: text of removed textprop with text is not freed
Bram Moolenaar <Bram@vim.org>
parents:
29451
diff
changeset
|
1699 |
89a97f70e8eb
patch 9.0.0117: text of removed textprop with text is not freed
Bram Moolenaar <Bram@vim.org>
parents:
29451
diff
changeset
|
1700 // negative ID: property with text - free the text |
89a97f70e8eb
patch 9.0.0117: text of removed textprop with text is not freed
Bram Moolenaar <Bram@vim.org>
parents:
29451
diff
changeset
|
1701 if (ii < gap->ga_len) |
89a97f70e8eb
patch 9.0.0117: text of removed textprop with text is not freed
Bram Moolenaar <Bram@vim.org>
parents:
29451
diff
changeset
|
1702 { |
89a97f70e8eb
patch 9.0.0117: text of removed textprop with text is not freed
Bram Moolenaar <Bram@vim.org>
parents:
29451
diff
changeset
|
1703 char_u **p = ((char_u **)gap->ga_data) + ii; |
89a97f70e8eb
patch 9.0.0117: text of removed textprop with text is not freed
Bram Moolenaar <Bram@vim.org>
parents:
29451
diff
changeset
|
1704 vim_free(*p); |
89a97f70e8eb
patch 9.0.0117: text of removed textprop with text is not freed
Bram Moolenaar <Bram@vim.org>
parents:
29451
diff
changeset
|
1705 *p = NULL; |
89a97f70e8eb
patch 9.0.0117: text of removed textprop with text is not freed
Bram Moolenaar <Bram@vim.org>
parents:
29451
diff
changeset
|
1706 did_remove_text = TRUE; |
89a97f70e8eb
patch 9.0.0117: text of removed textprop with text is not freed
Bram Moolenaar <Bram@vim.org>
parents:
29451
diff
changeset
|
1707 } |
89a97f70e8eb
patch 9.0.0117: text of removed textprop with text is not freed
Bram Moolenaar <Bram@vim.org>
parents:
29451
diff
changeset
|
1708 } |
89a97f70e8eb
patch 9.0.0117: text of removed textprop with text is not freed
Bram Moolenaar <Bram@vim.org>
parents:
29451
diff
changeset
|
1709 |
24649
31a7fa6b2e93
patch 8.2.2863: removing a text property does not redraw optimally
Bram Moolenaar <Bram@vim.org>
parents:
24647
diff
changeset
|
1710 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
|
1711 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
|
1712 last_changed = lnum; |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1713 ++rettv->vval.v_number; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1714 if (!do_all) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1715 break; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1716 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1717 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1718 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1719 } |
29552
89a97f70e8eb
patch 9.0.0117: text of removed textprop with text is not freed
Bram Moolenaar <Bram@vim.org>
parents:
29451
diff
changeset
|
1720 |
24649
31a7fa6b2e93
patch 8.2.2863: removing a text property does not redraw optimally
Bram Moolenaar <Bram@vim.org>
parents:
24647
diff
changeset
|
1721 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
|
1722 { |
29708
d97b2ce26258
patch 9.0.0194: cursor displayed in wrong position after removing text prop
Bram Moolenaar <Bram@vim.org>
parents:
29696
diff
changeset
|
1723 changed_line_display_buf(buf); |
24649
31a7fa6b2e93
patch 8.2.2863: removing a text property does not redraw optimally
Bram Moolenaar <Bram@vim.org>
parents:
24647
diff
changeset
|
1724 changed_lines_buf(buf, first_changed, last_changed + 1, 0); |
29732
89e1d67814a9
patch 9.0.0206: redraw flags are not named specifically
Bram Moolenaar <Bram@vim.org>
parents:
29730
diff
changeset
|
1725 redraw_buf_later(buf, UPD_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
|
1726 } |
29552
89a97f70e8eb
patch 9.0.0117: text of removed textprop with text is not freed
Bram Moolenaar <Bram@vim.org>
parents:
29451
diff
changeset
|
1727 |
89a97f70e8eb
patch 9.0.0117: text of removed textprop with text is not freed
Bram Moolenaar <Bram@vim.org>
parents:
29451
diff
changeset
|
1728 if (did_remove_text) |
89a97f70e8eb
patch 9.0.0117: text of removed textprop with text is not freed
Bram Moolenaar <Bram@vim.org>
parents:
29451
diff
changeset
|
1729 { |
89a97f70e8eb
patch 9.0.0117: text of removed textprop with text is not freed
Bram Moolenaar <Bram@vim.org>
parents:
29451
diff
changeset
|
1730 garray_T *gap = &buf->b_textprop_text; |
89a97f70e8eb
patch 9.0.0117: text of removed textprop with text is not freed
Bram Moolenaar <Bram@vim.org>
parents:
29451
diff
changeset
|
1731 |
89a97f70e8eb
patch 9.0.0117: text of removed textprop with text is not freed
Bram Moolenaar <Bram@vim.org>
parents:
29451
diff
changeset
|
1732 // Reduce the growarray size for NULL pointers at the end. |
89a97f70e8eb
patch 9.0.0117: text of removed textprop with text is not freed
Bram Moolenaar <Bram@vim.org>
parents:
29451
diff
changeset
|
1733 while (gap->ga_len > 0 |
89a97f70e8eb
patch 9.0.0117: text of removed textprop with text is not freed
Bram Moolenaar <Bram@vim.org>
parents:
29451
diff
changeset
|
1734 && ((char_u **)gap->ga_data)[gap->ga_len - 1] == NULL) |
89a97f70e8eb
patch 9.0.0117: text of removed textprop with text is not freed
Bram Moolenaar <Bram@vim.org>
parents:
29451
diff
changeset
|
1735 --gap->ga_len; |
89a97f70e8eb
patch 9.0.0117: text of removed textprop with text is not freed
Bram Moolenaar <Bram@vim.org>
parents:
29451
diff
changeset
|
1736 } |
29788
d08aa1bfe319
patch 9.0.0233: removing multiple text properties takes many calls
Bram Moolenaar <Bram@vim.org>
parents:
29748
diff
changeset
|
1737 |
d08aa1bfe319
patch 9.0.0233: removing multiple text properties takes many calls
Bram Moolenaar <Bram@vim.org>
parents:
29748
diff
changeset
|
1738 cleanup_prop_remove: |
d08aa1bfe319
patch 9.0.0233: removing multiple text properties takes many calls
Bram Moolenaar <Bram@vim.org>
parents:
29748
diff
changeset
|
1739 vim_free(type_ids); |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1740 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1741 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1742 /* |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1743 * 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
|
1744 */ |
17789
0f7ae8010787
patch 8.1.1891: functions used in one file are global
Bram Moolenaar <Bram@vim.org>
parents:
17694
diff
changeset
|
1745 static void |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1746 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
|
1747 { |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1748 char_u *name; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1749 buf_T *buf = NULL; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1750 dict_T *dict; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1751 dictitem_T *di; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1752 proptype_T *prop; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1753 |
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
|
1754 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
|
1755 && (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
|
1756 || 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
|
1757 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
|
1758 |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15182
diff
changeset
|
1759 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
|
1760 if (*name == NUL) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1761 { |
31319
243c35fad9cb
patch 9.0.0993: display errors when adding or removing text property type
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
1762 semsg(_(e_invalid_argument_str), "\"\""); |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1763 return; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1764 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1765 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1766 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
|
1767 return; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1768 dict = argvars[1].vval.v_dict; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1769 |
29649
a3a966b8b7a7
patch 9.0.0165: looking up a text property type by ID is slow
Bram Moolenaar <Bram@vim.org>
parents:
29627
diff
changeset
|
1770 prop = find_prop_type(name, buf); |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1771 if (add) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1772 { |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1773 hashtab_T **htp; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1774 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1775 if (prop != NULL) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1776 { |
26966
ac75c145f0a9
patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26962
diff
changeset
|
1777 semsg(_(e_property_type_str_already_defined), name); |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1778 return; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1779 } |
17659
121bdff812b4
patch 8.1.1827: allocating more memory than needed for extended structs
Bram Moolenaar <Bram@vim.org>
parents:
16924
diff
changeset
|
1780 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
|
1781 if (prop == NULL) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1782 return; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1783 STRCPY(prop->pt_name, name); |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1784 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
|
1785 prop->pt_flags = PT_FLAG_COMBINE; |
29649
a3a966b8b7a7
patch 9.0.0165: looking up a text property type by ID is slow
Bram Moolenaar <Bram@vim.org>
parents:
29627
diff
changeset
|
1786 if (buf == NULL) |
a3a966b8b7a7
patch 9.0.0165: looking up a text property type by ID is slow
Bram Moolenaar <Bram@vim.org>
parents:
29627
diff
changeset
|
1787 { |
a3a966b8b7a7
patch 9.0.0165: looking up a text property type by ID is slow
Bram Moolenaar <Bram@vim.org>
parents:
29627
diff
changeset
|
1788 htp = &global_proptypes; |
a3a966b8b7a7
patch 9.0.0165: looking up a text property type by ID is slow
Bram Moolenaar <Bram@vim.org>
parents:
29627
diff
changeset
|
1789 VIM_CLEAR(global_proparray); |
a3a966b8b7a7
patch 9.0.0165: looking up a text property type by ID is slow
Bram Moolenaar <Bram@vim.org>
parents:
29627
diff
changeset
|
1790 } |
a3a966b8b7a7
patch 9.0.0165: looking up a text property type by ID is slow
Bram Moolenaar <Bram@vim.org>
parents:
29627
diff
changeset
|
1791 else |
a3a966b8b7a7
patch 9.0.0165: looking up a text property type by ID is slow
Bram Moolenaar <Bram@vim.org>
parents:
29627
diff
changeset
|
1792 { |
a3a966b8b7a7
patch 9.0.0165: looking up a text property type by ID is slow
Bram Moolenaar <Bram@vim.org>
parents:
29627
diff
changeset
|
1793 htp = &buf->b_proptypes; |
a3a966b8b7a7
patch 9.0.0165: looking up a text property type by ID is slow
Bram Moolenaar <Bram@vim.org>
parents:
29627
diff
changeset
|
1794 VIM_CLEAR(buf->b_proparray); |
a3a966b8b7a7
patch 9.0.0165: looking up a text property type by ID is slow
Bram Moolenaar <Bram@vim.org>
parents:
29627
diff
changeset
|
1795 } |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1796 if (*htp == NULL) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1797 { |
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
|
1798 *htp = ALLOC_ONE(hashtab_T); |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1799 if (*htp == NULL) |
15144
7960bf50d345
patch 8.1.0582: text properties are not enabled
Bram Moolenaar <Bram@vim.org>
parents:
15138
diff
changeset
|
1800 { |
7960bf50d345
patch 8.1.0582: text properties are not enabled
Bram Moolenaar <Bram@vim.org>
parents:
15138
diff
changeset
|
1801 vim_free(prop); |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1802 return; |
15144
7960bf50d345
patch 8.1.0582: text properties are not enabled
Bram Moolenaar <Bram@vim.org>
parents:
15138
diff
changeset
|
1803 } |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1804 hash_init(*htp); |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1805 } |
31231
684e6dfa2fba
patch 9.0.0949: crash when unletting a variable while listing variables
Bram Moolenaar <Bram@vim.org>
parents:
30986
diff
changeset
|
1806 hash_add(*htp, PT2HIKEY(prop), "prop type"); |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1807 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1808 else |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1809 { |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1810 if (prop == NULL) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1811 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15390
diff
changeset
|
1812 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
|
1813 return; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1814 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1815 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1816 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1817 if (dict != NULL) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1818 { |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1819 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
|
1820 if (di != NULL) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1821 { |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1822 char_u *highlight; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1823 int hl_id = 0; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1824 |
29442
827d9f2b7a71
patch 9.0.0063: too many type casts for dict_get functions
Bram Moolenaar <Bram@vim.org>
parents:
29340
diff
changeset
|
1825 highlight = dict_get_string(dict, "highlight", FALSE); |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1826 if (highlight != NULL && *highlight != NUL) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1827 hl_id = syn_name2id(highlight); |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1828 if (hl_id <= 0) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1829 { |
26966
ac75c145f0a9
patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26962
diff
changeset
|
1830 semsg(_(e_unknown_highlight_group_name_str), |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1831 highlight == NULL ? (char_u *)"" : highlight); |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1832 return; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1833 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1834 prop->pt_hl_id = hl_id; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1835 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1836 |
16549
08557bad0b9d
patch 8.1.1278: missing change for "combine" field
Bram Moolenaar <Bram@vim.org>
parents:
16060
diff
changeset
|
1837 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
|
1838 if (di != NULL) |
08557bad0b9d
patch 8.1.1278: missing change for "combine" field
Bram Moolenaar <Bram@vim.org>
parents:
16060
diff
changeset
|
1839 { |
22127
9d3dfd420a45
patch 8.2.1613: Vim9: cannot pass "true" to prop_type_add()
Bram Moolenaar <Bram@vim.org>
parents:
22125
diff
changeset
|
1840 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
|
1841 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
|
1842 else |
08557bad0b9d
patch 8.1.1278: missing change for "combine" field
Bram Moolenaar <Bram@vim.org>
parents:
16060
diff
changeset
|
1843 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
|
1844 } |
08557bad0b9d
patch 8.1.1278: missing change for "combine" field
Bram Moolenaar <Bram@vim.org>
parents:
16060
diff
changeset
|
1845 |
29607
33d7c1fa2dac
patch 9.0.0144: text property cannot override 'cursorline' highlight
Bram Moolenaar <Bram@vim.org>
parents:
29585
diff
changeset
|
1846 di = dict_find(dict, (char_u *)"override", -1); |
33d7c1fa2dac
patch 9.0.0144: text property cannot override 'cursorline' highlight
Bram Moolenaar <Bram@vim.org>
parents:
29585
diff
changeset
|
1847 if (di != NULL) |
33d7c1fa2dac
patch 9.0.0144: text property cannot override 'cursorline' highlight
Bram Moolenaar <Bram@vim.org>
parents:
29585
diff
changeset
|
1848 { |
33d7c1fa2dac
patch 9.0.0144: text property cannot override 'cursorline' highlight
Bram Moolenaar <Bram@vim.org>
parents:
29585
diff
changeset
|
1849 if (tv_get_bool(&di->di_tv)) |
33d7c1fa2dac
patch 9.0.0144: text property cannot override 'cursorline' highlight
Bram Moolenaar <Bram@vim.org>
parents:
29585
diff
changeset
|
1850 prop->pt_flags |= PT_FLAG_OVERRIDE; |
33d7c1fa2dac
patch 9.0.0144: text property cannot override 'cursorline' highlight
Bram Moolenaar <Bram@vim.org>
parents:
29585
diff
changeset
|
1851 else |
33d7c1fa2dac
patch 9.0.0144: text property cannot override 'cursorline' highlight
Bram Moolenaar <Bram@vim.org>
parents:
29585
diff
changeset
|
1852 prop->pt_flags &= ~PT_FLAG_OVERRIDE; |
33d7c1fa2dac
patch 9.0.0144: text property cannot override 'cursorline' highlight
Bram Moolenaar <Bram@vim.org>
parents:
29585
diff
changeset
|
1853 } |
33d7c1fa2dac
patch 9.0.0144: text property cannot override 'cursorline' highlight
Bram Moolenaar <Bram@vim.org>
parents:
29585
diff
changeset
|
1854 |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1855 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
|
1856 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
|
1857 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
|
1858 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1859 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
|
1860 if (di != NULL) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1861 { |
22127
9d3dfd420a45
patch 8.2.1613: Vim9: cannot pass "true" to prop_type_add()
Bram Moolenaar <Bram@vim.org>
parents:
22125
diff
changeset
|
1862 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
|
1863 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
|
1864 else |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1865 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
|
1866 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1867 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1868 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
|
1869 if (di != NULL) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1870 { |
22127
9d3dfd420a45
patch 8.2.1613: Vim9: cannot pass "true" to prop_type_add()
Bram Moolenaar <Bram@vim.org>
parents:
22125
diff
changeset
|
1871 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
|
1872 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
|
1873 else |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1874 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
|
1875 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1876 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1877 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1878 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1879 /* |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1880 * prop_type_add({name}, {props}) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1881 */ |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1882 void |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1883 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
|
1884 { |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1885 prop_type_set(argvars, TRUE); |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1886 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1887 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1888 /* |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1889 * prop_type_change({name}, {props}) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1890 */ |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1891 void |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1892 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
|
1893 { |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1894 prop_type_set(argvars, FALSE); |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1895 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1896 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1897 /* |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1898 * prop_type_delete({name} [, {bufnr}]) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1899 */ |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1900 void |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1901 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
|
1902 { |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1903 char_u *name; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1904 buf_T *buf = NULL; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1905 hashitem_T *hi; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1906 |
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
|
1907 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
|
1908 && (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
|
1909 || 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
|
1910 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
|
1911 |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15182
diff
changeset
|
1912 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
|
1913 if (*name == NUL) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1914 { |
31319
243c35fad9cb
patch 9.0.0993: display errors when adding or removing text property type
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
1915 semsg(_(e_invalid_argument_str), "\"\""); |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1916 return; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1917 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1918 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1919 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
|
1920 { |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1921 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
|
1922 return; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1923 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1924 |
29649
a3a966b8b7a7
patch 9.0.0165: looking up a text property type by ID is slow
Bram Moolenaar <Bram@vim.org>
parents:
29627
diff
changeset
|
1925 hi = find_prop_type_hi(name, buf); |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1926 if (hi != NULL) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1927 { |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1928 hashtab_T *ht; |
15144
7960bf50d345
patch 8.1.0582: text properties are not enabled
Bram Moolenaar <Bram@vim.org>
parents:
15138
diff
changeset
|
1929 proptype_T *prop = HI2PT(hi); |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1930 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1931 if (buf == NULL) |
29649
a3a966b8b7a7
patch 9.0.0165: looking up a text property type by ID is slow
Bram Moolenaar <Bram@vim.org>
parents:
29627
diff
changeset
|
1932 { |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1933 ht = global_proptypes; |
29649
a3a966b8b7a7
patch 9.0.0165: looking up a text property type by ID is slow
Bram Moolenaar <Bram@vim.org>
parents:
29627
diff
changeset
|
1934 VIM_CLEAR(global_proparray); |
a3a966b8b7a7
patch 9.0.0165: looking up a text property type by ID is slow
Bram Moolenaar <Bram@vim.org>
parents:
29627
diff
changeset
|
1935 } |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1936 else |
29649
a3a966b8b7a7
patch 9.0.0165: looking up a text property type by ID is slow
Bram Moolenaar <Bram@vim.org>
parents:
29627
diff
changeset
|
1937 { |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1938 ht = buf->b_proptypes; |
29649
a3a966b8b7a7
patch 9.0.0165: looking up a text property type by ID is slow
Bram Moolenaar <Bram@vim.org>
parents:
29627
diff
changeset
|
1939 VIM_CLEAR(buf->b_proparray); |
a3a966b8b7a7
patch 9.0.0165: looking up a text property type by ID is slow
Bram Moolenaar <Bram@vim.org>
parents:
29627
diff
changeset
|
1940 } |
31231
684e6dfa2fba
patch 9.0.0949: crash when unletting a variable while listing variables
Bram Moolenaar <Bram@vim.org>
parents:
30986
diff
changeset
|
1941 hash_remove(ht, hi, "prop type delete"); |
15144
7960bf50d345
patch 8.1.0582: text properties are not enabled
Bram Moolenaar <Bram@vim.org>
parents:
15138
diff
changeset
|
1942 vim_free(prop); |
31319
243c35fad9cb
patch 9.0.0993: display errors when adding or removing text property type
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
1943 |
243c35fad9cb
patch 9.0.0993: display errors when adding or removing text property type
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
1944 // currently visibile text properties will disappear |
243c35fad9cb
patch 9.0.0993: display errors when adding or removing text property type
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
1945 redraw_all_later(UPD_CLEAR); |
243c35fad9cb
patch 9.0.0993: display errors when adding or removing text property type
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
1946 changed_window_setting_buf(buf == NULL ? curbuf : buf); |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1947 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1948 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1949 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1950 /* |
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
|
1951 * prop_type_get({name} [, {props}]) |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1952 */ |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1953 void |
19049
e47b04b01793
patch 8.2.0085: dead code in builtin functions
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1954 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
|
1955 { |
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
|
1956 char_u *name; |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1957 |
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
|
1958 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
|
1959 && (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
|
1960 || 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
|
1961 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
|
1962 |
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
|
1963 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
|
1964 if (*name == NUL) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1965 { |
31319
243c35fad9cb
patch 9.0.0993: display errors when adding or removing text property type
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
1966 semsg(_(e_invalid_argument_str), "\"\""); |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1967 return; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1968 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1969 if (rettv_dict_alloc(rettv) == OK) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1970 { |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1971 proptype_T *prop = NULL; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1972 buf_T *buf = NULL; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1973 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1974 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
|
1975 { |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1976 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
|
1977 return; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1978 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1979 |
29649
a3a966b8b7a7
patch 9.0.0165: looking up a text property type by ID is slow
Bram Moolenaar <Bram@vim.org>
parents:
29627
diff
changeset
|
1980 prop = find_prop_type(name, buf); |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1981 if (prop != NULL) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1982 { |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1983 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
|
1984 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1985 if (prop->pt_hl_id > 0) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1986 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
|
1987 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
|
1988 dict_add_number(d, "combine", |
08557bad0b9d
patch 8.1.1278: missing change for "combine" field
Bram Moolenaar <Bram@vim.org>
parents:
16060
diff
changeset
|
1989 (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
|
1990 dict_add_number(d, "start_incl", |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1991 (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
|
1992 dict_add_number(d, "end_incl", |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1993 (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
|
1994 if (buf != NULL) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1995 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
|
1996 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1997 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1998 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1999 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2000 static void |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2001 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
|
2002 { |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2003 long todo; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2004 hashitem_T *hi; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2005 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2006 todo = (long)ht->ht_used; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2007 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
|
2008 { |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2009 if (!HASHITEM_EMPTY(hi)) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2010 { |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2011 proptype_T *prop = HI2PT(hi); |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2012 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2013 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
|
2014 --todo; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2015 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2016 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2017 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2018 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2019 /* |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2020 * prop_type_list([{bufnr}]) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2021 */ |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2022 void |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2023 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
|
2024 { |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2025 buf_T *buf = NULL; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2026 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2027 if (rettv_list_alloc(rettv) == OK) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2028 { |
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
|
2029 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
|
2030 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
|
2031 |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2032 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
|
2033 { |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2034 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
|
2035 return; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2036 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2037 if (buf == NULL) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2038 { |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2039 if (global_proptypes != NULL) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2040 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
|
2041 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2042 else if (buf->b_proptypes != NULL) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2043 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
|
2044 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2045 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2046 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2047 /* |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2048 * Free all property types in "ht". |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2049 */ |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2050 static void |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2051 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
|
2052 { |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2053 long todo; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2054 hashitem_T *hi; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2055 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2056 if (ht == NULL) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2057 return; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2058 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2059 todo = (long)ht->ht_used; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2060 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
|
2061 { |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2062 if (!HASHITEM_EMPTY(hi)) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2063 { |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2064 proptype_T *prop = HI2PT(hi); |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2065 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2066 vim_free(prop); |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2067 --todo; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2068 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2069 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2070 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2071 hash_clear(ht); |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2072 vim_free(ht); |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2073 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2074 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2075 #if defined(EXITFREE) || defined(PROTO) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2076 /* |
15144
7960bf50d345
patch 8.1.0582: text properties are not enabled
Bram Moolenaar <Bram@vim.org>
parents:
15138
diff
changeset
|
2077 * Free all global property types. |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2078 */ |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2079 void |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2080 clear_global_prop_types(void) |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2081 { |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2082 clear_ht_prop_types(global_proptypes); |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2083 global_proptypes = NULL; |
29649
a3a966b8b7a7
patch 9.0.0165: looking up a text property type by ID is slow
Bram Moolenaar <Bram@vim.org>
parents:
29627
diff
changeset
|
2084 VIM_CLEAR(global_proparray); |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2085 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2086 #endif |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2087 |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2088 /* |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2089 * Free all property types for "buf". |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2090 */ |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2091 void |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2092 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
|
2093 { |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2094 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
|
2095 buf->b_proptypes = NULL; |
29649
a3a966b8b7a7
patch 9.0.0165: looking up a text property type by ID is slow
Bram Moolenaar <Bram@vim.org>
parents:
29627
diff
changeset
|
2096 VIM_CLEAR(buf->b_proparray); |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2097 } |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2098 |
20583
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
2099 // 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
|
2100 typedef struct |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
2101 { |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
2102 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
|
2103 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
|
2104 } adjustres_T; |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
2105 |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
2106 /* |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
2107 * 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
|
2108 * |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
2109 * 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
|
2110 * 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
|
2111 * "flags" can have: |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
2112 * APC_SUBSTITUTE: Text is replaced, not inserted. |
29748
7e2321707fea
patch 9.0.0214: splitting a line may duplicate virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29732
diff
changeset
|
2113 * APC_INDENT: Text is inserted before virtual text prop |
20583
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
2114 */ |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
2115 static adjustres_T |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
2116 adjust_prop( |
29560
14b139cbec49
patch 9.0.0121: cannot put virtual text after or below a line
Bram Moolenaar <Bram@vim.org>
parents:
29552
diff
changeset
|
2117 textprop_T *prop, |
14b139cbec49
patch 9.0.0121: cannot put virtual text after or below a line
Bram Moolenaar <Bram@vim.org>
parents:
29552
diff
changeset
|
2118 colnr_T col, |
14b139cbec49
patch 9.0.0121: cannot put virtual text after or below a line
Bram Moolenaar <Bram@vim.org>
parents:
29552
diff
changeset
|
2119 int added, |
14b139cbec49
patch 9.0.0121: cannot put virtual text after or below a line
Bram Moolenaar <Bram@vim.org>
parents:
29552
diff
changeset
|
2120 int flags) |
20583
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
2121 { |
29560
14b139cbec49
patch 9.0.0121: cannot put virtual text after or below a line
Bram Moolenaar <Bram@vim.org>
parents:
29552
diff
changeset
|
2122 proptype_T *pt; |
14b139cbec49
patch 9.0.0121: cannot put virtual text after or below a line
Bram Moolenaar <Bram@vim.org>
parents:
29552
diff
changeset
|
2123 int start_incl; |
14b139cbec49
patch 9.0.0121: cannot put virtual text after or below a line
Bram Moolenaar <Bram@vim.org>
parents:
29552
diff
changeset
|
2124 int end_incl; |
14b139cbec49
patch 9.0.0121: cannot put virtual text after or below a line
Bram Moolenaar <Bram@vim.org>
parents:
29552
diff
changeset
|
2125 int droppable; |
14b139cbec49
patch 9.0.0121: cannot put virtual text after or below a line
Bram Moolenaar <Bram@vim.org>
parents:
29552
diff
changeset
|
2126 adjustres_T res = {TRUE, FALSE}; |
14b139cbec49
patch 9.0.0121: cannot put virtual text after or below a line
Bram Moolenaar <Bram@vim.org>
parents:
29552
diff
changeset
|
2127 |
14b139cbec49
patch 9.0.0121: cannot put virtual text after or below a line
Bram Moolenaar <Bram@vim.org>
parents:
29552
diff
changeset
|
2128 // prop after end of the line doesn't move |
14b139cbec49
patch 9.0.0121: cannot put virtual text after or below a line
Bram Moolenaar <Bram@vim.org>
parents:
29552
diff
changeset
|
2129 if (prop->tp_col == MAXCOL) |
14b139cbec49
patch 9.0.0121: cannot put virtual text after or below a line
Bram Moolenaar <Bram@vim.org>
parents:
29552
diff
changeset
|
2130 { |
14b139cbec49
patch 9.0.0121: cannot put virtual text after or below a line
Bram Moolenaar <Bram@vim.org>
parents:
29552
diff
changeset
|
2131 res.dirty = FALSE; |
14b139cbec49
patch 9.0.0121: cannot put virtual text after or below a line
Bram Moolenaar <Bram@vim.org>
parents:
29552
diff
changeset
|
2132 return res; |
14b139cbec49
patch 9.0.0121: cannot put virtual text after or below a line
Bram Moolenaar <Bram@vim.org>
parents:
29552
diff
changeset
|
2133 } |
14b139cbec49
patch 9.0.0121: cannot put virtual text after or below a line
Bram Moolenaar <Bram@vim.org>
parents:
29552
diff
changeset
|
2134 |
14b139cbec49
patch 9.0.0121: cannot put virtual text after or below a line
Bram Moolenaar <Bram@vim.org>
parents:
29552
diff
changeset
|
2135 pt = text_prop_type_by_id(curbuf, prop->tp_type); |
14b139cbec49
patch 9.0.0121: cannot put virtual text after or below a line
Bram Moolenaar <Bram@vim.org>
parents:
29552
diff
changeset
|
2136 start_incl = (pt != NULL && (pt->pt_flags & PT_FLAG_INS_START_INCL)) |
28863
92736a673e3c
patch 8.2.4954: inserting line breaks text property spanning two lines
Bram Moolenaar <Bram@vim.org>
parents:
28526
diff
changeset
|
2137 || (flags & APC_SUBSTITUTE) |
92736a673e3c
patch 8.2.4954: inserting line breaks text property spanning two lines
Bram Moolenaar <Bram@vim.org>
parents:
28526
diff
changeset
|
2138 || (prop->tp_flags & TP_FLAG_CONT_PREV); |
29748
7e2321707fea
patch 9.0.0214: splitting a line may duplicate virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29732
diff
changeset
|
2139 if (prop->tp_id < 0 && (flags & APC_INDENT)) |
7e2321707fea
patch 9.0.0214: splitting a line may duplicate virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29732
diff
changeset
|
2140 // when inserting indent just before a character with virtual text |
7e2321707fea
patch 9.0.0214: splitting a line may duplicate virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29732
diff
changeset
|
2141 // shift the text property |
7e2321707fea
patch 9.0.0214: splitting a line may duplicate virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29732
diff
changeset
|
2142 start_incl = FALSE; |
29560
14b139cbec49
patch 9.0.0121: cannot put virtual text after or below a line
Bram Moolenaar <Bram@vim.org>
parents:
29552
diff
changeset
|
2143 end_incl = (pt != NULL && (pt->pt_flags & PT_FLAG_INS_END_INCL)) |
28863
92736a673e3c
patch 8.2.4954: inserting line breaks text property spanning two lines
Bram Moolenaar <Bram@vim.org>
parents:
28526
diff
changeset
|
2144 || (prop->tp_flags & TP_FLAG_CONT_NEXT); |
29560
14b139cbec49
patch 9.0.0121: cannot put virtual text after or below a line
Bram Moolenaar <Bram@vim.org>
parents:
29552
diff
changeset
|
2145 // do not drop zero-width props if they later can increase in size |
14b139cbec49
patch 9.0.0121: cannot put virtual text after or below a line
Bram Moolenaar <Bram@vim.org>
parents:
29552
diff
changeset
|
2146 droppable = !(start_incl || end_incl); |
20583
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
2147 |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
2148 if (added > 0) |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
2149 { |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
2150 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
|
2151 - (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
|
2152 // 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
|
2153 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
|
2154 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
|
2155 // 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
|
2156 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
|
2157 } |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
2158 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
|
2159 { |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
2160 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
|
2161 { |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
2162 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
|
2163 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
|
2164 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
|
2165 { |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
2166 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
|
2167 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
|
2168 } |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
2169 } |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
2170 else |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
2171 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
|
2172 } |
29826
bfd08e50e2c0
patch 9.0.0252: cursor in wrong place after virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29816
diff
changeset
|
2173 else if (prop->tp_len > 0 && prop->tp_col + prop->tp_len > col |
bfd08e50e2c0
patch 9.0.0252: cursor in wrong place after virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29816
diff
changeset
|
2174 && prop->tp_id >= 0) // don't change length for virtual text |
20583
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
2175 { |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
2176 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
|
2177 |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
2178 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
|
2179 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
|
2180 } |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
2181 else |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
2182 res.dirty = FALSE; |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
2183 |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
2184 return res; |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
2185 } |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
2186 |
15335
18c20ceee4b5
patch 8.1.0675: text property column in screen columns is not practical
Bram Moolenaar <Bram@vim.org>
parents:
15294
diff
changeset
|
2187 /* |
18c20ceee4b5
patch 8.1.0675: text property column in screen columns is not practical
Bram Moolenaar <Bram@vim.org>
parents:
15294
diff
changeset
|
2188 * 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
|
2189 * 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
|
2190 * 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
|
2191 * 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
|
2192 * "flags" can have: |
ba592f30c082
patch 8.1.1359: text property wrong after :substitute with backslash
Bram Moolenaar <Bram@vim.org>
parents:
16698
diff
changeset
|
2193 * 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
|
2194 * APC_SUBSTITUTE: Text is replaced, not inserted. |
29748
7e2321707fea
patch 9.0.0214: splitting a line may duplicate virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29732
diff
changeset
|
2195 * APC_INDENT: Text is inserted before virtual text prop |
16682
7847d281cbbf
patch 8.1.1343: text properties not adjusted for Visual block mode delete
Bram Moolenaar <Bram@vim.org>
parents:
16678
diff
changeset
|
2196 * 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
|
2197 * 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
|
2198 */ |
16698
23af483c4ceb
patch 8.1.1351: text property wrong after :substitute
Bram Moolenaar <Bram@vim.org>
parents:
16682
diff
changeset
|
2199 int |
15349
6abee072b93c
patch 8.1.0682: text properties not adjusted when backspacing replaced text
Bram Moolenaar <Bram@vim.org>
parents:
15341
diff
changeset
|
2200 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
|
2201 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
|
2202 colnr_T col, |
16698
23af483c4ceb
patch 8.1.1351: text property wrong after :substitute
Bram Moolenaar <Bram@vim.org>
parents:
16682
diff
changeset
|
2203 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
|
2204 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
|
2205 { |
15341
03a7a9fdb792
patch 8.1.0678: text properties as not adjusted for inserted text
Bram Moolenaar <Bram@vim.org>
parents:
15335
diff
changeset
|
2206 int proplen; |
03a7a9fdb792
patch 8.1.0678: text properties as not adjusted for inserted text
Bram Moolenaar <Bram@vim.org>
parents:
15335
diff
changeset
|
2207 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
|
2208 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
|
2209 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
|
2210 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
|
2211 |
6abee072b93c
patch 8.1.0682: text properties not adjusted when backspacing replaced text
Bram Moolenaar <Bram@vim.org>
parents:
15341
diff
changeset
|
2212 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
|
2213 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
|
2214 |
03a7a9fdb792
patch 8.1.0678: text properties as not adjusted for inserted text
Bram Moolenaar <Bram@vim.org>
parents:
15335
diff
changeset
|
2215 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
|
2216 if (proplen == 0) |
16698
23af483c4ceb
patch 8.1.1351: text property wrong after :substitute
Bram Moolenaar <Bram@vim.org>
parents:
16682
diff
changeset
|
2217 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
|
2218 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
|
2219 |
15349
6abee072b93c
patch 8.1.0682: text properties not adjusted when backspacing replaced text
Bram Moolenaar <Bram@vim.org>
parents:
15341
diff
changeset
|
2220 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
|
2221 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
|
2222 { |
19534
36ec10251b2b
patch 8.2.0324: text property not updated correctly when inserting/deleting
Bram Moolenaar <Bram@vim.org>
parents:
19100
diff
changeset
|
2223 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
|
2224 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
|
2225 |
20583
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
2226 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
|
2227 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
|
2228 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
|
2229 { |
16714
ba592f30c082
patch 8.1.1359: text property wrong after :substitute with backslash
Bram Moolenaar <Bram@vim.org>
parents:
16698
diff
changeset
|
2230 // 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
|
2231 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
|
2232 && 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
|
2233 return FALSE; |
16714
ba592f30c082
patch 8.1.1359: text property wrong after :substitute with backslash
Bram Moolenaar <Bram@vim.org>
parents:
16698
diff
changeset
|
2234 dirty = TRUE; |
22331
0271c2b8bb35
patch 8.2.1714: text properties corrupted with substitute command
Bram Moolenaar <Bram@vim.org>
parents:
22127
diff
changeset
|
2235 |
0271c2b8bb35
patch 8.2.1714: text properties corrupted with substitute command
Bram Moolenaar <Bram@vim.org>
parents:
22127
diff
changeset
|
2236 // 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
|
2237 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
|
2238 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
|
2239 } |
20583
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
2240 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
|
2241 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
|
2242 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
|
2243 ++wi; |
6abee072b93c
patch 8.1.0682: text properties not adjusted when backspacing replaced text
Bram Moolenaar <Bram@vim.org>
parents:
15341
diff
changeset
|
2244 } |
6abee072b93c
patch 8.1.0682: text properties not adjusted when backspacing replaced text
Bram Moolenaar <Bram@vim.org>
parents:
15341
diff
changeset
|
2245 if (dirty) |
6abee072b93c
patch 8.1.0682: text properties not adjusted when backspacing replaced text
Bram Moolenaar <Bram@vim.org>
parents:
15341
diff
changeset
|
2246 { |
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
|
2247 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
|
2248 |
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
|
2249 if ((curbuf->b_ml.ml_flags & ML_LINE_DIRTY) == 0) |
29340
fba9e366ced4
patch 9.0.0013: reproducing memory access errors can be difficult
Bram Moolenaar <Bram@vim.org>
parents:
29175
diff
changeset
|
2250 { |
fba9e366ced4
patch 9.0.0013: reproducing memory access errors can be difficult
Bram Moolenaar <Bram@vim.org>
parents:
29175
diff
changeset
|
2251 char_u *p = vim_memsave(curbuf->b_ml.ml_line_ptr, newlen); |
fba9e366ced4
patch 9.0.0013: reproducing memory access errors can be difficult
Bram Moolenaar <Bram@vim.org>
parents:
29175
diff
changeset
|
2252 |
fba9e366ced4
patch 9.0.0013: reproducing memory access errors can be difficult
Bram Moolenaar <Bram@vim.org>
parents:
29175
diff
changeset
|
2253 if (curbuf->b_ml.ml_flags & ML_ALLOCATED) |
fba9e366ced4
patch 9.0.0013: reproducing memory access errors can be difficult
Bram Moolenaar <Bram@vim.org>
parents:
29175
diff
changeset
|
2254 vim_free(curbuf->b_ml.ml_line_ptr); |
fba9e366ced4
patch 9.0.0013: reproducing memory access errors can be difficult
Bram Moolenaar <Bram@vim.org>
parents:
29175
diff
changeset
|
2255 curbuf->b_ml.ml_line_ptr = p; |
fba9e366ced4
patch 9.0.0013: reproducing memory access errors can be difficult
Bram Moolenaar <Bram@vim.org>
parents:
29175
diff
changeset
|
2256 } |
15349
6abee072b93c
patch 8.1.0682: text properties not adjusted when backspacing replaced text
Bram Moolenaar <Bram@vim.org>
parents:
15341
diff
changeset
|
2257 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
|
2258 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
|
2259 } |
16698
23af483c4ceb
patch 8.1.1351: text property wrong after :substitute
Bram Moolenaar <Bram@vim.org>
parents:
16682
diff
changeset
|
2260 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
|
2261 } |
18c20ceee4b5
patch 8.1.0675: text property column in screen columns is not practical
Bram Moolenaar <Bram@vim.org>
parents:
15294
diff
changeset
|
2262 |
15367
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
2263 /* |
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
2264 * 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
|
2265 * "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
|
2266 * "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
|
2267 * "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
|
2268 * "deleted" is the number of bytes deleted. |
30261
6b658ef69e93
patch 9.0.0466: virtual text wrong after adding line break after line
Bram Moolenaar <Bram@vim.org>
parents:
30253
diff
changeset
|
2269 * "at_eol" is true if the split is after the end of the line. |
15367
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
2270 */ |
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
2271 void |
16662
1fc9cd08cf3c
patch 8.1.1333: text properties don't always move after changes
Bram Moolenaar <Bram@vim.org>
parents:
16549
diff
changeset
|
2272 adjust_props_for_split( |
30261
6b658ef69e93
patch 9.0.0466: virtual text wrong after adding line break after line
Bram Moolenaar <Bram@vim.org>
parents:
30253
diff
changeset
|
2273 linenr_T lnum_props, |
6b658ef69e93
patch 9.0.0466: virtual text wrong after adding line break after line
Bram Moolenaar <Bram@vim.org>
parents:
30253
diff
changeset
|
2274 linenr_T lnum_top, |
6b658ef69e93
patch 9.0.0466: virtual text wrong after adding line break after line
Bram Moolenaar <Bram@vim.org>
parents:
30253
diff
changeset
|
2275 int kept, |
6b658ef69e93
patch 9.0.0466: virtual text wrong after adding line break after line
Bram Moolenaar <Bram@vim.org>
parents:
30253
diff
changeset
|
2276 int deleted, |
6b658ef69e93
patch 9.0.0466: virtual text wrong after adding line break after line
Bram Moolenaar <Bram@vim.org>
parents:
30253
diff
changeset
|
2277 int at_eol) |
15367
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
2278 { |
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
2279 char_u *props; |
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
2280 int count; |
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
2281 garray_T prevprop; |
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
2282 garray_T nextprop; |
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
2283 int i; |
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
2284 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
|
2285 |
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
2286 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
|
2287 return; |
16662
1fc9cd08cf3c
patch 8.1.1333: text properties don't always move after changes
Bram Moolenaar <Bram@vim.org>
parents:
16549
diff
changeset
|
2288 |
1fc9cd08cf3c
patch 8.1.1333: text properties don't always move after changes
Bram Moolenaar <Bram@vim.org>
parents:
16549
diff
changeset
|
2289 // 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
|
2290 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
|
2291 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
|
2292 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
|
2293 |
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
2294 // 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
|
2295 // 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
|
2296 // 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
|
2297 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
|
2298 { |
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
2299 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
|
2300 proptype_T *pt; |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
2301 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
|
2302 int cont_prev, cont_next; |
30245
8f85b5c45432
patch 9.0.0458: splitting a line with a text prop "above" moves it down
Bram Moolenaar <Bram@vim.org>
parents:
30233
diff
changeset
|
2303 int prop_col; |
15367
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
2304 |
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
2305 // 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
|
2306 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
|
2307 |
20583
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
2308 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
|
2309 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
|
2310 end_incl = (pt != NULL && (pt->pt_flags & PT_FLAG_INS_END_INCL)); |
30245
8f85b5c45432
patch 9.0.0458: splitting a line with a text prop "above" moves it down
Bram Moolenaar <Bram@vim.org>
parents:
30233
diff
changeset
|
2311 |
8f85b5c45432
patch 9.0.0458: splitting a line with a text prop "above" moves it down
Bram Moolenaar <Bram@vim.org>
parents:
30233
diff
changeset
|
2312 // a text prop "above" behaves like it is on the first text column |
8f85b5c45432
patch 9.0.0458: splitting a line with a text prop "above" moves it down
Bram Moolenaar <Bram@vim.org>
parents:
30233
diff
changeset
|
2313 prop_col = (prop.tp_flags & TP_FLAG_ALIGN_ABOVE) ? 1 : prop.tp_col; |
8f85b5c45432
patch 9.0.0458: splitting a line with a text prop "above" moves it down
Bram Moolenaar <Bram@vim.org>
parents:
30233
diff
changeset
|
2314 |
30261
6b658ef69e93
patch 9.0.0466: virtual text wrong after adding line break after line
Bram Moolenaar <Bram@vim.org>
parents:
30253
diff
changeset
|
2315 if (prop_col == MAXCOL) |
6b658ef69e93
patch 9.0.0466: virtual text wrong after adding line break after line
Bram Moolenaar <Bram@vim.org>
parents:
30253
diff
changeset
|
2316 { |
6b658ef69e93
patch 9.0.0466: virtual text wrong after adding line break after line
Bram Moolenaar <Bram@vim.org>
parents:
30253
diff
changeset
|
2317 cont_prev = at_eol; |
6b658ef69e93
patch 9.0.0466: virtual text wrong after adding line break after line
Bram Moolenaar <Bram@vim.org>
parents:
30253
diff
changeset
|
2318 cont_next = !at_eol; |
6b658ef69e93
patch 9.0.0466: virtual text wrong after adding line break after line
Bram Moolenaar <Bram@vim.org>
parents:
30253
diff
changeset
|
2319 } |
6b658ef69e93
patch 9.0.0466: virtual text wrong after adding line break after line
Bram Moolenaar <Bram@vim.org>
parents:
30253
diff
changeset
|
2320 else |
6b658ef69e93
patch 9.0.0466: virtual text wrong after adding line break after line
Bram Moolenaar <Bram@vim.org>
parents:
30253
diff
changeset
|
2321 { |
6b658ef69e93
patch 9.0.0466: virtual text wrong after adding line break after line
Bram Moolenaar <Bram@vim.org>
parents:
30253
diff
changeset
|
2322 cont_prev = prop_col + !start_incl <= kept; |
6b658ef69e93
patch 9.0.0466: virtual text wrong after adding line break after line
Bram Moolenaar <Bram@vim.org>
parents:
30253
diff
changeset
|
2323 cont_next = skipped <= prop_col + prop.tp_len - !end_incl; |
6b658ef69e93
patch 9.0.0466: virtual text wrong after adding line break after line
Bram Moolenaar <Bram@vim.org>
parents:
30253
diff
changeset
|
2324 } |
29748
7e2321707fea
patch 9.0.0214: splitting a line may duplicate virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29732
diff
changeset
|
2325 // when a prop has text it is never copied |
7e2321707fea
patch 9.0.0214: splitting a line may duplicate virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29732
diff
changeset
|
2326 if (prop.tp_id < 0 && cont_next) |
7e2321707fea
patch 9.0.0214: splitting a line may duplicate virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29732
diff
changeset
|
2327 cont_prev = FALSE; |
20583
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
2328 |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
2329 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
|
2330 { |
20583
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
2331 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
|
2332 |
15367
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
2333 *p = prop; |
20583
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
2334 ++prevprop.ga_len; |
30253
c0c7a6748061
patch 9.0.0462: ASAN warning for integer overflow
Bram Moolenaar <Bram@vim.org>
parents:
30245
diff
changeset
|
2335 if (p->tp_col != MAXCOL && p->tp_col + p->tp_len >= kept) |
15367
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
2336 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
|
2337 if (cont_next) |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
2338 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
|
2339 } |
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
2340 |
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
|
2341 // 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
|
2342 // zero. |
30261
6b658ef69e93
patch 9.0.0466: virtual text wrong after adding line break after line
Bram Moolenaar <Bram@vim.org>
parents:
30253
diff
changeset
|
2343 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
|
2344 { |
20583
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
2345 textprop_T *p = ((textprop_T *)nextprop.ga_data) + nextprop.ga_len; |
29627
dd96f3d8ed85
patch 9.0.0154: text properties wrong after splitting a line
Bram Moolenaar <Bram@vim.org>
parents:
29621
diff
changeset
|
2346 |
15367
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
2347 *p = prop; |
20583
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
2348 ++nextprop.ga_len; |
29627
dd96f3d8ed85
patch 9.0.0154: text properties wrong after splitting a line
Bram Moolenaar <Bram@vim.org>
parents:
29621
diff
changeset
|
2349 if (p->tp_col != MAXCOL) |
15367
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
2350 { |
29627
dd96f3d8ed85
patch 9.0.0154: text properties wrong after splitting a line
Bram Moolenaar <Bram@vim.org>
parents:
29621
diff
changeset
|
2351 if (p->tp_col > skipped) |
dd96f3d8ed85
patch 9.0.0154: text properties wrong after splitting a line
Bram Moolenaar <Bram@vim.org>
parents:
29621
diff
changeset
|
2352 p->tp_col -= skipped - 1; |
dd96f3d8ed85
patch 9.0.0154: text properties wrong after splitting a line
Bram Moolenaar <Bram@vim.org>
parents:
29621
diff
changeset
|
2353 else |
dd96f3d8ed85
patch 9.0.0154: text properties wrong after splitting a line
Bram Moolenaar <Bram@vim.org>
parents:
29621
diff
changeset
|
2354 { |
dd96f3d8ed85
patch 9.0.0154: text properties wrong after splitting a line
Bram Moolenaar <Bram@vim.org>
parents:
29621
diff
changeset
|
2355 p->tp_len -= skipped - p->tp_col; |
dd96f3d8ed85
patch 9.0.0154: text properties wrong after splitting a line
Bram Moolenaar <Bram@vim.org>
parents:
29621
diff
changeset
|
2356 p->tp_col = 1; |
dd96f3d8ed85
patch 9.0.0154: text properties wrong after splitting a line
Bram Moolenaar <Bram@vim.org>
parents:
29621
diff
changeset
|
2357 } |
15367
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
2358 } |
20583
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
2359 if (cont_prev) |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
2360 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
|
2361 } |
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
2362 } |
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
2363 |
16662
1fc9cd08cf3c
patch 8.1.1333: text properties don't always move after changes
Bram Moolenaar <Bram@vim.org>
parents:
16549
diff
changeset
|
2364 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
|
2365 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
|
2366 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
|
2367 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
|
2368 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
|
2369 ga_clear(&nextprop); |
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
2370 } |
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
2371 |
16678
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16676
diff
changeset
|
2372 /* |
20583
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
2373 * 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
|
2374 */ |
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16676
diff
changeset
|
2375 void |
20583
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
2376 prepend_joined_props( |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
2377 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
|
2378 int propcount, |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
2379 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
|
2380 linenr_T lnum, |
29585
e357bc89bb95
patch 9.0.0133: virtual text after line moves to joined line
Bram Moolenaar <Bram@vim.org>
parents:
29581
diff
changeset
|
2381 int last_line, |
16678
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16676
diff
changeset
|
2382 long col, |
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16676
diff
changeset
|
2383 int removed) |
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16676
diff
changeset
|
2384 { |
20583
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
2385 char_u *props; |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
2386 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
|
2387 int i; |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
2388 |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
2389 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
|
2390 { |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
2391 textprop_T prop; |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
2392 int end; |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
2393 |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
2394 mch_memmove(&prop, props + i * sizeof(prop), sizeof(prop)); |
29585
e357bc89bb95
patch 9.0.0133: virtual text after line moves to joined line
Bram Moolenaar <Bram@vim.org>
parents:
29581
diff
changeset
|
2395 if (prop.tp_col == MAXCOL && !last_line) |
e357bc89bb95
patch 9.0.0133: virtual text after line moves to joined line
Bram Moolenaar <Bram@vim.org>
parents:
29581
diff
changeset
|
2396 continue; // drop property with text after the line |
20583
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
2397 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
|
2398 |
20583
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
2399 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
|
2400 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
|
2401 |
29585
e357bc89bb95
patch 9.0.0133: virtual text after line moves to joined line
Bram Moolenaar <Bram@vim.org>
parents:
29581
diff
changeset
|
2402 if (last_line || end) |
20583
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
2403 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
|
2404 &prop, sizeof(prop)); |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
2405 else |
16678
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16676
diff
changeset
|
2406 { |
20583
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
2407 int j; |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
2408 int found = FALSE; |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
2409 |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
2410 // 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
|
2411 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
|
2412 { |
20583
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
2413 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
|
2414 |
20583
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
2415 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
|
2416 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
|
2417 && 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
|
2418 { |
20583
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
2419 found = TRUE; |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
2420 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
|
2421 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
|
2422 // 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
|
2423 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
|
2424 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
|
2425 break; |
16678
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16676
diff
changeset
|
2426 } |
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16676
diff
changeset
|
2427 } |
20583
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
2428 if (!found) |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
19644
diff
changeset
|
2429 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
|
2430 } |
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16676
diff
changeset
|
2431 } |
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16676
diff
changeset
|
2432 } |
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16676
diff
changeset
|
2433 |
18763
49b78d6465e5
patch 8.1.2371: FEAT_TEXT_PROP is a confusing name
Bram Moolenaar <Bram@vim.org>
parents:
18631
diff
changeset
|
2434 #endif // FEAT_PROP_POPUP |