Skip to content

Commit e05a89a

Browse files
committed
patch 8.2.0110: prop_find() is not implemented
Problem: prop_find() is not implemented. Solution: Implement prop_find(). (Ryan Hackett, closes #5421, closes #4970)
1 parent 2963456 commit e05a89a

6 files changed

Lines changed: 319 additions & 31 deletions

File tree

runtime/doc/textprop.txt

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,6 @@ prop_add({lnum}, {col}, {props})
154154
added to. When not found, the global property types are used.
155155
If not found an error is given.
156156

157-
See |text-properties| for information about text properties.
158-
159157
Can also be used as a |method|: >
160158
GetLnum()->prop_add(col, props)
161159
@@ -168,14 +166,11 @@ prop_clear({lnum} [, {lnum-end} [, {props}]]) *prop_clear()*
168166
When {props} contains a "bufnr" item use this buffer,
169167
otherwise use the current buffer.
170168

171-
See |text-properties| for information about text properties.
172-
173169
Can also be used as a |method|: >
174170
GetLnum()->prop_clear()
175171
<
176172
*prop_find()*
177173
prop_find({props} [, {direction}])
178-
{not implemented yet}
179174
Search for a text property as specified with {props}:
180175
id property with this ID
181176
type property with this type name
@@ -198,8 +193,6 @@ prop_find({props} [, {direction}])
198193
as with prop_list(), and additionally an "lnum" entry.
199194
If no match is found then an empty Dict is returned.
200195

201-
See |text-properties| for information about text properties.
202-
203196

204197
prop_list({lnum} [, {props}]) *prop_list()*
205198
Return a List with all text properties in line {lnum}.
@@ -223,8 +216,6 @@ prop_list({lnum} [, {props}]) *prop_list()*
223216
When "end" is zero the property continues in the next line.
224217
The line break after this line is included.
225218

226-
See |text-properties| for information about text properties.
227-
228219
Can also be used as a |method|: >
229220
GetLnum()->prop_list()
230221
<
@@ -248,8 +239,6 @@ prop_remove({props} [, {lnum} [, {lnum-end}]])
248239

249240
Returns the number of properties that were removed.
250241

251-
See |text-properties| for information about text properties.
252-
253242
Can also be used as a |method|: >
254243
GetProps()->prop_remove()
255244
@@ -275,8 +264,6 @@ prop_type_add({name}, {props}) *prop_type_add()* *E969* *E970*
275264
end_incl when TRUE inserts at the end position will be
276265
included in the text property
277266

278-
See |text-properties| for information about text properties.
279-
280267
Can also be used as a |method|: >
281268
GetPropName()->prop_type_add(props)
282269
@@ -285,8 +272,6 @@ prop_type_change({name}, {props}) *prop_type_change()*
285272
property with this name does not exist an error is given.
286273
The {props} argument is just like |prop_type_add()|.
287274

288-
See |text-properties| for information about text properties.
289-
290275
Can also be used as a |method|: >
291276
GetPropName()->prop_type_change(props)
292277
@@ -301,8 +286,6 @@ prop_type_delete({name} [, {props}]) *prop_type_delete()*
301286

302287
When text property type {name} is not found there is no error.
303288

304-
See |text-properties| for information about text properties.
305-
306289
Can also be used as a |method|: >
307290
GetPropName()->prop_type_delete()
308291
@@ -316,8 +299,6 @@ prop_type_get([{name} [, {props}]) *prop_type_get()*
316299
{props} can contain a "bufnr" item. When it is given, use
317300
this buffer instead of the global property types.
318301

319-
See |text-properties| for information about text properties.
320-
321302
Can also be used as a |method|: >
322303
GetPropName()->prop_type_get()
323304
@@ -327,8 +308,6 @@ prop_type_list([{props}]) *prop_type_list()*
327308
{props} can contain a "bufnr" item. When it is given, use
328309
this buffer instead of the global property types.
329310

330-
See |text-properties| for information about text properties.
331-
332311

333312
==============================================================================
334313
3. When text changes *text-prop-changes*

src/evalfunc.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,7 @@ static funcentry_T global_functions[] =
620620
#ifdef FEAT_PROP_POPUP
621621
{"prop_add", 3, 3, FEARG_1, f_prop_add},
622622
{"prop_clear", 1, 3, FEARG_1, f_prop_clear},
623+
{"prop_find", 1, 2, FEARG_1, f_prop_find},
623624
{"prop_list", 1, 2, FEARG_1, f_prop_list},
624625
{"prop_remove", 1, 3, FEARG_1, f_prop_remove},
625626
{"prop_type_add", 2, 2, FEARG_1, f_prop_type_add},

src/proto/textprop.pro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ int get_text_props(buf_T *buf, linenr_T lnum, char_u **props, int will_change);
66
int find_visible_prop(win_T *wp, int type_id, int id, textprop_T *prop, linenr_T *found_lnum);
77
proptype_T *text_prop_type_by_id(buf_T *buf, int id);
88
void f_prop_clear(typval_T *argvars, typval_T *rettv);
9+
void f_prop_find(typval_T *argvars, typval_T *rettv);
910
void f_prop_list(typval_T *argvars, typval_T *rettv);
1011
void f_prop_remove(typval_T *argvars, typval_T *rettv);
1112
void f_prop_type_add(typval_T *argvars, typval_T *rettv);

src/testdir/test_textprop.vim

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,118 @@ func Get_expected_props()
103103
\ ]
104104
endfunc
105105

106+
func Test_prop_find()
107+
new
108+
call setline(1, ['one one one', 'twotwo', 'three', 'fourfour', 'five', 'sixsix'])
109+
110+
" Add two text props on lines 1 and 5, and one spanning lines 2 to 4.
111+
call prop_type_add('prop_name', {'highlight': 'Directory'})
112+
call prop_add(1, 5, {'type': 'prop_name', 'id': 10, 'length': 3})
113+
call prop_add(2, 4, {'type': 'prop_name', 'id': 11, 'end_lnum': 4, 'end_col': 9})
114+
call prop_add(5, 4, {'type': 'prop_name', 'id': 12, 'length': 1})
115+
116+
let expected = [
117+
\ {'lnum': 1, 'col': 5, 'length': 3, 'id': 10, 'type': 'prop_name', 'start': 1, 'end': 1},
118+
\ {'lnum': 2, 'col': 4, 'id': 11, 'type': 'prop_name', 'start': 1, 'end': 0},
119+
\ {'lnum': 5, 'col': 4, 'length': 1, 'id': 12, 'type': 'prop_name', 'start': 1, 'end': 1}
120+
\ ]
121+
122+
" Starting at line 5 col 1 this should find the prop at line 5 col 4.
123+
call cursor(5,1)
124+
let result = prop_find({'type': 'prop_name'}, 'f')
125+
call assert_equal(expected[2], result)
126+
127+
" With skipstart left at false (default), this should find the prop at line
128+
" 5 col 4.
129+
let result = prop_find({'type': 'prop_name', 'lnum': 5, 'col': 4}, 'b')
130+
call assert_equal(expected[2], result)
131+
132+
" With skipstart set to true, this should skip the prop at line 5 col 4.
133+
let result = prop_find({'type': 'prop_name', 'lnum': 5, 'col': 4, 'skipstart': 1}, 'b')
134+
unlet result.length
135+
call assert_equal(expected[1], result)
136+
137+
" Search backwards from line 1 col 10 to find the prop on the same line.
138+
let result = prop_find({'type': 'prop_name', 'lnum': 1, 'col': 10}, 'b')
139+
call assert_equal(expected[0], result)
140+
141+
" with skipstart set to false, if the start position is anywhere between the
142+
" start and end lines of a text prop (searching forward or backward), the
143+
" result should be the prop on the first line (the line with 'start' set to 1).
144+
call cursor(3,1)
145+
let result = prop_find({'type': 'prop_name'}, 'f')
146+
unlet result.length
147+
call assert_equal(expected[1], result)
148+
let result = prop_find({'type': 'prop_name'}, 'b')
149+
unlet result.length
150+
call assert_equal(expected[1], result)
151+
152+
" with skipstart set to true, if the start position is anywhere between the
153+
" start and end lines of a text prop (searching forward or backward), all lines
154+
" of the prop will be skipped.
155+
let result = prop_find({'type': 'prop_name', 'skipstart': 1}, 'b')
156+
call assert_equal(expected[0], result)
157+
let result = prop_find({'type': 'prop_name', 'skipstart': 1}, 'f')
158+
call assert_equal(expected[2], result)
159+
160+
" Use skipstart to search through all props with type name 'prop_name'.
161+
" First forward...
162+
let lnum = 1
163+
let col = 1
164+
let i = 0
165+
for exp in expected
166+
let result = prop_find({'type': 'prop_name', 'lnum': lnum, 'col': col, 'skipstart': 1}, 'f')
167+
if !has_key(exp, "length")
168+
unlet result.length
169+
endif
170+
call assert_equal(exp, result)
171+
let lnum = result.lnum
172+
let col = result.col
173+
let i = i + 1
174+
endfor
175+
176+
" ...then backwards.
177+
let lnum = 6
178+
let col = 4
179+
let i = 2
180+
while i >= 0
181+
let result = prop_find({'type': 'prop_name', 'lnum': lnum, 'col': col, 'skipstart': 1}, 'b')
182+
if !has_key(expected[i], "length")
183+
unlet result.length
184+
endif
185+
call assert_equal(expected[i], result)
186+
let lnum = result.lnum
187+
let col = result.col
188+
let i = i - 1
189+
endwhile
190+
191+
" Starting from line 6 col 1 search backwards for prop with id 10.
192+
call cursor(6,1)
193+
let result = prop_find({'id': 10, 'skipstart': 1}, 'b')
194+
call assert_equal(expected[0], result)
195+
196+
" Starting from line 1 col 1 search forwards for prop with id 12.
197+
call cursor(1,1)
198+
let result = prop_find({'id': 12}, 'f')
199+
call assert_equal(expected[2], result)
200+
201+
" Search for a prop with an unknown id.
202+
let result = prop_find({'id': 999}, 'f')
203+
call assert_equal({}, result)
204+
205+
" Search backwards from the proceeding position of the prop with id 11
206+
" (at line num 2 col 4). This should return an empty dict.
207+
let result = prop_find({'id': 11, 'lnum': 2, 'col': 3}, 'b')
208+
call assert_equal({}, result)
209+
210+
" When lnum is given and col is omitted, use column 1.
211+
let result = prop_find({'type': 'prop_name', 'lnum': 1}, 'f')
212+
call assert_equal(expected[0], result)
213+
214+
call prop_clear(1,6)
215+
call prop_type_delete('prop_name')
216+
endfunc
217+
106218
func Test_prop_add()
107219
new
108220
call AddPropTypes()

0 commit comments

Comments
 (0)