To: vim_dev@googlegroups.com Subject: Patch 8.1.1986 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.1.1986 Problem: More functions can be used as methods. Solution: Make textprop functions usable as a method. Files: runtime/doc/textprop.txt, src/evalfunc.c, src/testdir/test_textprop.vim *** ../vim-8.1.1985/runtime/doc/textprop.txt 2019-08-13 22:27:27.746277630 +0200 --- runtime/doc/textprop.txt 2019-09-04 21:50:33.093093582 +0200 *************** *** 157,162 **** --- 157,165 ---- See |text-properties| for information about text properties. + Can also be used as a |method|: > + GetLnum()->prop_add(col, props) + prop_clear({lnum} [, {lnum-end} [, {props}]]) *prop_clear()* Remove all text properties from line {lnum}. *************** *** 168,176 **** See |text-properties| for information about text properties. *prop_find()* prop_find({props} [, {direction}]) ! NOT IMPLEMENTED YET Search for a text property as specified with {props}: id property with this ID type property with this type name --- 171,182 ---- See |text-properties| for information about text properties. + Can also be used as a |method|: > + GetLnum()->prop_clear() + < *prop_find()* prop_find({props} [, {direction}]) ! {not implemented yet} Search for a text property as specified with {props}: id property with this ID type property with this type name *************** *** 220,226 **** See |text-properties| for information about text properties. ! *prop_remove()* *E968* prop_remove({props} [, {lnum} [, {lnum-end}]]) Remove a matching text property from line {lnum}. When --- 226,234 ---- See |text-properties| for information about text properties. ! Can also be used as a |method|: > ! GetLnum()->prop_list() ! < *prop_remove()* *E968* prop_remove({props} [, {lnum} [, {lnum-end}]]) Remove a matching text property from line {lnum}. When *************** *** 243,252 **** See |text-properties| for information about text properties. prop_type_add({name}, {props}) *prop_type_add()* *E969* *E970* Add a text property type {name}. If a property type with this ! name already exists an error is given. {props} is a dictionary with these optional fields: bufnr define the property only for this buffer; this avoids name collisions and automatically --- 251,263 ---- See |text-properties| for information about text properties. + Can also be used as a |method|: > + GetProps()->prop_remove() + prop_type_add({name}, {props}) *prop_type_add()* *E969* *E970* Add a text property type {name}. If a property type with this ! name already exists an error is given. Nothing is returned. {props} is a dictionary with these optional fields: bufnr define the property only for this buffer; this avoids name collisions and automatically *************** *** 267,272 **** --- 278,285 ---- See |text-properties| for information about text properties. + Can also be used as a |method|: > + GetPropName()->prop_type_add(props) prop_type_change({name}, {props}) *prop_type_change()* Change properties of an existing text property type. If a *************** *** 275,280 **** --- 288,295 ---- See |text-properties| for information about text properties. + Can also be used as a |method|: > + GetPropName()->prop_type_change(props) prop_type_delete({name} [, {props}]) *prop_type_delete()* Remove the text property type {name}. When text properties *************** *** 289,294 **** --- 304,311 ---- See |text-properties| for information about text properties. + Can also be used as a |method|: > + GetPropName()->prop_type_delete() prop_type_get([{name} [, {props}]) *prop_type_get()* Returns the properties of property type {name}. This is a *************** *** 302,307 **** --- 319,326 ---- See |text-properties| for information about text properties. + Can also be used as a |method|: > + GetPropName()->prop_type_get() prop_type_list([{props}]) *prop_type_list()* Returns a list with all property type names. *** ../vim-8.1.1985/src/evalfunc.c 2019-09-04 20:59:10.487410001 +0200 --- src/evalfunc.c 2019-09-04 21:55:19.364114363 +0200 *************** *** 663,677 **** {"prompt_setprompt", 2, 2, FEARG_1, f_prompt_setprompt}, #endif #ifdef FEAT_TEXT_PROP ! {"prop_add", 3, 3, 0, f_prop_add}, ! {"prop_clear", 1, 3, 0, f_prop_clear}, ! {"prop_list", 1, 2, 0, f_prop_list}, ! {"prop_remove", 1, 3, 0, f_prop_remove}, ! {"prop_type_add", 2, 2, 0, f_prop_type_add}, ! {"prop_type_change", 2, 2, 0, f_prop_type_change}, ! {"prop_type_delete", 1, 2, 0, f_prop_type_delete}, ! {"prop_type_get", 1, 2, 0, f_prop_type_get}, ! {"prop_type_list", 0, 1, 0, f_prop_type_list}, #endif {"pum_getpos", 0, 0, 0, f_pum_getpos}, {"pumvisible", 0, 0, 0, f_pumvisible}, --- 663,677 ---- {"prompt_setprompt", 2, 2, FEARG_1, f_prompt_setprompt}, #endif #ifdef FEAT_TEXT_PROP ! {"prop_add", 3, 3, FEARG_1, f_prop_add}, ! {"prop_clear", 1, 3, FEARG_1, f_prop_clear}, ! {"prop_list", 1, 2, FEARG_1, f_prop_list}, ! {"prop_remove", 1, 3, FEARG_1, f_prop_remove}, ! {"prop_type_add", 2, 2, FEARG_1, f_prop_type_add}, ! {"prop_type_change", 2, 2, FEARG_1, f_prop_type_change}, ! {"prop_type_delete", 1, 2, FEARG_1, f_prop_type_delete}, ! {"prop_type_get", 1, 2, FEARG_1, f_prop_type_get}, ! {"prop_type_list", 0, 1, FEARG_1, f_prop_type_list}, #endif {"pum_getpos", 0, 0, 0, f_pum_getpos}, {"pumvisible", 0, 0, 0, f_pumvisible}, *** ../vim-8.1.1985/src/testdir/test_textprop.vim 2019-08-13 22:27:27.746277630 +0200 --- src/testdir/test_textprop.vim 2019-09-04 21:55:15.052129157 +0200 *************** *** 25,31 **** call prop_type_add('one', {}) call assert_equal(1, len(prop_type_list())) ! let proptype = prop_type_get('one') call assert_false(has_key(proptype, 'highlight')) call assert_equal(0, proptype['priority']) call assert_equal(0, proptype['start_incl']) --- 25,31 ---- call prop_type_add('one', {}) call assert_equal(1, len(prop_type_list())) ! let proptype = 'one'->prop_type_get() call assert_false(has_key(proptype, 'highlight')) call assert_equal(0, proptype['priority']) call assert_equal(0, proptype['start_incl']) *************** *** 53,59 **** call assert_equal(1, proptype['end_incl']) call prop_type_delete('comment', {'bufnr': bufnr}) ! call assert_equal(0, len(prop_type_list({'bufnr': bufnr}))) call prop_type_add('one', {'bufnr': bufnr}) let proptype = prop_type_get('one', {'bufnr': bufnr}) --- 53,59 ---- call assert_equal(1, proptype['end_incl']) call prop_type_delete('comment', {'bufnr': bufnr}) ! call assert_equal(0, len({'bufnr': bufnr}->prop_type_list())) call prop_type_add('one', {'bufnr': bufnr}) let proptype = prop_type_get('one', {'bufnr': bufnr}) *************** *** 89,95 **** func SetupPropsInFirstLine() call setline(1, 'one two three') call prop_add(1, 1, {'length': 3, 'id': 11, 'type': 'one'}) ! call prop_add(1, 5, {'length': 3, 'id': 12, 'type': 'two'}) call prop_add(1, 9, {'length': 5, 'id': 13, 'type': 'three'}) call prop_add(1, 1, {'length': 13, 'id': 14, 'type': 'whole'}) endfunc --- 89,95 ---- func SetupPropsInFirstLine() call setline(1, 'one two three') call prop_add(1, 1, {'length': 3, 'id': 11, 'type': 'one'}) ! eval 1->prop_add(5, {'length': 3, 'id': 12, 'type': 'two'}) call prop_add(1, 9, {'length': 5, 'id': 13, 'type': 'three'}) call prop_add(1, 1, {'length': 13, 'id': 14, 'type': 'whole'}) endfunc *************** *** 139,145 **** call assert_equal(props, prop_list(1)) " remove by id ! call assert_equal(1, prop_remove({'id': 12}, 1)) unlet props[2] call assert_equal(props, prop_list(1)) --- 139,145 ---- call assert_equal(props, prop_list(1)) " remove by id ! call assert_equal(1, {'id': 12}->prop_remove(1)) unlet props[2] call assert_equal(props, prop_list(1)) *************** *** 344,351 **** call SetupPropsInFirstLine() call assert_equal(Get_expected_props(), prop_list(1)) ! call prop_clear(1) ! call assert_equal([], prop_list(1)) call DeletePropTypes() bwipe! --- 344,351 ---- call SetupPropsInFirstLine() call assert_equal(Get_expected_props(), prop_list(1)) ! eval 1->prop_clear() ! call assert_equal([], 1->prop_list()) call DeletePropTypes() bwipe! *************** *** 489,495 **** endfunc func Test_prop_multiline() ! call prop_type_add('comment', {'highlight': 'Directory'}) new call setline(1, ['xxxxxxx', 'yyyyyyyyy', 'zzzzzzzz']) --- 489,495 ---- endfunc func Test_prop_multiline() ! eval 'comment'->prop_type_add({'highlight': 'Directory'}) new call setline(1, ['xxxxxxx', 'yyyyyyyyy', 'zzzzzzzz']) *************** *** 672,682 **** \ "hi BackgroundProp ctermbg=lightgrey", \ "hi UnderlineProp cterm=underline", \ "call prop_type_add('number', {'highlight': 'NumberProp'})", ! \ "call prop_type_add('long', {'highlight': 'LongProp'})", \ "call prop_type_add('start', {'highlight': 'NumberProp', 'start_incl': 1})", \ "call prop_type_add('end', {'highlight': 'NumberProp', 'end_incl': 1})", \ "call prop_type_add('both', {'highlight': 'NumberProp', 'start_incl': 1, 'end_incl': 1})", ! \ "call prop_type_add('background', {'highlight': 'BackgroundProp', 'combine': 1})", \ "call prop_type_add('error', {'highlight': 'UnderlineProp', 'combine': 1})", \ "call prop_add(1, 4, {'end_lnum': 3, 'end_col': 3, 'type': 'long'})", \ "call prop_add(2, 9, {'length': 3, 'type': 'number'})", --- 672,684 ---- \ "hi BackgroundProp ctermbg=lightgrey", \ "hi UnderlineProp cterm=underline", \ "call prop_type_add('number', {'highlight': 'NumberProp'})", ! \ "call prop_type_add('long', {'highlight': 'NumberProp'})", ! \ "call prop_type_change('long', {'highlight': 'LongProp'})", \ "call prop_type_add('start', {'highlight': 'NumberProp', 'start_incl': 1})", \ "call prop_type_add('end', {'highlight': 'NumberProp', 'end_incl': 1})", \ "call prop_type_add('both', {'highlight': 'NumberProp', 'start_incl': 1, 'end_incl': 1})", ! \ "call prop_type_add('background', {'highlight': 'NumberProp', 'combine': 1})", ! \ "eval 'background'->prop_type_change({'highlight': 'BackgroundProp'})", \ "call prop_type_add('error', {'highlight': 'UnderlineProp', 'combine': 1})", \ "call prop_add(1, 4, {'end_lnum': 3, 'end_col': 3, 'type': 'long'})", \ "call prop_add(2, 9, {'length': 3, 'type': 'number'})", *** ../vim-8.1.1985/src/version.c 2019-09-04 20:59:10.491409987 +0200 --- src/version.c 2019-09-04 21:56:21.115902362 +0200 *************** *** 759,760 **** --- 759,762 ---- { /* Add new patch number below this line */ + /**/ + 1986, /**/ -- hundred-and-one symptoms of being an internet addict: 187. You promise yourself that you'll only stay online for another 15 minutes...at least once every hour. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///